Conversation
…ocused tile The Bot Mode 'session not found' / bot-runs-on-wrong-backend bug. wiring's requestGateway is ONE shared closure for every session-scoped RPC in the window, but it derived the owning profile from the globally-FOCUSED tile ($focusedStoredSessionId). A bot chat is a background tile while another pane is active, so its prompt.submit carried the bot's own session_id yet was dispatched on the FOCUSED tile's backend — the default backend served the bot via ?profile= from the default's state.db, or answered 4001 'session not found' when it didn't hold the runtime session. Route by the session the RPC TARGETS (params.session_id) instead. session_id is a RUNTIME id while tiles/rows key on the STORED id, so translate via the state cache then a reverse scan of the stored->runtime map (the same ladder use-session-tile-delegate's storedSessionIdForRuntime uses); an unresolved id is already a stored id (several RPCs pass stored ids directly). RPCs with no session_id (ambient/config) keep the focused->selected fallback. Pure helpers extracted to wiring-routing.ts so they're unit-testable without importing the React controller; 6 tests cover the target-vs-focused routing, the stored-id passthrough, and the no-session fallback. tsc 0 errors. Diagnosis verified on a live install: the fix was present in source but the running build still misrouted, and logs showed the bot's turn executing on the default backend while its own per-profile backend sat idle.
૮ >ﻌ< ა ci reviewran on fbd4f0c — fix(desktop): route each session RPC by its target session,
|
|
Superseded by #93296 (merged), which lands the same fix — route session-scoped RPCs by |
Duplicate of merged #93296: current main already contains the target-session RPC routing repair. |
|
Reviewed this against main — the diagnosis is exactly right (it's the same root cause I implemented in #93296 from your traced repro, which merged first and is why this branch now conflicts: both PRs rewrite the same Rather than close it as superseded, I salvaged it: #93311 carries this commit verbatim (your authorship preserved via cherry-pick) with the conflict resolved by unifying the two implementations — and the unified version keeps YOUR semantics on the two points where they're better than what main has:
The one thing the salvage adds to your ladder: main's Validation on the salvage: tsc clean, your test file + main's routing tests green (81), full contrib+store sweep 1163 passed. |
The bug
Bot Mode: messaging any bot except the launch profile silently runs on the default backend (served via
?profile=from the default'sstate.db), or fails with "session not found" (4001) when the default backend doesn't hold the runtime session. Verified on a live install — logs show the bot's turn executing in the default backend's log while the bot's own per-profile backend sits idle.Root cause
requestGatewayinapps/desktop/src/app/contrib/wiring.tsxis one shared closure used for every session-scoped RPC in the window, but it derived the owning profile from the globally-focused tile:A bot chat is a background tile while another pane is active. So its
prompt.submitcarried the bot's ownsession_idinparams, but was routed by the focused tile's owner (the default chat) → default backend. This is downstream of the tile-ownerRoute fix (#92956): that made bot chats carry their owner, but the router still read the wrong session's owner.Fix
Route by the session the RPC targets (
params.session_id), not the focused tile.session_idis a runtime id while tiles/rows key on the stored id, so translate via the state cache, then a reverse scan of the stored→runtime map (the same ladderuse-session-tile-delegate'sstoredSessionIdForRuntimeuses). An unresolved id is already a stored id (several RPCs pass stored ids directly). RPCs with nosession_id(ambient/config calls) keep the focused→selected fallback.Pure helpers (
findStoredIdForRuntimeId,resolveRoutingSessionId) extracted towiring-routing.tsso they're unit-testable without importing the React controller (there was nowiring.tsxtest before — that gap is why this class of bug went uncaught).Verification
tsc --noEmit: 0 errors.wiring-routing.test.ts: target-vs-focused routing (the misroute), stored-id passthrough on runtime miss, and the no-session focused→selected→null fallback.Credit
Root cause + the target-vs-focused routing approach were diagnosed collaboratively; this PR packages it with the runtime→stored translation, extracted testable helpers, and coverage.