Repository navigation
fix(server): auto-settle on merge waits for a pending Claude wake turn - #26108
juliusmarminge wants to merge 7 commits into
Conversation
These tests reproduce #26083. Claude's per-thread background-work probe reports nothing once a finished task's notification is buffered, and thread.auto-settle settles a thread whose live provider session still reports background work, detaching the session before the wake run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d work ends When a Claude background task finished, its task_notification sat in the wake buffer while the roster emptied, so the merged-PR sweep could settle the thread and close the session before Claude's wake run attached. Claude's per-thread background-work probe now counts a buffered wake-eligible notification for up to CLAUDE_WAKE_TURN_START_DEADLINE, and thread.auto-settle refuses while any live provider session of the thread still reports background work for its provider thread. Manual settle is unchanged; the settlement sweep re-evaluates the thread afterwards. Fixes #26083 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k is a dev server Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Auto-settle read hasPendingBackgroundWorkForThread, which also means "a dev server is running". Codex reports its background commands that way, so Codex threads with a dev server stopped settling on merge, and the roster-based skip let a Claude thread with a dev server settle before its wake turn attached. Add an optional hasPendingWakeForThread runtime probe that only Claude implements (a buffered task_notification younger than the wake deadline), make auto-settle refuse while it reports true, and restore Claude's hasPendingBackgroundWorkForThread and the settleBackgroundWork helper to main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es the roster Claude can drop a finished background task from background_tasks_changed before its task_notification arrives. The pending-wake probe now also counts a wake-eligible task the roster dropped, timed from when the wake first became expected, and the dev-server auto-settle case lists its dev server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Automatic settlement now waits briefly when Claude has evidence of a pending wake turn. The wait is bounded by the existing two-minute deadline, leaves manual settlement unchanged, and does not block settlement when the probe fails. You can add or adjust custom eligibility rules. Learn more. |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Track and expose Claude pending wakes packages/provider-core/src/server/ProviderAdapter.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts |
The session runtime adds an optional pending-wake probe. The Claude adapter records wake expectations from roster changes and buffered notifications, and expires them after the configured deadline. Tests cover buffered notifications, successive wakes, and deadline behavior. |
Guard automatic settlement apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts |
Before settling, the orchestrator checks available provider-session probes and rejects settlement when a probe reports a pending wake. Integration tests cover pending wakes, dev-server tasks, and probe failures. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant Orchestrator
participant ProviderAdapterV2SessionRuntime
participant ClaudeAdapterV2
Orchestrator->>ProviderAdapterV2SessionRuntime: Check pending wake for provider thread
ProviderAdapterV2SessionRuntime->>ClaudeAdapterV2: Check pending wake evidence for native thread
ClaudeAdapterV2-->>ProviderAdapterV2SessionRuntime: Return pending-wake status
ProviderAdapterV2SessionRuntime-->>Orchestrator: Return pending-wake status
Orchestrator->>Orchestrator: Reject settlement if a wake is pending
Possibly related issues
pingdotgg/t3code#17625— The changes add a pending-wake guard to auto-settlement for background work that can trigger a Claude wake.
Suggested reviewers: t3dotgg
Merge Risk: 
Minimal · up to 07f6b
-
Pending Claude wakes defer automatic settlement, while a wake that never opens does not leave the thread indefinitely unsettled. The change is mergeable after normal checks.
Pre-merge checks: 
4
-
Full details: Title check
-
Explanation
The title "fix(server): auto-settle on merge waits for a pending Claude wake turn" matches the main change. The diff adds a Claude-specific pending-wake probe (hasPendingWakeForThread) and makes thread.auto-settle defer while a wake turn is pending, which is what the title describes. It uses a conventional commit prefix and plain language, and it is specific enough for a teammate scanning history. The title is 70 characters, within normal limits.
Full details: Description check
-
Explanation
The description follows the repository template. It has Problem, Change, Scope and approval, and Verification sections. The Problem section gives the race, expected behavior, and reproduction steps with transcripts. The Change section explains the probe, the auto-settle decider guard, and the unchanged paths. Scope links issue
#26083as the fixed issue. Verification lists focused tests, the pass counts, and a runtime before/after transcript with a driver script. It also states what was not checked (other Claude CLI versions) and names the model and harness. The Scope and approval section is brief. It cites the linked issue but does not link an explicit maintainer approval comment, which the template asks for. The template asks for explicit approval or an exemption rationale, and the description does not give one. This is a minor gap, so the check passes.
Full details: Linked Issues check
-
Explanation
Issue
#26083requires automatic merge settlement to avoid closing a Claude session before an awaited background-task wake runs. The Claude adapter records wake evidence, applies the two-minute deadline, and exposeshasPendingWakeForThread.thread.auto-settlechecks live provider sessions and defers settlement when the probe reports a pending wake. Focused adapter and integration tests cover buffered notifications, roster removal, deadlines, dev-server behavior, and probe failure.
Full details: Out of Scope Changes check
-
Explanation
The changed production files implement the
#26083wake probe, the provider runtime contract, and the automatic-settlement guard. The added unit and integration tests verify those changes. No unrelated production behavior or unrelated tests appear in the reviewed change set.
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Note Written by We hit #26083 on a fork and fixed it in the Claude adapter, in issuelt#62. These frame orders also lost the wake turn for us, so they may be worth checking against this PR:
Our fix keeps a notified task on the roster, marked awaited, until the result of its own wake turn. It ends the hold after the existing 2-minute wake-turn start deadline when no turn starts. The fork PR has a failing-first test for each case. We're glad to open any part of it here from a personal fork if that would help. |
|
Thanks for the earlier work on this wake race. Closing in favor of #30837 by @HarryMattocks, which addresses the same auto-settle race and currently merges cleanly. This older PR now conflicts with main. |
Problem
With
sidebarAutoSettleOnMergeon, a Claude thread whose linked pull request has merged is settled the moment an awaited background task finishes: the empty task list triggers a settlement sweep,thread.auto-settlesettles the thread, and settling detaches and closes the Claude session before Claude's wake turn attaches. The agent never runs its post-merge steps. Reproduced with real Claude 2.1.304: backgroundsleep+t3_background_waiton a thread linked to a merged PR, then end the turn (transcripts below).Change
hasPendingWakeForThreadprobe. Only the Claude adapter implements it: true while a finished background task is waiting for its wake turn, i.e. a wake-eligible task has left the roster or itstask_notificationis buffered, from whichever came first until the wake run claims the buffer, the task is stopped, or the query is replaced. It expires after the adapter's existingCLAUDE_WAKE_TURN_START_DEADLINE(2 minutes), and each new wake gets its own window. A task still on the roster (a dev server) never counts.thread.auto-settledecider asks each live session of the thread and refuses while a wake is pending, the same way it already refuses when the thread changed. When the wake run completes, the existingrun.updatedsweep settles the thread; a probe that fails lets the thread settle.hasPendingBackgroundWorkForThread, manual settle, other providers, and the settlement service are unchanged, so threads running only a dev server still auto-settle on merge (Claude and Codex).Scope and approval
Fixes #26083
Verification
Focused tests, each confirmed to fail before its fix:
ClaudeAdapterV2.test.ts: a pending wake is reported once the buffered notification arrives (with and without a dev server on the roster), once the finished task leaves the roster before its notification, stops after 2 minutes when no wake turn opens, and a later wake gets its own deadline.BackgroundWorkStop.integration.test.ts(real Orchestrator and effect worker): auto-settle waits for a pending wake turn (empty roster, and beside a dev server); settles a thread running only a dev server; settles when the wake probe fails.ClaudeAdapterV2,BackgroundWorkStop.integration,ThreadSettlementService,ProviderSessionManager,RunExecutionService,ClaudeAutomaticDelivery.integration,ClaudeReplayFixtures.integration: 425/425 passed.vp run check:changedpasses.Runtime transcript, real T3 server per side on a fresh database (
T3CODE_DEV_SEED=0), Claude CLI 2.1.304,claude-sonnet-4-6, the same driver both sides, 3 runs each. Before =bc1ea26cc0(main), after =27b71881c7(this branch before its last commit, which only gives successive wakes their own deadline). The linked PR is a real merged PR (https://git.cafe/pingdotgg/t3code/pulls/26057) resolved throughPullRequestService; because it merged before the fresh thread existed, the driver moved the thread link's cachedmergedAtafter thread creation through RPC (settlement only honours merges after the user's last message). Times UTC, 2026-10-27:19:51:20.22119:51:20.242DONE; one completed run19:51:21.60819:51:21.652automatic thread settlement skipped: "… is waiting for a provider wake turn."19:51:21.77719:51:22.525DONE19:51:22.57719:51:23.005Driver script (synthetic data; not committed)
Not checked: Claude CLI versions other than 2.1.304 (the roster-first frame order is covered by the adapter test from the recorded SDK fixture).
Model and harness: Claude Opus 5.5 (lead, reproduce-test, implement) and GPT-6.1 Sol (review, runtime capture), via T3 Code.
🤖 Generated with Claude Code