Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): stop the reaper from silently killing live background subagents #5677

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/5677/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Background 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).

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 104ac590ec111e13bd984ca81e4b368383268793. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

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".

Macroscope summarized 104ac59.
    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: b4e06757-3315-4095-b459-d6feac210d0a

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire11.4 KiB11.3 KiB−29 B (−0.2%)15.1 KiB✅
      CodexThread snapshot wire5.5 KiB5.5 KiB+2 B (+0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire5.9 KiB5.9 KiB−31 B (−0.5%)7.8 KiB✅
      CodexLive turn WebSocket decoded49.7 KiB49.7 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages16160 (0.0%)21✅
      ClaudeTotal thread wire11.3 KiB11.3 KiB+2 B (+0.0%)15.1 KiB✅
      ClaudeThread snapshot wire5.5 KiB5.5 KiB+3 B (+0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire5.9 KiB5.9 KiB−1 B (−0.0%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded50.6 KiB50.6 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages16160 (0.0%)21✅

      Baseline: 4eaf5ef · PR result: 104ac59 · Source CI: success

      Scenario 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.

    4. 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).

Sign in to join this conversation.