Skip to content

feat(coding-agent): move_session revoke seals an imported copy (#4003) - #4004

Merged
code-yeongyu merged 24 commits into
mainfrom
feat/4003-move-revoke
Oct 23, 2026
Merged

code-yeongyu merged 24 commits into
mainfrom
feat/4003-move-revoke

Conversation

@code-yeongyu

@code-yeongyu code-yeongyu commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Fixes #4003. Part of desktop app item 3137 (tracked internally); desktop#4008 gates its take-back on the move_session_revoke capability.

What

move_session {op:"revoke", sessionPath, moveId} seals the copy a receiving host IMPORTED for a move, after the sender took the session back:

  • runs under the move lock (withSessionMoveLock, the same lock as export/finish): session_held when another process holds the copy, session_open_here when this host has it open;
  • appends session_moved with { 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 with session_moved_away;
  • only a file whose latest ownership entry is this move's session_moved_in is revoked; a repeat for the same move is a no-op that answers the same;
  • anything else (another move id, the sender's released copy, a never-imported writable session) is refused with move_mismatch.
  • capability move_session_revoke is advertised by multi-session hosts next to move_session.

Wire: request { type: "move_session", op: "revoke", sessionPath, moveId } -> success data: { ownership: "moved" }; refusals error/errorCode: move_mismatch, session_held, session_open_here, invalid_move_request (missing sessionPath or bad moveId), with errorData.detail.

Import and finish behavior are unchanged (finish's return path now shares one ownershipOf helper 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 calls moveStep(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.

Step On disk Receiver record A crash or throw there must leave
import:received bundle verified; nothing landed receiving, target recorded nothing landed: status receiving; a same-folder import lands it, other folders are fenced
import:stamped nothing landed; staged copy ready receiving, target, committing every import fenced (lands once); status finds no file at the target, so failed and the sender takes it back
import:renamed copy landed at the target, writable still receiving + committing status or a same-file import confirms it (accepted); a failure here never records failed; other folders fenced
import:accepted copy landed accepted, target (final) done
revoke:sealed receiver copy sealed (session_moved reason revoked) accepted, mark not yet written status reads the sealed file and answers revoked, writing the mark; a repeated revoke writes it too
revoke:marked receiver copy sealed accepted + revoked done
finish:recorded sender file records moved / reclaimed; bundle kept (sender side) a repeated finish re-queues the dropped input once and removes the bundle
finish:requeued input re-queued; bundle still there (sender side) a repeated finish finds the input queued and removes the bundle
  • Stamp before the rename: commit stamps committing under the ledger lock after its prepare steps (replacePredecessor, extension state, which land nothing, so a refusal there still records failed) and before the rename. A stamped record never lands again.
  • Never failed beside a landed copy: fail()/settle refuse to overwrite a stamped record (the probed MEDIUM). status settles the stamped record from the file at the recorded target.
  • Revoke mark kept: confirmLanded keeps a revoke mark (the LOW), and status restores a mark a crash lost after the seal.
  • One sweep test (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.
  • The suite can fail: removing the settle refusal fails 2 sweep/probe tests, removing the revoke reconcile fails 4, and removing the commit stamp fails 2.
  • Residual, in the CHANGELOG: a move an older version started receiving and that never landed cannot be finished; the user copies the session to a new thread.
  • Layout: the landing rules moved to move-landing.ts and the ledger lock to move-ledger-lock.ts, keeping move-ledger.ts under the 250-line ceiling (244).

Lands-once fold (head 48d1f61)

  • A move lands once (probed M1, conservative fix: fewer states, fewer split-brain cases): an accepted record never lands again, revoked or not, at any target. A deleted copy is gone; the user copies the session to a new thread. This removes the re-land added in 6969bac, which a lost revoke mark plus a deleted copy could turn into a second writable copy.
  • An old-build receiving record 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 before beginReceive.
  • L2 (the exact-string target compare fails closed) and L3 (concurrent same-folder imports share one staging directory; pre-existing) are filed as move_session import: landing target compared as an exact string; concurrent same-folder imports share a staging dir #4016 and not folded in here.

Landing target fold (head 6969bac)

  • The ledger records where a move lands (probed HIGH + MEDIUM, one root cause):
    • 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 with move_fenced before anything is written. That covers two imports at once (H1) and an import after a lost accepted write (M1).
    • commit(moveId, target, rename) renames only into the stored target: from receiving, or for a re-land, from accepted when not revoked. Any other case throws MoveFencedError.
    • The same-file early return now calls 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 ends accepted; a landed file at a different path is fenced.
    • The stored target never appears in an answer, because records are parsed field by field.
  • Re-land of a deleted copy: removed again in 48d1f61 (a move lands once).
  • Sweep: only import.ts lands a session file for a move id (rebindSessionFile runs only inside commit's callback, into the same target path), and all three of its ledger calls now carry the target. export.ts writes the sender's bundle, not a session file.
  • An old-build receiving record claims its target on the next import: replaced in 48d1f61 (refused, except its already landed file).

Import fence fold (head e772ca4)

  • An accepted move lands once (probed MEDIUM; this fixes the whole class, not only the revoked case): beginReceive refuses any accepted record, revoked or not, with move_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.
  • Seal before flag, on purpose (L1): revoke seals the copy first and marks the record afterwards. Flag-first would let a sender hear revoked and reclaim while the receiver's copy is still writable: two writers. Seal-first can only crash into "sealed, record plain accepted", where nobody is wrongly writable. rpc.md now says a client whose revoke did not succeed repeats it before acting on any status.
  • A ledger test (L2) shows a repeat revoke restores revoked: true after the record is deleted or reset to plain accepted.

Delta review folds (head 243a890)

  • the ledger records the revoke (MEDIUM): revoke adds revoked: true to the move's accepted ledger record under the same move lock, after the seal. The state stays accepted, 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. status reports {accepted, revoked: true} with or without sessionPath, and cancel/prepare return the same record.
  • a revoked answer for a sender already marked moved (LOW-1) is refused with move_already_moved (new wire code, documented), and nothing changes.
  • status with a wrong sessionPath (LOW-2): a file that exists but is not this move's import is refused with move_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.ts JSDoc reflowed (LOW-3).

Review folds (head de1bbf8)

  • status after a revoke (MEDIUM 1, lead ruling: additive): the ledger's accepted stays final and unchanged. status with the copy's sessionPath answers { state: "accepted", revoked: true } when the latest record for that move id on the file is the session_moved with reason revoked. Old readers see accepted as before. revoked: true wins for writability: the write guard refuses every write to that copy (session_moved_away). Without sessionPath, the answer comes from the ledger alone and stays plain accepted, as documented.
  • finish honors the revoke (lead condition: revoked: true wins for every reader that decides writability): parseMoveStatus keeps the flag, and finish with { accepted, revoked: true } is a take-back, never a move. A sender still sealed for the move reclaims it on the same path as declined (session_reclaimed with reason: "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. Plain accepted still marks the sender moved.
  • a used copy is still revoked (MEDIUM 2): turns written after the import are kept, and the copy becomes read-only for good; the client offers "Copy to a new thread". Refusing would leave two writable copies. Documented and tested.
  • take-back order (LOW 1): docs/rpc.md says the client sends cancel first (it fences a pending move), then revoke if the import already landed; a cancel that answers receiving waits on status.
  • restatement test removed (LOW 2); re-imported copy refuses a revoke for the earlier move id with move_mismatch (LOW 3, new test).
  • session-move-commands.ts is unchanged (248 code lines); the repo has no LOC gate.

Evidence

Step table / crash fold (head 675f380):

  • RED (tests-only commit 721e50d, run at 48d1f61): Tests 3 failed (3).
    • The interrupted commit plus a deleted copy re-landed (success: true).
    • A failure after the rename recorded failed (import_failed) beside the landed writable copy.
    • A same-file re-import dropped the revoke mark.
  • GREEN (675f380): 24 move/protocol-info files -> Test Files 24 passed (24) / Tests 146 passed (146), including the 32-case step sweep. Root tsc is clean, bun run check exit 0, biome clean. The mutation checks are listed above.
  • Static receipt on a fresh clone at 675f380: label mds-4004-static8, GATES_DONE fail=0: the 24 move/protocol-info files passed, plus tsc, bun run check, build, check-pr-changelog --base 4dd6f3c135 PASS and the marker grep; senpi-static receipt FILED GREEN ... #4004-675f380fcd.json failures: [] refusals=0/7.

Lands-once fold (head 48d1f61):

  • RED (tests-only commit 2745354, run at 6969bac): Tests 5 failed | 10 passed (15).
    • A retry after the landed copy was deleted re-landed, with the move not revoked and with its revoke mark lost (success: true).
    • An old-build receiving record with no target let an import into another folder land.
    • The ledger let an accepted move re-land at its own target and let a target-less receiving record start a receive.
  • GREEN (48d1f61): 22 move/protocol-info files -> Test Files 22 passed (22) / Tests 111 passed (111); bun run check exit 0; biome clean.
  • Static receipt on a fresh clone at 48d1f61: label mds-4004-static7, GATES_DONE fail=0: the 22 move/protocol-info files passed, plus tsc, bun run check, build, check-pr-changelog --base 4dd6f3c135 PASS and the marker grep; senpi-static receipt FILED GREEN ... #4004-48d1f6144c.json failures: [] refusals=0/7.

Landing target fold (head 6969bac):

  • RED (tests-only commit e58113a, run at e772ca4): Tests 3 failed | 12 passed (15).
    • Two concurrent imports into different folders landed 2 files (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.
    • After a lost accepted write, an import into another folder succeeded.
    • A not-revoked retry after the landed copy was deleted was refused.
  • GREEN (6969bac): 22 move/protocol-info files -> Test Files 22 passed (22) / Tests 108 passed (108). The landing suite passed 5 of 5 repeated runs. Root tsc is clean, bun run check exit 0, biome clean. The ledger unit tests pass the new target argument, 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.
  • Static receipt on a fresh clone at 6969bac: label mds-4004-static6, GATES_DONE fail=0: the 22 move/protocol-info files passed, plus tsc, bun run check, build, check-pr-changelog --base 4dd6f3c135 PASS and the marker grep; senpi-static receipt FILED GREEN ... #4004-6969bac671.json failures: [] refusals=0/7.

Import fence fold (head e772ca4):

  • RED (tests-only commit c8be48d, run at 243a890): Tests 3 failed | 6 passed (9). Both re-import cases (revoked and plain) got success: true instead of move_fenced, and beginReceive resolved on an accepted record. The L2 repeat-revoke test passes on the current code.
  • GREEN (e772ca4): 21 move/protocol-info files -> Test Files 21 passed (21) / Tests 103 passed (103); bun run check exit 0; biome clean.
  • Static receipt on a fresh clone at e772ca4: label mds-4004-static5, GATES_DONE fail=0: the 21 move/protocol-info files passed, plus tsc, bun run check, build, check-pr-changelog --base 4dd6f3c135 PASS and the marker grep; senpi-static receipt FILED GREEN ... #4004-e772ca4768.json failures: [] refusals=0/7.

Delta review folds (head 243a890):

  • RED (tests-only commit ff24a3f, run at de1bbf8): Tests 4 failed | 10 passed (14). Status without a path lacked "revoked": true (2 tests), a wrong path got success instead of move_mismatch, and a moved sender's finish got success instead of move_already_moved.
  • GREEN (243a890): 20 move/protocol-info files -> Test Files 20 passed (20) / Tests 99 passed (99); root tsc clean; bun run check exit 0; biome clean.
  • Static receipt on a fresh clone at 243a890: label mds-4004-static4, GATES_DONE fail=0: the 20 move/protocol-info files passed, plus tsc, bun run check, build, check-pr-changelog --base 4dd6f3c135 PASS and the marker grep; senpi-static receipt FILED GREEN ... #4004-243a890ddc.json failures: [] refusals=0/7.

Finish fold (head de1bbf8):

  • RED (tests-only commit 9d0f7c8, run at 81d45f8): Tests 1 failed | 10 passed (11); finish with {accepted, revoked:true} answered - "ownership": "writable" / + "ownership": "moved".
  • GREEN (de1bbf8): 19 move/protocol-info files -> Test Files 19 passed (19) / Tests 96 passed (96); bun run check exit 0; biome clean. (The GREEN commit also points the RED assertion at the session_reclaimed entry rather than the requeued input that follows it.)
  • Static receipt on a fresh clone at de1bbf8: label mds-4004-static3, GATES_DONE fail=0: the 19 move/protocol-info files passed, plus tsc, bun run check, build, check-pr-changelog --base 4dd6f3c135 PASS and the marker grep; senpi-static receipt FILED GREEN ... #4004-de1bbf8dd7.json failures: [] refusals=0/7.

Review folds (head 81d45f8):

  • RED (tests-only commit 8a926ea, rpc-move-session-revoke.test.ts): Tests 1 failed | 8 passed (9); the failure is the status test (- "revoked": true missing from the answer). The used-copy and re-import tests pass on the old code: they pin semantics the code already had.
  • GREEN (81d45f8): the 17 session-move*/rpc-move* files plus rpc-multi-session-protocol-info -> Test Files 18 passed (18) / Tests 94 passed (94); bun run check exit 0; biome clean on the touched files.
  • Static receipt on a fresh clone at 81d45f8: label mds-4004-static2, GATES_DONE fail=0: the 18 move/protocol-info files passed, plus tsc, bun run check, build, check-pr-changelog --base 4dd6f3c135 PASS and the marker grep; senpi-static receipt FILED 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 check 0; check-pr-changelog PASS.


Summary by cubic

Fixes #4003: adds a revoke op to move_session so 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.

  • revoke runs under the move lock, refuses held or open sessions, seals the copy with a session_moved entry (reason revoked), and marks the ledger record revoked: true; a repeat is a no-op and anything else is refused with move_mismatch.
  • status answers {accepted, revoked: true} (with or without the copy's path), and finish with a revoked answer is a take-back, never a move; a sender already marked moved refuses with move_already_moved.
  • The ledger records the target the first import lands at, so an accepted move never lands a second copy and an import into another folder is fenced with move_fenced.
  • Every durable step is settled from the files after a crash or throw (move-steps.ts step table, swept fault-by-fault), keeping at most one writable copy and never losing the revoke mark.
  • Multi-session hosts advertise the move_session_revoke capability; a record write outside its lock is refused with move_record_unlocked.
  • A move an older version started receiving, that never landed, cannot be finished; the user copies the session to a new thread (documented in the CHANGELOG).

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

View guided diff Turn on auto-fix

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
@code-yeongyu code-yeongyu added the review-queued Queued for batched Opus review label Oct 23, 2026
@code-yeongyu
code-yeongyu merged commit 4094439 into main Oct 23, 2026
43 checks passed
@code-yeongyu
code-yeongyu deleted the feat/4003-move-revoke branch October 23, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-queued Queued for batched Opus review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

move_session: add a revoke op to seal an imported copy after a take-back

1 participant