Skip to content

fix(core): resolve workspace for cron prompt-mode jobs in multi-workspace mode#556

Merged
chenhg5 merged 1 commit intochenhg5:mainfrom
Cigarrr:fix/cron-prompt-workspace-resolution
Apr 15, 2026
Merged

fix(core): resolve workspace for cron prompt-mode jobs in multi-workspace mode#556
chenhg5 merged 1 commit intochenhg5:mainfrom
Cigarrr:fix/cron-prompt-workspace-resolution

Conversation

@Cigarrr
Copy link
Copy Markdown
Contributor

@Cigarrr Cigarrr commented Apr 11, 2026

Summary

In multi-workspace mode, ExecuteCronJob() for prompt (non-shell) jobs always used the global e.agent and passed an empty workspaceDir to processInteractiveMessageWith(). This caused the Claude Code agent to start with the wrong working directory (typically ~/.cc-connect) instead of the workspace bound to the cron job's channel.

The fix mirrors handleMessage()'s workspace resolution logic:

  1. Extract channelID from the cron job's sessionKey
  2. Resolve the workspace binding via resolveWorkspace()
  3. Get a workspace-specific agent/sessions via workspaceContext()
  4. Pass the resolved agent and workspaceDir to processInteractiveMessageWith()

job.WorkDir, when explicitly set, takes highest priority as an override.

Priority chain: job.WorkDir (explicit) → workspace binding resolution → global agent fallback

Closes #555

Related

Test plan

  • go test ./core/ -count=1 — all tests pass
  • go build ./... — clean build
  • Manually verified: cron prompt jobs now execute in the correct workspace directory (confirmed via gitStatus in agent context)
  • Verified job.WorkDir override takes precedence when explicitly set
  • Verified non-multi-workspace mode is unaffected (falls through to global agent)

🤖 Generated with Claude Code

…pace mode

In multi-workspace mode, ExecuteCronJob() for prompt (non-shell) jobs
always used the global e.agent and passed an empty workspaceDir to
processInteractiveMessageWith(). This caused the Claude Code agent to
start with the wrong working directory (often ~/.cc-connect) instead
of the workspace bound to the cron job's channel.

The fix mirrors handleMessage()'s workspace resolution logic:
1. Extract channelID from the cron job's sessionKey
2. Resolve the workspace binding via resolveWorkspace()
3. Get a workspace-specific agent via workspaceContext()
4. Pass the resolved workspace agent and dir to processInteractiveMessageWith()

job.WorkDir, when explicitly set, takes highest priority as an override.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Cron job now correctly resolves workspace context in multi-workspace mode — respects job.WorkDir priority over channel binding. Proper session routing.

PR: #556

@chenhg5 chenhg5 merged commit 2c46faf into chenhg5:main Apr 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cron prompt-mode jobs bypass workspace resolution in multi-workspace mode

2 participants