fix(nudge): route completion notifications through sendUserMessage to fire before_agent_start#61
Open
anh-chu wants to merge 1 commit into
Conversation
…ming, flush in agent_end
c430c2c to
7afb77e
Compare
williamleong
added a commit
to williamleong/pi-subagents
that referenced
this pull request
May 23, 2026
williamleong
added a commit
to williamleong/pi-subagents
that referenced
this pull request
May 23, 2026
Includes upstream-referenced fixes from tintinweb#47/tintinweb#72, tintinweb#75, tintinweb#68, and tintinweb#61.
williamleong
added a commit
to williamleong/pi-subagents
that referenced
this pull request
May 23, 2026
Merges upstream-referenced fixes from tintinweb#47/tintinweb#72, tintinweb#75, tintinweb#68, and tintinweb#61.
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
sendMessage({ triggerTurn: true })callsagent.prompt()directly on the underlying SDK agent, bypassingAgentSession.prompt()and therefore thebefore_agent_startextension event.Extensions that rely on
before_agent_startfor per-turn setup (for example, injecting billing or auth context into the provider request) will fail to fire when the orchestrator turn is triggered this way. The result is that the provider rejects the turn with an error and the orchestrator goes silent after a background agent completes. The user has to manually type something to recover.This happens in both cases:
sendMessage({ triggerTurn: true })callsagent.prompt()directly, nobefore_agent_start.deliverAs: "followUp"queues a continuation viarunAgentLoopContinue, which also skipsbefore_agent_start.Fix
When the orchestrator is idle, send the notification widget and then call
pi.sendUserMessage(). This goes throughAgentSession.prompt(), which firesbefore_agent_startcorrectly.When the orchestrator is streaming, queue the notification with
deliverAs: "nextTurn"so it is included in the next user-initiated turn, which firesbefore_agent_startnaturally. The pi-subagents widget already provides immediate visual feedback in the streaming case.