Skip to content

fix(core): route relay through multi-workspace bindings#328

Open
xxb wants to merge 1 commit intochenhg5:mainfrom
xxb:fix/relay-multi-workspace
Open

fix(core): route relay through multi-workspace bindings#328
xxb wants to merge 1 commit intochenhg5:mainfrom
xxb:fix/relay-multi-workspace

Conversation

@xxb
Copy link
Copy Markdown
Contributor

@xxb xxb commented Mar 25, 2026

Summary

This fixes bot-to-bot relay in multi-workspace mode.

Before this change, relay requests only passed chatID into the target engine, so the target side bypassed normal workspace routing and used the global agent/session manager. That caused relayed messages to run in the wrong workspace.

What changed

  • pass the full source sessionKey through relay handling
  • resolve relay workspace on the target side from the source session context
  • route relay turns to the workspace-specific agent and session manager in multi-workspace mode
  • use a platform-qualified relay session key to avoid cross-platform collisions
  • keep CC_SESSION_KEY set to the original source session key for agent-side relay/cron context
  • add regression tests for:
    • single-workspace relay staying on the global agent
    • multi-workspace relay routing by source session key
    • multi-workspace relay failing cleanly when no workspace binding exists
    • existing relay timeout behavior

Behavior note

In multi-workspace mode, relay from an unbound source channel now fails explicitly instead of silently falling back to the global agent. This is intentional so relay behavior matches workspace-aware routing expectations.

Validation

nix shell nixpkgs#go -c go test ./core -run 'TestHandleRelay|TestSessionContextForKey|TestMultiWorkspaceResolution' -count=1
nix shell nixpkgs#go -c go test ./core -count=1
nix shell nixpkgs#go -c go test ./... -run '^$' -count=1

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. Well-implemented multi-workspace relay routing.

Review notes:

  • ✅ CI passes
  • ✅ Correct approach: routes relay through workspace bindings
  • ✅ Uses sourceSessionKey to resolve workspace properly
  • ✅ Falls back to global agent/sessions when not multi-workspace
  • ✅ Tests cover both single and multi-workspace scenarios
  • ✅ Error handling for missing workspace bindings

This enables relay to work correctly with workspace isolation. Approved for merge.

@xxb
Copy link
Copy Markdown
Contributor Author

xxb commented Mar 31, 2026

Thanks for the review.

This PR is ready to merge as-is:

  • fixes relay routing to the correct workspace in multi-workspace mode
  • preserves existing single-workspace behavior
  • adds regression coverage for both paths

It is also still cleanly mergeable right now; merging sooner may help avoid future drift/conflicts since core/engine.go is seeing active changes on main.

@xxb xxb force-pushed the fix/relay-multi-workspace branch from 486a372 to e2cb877 Compare April 1, 2026 15:28
@xxb xxb force-pushed the fix/relay-multi-workspace branch from e2cb877 to cd00b10 Compare April 8, 2026 16:51
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.

2 participants