[Bug]: After Settle stops a thread's background server, the thread still shows "Waiting" with a Stop button #15239
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#
- In a Claude thread, have the agent start a server as a background task (
python3 -m http.server 8765withrun_in_background) and end its turn. The composer shows the Waiting strip with a Stop button. - Settle the thread.
- Check the server's port and look at the thread.
Expected behavior#
Settle stops the server, and the thread no longer shows the Waiting strip or the Stop button.
Actual behavior#
Settle does stop the server: about two seconds after thread.settle the provider log shows query.close, and the server's whole process chain is gone. But the Waiting strip and its Stop button stay. Pressing Stop afterwards closes nothing, since no provider process is left, and only then does the strip go away.
Settle reaches the adapter through provider-session.detach, which closes the session scope, and closeSession only closes the query. The step that clears the thread's background work, thread.background-work.settle, is dispatched only after an interrupt (EffectWorker.ts), that is, only on Stop. So the thread keeps showing work no process will report on, which the settle comment says must not keep running after Settle.
A possible fix is to dispatch the same thread.background-work.settle after the detach that Settle and archive trigger.
Impact#
Minor bug or occasional failure
Version or commit#
0.0.46-nightly.20261003.2623 (fed41fa)
Environment#
Desktop app on Linux (NixOS, Wayland, niri); Claude Code 2.1.288
Logs or stack traces#
No response
Screenshots, recordings, or supporting files#
No response
Workaround#
No response
Vantrongs(GitHub profile, opens in a new tab) added labelsbug
Vantrongs(GitHub profile, opens in a new tab) added labelsneeds-triage
juliusmarminge removed labelsneeds-triage
juliusmarminge added labelsvia-triage
A related case on a provider adapter that is not upstream yet: a Muse Code adapter (
MuseAdapterV2) in a fork, running on nightly 0.0.46. It reaches the same "Waiting" state by another route, so it may be worth covering in the same fix.How it happens. The Muse lead turn launches a native background
workflowtool, and the Muse runtime ends that turn about 30 seconds later. The workflow keeps running for about 25 minutes, as adynamic_toolturn item with nestedsubagentitems. When it finishes, T3 starts a continuation run, the agent posts its final message, and the run completes.What we see.
- While the workflow is genuinely working, the sidebar says "Waiting", because
pendingBackgroundTasksis non-empty. To the user that reads as idle or blocked, not as "working in the background". - From reading the code (not reproduced), the adapter only accepts late child updates through an in-memory map of the children it is tracking. A service restart clears that map, and so does a fork or rollback. Leftover children are only settled on host failure or interrupt, never when a later run completes normally. So if the service restarts mid-workflow, the workflow and subagent items can stay
runningafter the continuation run completes.derivePendingBackgroundWork(packages/shared/src/orchestrationV2PendingBackgroundWork.ts) and the matching projection query count any non-terminalcommand_execution/dynamic_tool/subagentitem. A finished thread would then show "Waiting" forever, the same symptom as this issue.
Suggestion, provider-agnostic.
- When a later run on the thread completes, settle any leftover non-terminal background items from earlier runs.
- At startup, reconcile items that no live provider session owns.
- Label genuine background work differently from waiting on the user, for example "Working in background".
Also related: #15358 (stranded waiting after a backend restart) and #17512 (subagent node stays Running after the child completes).
- While the workflow is genuinely working, the sidebar says "Waiting", because
Another route to the same stale "Waiting" state, and possibly worth covering in the same fix: a provider session that's released, for example after going idle, rather than settled. As far as I can tell from the code on
main(9c9ae43d80), the release path never clears the saved background-task roster.This is from reading the code, not a fresh reproduction on upstream. We hit it in a fork with a finished Claude
Monitortask that kept a thread "Waiting" for hours after its session was released.The chain, on
main:- The release: it ends subscribers and closes the session scope. Its session-state write emits
provider-session.updated. - The roster: the provider thread's
pendingBackgroundTaskslive in the provider-thread projection, written by a separate handler. A session update touches only the session table, so the roster outlives the process that owned it. - The display: the shell derives pending work from those provider threads, and the shared derivation doesn't look at session status. A leftover entry keeps the runtime idle-but-waiting, which the sidebar shows as Waiting even after the run completed.
The fix we made in the fork: when a session is released, clear the rosters owned by that runtime. That includes threads it served that had already detached. It's guarded so a replacement runtime resuming the same session ID isn't affected, and shutdown recovery still records its cancelled work, as it does now.
If that's in scope for this issue, I can send it as a focused PR with tests:
- release with a pending Monitor;
- a resume racing the session close;
- shutdown recovery.
Drafted with Claude Code and Codex (GPT-6.1 Sol).
- The release: it ends subscribers and closes the session scope. Its session-state write emits
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Note
Grok responding on behalf of Julius.
Triage#
Thanks @Vantrongs for the precise repro and for pointing straight at the missing
thread.background-work.settlestep.Confirmed on current
main(ce90eec). Settle stops the background server as intended. The bug is the Waiting strip that stays up afterwards.thread.settleis allowed once the run is idle, and background work doesn't count as active. Settle then detaches the live provider session, just like archive does. For Claude,closeSessiononly callsquery.close, which matches the provider log and the server process going away. Nothing on that path clears the provider-thread background roster or marks leftover background items as interrupted, andthread.settledonly updates the thread record.The Waiting strip comes from
derivePendingBackgroundWork, which reads the background roster plus any still-active command, subagent, and dynamic-tool items. Those stay untilthread.background-work.settleruns, and that only happens afterprovider-turn.interrupt, which is Stop. That's why the extra Stop clears the strip even though there's no process left to kill.This isn't the Stop gap fixed in #13792 and #14636, which are both merged. Settle just never runs the same follow-up. Inactivity auto-settle goes through
thread.settletoo, so it has the same gap, and archive uses the same detach.Likely fix area#
Dispatching
thread.background-work.settleafter the settle and archive detach, as you suggested, lines up with the code. There are two details to watch:settleBackgroundWorkleaves the roster in place while a live session still exists, because a live process is expected to report the clear itself.dispatchBackgroundWorkSettlequietly does nothing.A maintainer will decide on the fix direction.