fix(rpc): refuse a write into a sealed session with session_moved_away (#5889)

Merged
CO
19d ago
+115-4

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 private current). This is the same verdict every persisted write is checked against, so the admission check and the write path cannot disagree.
  • handleClientInput checks it at the start of a NEW admission and throws the guard's SessionMovedAwayError. The refusal spread maps that error to errorCode + 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 the session_moved entry a revoke appends, then prompt / follow_up / steer must answer session_moved_away with state: "moved" and leave the file byte-identical.
    • RED at main: 3/3 failed (no errorCode; prompt answered success:true).
    • With only the refusal mapping (no admission check): prompt still failed with success:true.
    • GREEN: 3/3.
  • Mutation: forcing errorData.state to "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; state is "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.md and a regression test over the in-process host.