Repository navigation
Conversation
HoloNova
force-pushed
the
pr/delegated-busy
branch
from
September 30, 2026 01:43
ca349ea to
fdfe2ce
Compare
isRunning() only described a wrapper's own turn, so a session whose async subagent was still working looked idle: the idle shutdown could close it and kill an in-process child with it. /api/agent/running had the same hole, so anything that waits for a quiet service — a nightly restart guard, for instance — could skip a busy host. isBusy() now means "own turn or delegated work". Delegated work is read from two read-only signals: a built-in subagent run whose parent is this session, and recent writes under <session file without .jsonl>/ — the directory every child run writes its own session into, whichever plugin spawned it. An incomplete scan counts as busy. The idle timer treats delegated work exactly as it treats a running turn: the window starts over rather than the session being closed the moment a child exits, so a result on its way back to the parent always lands.
HoloNova
force-pushed
the
pr/delegated-busy
branch
from
September 30, 2026 02:00
fdfe2ce to
09d320b
Compare
A quiet answer was cached for ten seconds just like a busy one, so a child that started right after an idle probe stayed invisible until the entry expired. The asymmetry matters: a busy that outlives its cause only keeps a session alive a little longer, while a quiet that outlives its cause can have a live child reclaimed with its parent. Only the busy answer is reused now; a quiet answer is measured again on every call, and it clears any stale entry for the same key. The scan stays bounded (depth and entry caps, unreadable or truncated reads still report busy), and the built-in subagent state and activity window are unchanged.
Owner
|
Thanks @HoloNova, the fail-closed reasoning and the one-sided cache are careful work. I'm closing this one, though:
If a plugin's children need the parent kept alive, Generated by Claude Code |
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.
What
isRunning()only describes a wrapper's own turn — a pending prompt, streamingoutput, a compaction, a shell command. A delegated child keeps working after the
parent turn has returned, so a session with a live async subagent looked idle:
the idle shutdown could close the wrapper and kill an in-process child with it.
GET /api/agent/runninghad the same hole, and so anything that waits for aquiet service — a nightly restart guard, for instance — could skip a busy host.
isBusy()now means "own turn or delegated work", and every path that closesor reports a session asks that instead of
isRunning().How
Two read-only signals, and no plugin-specific state:
session and whose status is
starting,queuedorrunning. Exact, inprocess, no filesystem involved.
under
<session file without .jsonl>/, whichever plugin spawned it, so arecent write anywhere in that subtree means a child is alive. Bounded in depth
and entry count with a 10 s cache, reading nothing but mtimes. The window is
PI_WEB_DELEGATED_ACTIVITY_WINDOW_MS(default 3 min, clamped to 10 s – 30 min).The filesystem signal is a heuristic and is documented as one: a child that
writes nothing for longer than the window is invisible to it. The other
direction fails closed — an unreadable directory, or a scan that had to stop
early (entry or depth limit), reports busy, because holding a session a
little longer is recoverable and killing a child mid-run is not.
The idle timer treats delegated work exactly as it treats a running turn: the
window starts over. Nothing closes a session the moment a child exits, so a
result on its way back to its parent — the notification that triggers the
parent's next turn — always lands. Reclaiming an idle session sooner than its
idle window is a memory-policy decision, not the idle timer's.
Behaviour change (normal mode, not Lite-mode code)
GET /api/agent/runningreports a session with a live child, so a caller thatwaits for a quiet service no longer skips it;
hasBusyRpcSessionForCwd()uses the same predicate.A running turn is still never interrupted, and nothing here kills a process.
Verified
node --experimental-strip-types --test lib/delegated-work.test.mjs lib/rpc-manager-delegated-reclaim.test.mjs lib/rpc-manager.test.mjs42 tests pass, including the new cases: a child writing under the artifact
directory keeps the session busy, the window restarts while it writes, a session
whose child went quiet is reclaimed on the following window (not before), a
running turn is never interrupted, a truncated scan counts as busy, a busy
answer is reused for its short TTL, and a quiet answer is measured again on
every call. A wider
pass over the agent/subagent/session suites: 94 and 21 tests pass.
tsc --noEmitandeslintclean.The probe cache is one-sided
Only a busy answer is cached (10 s). A quiet answer is measured again on every
call, and it clears any entry for that key. The asymmetry is the point: caching
a quiet answer would open a window in which a child that started just after the
probe is invisible, and closing the parent then kills a live child. A busy
answer that outlives its cause only keeps a session alive a little longer. The
scan itself stays bounded and still fails closed on an unreadable or truncated
tree.