Conversation
…spam
While a goal is active, agent_end unconditionally queues a continuation
turn. When the only correct action is to end the turn and passively wait
for an external wake (e.g. a background task terminal notification), this
creates a no-op loop: the agent replies 'still waiting', agent_end fires,
a new continuation turn starts ~5s later, forever. Observed in practice:
383 continuation events at ~5s intervals burning API calls.
- add a 'waiting' goal status, set by the model via
update_goal({ status: 'waiting' })
- agent_end does not queue a continuation while waiting
- any externally triggered turn (user message or event notification)
auto-resumes the goal to active at turn_start
- the continuation prompt teaches the model to mark waiting instead of
replying with no-op status messages
waiting is a scheduling hint, not lifecycle control: pause, resume,
clear, and budget limiting remain user/runtime-owned. The final turn is
still accounted while waiting; budget_limited still flips on the next
active turn_end.
hieusats
force-pushed
the
fix/goal-waiting-status
branch
from
August 27, 2026 15:10
1c98bb9 to
c5824fe
Compare
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
While a goal is
active,agent_endunconditionally queues a continuation turn. When the only correct action is to end the turn and passively wait for an external wake — exactly what pi advises for background task notifications — this creates an infinite no-op loop:Observed in a real session: 383 continuation events at ~5 second intervals, each one a paid API call, for as long as the background task ran. The agent behaved correctly (no polling); the extension punished that behavior. Worse, because the wake notification arrives as a pending message and then the loop resumes, every external event adds another no-op cycle.
There is currently no way for the model to declare "I am blocked on an external event — do not re-trigger me".
Fix
waitinggoal status, set by the model viaupdate_goal({ status: "waiting" })agent_enddoes not queue a continuation whilewaitingactiveatturn_start, so normal continuation resumes after the wakewaitinginstead of replying with no-op status messagesstatusLine/ event labels cover the new status; README documents itContract note
waitingis a scheduling hint, not lifecycle control: pause, resume, clear, and budget limiting remain user/runtime-owned. Thesource-contracttest is updated to pin the new schema (enum: ["complete", "waiting"]) while keeping the "no pause/resume/abandon/budget-limit via update_goal" assertion. Usage is still accounted on waiting turns, andbudget_limitedstill flips on the next activeturn_end.Tests
test/agent-loop.test.cjs: runtime harness driving the real extension code through jiti with mockedExtensionAPI/ExtensionContext— asserts exactly-one continuation while active, zero continuation while waiting, auto-resume on the next turn, continuation resuming after the wake, idempotentwaiting, rejection of lifecycle statuses, and usage accounting during waitingtest/goal-state.test.cjs:statusLine+goalEventStatuscases forwaitingtest/source-contract.test.cjs: updatedupdate_goalschema contractnpm test→ 28/28 pass;npm run checkpasses