You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): keep sessions alive for running subagents - #42641
Idle cleanup could close a Pi session while an asynchronous subagent was queued or still running. The session manager now keeps Pi open while its latest async snapshot confirms that the session owns live subagent work. When the run settles or drops out of the snapshot, the session returns to ordinary idle cleanup.
Start the web app from this main and open it in a browser.
Open a new chat that uses the Pi provider.
Ask Pi to start an asynchronous subagent workflow with one step that sleeps for five hours and then reports done, and to finish its reply without waiting for that step.
Wait until Pi's reply in the chat is finished and that step still shows Running.
Leave that chat alone, with the app still running, for four and a half hours, and do not send another message, so the step's status and model stay the same.
Look at that step in the chat.
About four and a half hours after Pi's reply finishes, the step changes from Running to Stopped, and its done result never appears. Expected: The step stays Running for the whole five hours, and when the sleep finishes the chat shows that the step completed and reports done.
The cause is at apps/server/src/orchestration-v2/ProviderSessionManager.ts:1677. Ran cd apps/server && pnpm exec vp test run src/orchestration-v2/ProviderSessionManager.test.ts with the repro test added: it failed in 2 of 2 runs on a clean checkout, with expected 'interrupted' to be 'running' // Object.is equality in the output.
Evidence
Environment: Linux x64, the repository's own tests.
The Pi adapter now reports live async native subagents. The session manager uses that state, along with existing pending-work checks, when deciding whether an idle session remains open. Unit and integration tests cover liveness and idle-pin behavior.
Changes: Native subagent idle retention
Layer / File(s)
Summary
Track and expose live subagents packages/provider-core/src/server/ProviderAdapter.ts, packages/provider-pi/src/server/adapter.ts, packages/provider-pi/src/server/adapter.test.ts
The runtime adds an optional hasLiveNativeSubagents effect. The Pi adapter tracks active runs and unsettled children. Tests cover queued, running, untracked, and completed snapshots.
Apply liveness to idle release apps/server/src/orchestration-v2/ProviderSessionManager.ts, apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
The session manager considers live native subagents when evaluating pending work and idle-pin expiry. A regression test checks that a running subagent remains active across idle-time checkpoints.
Integration tests cover command, finished-subagent, and stale-subagent cases. They check session retention over timed intervals and session closure after pending work clears.
sequenceDiagram
participant PiAdapter as Pi adapter runtime
participant SessionManager as ProviderSessionManager
participant Session as Provider session
SessionManager->>PiAdapter: Query hasLiveNativeSubagents
PiAdapter-->>SessionManager: Return live-state result
SessionManager->>Session: Defer release while work remains pending
Loading
Possibly related issues
Async Pi subagent visibility in the subagent UI: this change tracks async subagent liveness for session retention, but does not show that UI emission is addressed.
Suggested reviewers:juliusmarminge, yash-singh1
Merge Risk: Minimal · up to b6303
Idle cleanup no longer interrupts Pi sessions that own live async subagents, and ordinary cleanup resumes once the work settles. The inspected evidence shows no concrete merge-blocking defect. The open items are a minor test-style question and an unverified assumption about how the Pi subagent producer signals completion.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(server): keep sessions alive for running subagents" matches the main change. The PR keeps Pi sessions open while their async subagents are queued or running, and the summaries confirm c…
Description check
The description follows the template. It has a problem statement, a reproduction with expected behavior, an explanation of the change, a scope that refers to a bug fix with related issues, and a verif…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix(server): keep sessions alive for running subagents" matches the main change. The PR keeps Pi sessions open while their async subagents are queued or running, and the summaries confirm changes to idle cleanup in ProviderSessionManager and the Pi adapter. It follows the conventional commit style the template asks for. The title is specific and does not cover every detail, which is expected.
Full details: Description check
Explanation
The description follows the template. It has a problem statement, a reproduction with expected behavior, an explanation of the change, a scope that refers to a bug fix with related issues, and a verification section. The verification shows observed results for the changed behavior: the repro test failed before the fix and passed on head. It also lists what is out of scope. The Scope section links related issues but does not clearly say why this is a bug fix rather than a feature, and the Problem section gives the reproduction steps but does not state the environment beyond Linux x64. These gaps are minor, so the description is mostly complete.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
3719-3720: Minor · Functional Correctness · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Wait for the idle decision before checking the projection.
Release removes the session before it settles persisted subagents. This assertion can therefore read "running" while release is already in progress.
Expose and await a Deferred for the completed idle decision. Then check manager.isLive and the subagent status. Use a release-record milestone for expected-release assertions in the integration cases.
As per path instructions, server tests must “drain the effect worker or await the specific persisted event or Deferred marking the milestone.”
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:M30-99 changed lines (additions + deletions).vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Idle cleanup could close a Pi session while an asynchronous subagent was queued or still running. The session manager now keeps Pi open while its latest async snapshot confirms that the session owns live subagent work. When the run settles or drops out of the snapshot, the session returns to ordinary idle cleanup.
Related: #36324, #23082, #29361, #27254, #38578
Reproduction on main
Commit a03bbfc44a (main), in the running web app:
About four and a half hours after Pi's reply finishes, the step changes from Running to Stopped, and its done result never appears. Expected: The step stays Running for the whole five hours, and when the sleep finishes the chat shows that the step completed and reports done.
The cause is at
apps/server/src/orchestration-v2/ProviderSessionManager.ts:1677. Rancd apps/server && pnpm exec vp test run src/orchestration-v2/ProviderSessionManager.test.tswith the repro test added: it failed in 2 of 2 runs on a clean checkout, withexpected 'interrupted' to be 'running' // Object.is equalityin the output.Evidence
Environment: Linux x64, the repository's own tests.
Proven: the repro fails at the test commit db7dc99724 and passes on the head b6303a5270, both on main 2c95b69f25.
Outside view: a person sees it in the running web app by following the steps under Reproduction on main.
Tests
pnpm exec vp run check:changed 2c95b69f25df37f50d5738ffe2a64663604fd042passed on head.Not in this change
Who did the work
Made in T3 Code by GPT 6.2 Sol, Claude Opus 5.5, Grok 4.7 and Gemini 4 Neon