📣 Pi agent completion: deliver on the same tick and mark consumed runs - #194
Merged
Conversation
Non-blocking sub-agents that reached terminal status during a polling tick deferred the completion message by one cycle, then relied on a later tick to send it. When the completing run was the last live run, polling stopped after the defer tick so the completion was never delivered — the sub-agent showed "done" without notifying the session. The status notification also fired for runs that avenor_result was already awaiting, producing redundant toasts. Changes: - Send the completion on the same tick it is observed, so last-live runs are no longer stranded. - Suppress the automatic completion once avenor_result has delivered the result: `consumed` is set only on a successful (non-interrupted) result, and re-authorizes delivery if avenor_result is aborted, times out, or still waits. - Replace the defer mechanism (completionPending) with a `consumed` flag and a two-state decideCompletion (`skip` | `send`). - Move the brief status notification inside the delivery path so awaited and consumed runs stay quiet.
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.
Why
The Pi extension's agent-completion notifications were posted in reverse order from intent:
avenor_resultwas already awaiting still fired a brief status notification, and the deferred completion could be sent after the result had been consumed, producing redundant notifications.Changes
avenor_resulthas delivered the result. A newconsumedflag is set only on a successful (result.ready) call; an interrupted call (aborted, timed out, still waiting) leaves it unset so the completion is still delivered later.completionPending) with theconsumedflag and a two-statedecideCompletion(skip|send).waitPollMatchingharness helper so the notification tests no longer rely on timer sleeps.Validation
bun test→ 97 pass, 0 fail (3 new integration tests: last-live-run delivery, awaited/consumed suppression, interrupted-avenor_resultdelivery).bun run build→ tsdown clean.Notes
Removing the defer means a fire-and-forget run that finishes now gets its auto-completion on the next tick; if the caller also pulls
avenor_resultafterwards, that explicit call surfaces the result separately. This is the agreed tradeoff, not a duplicate status notification.