Skip to content

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

Merged
code-yeongyu merged 3 commits into
mainfrom
fix/5889-session-moved-away-code
Nov 6, 2026
Merged

code-yeongyu merged 3 commits into
mainfrom
fix/5889-session-moved-away-code

Conversation

@code-yeongyu

@code-yeongyu code-yeongyu commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

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.

Written for commit d5a07a1. Summary will update on new commits.

View guided diff Turn on auto-fix

#5889)

A prompt, steer or follow_up into a session that is moving or moved is refused at
admission with errorCode session_moved_away and errorData.state. Before, a prompt
was accepted and failed only when its turn wrote the message, and every refusal
carried message text only.
@code-yeongyu
code-yeongyu merged commit 7a25deb into main Nov 6, 2026
11 checks passed
@code-yeongyu
code-yeongyu deleted the fix/5889-session-moved-away-code branch November 6, 2026 01:00
code-yeongyu added a commit that referenced this pull request Nov 6, 2026
main extracted admitPrompt/admitInput/UNSERVED_INPUT_FIELDS into
session-control-input-commands.ts. Keep main's file untouched (#5906's
session_moved_away work, no admission widening for senpi#6074) and carry
#5923's one change - chainCount in UNSERVED_INPUT_FIELDS - into the new home.
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.

1 participant