Skip to content

fix(server): keep sessions alive for running subagents - #42641

Closed
StiensWout wants to merge 4 commits into
pingdotgg:mainfrom
StiensWout:wf/find-275d07f722482c549ce4b363
Closed

StiensWout wants to merge 4 commits into
pingdotgg:mainfrom
StiensWout:wf/find-275d07f722482c549ce4b363

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

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:

  1. Start the web app from this main and open it in a browser.
  2. Open a new chat that uses the Pi provider.
  3. 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.
  4. Wait until Pi's reply in the chat is finished and that step still shows Running.
  5. 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.
  6. 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.

Proven: the repro fails at the test commit db7dc99724 and passes on the head b6303a5270, both on main 2c95b69f25.

Before After
Commit db7dc99724 b6303a5270
Result failed with "expected 'interrupted' to be 'running' // Object.is equality" passed

Outside view: a person sees it in the running web app by following the steps under Reproduction on main.

Tests

  • db7dc99724 adds the failing test, alone, before the fix.
  • pnpm exec vp run check:changed 2c95b69f25df37f50d5738ffe2a64663604fd042 passed on head.

Not in this change

  • Background commands, wakeups, and delegated results awaiting delivery still use the ordinary idle pin budget.
  • Providers without a native subagent liveness probe still use the bounded extension for projected running subagents.
  • Pi uses live session ownership for retention. Persisted provider-thread records still identify where subagent status is displayed.

Who did the work

  • Repro written by GPT 6.2 Sol, in Codex
  • Outside view by Grok 4.7, in Grok
  • Duplicate check judged by Claude Opus 5.5, in Claude Code
  • Written by GPT 6.2 Sol, in Codex
  • Trimmed by Claude Opus 5.5, in Claude Code
  • Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex, and by Gemini 4 Neon, in Antigravity
  • Reproduction, checks and proof run by a program on base and head, not by an agent

Made in T3 Code by GPT 6.2 Sol, Claude Opus 5.5, Grok 4.7 and Gemini 4 Neon

StiensWout and others added 4 commits November 25, 2026 06:32
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

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.
Verify idle-pin scenarios
apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts
Integration tests cover command, finished-subagent, and stale-subagent cases. They check session retention over timed intervals and session closure after pending work clears.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1

apps/server/src/orchestration-v2/ProviderSessionManager.test.ts-3719-3720: 1

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

Source: Path instructions

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5f1fcf7 and b6303a5.

Files selected for processing: 6

  • apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts
  • apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
  • apps/server/src/orchestration-v2/ProviderSessionManager.ts
  • packages/provider-core/src/server/ProviderAdapter.ts
  • packages/provider-pi/src/server/adapter.test.ts
  • packages/provider-pi/src/server/adapter.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@StiensWout StiensWout closed this Nov 25, 2026
@StiensWout
StiensWout deleted the wf/find-275d07f722482c549ce4b363 branch November 25, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant