fix(rpc): refuse a write into a sealed session with session_moved_away (#5889)
Part of #5889 (part 1 of 2: the typed refusal. The copy RPC is part 2).
What
A prompt, steer or follow_up into a session file that is moving or moved (a finished move, or a copy sealed by move_session revoke, #4004) is refused at admission with:
{"type":"response","command":"prompt","success":false,"error":"This session was moved to ...","errorCode":"session_moved_away","errorData":{"state":"moved"}}
Before, steer/follow_up were refused with message text only. A prompt was accepted (success:true), and the write guard refused it only later, when the turn persisted the user message. A client branching on codes could not tell the session was read-only.
How
SessionManager.getOwnership()exposes the write guard's own incremental fold (SessionWriteGuard.ownership, formerly the privatecurrent). This is the same verdict every persisted write is checked against, so the admission check and the write path cannot disagree.handleClientInputchecks it at the start of a NEW admission and throws the guard'sSessionMovedAwayError. The refusal spread maps that error toerrorCode+errorData.state. A replay of an already admitted id is answered as before.docs/rpc.md: the "Sealed session" refusal.
Tests
- RED -> GREEN:
test/suite/regressions/5889-session-moved-away-prompt-code.test.ts, on the real in-process host with the faux provider. A hosted session gets thesession_movedentry a revoke appends, thenprompt/follow_up/steermust answersession_moved_awaywithstate: "moved"and leave the file byte-identical.- RED at main: 3/3 failed (no
errorCode;promptansweredsuccess:true). - With only the refusal mapping (no admission check):
promptstill failed withsuccess:true. - GREEN: 3/3.
- RED at main: 3/3 failed (no
- Mutation: forcing
errorData.stateto"moving"fails the test. - Neighbouring suites: revoke, revoke-finish, move-session, release-session-failure, prompt-response-semantics.
Summary by cubic
Fixes RPC refusals for writes into a sealed session: prompt, steer, and follow_up sent into a session file that is moving or moved (including after a move_session revoke) are now refused at admission with errorCode: "session_moved_away" and errorData.state. Before, prompt was accepted (success: true) and failed only later when its turn wrote the message, while steer and follow_up were refused with text only.
Bug Fixes
- The admission check reads the same ownership fold every persisted write is validated against, so the refusal and the write path cannot disagree;
stateis"moving"while a move is in flight and"moved"once it finished or was revoked, and the file stays readable and untouched. - Only new admissions are refused; replays of an already admitted id are answered as before.
- Adds the refusal to
docs/rpc.mdand a regression test over the in-process host.