Skip to content

fix(coding-agent): a re-run move import accepts a landed session file even after a lost accepted write - #3998

Merged
code-yeongyu merged 11 commits into
mainfrom
fix/move-import-file-authority
Oct 22, 2026
Merged

code-yeongyu merged 11 commits into
mainfrom
fix/move-import-file-authority

Conversation

@code-yeongyu

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

Copy link
Copy Markdown
Owner

Part of desktop app item 3137, tracked internally (desktop#4008 handover).

Bug

When a move's session file already carries session_moved_in, importMovedSession treats the file as the authority, but it called ledger.commit, which refuses a failed record. If the accepted write failed after the rename, the import's catch recorded failed{import_failed}, and every re-run of the idempotent import then threw move_fenced, although the session file was landed and writable.

Fix

  • Once this move's file has landed at the target, the import records no failure. fail(moveId, reason, { unlessLanded }) evaluates the landed check under the move's lock, right before writing, so a failure queued behind an overlapping commit cannot write failed beside the file that commit just landed. This covers the commit catch and the verifyBundle catch. The repository decline is skipped once the file has landed. A lost accepted write therefore leaves the move receiving, so a status call without sessionPath never reports failed for a landed move.
  • The new MoveLedger.accept(moveId) is used by the file-authority branch. It overrides only receiving; a missing record (lost ledger) and an existing accepted are also accepted. It refuses ready, declined and failed, so an answer a sender may have heard never changes.
  • A lost ledger becomes accepted only if the import is re-run before anyone asks: a status call without sessionPath fences a missing record as declined/no_record first.

Evidence (fresh clone on a second machine, bun install --frozen-lockfile --ignore-scripts)

RED: two tests-only commits, each run before its fix.

  • 5d7969e: the lost-accepted-write case reads expected { state: 'failed', ... } to deeply equal { state: 'receiving' }, and accept on a failed record failed with "promise resolved undefined instead of rejecting".

  • 4e9af89: the first overlapping-imports case (B lands the file and loses accepted between A's landed check and A's verifyBundle) reads expected { state: 'failed', ... } to deeply equal { state: 'receiving' }.

  • 92297b0: A's fail is queued behind B's commit lock and B lands the file then loses accepted (deterministic gates, no sleeps): expected { state: 'failed', ... } to deeply equal { state: 'receiving' } at the then-head code.

GREEN at fc36c4e:

  • The new tests, session-move*, rpc-move-session* and no-sync-in-session-path: 19 test files passed.
  • Root tsc --noEmit, bun run check, bun run build, scripts/check-pr-changelog.mjs --base 2faff41b45 and the conflict-marker grep all exited 0.
  • The senpi-static receipt was filed GREEN at fc36c4e (0/7 refusals).

@code-yeongyu
code-yeongyu merged commit 6c9ee3f into main Oct 22, 2026
32 of 33 checks passed
@code-yeongyu
code-yeongyu deleted the fix/move-import-file-authority branch October 22, 2026 17:28
code-yeongyu added a commit that referenced this pull request Oct 22, 2026
…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.
code-yeongyu added a commit that referenced this pull request Oct 22, 2026
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.
code-yeongyu added a commit that referenced this pull request Oct 22, 2026
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.
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