Now I fully understand the issue. Let me summarize my analysis.
Analysis Summary
Issue
Extensions receive agent_start events before the UI creates the loadingAnimation component, causing setWorkingMessage() calls in agent_start handlers to silently fail (since it checks if (this.loadingAnimation) which is undefined at that point).
Root Cause
The issue report's analysis is correct. In agent-session.ts, the _handleAgentEvent method processes events in this order:
The _emit(event) triggers the UI's handleEvent method in interactive-mode.ts, which creates loadingAnimation on agent_start:
But by the time the UI creates loadingAnimation, the extension's agent_start handler has already run and called setWorkingMessage(), which was a no-op because loadingAnimation was still undefined:
Proposed Fix
There are two clean approaches:
Option A: Queue the message if loadingAnimation doesn't exist yet
In interactive-mode.ts, store a pending working message and apply it when loadingAnimation is created:
Option B: Emit UI event before extension event for agent_start
In agent-session.ts, swap the order specifically for agent_start events so UI creates the loader before extensions run:
Recommendation
Option A is preferred because:
- It's more surgical and doesn't change event ordering semantics
- It handles edge cases like multiple
setWorkingMessage calls before the loader exists
- It's isolated to the UI code, not affecting the core event flow
Affected Files
packages/coding-agent/src/modes/interactive/interactive-mode.ts