Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): settle on merge no longer cancels a wake queued behind a finished turn #29934

Mergedjuliusmarmingemerged 12 commits intomain fromrefs/pull/29934/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Problem

With Settle on merge on, a PR-watch wake that arrives while a turn is running is queued as a run behind it. When the turn completes, the next queued run is started in a separate locked step after the completion commits. The settlement sweep reacts to the same completion and can dispatch thread.auto-settle first; thread.settle then cancels queued automatic (notification) runs and detaches the session, so the agent never sees the wake.

Reproduced on main at 61c3794c32 with a test against the real orchestrator: a monitor wake queued behind an active run, the run completes, and thread.auto-settle is dispatched while the completion reaction is held before it promotes the queue. The thread settles and the wake is cancelled.

Change

thread.auto-settle now refuses while the thread has a queued run and its latest executed run ended less than the existing queued-turn grace (QUEUED_TURN_START_GRACE_MS, 2 minutes) ago. In that window the completion reaction starts or holds the queue within milliseconds, so the wake runs and the sweep that follows its completion settles the thread. Past the grace the decision is unchanged from main: the one-minute full sweep settles the thread, and a queued automatic wake that is still waiting (held for the user, a usage limit, the runtime-mode ceiling, or after a restart) is cancelled as before. The check runs under the thread lock against live state, so it cannot read a stale sweep snapshot.

The grace constant moves from ThreadSettlementService.ts to Orchestrator.ts (which the settlement service already imports) so both uses share one definition. Manual settle is unchanged.

Scope and approval

Fixes pingdotgg/t3code#29898

Verification

Focused tests in apps/server/src/orchestration-v2/runtimeLayer.test.ts:

Testmain 61c3794c32this branch
automatic settlement leaves a queued pull request watch wake to runfailspasses
automatic settlement refuses a held wake only within the queued-turn gracefailspasses

The first holds the real completion reaction (spying on ThreadCommandExecutor.withLock) between the run's completion and queue promotion, dispatches thread.auto-settle there, then releases the reaction and checks the wake reaches starting. The second writes the completion with the startup-recovery command prefix (no reaction, as after a restart), checks auto-settle is refused inside the grace, advances TestClock by the grace, and checks the thread settles and the wake is cancelled, so the refusal is bounded.

Runtime transcript (vp test run src/orchestration-v2/runtimeLayer.test.ts -t "automatic settlement"), main's Orchestrator.ts and ThreadSettlementService.ts swapped in:

AssertionError: automatic settlement must wait for the queued pull request watch wake: expected DateTime.Utc(1970-01-01T00:00:00.000Z) to equal null
AssertionError: expected 'Success' to equal 'Failure'
 × automatic settlement leaves a queued pull request watch wake to run
 × automatic settlement refuses a held wake only within the queued-turn grace

This branch:

 Test Files  1 passed (1)
      Tests  2 passed | 112 skipped (114)

vp run check:changed: format, lint, knip, typecheck (3 packages) and tests (5 files, 164 tests) pass.

Not checked: a live end-to-end run with a real provider turn and a real PR merge landing in the race window (the window is milliseconds wide and cannot be hit on demand). No render path changes, so no captures.

Model and harness: Claude Opus 5.5 (Claude Code, run from T3 Code), with reviews by GPT-6.1 Sol (Codex) and Claude Opus 5.5.

🤖 Generated with Claude Code

    1. Pushedc8f7db7

    2. Pushed5dd2fb6

    3. Pushedff95dd6

    4. juliusmarminge merged this2c3d3b4

    5. juliusmarminge closed this

    6. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.