fix(server): stop the reaper from silently killing live background subagents #5677
main fromrefs/pull/5677/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubBackground subagent fleets, workflow runs, and monitor watch loops kept getting killed mid-work with no signal to the user. The session reaper was the culprit: it only skips threads with an active turn, but background work runs on after the turn settles, and nothing bumps the binding's lastSeenAt between turns. Thirty idle minutes later the sweep called stopSession, tearing down the provider process and everything running inside it.
The thread shell the reaper already fetches carries backgroundLiveness from ThreadBackgroundLivenessService (the same signal the sidebar pill uses: "working" for live agent work, "monitoring" for watch loops). The sweep now skips threads with live background work, exactly like it skips active turns, and logs the skip. The liveness registry is in-memory and empty after a server restart, so orphaned bindings still get reaped.
Also folded the reaper tests' repeated start boilerplate into a helper so the new test stays under the file's manual-runner lint baseline.
Change authored by Claude Fable 5 via Claude Code.
Note
Medium Risk Changes when long-idle provider sessions are stopped; wrong liveness could leave sessions running longer or still reap too aggressively after restart when the in-memory registry is empty.
Overview
The provider session reaper no longer calls stopSession on idle bindings when the thread shell reports backgroundLiveness (working or monitoring), mirroring the existing skip for an active turn. That closes a gap where subagent fleets, workflows, and monitor loops could keep running after the turn settled without refreshing lastSeenAt, so inactivity sweeps tore down the provider process with no user-visible signal. Skips are logged as provider.session.reaper.skipped-background-work.
Tests now model backgroundLiveness on the read-model fixture, add coverage for the skip path, and centralize reaper startup in a startReaper helper (including drain/assertions on the active-turn case).
Note
Fix ProviderSessionReaper to skip sessions with live background subagents#
The reaper previously stopped sessions without checking whether background subagents were still active. A new guard in ProviderSessionReaper.ts checks the thread's backgroundLiveness field from the projection snapshot and skips stopSession if it is non-null, logging a provider.session.reaper.skipped-background-work debug event instead. A corresponding test in ProviderSessionReaper.test.ts covers the new skip behavior with backgroundLiveness set to "working".
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 11.4 KiB 11.3 KiB −29 B (−0.2%) 15.1 KiB ✅ Codex Thread snapshot wire 5.5 KiB 5.5 KiB +2 B (+0.0%) 7.3 KiB ✅ Codex Live turn WebSocket wire 5.9 KiB 5.9 KiB −31 B (−0.5%) 7.8 KiB ✅ Codex Live turn WebSocket decoded 49.7 KiB 49.7 KiB 0 B (0.0%) 66.4 KiB ✅ Codex Live turn messages 16 16 0 (0.0%) 21 ✅ Claude Total thread wire 11.3 KiB 11.3 KiB +2 B (+0.0%) 15.1 KiB ✅ Claude Thread snapshot wire 5.5 KiB 5.5 KiB +3 B (+0.1%) 7.3 KiB ✅ Claude Live turn WebSocket wire 5.9 KiB 5.9 KiB −1 B (−0.0%) 7.8 KiB ✅ Claude Live turn WebSocket decoded 50.6 KiB 50.6 KiB 0 B (0.0%) 66.4 KiB ✅ Claude Live turn messages 16 16 0 (0.0%) 21 ✅ Baseline:
4eaf5ef· PR result:104ac59· Source CI: successScenario and decoded snapshot size
10 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.
- Codex decoded thread snapshot: 94.6 KiB
- Claude decoded thread snapshot: 95.4 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved 104ac59
This is a straightforward bug fix that adds a guard condition to prevent the session reaper from killing sessions with active background work. The change follows the existing pattern in the code, is well-tested, and has limited scope.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
b4e06757-3315-4095-b459-d6feac210d0aYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share