feat(agent): run subagents in the background - #581
Open
changer-changer wants to merge 5 commits into
Open
changer-changer wants to merge 5 commits into
changer-changer wants to merge 5 commits into
Conversation
This was referenced Sep 14, 2026
# Conflicts: # src/agent/loop/AgentLoop.ts
Author
|
Merged current Validation: |
A retained terminal agent record can be pruned by new managed work while task_wait is still awaiting; the post-await getOutput then failed with a raw Unknown taskId. The wait result now carries the output slice captured from the entry the wait itself holds, mirroring the task_stop fallback.
Preserve upstream timeline ordering and child block identities alongside background ownership and cancellation. Cover live/history identity and early iterator return in background regressions.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An
agentcall currently blocks the parent until its child finishes. This adds optionalrun_in_background: true: the call returns a task id immediately, the parent can work on independent steps, and the child's result is delivered before the parent's normal final answer. Omission preserves synchronous behavior.The implementation reuses
BackgroundTaskRuntimeand the existingtask_list,task_output,task_wait, andtask_stoptools. Agent tasks are scoped to the owning session. Completed results are persisted once as bounded, labelled untrusted tool output; pending children are joined within the parent's turn budget and cancelled when the request ends. Cancellation status is flushed before the parent completes, and late child events cannot leak into a later turn. Queue-capacity errors fail immediately.This is active-request background work, with the existing child timeout and permissions. It adds no detached daemon, restart recovery, or settings page. Cancellation is cooperative; arbitrary JavaScript cannot be forcibly terminated. See the background contract for limits and examples.
Validation:
networkFetchcancellations also occur on the unchanged baseline. A subsequent regression test covers a stopped task being pruned before the tool returns.This PR is based directly on
mainfor independent review. Related subagent PRs touch the same fork path; the combined validation branch contains resolved integration changes. That branch supports synchronous continuation of a completed background child; combiningtask_idwithrun_in_background: trueis explicitly rejected rather than silently starting fresh.Merge sequencing (added 2026-09-14)
This PR is one of four coordinated subagent-lifecycle PRs (#579, #576, #580, #581). The features are semantically independent but overlap textually in the agent core, so an explicit merge order is proposed in #583.
Proposed order: #579 → #576 → #580 → #581 (this PR: 4 (last)).
This branch now includes
mainatecedc5cvia merge commit3341430(2026-09-17). The conflicts with upstream #593 inAgentLoop.tsandevents.tsare resolved: upstream timeline allocation remains the public run wrapper, background child ownership/cancellation runs inside it, and child block identities are retained. Sibling PRs still overlap in the agent core; their integration needs to be rechecked as they merge.After each sibling PR merges, I will rebase the remaining branches onto
mainand re-run the targeted test suites before updating the PRs.Validation after main sync (2026-09-17)
mainnetwork-fetch source/test files.These are local validation results; remote CI and maintainer review remain separate requirements.