Support run_in_background on resume - #214
Open
akram-ahrardi wants to merge 1 commit into
Open
Conversation
Resuming an agent silently ignored `run_in_background`. The Agent tool's
resume branch returned before its background branch, and `AgentManager.resume`
only ever awaited the run inline, so a resumed agent always blocked the main
loop until it finished — unlike a fresh background spawn.
`resume()` now takes an `isBackground` option. When set, it runs detached via
a new `startResume()` that mirrors `startAgent`'s background path: fresh abort
controller (so `/agents` stop and steering target this run, and the run isn't
tied to the tool-call signal that ends the moment the tool returns),
concurrency-pool accounting, queueing at the limit, output-file flush, child
cleanup, and `onComplete` (so the normal completion notification fires). It
returns immediately with the record still "running" (or "queued") and sets
`record.promise`, so `get_subagent_result(wait: true)` works on it too. The
queue entry was generalized from `{id, args}` to `{id, start}` so a resume can
be queued alongside spawns.
The Agent tool gains a background-resume branch that returns the agent ID
immediately, wires transcript streaming on the already-existing session, emits
`subagents:created`, and registers the run in the widget/fleet — matching the
background-spawn path.
Foreground resume behavior is unchanged.
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.
Problem
Resuming an agent silently ignores
run_in_background. In theAgenttool handler theif (params.resume)branch returns before theif (runInBackground)branch, andAgentManager.resume()only everawaits the run inline — so a resumed agent always blocks the main loop until it finishes, unlike a fresh background spawn. There's no error; the flag is just ignored. (Confirmed onmaster@ 0.14.3.)Change
AgentManager.resume(id, prompt, signal?, options?)gains anisBackgroundoption. When set, the run is detached via a new privatestartResume()that mirrorsstartAgent's background path:AbortController, so/agentsstop and steering target this run — and the run isn't tied to the tool-call signal, which resolves the moment the tool returns;maxConcurrent;onComplete(so the normal completion notification fires);running(orqueued) and setsrecord.promise, soget_subagent_result(wait: true)works on it.{ id, args }to{ id, start }so a resume can be queued alongside spawns.Agenttool gains a background-resume branch: returns the agent ID immediately, attaches a fresh transcript and streams it on the already-existing session, emitssubagents:created, and registers the run in the widget/fleet — matching the background-spawn path.Tests
Added 5 unit tests in
test/agent-manager.test.ts: background resume returns immediately + notifies on completion; a failed final turn maps toerrorand still notifies; activity/usage callbacks are forwarded; a resume queues when the concurrency pool is full; foreground resume is unchanged.npm run lint,npm run typecheck,npm run build, andnpm run test(830 tests) all pass. README updated per CONTRIBUTING; CHANGELOG left untouched per CONTRIBUTING.