Skip to content

fix(agent-runtime): deliver delegate reports that settled before the parent idled - #228

Merged
vastsa merged 1 commit into
vastsa:mainfrom
L4XB:fix/deliver-settled-delegate-reports-on-idle
Sep 11, 2026
Merged

fix(agent-runtime): deliver delegate reports that settled before the parent idled#228
vastsa merged 1 commit into
vastsa:mainfrom
L4XB:fix/deliver-settled-delegate-reports-on-idle

Conversation

@L4XB

@L4XB L4XB commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Closes #226.

resumeAfterDelegations kept the turn open and auto-fed reports only while delegates of the current turn were still running (currentTurnDelegations() filters runningDelegations()). A delegate that finished before the parent went idle, with no TaskWait in between, was settled but never delivered: the running set was empty, the loop returned, and the parent continued as if the delegate had produced nothing. As the issue puts it, such a report is "done and unpublished", not "unfinished".

Change (packages/agent-runtime/src/runtime.ts), following the proposal in the issue:

  • DelegationRecord.reportDelivered marks a report that reached the parent's context once.
  • pendingCurrentTurnDelegations(): same turnEpoch, !reportDelivered, not stopped/aborted. keepTurnOpenForDelegates() keeps the turn open while running or pending-undelivered delegates exist.
  • resumeAfterDelegations loops over the pending set, waits (settled records resolve immediately in waitForDelegations), injects only settled records that are still undelivered and marks them delivered once.
  • TaskWait marks the settled records it returned as delivered, so the idle resume does not repeat them; still-running records keep their shot, so a timeout or an early mode: "any" convergence does not consume a future auto-resume.
  • Stop / abort / parent fatal error paths are unchanged: stopped and aborted runs are excluded from the pending set, and the existing runCancelled / turnHadError guards stay.

Tests (runtime.test.ts): a delegate that settles before the parent idles is delivered exactly once through the resume prompt and the turn stays open until then (fails on main: the prompt is never called); a report already returned by TaskWait is not replayed on idle. npx vitest run src/runtime.test.ts → 141 passed; tsc --noEmit clean for the package.

…parent idled

resumeAfterDelegations kept the turn open and auto-fed reports only while
delegates of the current turn were still running. A delegate that finished
before the parent went idle, with no TaskWait in between, was settled but
never delivered: runningDelegations() was empty, the resume loop returned,
and the parent continued as if the delegate had produced nothing.

The wait set is now "current turn, report not yet delivered": a new
reportDelivered flag on each record, pendingCurrentTurnDelegations() as the
loop/keep-open condition, and single-shot delivery. TaskWait marks the
settled records it returned as delivered so the idle resume does not repeat
them; still-running records keep their shot, so a timeout or an early
mode "any" convergence does not consume a future auto-resume. Stopped and
aborted runs are not auto-delivered, as before.

Refs vastsa#226
Copilot AI lite review requested due to automatic review settings September 11, 2026 07:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
pi-desktop-docs Skipped Skipped Sep 11, 2026 7:17am UTC

@vastsa
vastsa merged commit d4e44ac into vastsa:main Sep 11, 2026
4 checks passed
@vastsa

vastsa commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Merged PR #228 with the contributor commit preserved. The linked idle-parent race is real: the previous resume path only considered currently running delegates, so a settled same-turn report could be skipped.\n\nFollow-up fix landed locally after the merge in c1d70e2a and was merged into local main as 6c3d5d06. It makes reportDelivered track only report blocks that actually fit in the model-facing bounded TaskWait content; omitted reports remain pending and are delivered once on idle resume.\n\nValidation: fork-head subagent E2E 18/18 passed; follow-up runtime tests 142/142 passed; agent-runtime typecheck passed. Nothing was pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 父代理 idle 时漏掉已完成未回传的子代理报告 / Idle parent misses already-finished undelivered subagent reports

3 participants