Skip to content

fix(session): announce the session workspace when a turn starts - #3687

Closed
sivenDev wants to merge 1 commit into
openBitFun:mainfrom
sivenDev:fix/dialog-turn-started-workspace
Closed

sivenDev wants to merge 1 commit into
openBitFun:mainfrom
sivenDev:fix/dialog-turn-started-workspace

Conversation

@sivenDev

@sivenDev sivenDev commented Nov 2, 2026 •

Copy link
Copy Markdown

Summary

A session whose turn is started by the backend (for example, a scheduled job) can appear under the wrong assistant/workspace in the Desktop UI. This happens when the UI has not loaded that session yet. DialogTurnStarted carried no workspace facts, so the Web UI placeholder fell back to the foreground workspace.

This PR makes the host announce the session's own workspace binding on DialogTurnStarted and has the Web UI place unknown sessions from it.

No existing issue; found while investigating a misplaced scheduled-job session on Desktop.

Type and Areas

Type: bug fix

Areas: Rust core (events contract, coordinator, session manager), web UI (flow chat event handling)

Motivation / Impact

Observed on Desktop:

  1. Assistant A owns session S, and a scheduled job targets S every 10 minutes.
  2. After restart, the UI opens assistant B. Only B's sessions are loaded.
  3. The job starts a turn on S. The UI receives agentic://dialog-turn-started for an unknown session and creates a "Remote Session" placeholder.
  4. resolveExternalSessionWorkspace finds no workspace facts on the event. It falls back to currentWorkspaceId/currentWorkspacePath, so S appears under assistant B.
  5. The UI then saves turns and metadata against B's storage. The backend rejects them with Session ID is already bound to another workspace, which also breaks get_session_stats. Persisted data stays correct; restarting the app hides the problem until the next background turn.

Changes:

  • openbitfun-events
    • New SessionWorkspaceFacts: workspace path and id, project workspace path and id, execution target, remote connection, SSH host.
    • DialogTurnStarted gets an optional session_workspace field (#[serde(default, skip_serializing_if = "Option::is_none")]).
    • The frontend projection exposes these facts with the same flat keys as agentic://session-created. When the field is absent, the payload is unchanged.
  • openbitfun-core
    • SessionManager::get_session_workspace_facts reads only the config fields.
    • All five coordinator DialogTurnStarted emit sites fill it.
  • Web UI
    • handleDialogTurnStarted and handleSessionCreated share resolveExternalSessionBinding.
    • The placeholder now gets workspace id/path, project path/id, and execution target from the event.
  • Other DialogTurnStarted literals (journal, remote connect, CLI tests) set session_workspace: None.

User-facing: background turns in an assistant the UI has not opened stay under their own assistant. The already bound to another workspace save errors stop.

Verification

Run on top of current main:

  • cargo test --locked -p openbitfun-events --lib frontend_projection: 17 passed. New tests cover projection of the binding and a legacy payload without the field: it deserializes, re-serializes unchanged, and projects no workspace keys.
  • cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git --lib user_shell_command_persists_a_standard_exec_command_tool_turn: passed. It now asserts that the started event announces the session's own workspace path.
  • cargo test --locked -p openbitfun-agent-runtime --features agent-runtime --lib session_event_journal: 18 passed.
  • cargo test --locked -p openbitfun-services-integrations --features remote-connect --test remote_connect_contracts: 81 passed.
  • cargo test --locked -p openbitfun-services-integrations --features remote-connect --lib remote_connect: 219 passed.
  • cargo +1.95.0 check --locked -p openbitfun-cli --tests: ok.
  • vitest run src/flow_chat/services/flow-chat-manager/EventHandlerModule.test.ts: 83 passed. New tests:
    • the placeholder uses the announced workspace, not the foreground one;
    • a legacy event without the binding keeps the foreground fallback.
  • tsc --noEmit on web-ui: no errors in the changed files.

Not run: an end-to-end reproduction in a rebuilt app; remote workspace, remote control, and Peer Device scenarios. Remote control and peer paths go through project_agentic_frontend_event, so they get the same additive fields, but this was not exercised.

Reviewer Notes

  • Upgrade compatibility:
    • The field is optional and additive.
    • Events written by older hosts, including the persisted runtime-event journal, deserialize unchanged.
    • Newer UIs talking to an older peer host still get the previous fallback.
    • Older UIs ignore the extra keys.
  • The fallback to the foreground workspace is kept only for legacy events without facts. Its doc comment now says so instead of claiming the host only forwards subscribed workspaces.
  • AI-assisted (Claude Code). Testing level: unit/contract tested as listed above. Not manually tested end-to-end.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable. (No user-facing strings changed.)

🤖 Generated with Claude Code

A scheduled job that started a turn in an assistant the UI had not loaded
showed up under the foreground assistant: DialogTurnStarted carried no
workspace, so the Web UI placeholder fell back to the current workspace.
Its saves were then rejected because the session was bound elsewhere.

DialogTurnStarted now carries an optional SessionWorkspaceFacts filled
from the session config, and the frontend projection exposes it with the
same flat keys as session-created. The Web UI places unknown sessions from
those facts, including project and execution target. Events from older
hosts omit the field and keep the legacy fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kev1n77

kev1n77 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

#3894 has been merged into main. DialogTurnStarted now carries the session's workspace binding, which the frontend uses to place or correct session placeholders. Closing this PR as superseded by #3894.

@kev1n77 kev1n77 closed this Nov 19, 2026
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