Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
- Leave Auto-settle merged threads enabled under Settings → Threads → Auto-settle (default).
- In a thread with an open linked PR and no active PR watch, start an async
delegate_taskand end the parent turn. - While the delegated task is still running, merge the linked PR so zero linked PRs remain open.
- Wait for the delegated task to finish without sending a new user message.
(Same race also applies when a single parent turn merges the last open linked PR with no active PR watch and launches an async delegate_task before ending.)
Expected behavior
The parent thread stays active until the delegated task's completion wake is delivered and the parent finishes handling the result. Its subagent threads do not move to Settled mid-workflow, and its live provider session stays open for the wake turn.
Actual behavior
When the delegated task finishes, pending background work clears before the completion wake becomes a message or queued run, and auto-settle can win the race:
- The parent thread jumps to Settled mid-workflow, running settle cleanup and closing its live provider session (
272 msdetach). - The cascading settle sweep moves the parent's subagent threads to Settled (
~61 msafter the parent's settle started,~41 msafter it committed). - Moments later, the delegated-completion wake arrives on the settled parent and reopens it with a
~1.55 sdelay (1.30 sto cold-start a fresh provider session) before handling the result.
In the server trace below, auto-settle started 19.95 ms before the delegated-completion message dispatch began and committed 0.4 ms before it (even though the wake had already been offered to the continuation queue 12 ms before auto-settle started). Because this is a scheduling race between the settlement sweep and continuation dispatch, it fires intermittently (observed on 1 of 7 delegated-completion wakes in the retained ~70-minute trace window). Code inspection of main (78cffe29ec, unchanged at 7c95302f7a) shows pending background work only counts active tasks, not a finished delegated task whose completion wake has not been dispatched into a message yet.
Related but different: #26083 (Claude-native background Bash with t3_background_wait), #29898 / open PR #29934 (guards only when a wake run is already queued behind an active turn), and #38840 (closed as not planned; settling while a delegate_task wake is already queued drops sibling wakes). Here, auto-settle commits before the wake becomes a message or queued run.
Impact
Minor bug or occasional failure
Version or commit
0.1.12-nightly.20261123.5151 (code path also checked on main @ 7c95302)
Environment
Linux x64 (Arch / Omarchy), T3 Code desktop & server 0.1.12-nightly.20261123.5151, Antigravity (Gemini 4 Neon) parent delegating to Claude (Claude Opus 5.5)
Logs or stack traces
# Redacted thread IDs from server.trace.ndjson (2026-11-23 UTC)
# Note: ProviderContinuationRequests.offer, ProviderSessionManager.detach, and ProviderTurnStartService.start
# spans carry no thread_id attribute; ordering and settle behavior attribute them to this wake and detach/restart.
23:51:40.483965Z | 2.86ms | Success | CHILD | orchestrationV2.EventSink.writeIfRunCurrent
23:51:40.567838Z | 18.70ms | Success | PARENT | orchestrationV2.EventSink.write
23:51:40.605219Z | 6.92ms | Success | CHILD | orchestrationV2.dispatch.withReceipt provider-session.detach
23:51:40.616710Z | 0.04ms | Success | SERVER | ProviderContinuationRequests.offer
23:51:40.628236Z | 13.64ms | Success | SERVER | ProviderSessionManager.detach (child detach)
23:51:40.628663Z | 19.54ms | Success | PARENT | orchestrationV2.dispatch.withReceipt thread.auto-settle
23:51:40.628905Z | 14.24ms | Success | PARENT | orchestrationV2.dispatch.once thread.auto-settle
23:51:40.648611Z | 67.92ms | Success | PARENT | orchestrationV2.dispatch.withReceipt message.dispatch (delegated-completion)
23:51:40.653173Z | 272.18ms | Success | SERVER | ProviderSessionManager.detach (parent detach / session close)
23:51:40.656074Z | 45.02ms | Success | PARENT | orchestrationV2.dispatch.once message.dispatch (delegated-completion)
23:51:40.689508Z | 33.73ms | Success | CHILD | orchestrationV2.dispatch.withReceipt thread.auto-settle
23:51:40.926178Z | 1296.22ms | Success | SERVER | ProviderTurnStartService.start (parent cold restart)
23:51:42.201811Z | 12.33ms | Success | PARENT | orchestrationV2.EventSink.writeIfRunCurrent (wake run started, 1.55s after dispatch)Workaround
Pin the parent thread while multi-step post-merge delegation runs, or disable Auto-settle merged threads globally (Settings → Threads → Auto-settle) or for that project.
Activity
juliusmarminge commentedon Nov 24, 2026
I tried to reproduce this on the current build and could not.
Not reproduced in a running app: the bug is an intermittent race between the settlement sweep and the delegated-completion dispatch, and triggering it end to end needs a real linked PR merged mid-flow. Instead I reproduced the decisive state against the real orchestrator, event sink and projection on origin/main cd128e7, with a test in apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts ('auto-settle waits for an open completion delivery that is not a message yet'). Using the existing seedParentWithTerminalTask fixture, it seeds a parent thread whose run is completed, with an app-owned delegated task that is completed with completionDelivery 'claimed' and completionWake 'always', and with the run's delegatedCompletion disposition 'open' and a delivery {generation 1, messageId, taskIds} that has not been dispatched as a message. It then dispatches thread.auto-settle with snapshotAt equal to the thread's current updatedAt, matching what the sweep sends. Observed: the dispatch succeeds and thread.settledOverride becomes 'settled' (assertion 'expected settled to equal null'). The parent is settled before its completion wake exists, which is the state the reporter's trace shows (auto-settle commits ~0.4 ms before message.dispatch for the delegated completion). Command: cd apps/server && vp test run src/orchestration-v2/DelegatedCompletionDelivery.test.ts -t "auto-settle waits".
Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.