Repository navigation
fix(sdk): run a turn again when its activity lock was lost - #382
Open
ChrisKrawczyk wants to merge 5 commits into
Open
ChrisKrawczyk wants to merge 5 commits into
ChrisKrawczyk wants to merge 5 commits into
Conversation
ChrisKrawczyk
marked this pull request as ready for review
November 24, 2026 18:43
This was referenced Nov 24, 2026
Open
0.8.16 (#367) stopped saving a turn the worker's drain cuts. A lock lost outside a drain still saved the aborted attempt's `cancelled` result under the turn's key; the retry (same turnKey) adopted it through already-committed recovery and the orchestration ended the turn without running it, dropping the prompt. - runTurnCommit skips the commit of a cancelled attempt and leaves the sentinel dirty; the worker records `session.snapshot_unpublished { reason: "cancelled" }`. - Already-committed recovery and the commit's same-turnKey adoption never adopt a stored cancelled result (left by an earlier release): the retry runs the turn on the saved state. - The attempt marks the session cut (markTurnCut) when it latches the cancellation, so neither the idle sweep nor the shutdown release reclaims its unsaved dir or workspace before the retry; the next attempt of the session on this worker clears the mark (clearTurnCut). If the retry runs on another worker, the mark and the local dir stay until this worker restarts. No CMS migration and no session orchestration or Workflow controller version change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
Model a runTurn attempt cut by a drain or a lost activity lock and its retry under the same turnKey: the cut attempt is never saved, the retry never adopts a stored cancelled result (from 0.8.15/0.8.17 too) and runs from the last committed snapshot, and a graceful shutdown neither releases the cut session's workspace nor reclaims its dir. Batch tc1, bound to 2078582: 15 of 15 as expected (5 PASS, 10 expected violations, 0 unexpected, 0 PARTIAL, 0 VOID), TLC 2.19. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
Review of #382 (MF-1, MF-2, SF-1, SF-2, SF-3, SF-5, C-2): - A legacy dehydrate, the safety checkpoint and the eviction sweep never publish a session whose local files hold an uncommitted turn (a dirty turn sentinel) or a cut turn (the cut mark): _legacyPublishBlocker, checked under the session lock before any archive. The store keeps its last commit; dehydrate and checkpoint return { unpublished } and the dehydrate activity records session.snapshot_unpublished. - The sweeps skip a cut session only while the worker drains. On a live worker the eviction sweep reclaims it: it releases the workspace (cancelling its background tasks), destroys the handle, deletes the dir unpublished and then clears the mark. - The retry on this worker clears the mark once its preamble resolved the session from the store; a failed probe keeps it. destroySession clears it, and a cancel latched after the attempt's commit marks nothing. - When an older build's cancelled commit wins the CAS, the attempt returns its own result unpublished (foreign_cancelled_winner), with no control-cursor or carried-steer credit. - The activity re-reads its cancellation before every send, steer, corrective prompt and recovery: a cancelled activity starts no run, sends nothing and never resets the stored session state. - The cancelled unpublished message no longer promises a retry. - CHANGELOG: the hazard dates from v0.6.0; dropped prompts are not recovered; side effects may repeat; stop every worker before an upgrade. snapshot-store-wins.md gets back its lost-lock caveat. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
Bind TurnCut to 2ab2a85e, the fixes from the review of #382, and model what the review found: the legacy publish guard (a dirty turn sentinel or the cut mark) on the dehydrate, the checkpoint and the sweep; the sweep's skip only while the worker drains, with a live worker's sweep releasing a cut session and deleting its dir; the mark cleared only after the retry's preamble and when the session is destroyed; a terminal cancel; a shutdown that begins after an ordinary lost-lock cut; and a retry beaten by an older build's cancelled commit (unpublished). A new mode "head" models the branch before its review (2078582); mode "old" is v0.6.0 to 0.8.15. A cut and a shutdown are no longer fair (C-5). 26 cases (11 faults, 6 comparisons, 5 witnesses); the tc1 witness wit.tc-lingering-mark is retired to cases-retired.json. TLC 2.19: 26 of 26 as expected. CORRESPONDENCE-2ab2a85e-tc2.md maps the model to the code; both READMEs and SHA256SUMS are updated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
The rebase onto 0.8.18 (1f6af95) moved the bound session-manager.ts lines by four after main's custom-agents change; the modelled paths are unchanged, and so are the other bound source files and the cited tests. Re-read every line, bind tc1 to f9b958c and tc2 to 63024c6 (mode "main" stays at ac86a39), point the model and case notes at 35a6865, and re-run both batches: tc2 26 of 26 and tc1 15 of 15 as expected, with the same PASS and liveness state counts as the first tc2 run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
ChrisKrawczyk
force-pushed
the
fix/turn-cut-lost-lock
branch
from
November 25, 2026 04:27
9ac0cff to
606a4cd
Compare
This branch has not been deployed
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.
A turn whose activity lock is lost outside a worker drain could drop the user's prompt. 0.8.16 (#367) stopped saving a turn that the worker's own drain cuts. A lock lost any other way still saved the aborted attempt's
cancelledresult under the turn's key. For example, the lock expires while the worker is busy, and duroxide hands the activity to another attempt (microsoft/duroxide#56). The retry runs with the same turnKey, so it adopted that result through already-committed recovery, and the orchestration ended the turn without running it.The hazard has been present since v0.6.0, the initial versioned-snapshot release, for snapshot-enabled turns. The fix does not recover prompts that were already dropped. An affected session shows a
runTurnactivity that completed with resultcancelled(turn.ts1609-1611).No orchestration version, no Workflow controller version and no CMS migration: the change is inside the
runTurnactivity and the worker's local cleanup. Upgrade: stop every worker before you deploy (CHANGELOG). An older worker would still commit a cancelled attempt that a new worker then has to work around.Fix
runTurnCommitleaves the turn sentinel dirty, and the worker recordssession.snapshot_unpublished { reason: "cancelled" }. The message no longer promises a retry.cancelledresult is never adopted, whether through already-committed recovery or through the commit's same-turnKey adoption. Any release from v0.6.0 to 0.8.17 can leave one behind; the retry then runs the turn on the saved state.foreign_cancelled_winner). It gets no control-cursor credit and no carried-steer credit, so its steers are kept.markTurnCut). A cancel latched after the attempt's commit marks nothing.destroySessionclears it._legacyPublishBlockerruns under the session lock before any archive, and the store keeps its last commit. fix(sdk): never reuse a dead Copilot runtime (#329) #376 adds the same guard for a dirty sentinel. Whichever PR merges second takes the union ("dirty_turn" | "turn_cut"), and fix(sdk): never reuse a dead Copilot runtime (#329) #376'sdestroyDeadlineMsoninvalidateWarmSession.Formal model
TurnCutindocs/formal/session-orchestration/, TLC 2.19:tc1, bound to
f9b958c1(CORRESPONDENCE-f9b958c1-tc1.md): 15 of 15 as expected.tc2, bound to
63024c6c(CORRESPONDENCE-63024c6c-tc2.md), models what the review found. It covers:It has 26 cases: 11 faults, 6 comparisons, 4 holds and 5 witnesses. All 26 are as expected, with 0 PARTIAL and 0 VOID.
"head"reproduces the pre-review branch."old"is v0.6.0 to 0.8.15.wit.tc-lingering-markis retired.The whole
session-orchestrationfolder re-ran with 0 mismatches.After the rebase onto 0.8.18 (
1f6af957, which changes no modelled code), tc1 and tc2 re-ran with the same results; tc2's PASS and liveness cases found the same distinct-state counts (tc1's first run recorded none).Bounds and what is not covered are in
CORRESPONDENCE-63024c6c-tc2.md. #376 also adds cases to this folder. Whichever merges second re-tables it and re-runsRuntimeLossandTurnCuton the combined code, which neither PR's TLC run covers (review C-3).Tests
Each test fails without its fix:
turn-control-run-turn.test.js,runTurnV4: a turn whose activity lock is lost. These drivesession-proxy.tswith a real snapshot store:turn-lifecycle.test.js(M4 cases):turn-control-live.test.js: a cancelled activity sends nothing (no initial send, no steer, no corrective prompt).session-proxy-events.test.js: a refused dehydrate of a cut turn recordssnapshot_unpublished, notdehydrated.session-workspace-release.test.mjs:Multi-model review
Three models (Claude Opus 5.5, GPT-6.2 Sol and Gemini 4 Argon) reviewed this PR as five specialists in a threaded debate, and a synthesis kept only findings grounded in the diff. The consensus was 2 must-fix and 6 should-fix findings, plus 2 trade-offs and 7 to consider.
The must-fix and should-fix findings are fixed in
63024c6cand102c701d:SF-4 is fixed for the live-session-lost recovery and the transcript reset. The other recovery branches and the tests of those two guards are follow-ups (#393).
The considered items C-2, C-4 and C-5 are done, as is the part of C-1 that fits this PR.
Both trade-offs keep this PR's conservative choice, with the alternative recorded in #394:
Other follow-ups:
Validation
All runs were on Linux (Node 24.22.1, PostgreSQL 16), one suite at a time, at
102c701d(this head's code; the last commit changes onlydocs/formal/), rebased on 0.8.18 (1f6af957).run-tests.sh: 441 of 441 files; 4540 passed, 0 failed and 26 skipped of 4566.check-packet.shandtlc_cases.py check --allpass.