Skip to content

Fix: Handle background_requested pause results in Claude session manager#897

Merged
natllian merged 1 commit into
mainfrom
nathan/analyze-issue-891-solution
Jun 24, 2026
Merged

Fix: Handle background_requested pause results in Claude session manager#897
natllian merged 1 commit into
mainfrom
nathan/analyze-issue-891-solution

Conversation

@natllian

@natllian natllian commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

closes #891

Summary

Fix for issue #891: Claude turns were ending prematurely when a subagent was moved to the background. The main agent now stays paused and resumes once the background task completes.

Changes

  • session-manager.ts: Added detection and filtering of background_requested intermediate results. These pause results are no longer treated as terminal — usage is recorded but the results stay out of the pipeline, allowing the SDK to resume the same query via task_notification.
  • background-resume.test.ts: Comprehensive regression test covering the backgrounded-task resume flow, with fallback tests for SDK edge cases.
  • .changeset: Version bump documentation.

Details

When the Claude SDK moves a task to the background, it emits an intermediate result with terminal_reason === "background_requested". The old code treated ANY result as terminal, which fired end and tore down the session — so the later task_notification resumption was lost.

The fix filters these pause results before passthrough to the pipeline, preventing premature turn termination while still recording context usage. The event loop continues draining until the genuinely terminal result arrives.

Test Plan

  • ✅ New regression tests in background-resume.test.ts validate the pause-and-resume flow
  • ✅ Fallback test verifies graceful handling if SDK closes early
  • ✅ Pre-commit hooks (biome) passed

- Filter intermediate background_requested results to prevent premature turn termination
- Record usage for paused tasks but keep pause results out of the pipeline
- Add regression tests for backgrounded subagent resume flow (#891)
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 24, 2026
@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
helmor-marketing Ignored Ignored Preview Jun 24, 2026 7:37pm

Request Review

@natllian natllian merged commit fe6108d into main Jun 24, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backgrounded subagents never resume the main Claude agent — turn ends prematurely

1 participant