Repository navigation
feat(coding-agent): move_session revoke seals an imported copy (#4003) - #4004
Merged
Merged
Conversation
status after a revoke must say revoked: true; a used copy is still revoked with its turns kept; a copy re-imported for a later move refuses the earlier id. Drops the capability restatement test.
#4004 review) status keeps the ledger's final accepted and adds revoked: true when the latest record for the move on the given sessionPath is a revoke; the write guard still refuses that copy. docs/rpc.md: used copies are revoked with their turns kept, take-back sends cancel first then revoke, and status without sessionPath stays plain.
A sender still sealed for the move that finishes with { accepted, revoked: true }
must take the session back writable, never be marked moved; plain accepted is
unchanged. importedOnB moves to the shared move-session support.
…4004) parseMoveStatus keeps revoked: true, and finish treats accepted + revoked as a take-back: a sender still sealed for the move reclaims it (session_reclaimed reason revoked, queued input back) under the move lock; never session_moved. The RED test now reads the session_reclaimed entry, not the requeued input.
status without sessionPath must report a revoke (the ledger's accepted record carries revoked: true); finish with a revoked answer on a sender already marked moved refuses move_already_moved; status with a sessionPath that is not this move's import refuses move_mismatch.
…sals (#4004 review) revoke adds revoked: true to the move's accepted record under the move lock after the seal (idempotent; a repeated import keeps it), so status reports the revoke with or without sessionPath. finish refuses a revoked answer for a sender already marked moved (move_already_moved). status refuses a sessionPath that is not the move's import (move_mismatch) and reads the file in the move queue.
An import of an already accepted move into another folder, revoked or not, must be fenced and land nothing; the same-file re-import stays a no-op. Ledger: beginReceive refuses any accepted record, and a repeated revoke restores revoked: true after the record was lost or reset.
…review) beginReceive fences any accepted record, revoked or not: re-importing the move's own file still returns early before it, and #3998's lost-write path ('receiving') is unchanged, but an import into another folder is refused move_fenced and writes nothing. rpc.md: the import rule, and repeat a revoke that did not succeed before acting on any status.
Two imports of one move into different folders at once must land exactly one file; after a lost accepted write an import into another folder is refused; a retry after the landed copy was deleted lands again unless the move was revoked. exportedForB joins the shared move-session support.
beginReceive records the session file the first import lands as; an import for another target is fenced while the move is receiving or accepted, and commit renames only into the recorded target (concurrent imports, and an import after a lost accepted write, can no longer land a second copy). The same-file early return goes through confirmLanded, keeping #3998's lost-write path; a deleted copy re-lands at its own target unless the move was revoked.
A deleted landed copy never lands again, revoked or not, including when the record lost its revoke mark; a receiving record an older build wrote without a landing target refuses an import into another folder and accepts the file that already landed. The ledger fences any accepted record and a targetless receive.
An accepted move never lands again, revoked or not: a deleted copy is gone, so a lost revoke mark can no longer re-land a writable copy. A receiving record with no landing target (an older build) refuses every new receive; its already landed file is still confirmed by the same-file check. Follow-ups filed as #4016.
Rebuilt from the state each crash leaves: an import stopped after its rename (record receiving, stamped committing) plus a deleted copy must not land again; a failure right after the rename must not record failed beside the landed copy; a same-file re-import after a lost revoke mark must keep revoked: true.
…4004 review) move-steps.ts holds the step table (import, revoke, finish: what is on disk, what the record says, what a crash or throw there must leave) and the test seam each durable step calls. commit stamps the record committing before the rename (after replacePredecessor/extension state, which land nothing); settle/fail never overwrite a stamped record; status settles a committing or unmarked record from the file at the recorded target; confirmLanded keeps a revoke mark. One sweep (rpc-move-session-steps) faults every row by crash and by throw and replays the follow-ups. The landing rules move to move-landing.ts, the ledger lock to move-ledger-lock.ts.
Conflicts with #3998 (move import file authority) in session-move/import.ts and move-ledger.ts: keep main's landed() guard (fail/decline unlessLanded) and the settle/settleLocked split, call this PR's confirmLanded for an already landed file (it covers main's accept: fences ready/declined/failed, plus the target fence and revoke mark), and keep the committing guard inside settleLocked. main's two #3998 tests are ported to commit(moveId, target, rename, prepare); a failed pre-rename commit stays committing until the sender's status path settles it failed, so that assertion reads through answerMoveStatus.
# Conflicts: # packages/coding-agent/src/modes/rpc/host-capabilities.ts # packages/coding-agent/test/suite/rpc-multi-session-protocol-info.test.ts
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4003. Part of desktop app item 3137 (tracked internally); desktop#4008 gates its take-back on the
move_session_revokecapability.What
move_session {op:"revoke", sessionPath, moveId}seals the copy a receiving host IMPORTED for a move, after the sender took the session back:withSessionMoveLock, the same lock as export/finish):session_heldwhen another process holds the copy,session_open_herewhen this host has it open;session_movedwith{ move_id, session_id, target: <import's from>, reason: "revoked", moved_at }, so the existing ownership fold makes the file read-only and the write guard refuses later writes withsession_moved_away;session_moved_inis revoked; a repeat for the same move is a no-op that answers the same;move_mismatch.move_session_revokeis advertised by multi-session hosts next tomove_session.Wire: request
{ type: "move_session", op: "revoke", sessionPath, moveId }-> successdata: { ownership: "moved" }; refusalserror/errorCode:move_mismatch,session_held,session_open_here,invalid_move_request(missing sessionPath or bad moveId), witherrorData.detail.Import and finish behavior are unchanged (finish's return path now shares one
ownershipOfhelper with revoke; same value).Step table and crash fold (head 675f380)
Every durable step on one device, in order. The same table is in
src/core/session-move/move-steps.ts(MOVE_STEPS); the code callsmoveStep(step)right after each step, and one test faults every row. Rules after every row: at most one writable copy, the record agrees with the files, and a revoke mark is never lost.import:receivedreceiving; a same-folder import lands it, other folders are fencedimport:stampedfailedand the sender takes it backimport:renamedaccepted); a failure here never recordsfailed; other folders fencedimport:acceptedrevoke:sealedsession_movedreason revoked)revoked, writing the mark; a repeated revoke writes it toorevoke:markedfinish:recordedfinish:requeuedcommitstampscommittingunder the ledger lock after its prepare steps (replacePredecessor, extension state, which land nothing, so a refusal there still recordsfailed) and before the rename. A stamped record never lands again.failedbeside a landed copy:fail()/settlerefuse to overwrite a stamped record (the probed MEDIUM).statussettles the stamped record from the file at the recorded target.confirmLandedkeeps a revoke mark (the LOW), andstatusrestores a mark a crash lost after the seal.rpc-move-session-steps.test.ts) faults every row of the table two ways: a crash (the files are restored to that moment, so no catch handler's write survives) and a throw (catch handlers run). For import and revoke it also runs a variant with the receiver's copy deleted. It then replays the client's follow-ups (repeat the failed call, status with and without the path, finish, an import here and in another folder) and asserts the three rules after each.move-landing.tsand the ledger lock tomove-ledger-lock.ts, keepingmove-ledger.tsunder the 250-line ceiling (244).Lands-once fold (head 48d1f61)
receivingrecord with no landing target (probed L1) refuses every new receive (move_fenced). The file it already landed is still accepted through the same-file check (confirmLanded), which runs beforebeginReceive.Landing target fold (head 6969bac)
beginReceive(moveId, target)stores the session file the first import lands as, under the ledger lock, and the first claimant wins. While the move is receiving or accepted, any import for another target is refused withmove_fencedbefore anything is written. That covers two imports at once (H1) and an import after a lostacceptedwrite (M1).commit(moveId, target, rename)renames only into the stored target: fromreceiving, or for a re-land, fromacceptedwhen not revoked. Any other case throwsMoveFencedError.confirmLanded(moveId, target). A landed file at the stored path proves the commit, so fix(coding-agent): a re-run move import accepts a landed session file even after a lost accepted write #3998's lost-write path still endsaccepted; a landed file at a different path is fenced.Re-land of a deleted copy: removed again in 48d1f61 (a move lands once).import.tslands a session file for a move id (rebindSessionFileruns only insidecommit's callback, into the same target path), and all three of its ledger calls now carry the target.export.tswrites the sender's bundle, not a session file.An old-build: replaced in 48d1f61 (refused, except its already landed file).receivingrecord claims its target on the next importImport fence fold (head e772ca4)
beginReceiverefuses any accepted record, revoked or not, withmove_fenced. An import of the same bundle into another folder is refused and writes nothing, so a second writable copy can't appear on the receiver. This also closes the earlier bug where a plain accepted move could land twice.import.ts, beforebeginReceive.receiving) is unchanged.revokeseals the copy first and marks the record afterwards. Flag-first would let a sender hearrevokedand reclaim while the receiver's copy is still writable: two writers. Seal-first can only crash into "sealed, record plainaccepted", where nobody is wrongly writable. rpc.md now says a client whoserevokedid not succeed repeats it before acting on any status.revoked: trueafter the record is deleted or reset to plainaccepted.Delta review folds (head 243a890)
revokeaddsrevoked: trueto the move's accepted ledger record under the same move lock, after the seal. The state staysaccepted, so the ledger-final rule is unchanged. A repeat writes it again if a crash lost it, and a repeated import of the same bundle keeps it.statusreports{accepted, revoked: true}with or withoutsessionPath, andcancel/preparereturn the same record.move_already_moved(new wire code, documented), and nothing changes.statuswith a wrongsessionPath(LOW-2): a file that exists but is not this move's import is refused withmove_mismatch. The file is read in this host's queue for that session file. The cross-process holder lock would refuse while the receiver has the session open, so instead docs/rpc.md says a cross-process race is settled by asking again. A path with no file answers from the ledger.finish.tsJSDoc reflowed (LOW-3).Review folds (head de1bbf8)
acceptedstays final and unchanged.statuswith the copy'ssessionPathanswers{ state: "accepted", revoked: true }when the latest record for that move id on the file is thesession_movedwith reasonrevoked. Old readers seeacceptedas before.revoked: truewins for writability: the write guard refuses every write to that copy (session_moved_away). WithoutsessionPath, the answer comes from the ledger alone and stays plainaccepted, as documented.revoked: truewins for every reader that decides writability):parseMoveStatuskeeps the flag, andfinishwith{ accepted, revoked: true }is a take-back, never a move. A sender still sealed for the move reclaims it on the same path asdeclined(session_reclaimedwithreason: "revoked", queued input back, under the move lock). A sender that already took the session back is left as it is, and a repeat changes nothing. Plainacceptedstill marks the sender moved.cancelfirst (it fences a pending move), thenrevokeif the import already landed; acancelthat answersreceivingwaits onstatus.move_mismatch(LOW 3, new test).session-move-commands.tsis unchanged (248 code lines); the repo has no LOC gate.Evidence
Step table / crash fold (head 675f380):
Tests 3 failed (3).success: true).failed(import_failed) beside the landed writable copy.Test Files 24 passed (24) / Tests 146 passed (146), including the 32-case step sweep. Root tsc is clean,bun run checkexit 0, biome clean. The mutation checks are listed above.mds-4004-static8,GATES_DONE fail=0: the 24 move/protocol-info files passed, plus tsc,bun run check, build,check-pr-changelog --base 4dd6f3c135PASS and the marker grep;senpi-staticreceiptFILED GREEN ... #4004-675f380fcd.json failures: [] refusals=0/7.Lands-once fold (head 48d1f61):
Tests 5 failed | 10 passed (15).success: true).receivingrecord with no target let an import into another folder land.receivingrecord start a receive.Test Files 22 passed (22) / Tests 111 passed (111);bun run checkexit 0; biome clean.mds-4004-static7,GATES_DONE fail=0: the 22 move/protocol-info files passed, plus tsc,bun run check, build,check-pr-changelog --base 4dd6f3c135PASS and the marker grep;senpi-staticreceiptFILED GREEN ... #4004-48d1f6144c.json failures: [] refusals=0/7.Landing target fold (head 6969bac):
Tests 3 failed | 12 passed (15).expected length 1, got 2). The test forces the race with a ledger subclass that holds each commit until both imports reach it or one settles: no sleeps.Test Files 22 passed (22) / Tests 108 passed (108). The landing suite passed 5 of 5 repeated runs. Root tsc is clean,bun run checkexit 0, biome clean. The ledger unit tests pass the newtargetargument, and the earlier "accepted is fenced" ledger test now checks the lead's rule: another target is always fenced, the own target only once revoked.mds-4004-static6,GATES_DONE fail=0: the 22 move/protocol-info files passed, plus tsc,bun run check, build,check-pr-changelog --base 4dd6f3c135PASS and the marker grep;senpi-staticreceiptFILED GREEN ... #4004-6969bac671.json failures: [] refusals=0/7.Import fence fold (head e772ca4):
Tests 3 failed | 6 passed (9). Both re-import cases (revoked and plain) gotsuccess: trueinstead ofmove_fenced, andbeginReceiveresolved on an accepted record. The L2 repeat-revoke test passes on the current code.Test Files 21 passed (21) / Tests 103 passed (103);bun run checkexit 0; biome clean.mds-4004-static5,GATES_DONE fail=0: the 21 move/protocol-info files passed, plus tsc,bun run check, build,check-pr-changelog --base 4dd6f3c135PASS and the marker grep;senpi-staticreceiptFILED GREEN ... #4004-e772ca4768.json failures: [] refusals=0/7.Delta review folds (head 243a890):
Tests 4 failed | 10 passed (14). Status without a path lacked"revoked": true(2 tests), a wrong path got success instead ofmove_mismatch, and a moved sender'sfinishgot success instead ofmove_already_moved.Test Files 20 passed (20) / Tests 99 passed (99); root tsc clean;bun run checkexit 0; biome clean.mds-4004-static4,GATES_DONE fail=0: the 20 move/protocol-info files passed, plus tsc,bun run check, build,check-pr-changelog --base 4dd6f3c135PASS and the marker grep;senpi-staticreceiptFILED GREEN ... #4004-243a890ddc.json failures: [] refusals=0/7.Finish fold (head de1bbf8):
Tests 1 failed | 10 passed (11);finishwith{accepted, revoked:true}answered- "ownership": "writable" / + "ownership": "moved".Test Files 19 passed (19) / Tests 96 passed (96);bun run checkexit 0; biome clean. (The GREEN commit also points the RED assertion at thesession_reclaimedentry rather than the requeued input that follows it.)mds-4004-static3,GATES_DONE fail=0: the 19 move/protocol-info files passed, plus tsc,bun run check, build,check-pr-changelog --base 4dd6f3c135PASS and the marker grep;senpi-staticreceiptFILED GREEN ... #4004-de1bbf8dd7.json failures: [] refusals=0/7.Review folds (head 81d45f8):
rpc-move-session-revoke.test.ts):Tests 1 failed | 8 passed (9); the failure is the status test (- "revoked": truemissing from the answer). The used-copy and re-import tests pass on the old code: they pin semantics the code already had.session-move*/rpc-move*files plusrpc-multi-session-protocol-info->Test Files 18 passed (18) / Tests 94 passed (94);bun run checkexit 0; biome clean on the touched files.mds-4004-static2,GATES_DONE fail=0: the 18 move/protocol-info files passed, plus tsc,bun run check, build,check-pr-changelog --base 4dd6f3c135PASS and the marker grep;senpi-staticreceiptFILED GREEN ... #4004-81d45f80c6.json failures: [] refusals=0/7.Earlier (8e6d990): RED efc2b8b
Tests 8 failed (8); GREEN 2 files / 8 tests plus the move set;bun run check0;check-pr-changelogPASS.Summary by cubic
Fixes #4003: adds a
revokeop tomove_sessionso a receiving host can seal the copy it imported for a move once the sender takes the session back, preventing two writable copies of the same session.revokeruns under the move lock, refuses held or open sessions, seals the copy with asession_movedentry (reasonrevoked), and marks the ledger recordrevoked: true; a repeat is a no-op and anything else is refused withmove_mismatch.statusanswers{accepted, revoked: true}(with or without the copy's path), andfinishwith a revoked answer is a take-back, never a move; a sender already marked moved refuses withmove_already_moved.move_fenced.move-steps.tsstep table, swept fault-by-fault), keeping at most one writable copy and never losing the revoke mark.move_session_revokecapability; a record write outside its lock is refused withmove_record_unlocked.Written for commit a00e1af. Summary will update on new commits.