Skip to content

fix(nudge): route completion notifications through sendUserMessage to fire before_agent_start#61

Open
anh-chu wants to merge 1 commit into
tintinweb:masterfrom
anh-chu:fix/notification-trigger-before-agent-start
Open

fix(nudge): route completion notifications through sendUserMessage to fire before_agent_start#61
anh-chu wants to merge 1 commit into
tintinweb:masterfrom
anh-chu:fix/notification-trigger-before-agent-start

Conversation

@anh-chu

@anh-chu anh-chu commented May 9, 2026

Copy link
Copy Markdown

Problem

sendMessage({ triggerTurn: true }) calls agent.prompt() directly on the underlying SDK agent, bypassing AgentSession.prompt() and therefore the before_agent_start extension event.

Extensions that rely on before_agent_start for 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:

  • Orchestrator idle: sendMessage({ triggerTurn: true }) calls agent.prompt() directly, no before_agent_start.
  • Orchestrator streaming: deliverAs: "followUp" queues a continuation via runAgentLoopContinue, which also skips before_agent_start.

Fix

When the orchestrator is idle, send the notification widget and then call pi.sendUserMessage(). This goes through AgentSession.prompt(), which fires before_agent_start correctly.

When the orchestrator is streaming, queue the notification with deliverAs: "nextTurn" so it is included in the next user-initiated turn, which fires before_agent_start naturally. The pi-subagents widget already provides immediate visual feedback in the streaming case.

@anh-chu anh-chu force-pushed the fix/notification-trigger-before-agent-start branch from c430c2c to 7afb77e Compare May 9, 2026 20:37
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
williamleong added a commit to williamleong/pi-subagents that referenced this pull request May 23, 2026
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.

1 participant