#8598: fix: emit agent events for CLI agents targeting webchat
commands
stale
## Summary
Fixes #8583
CLI agents (e.g., `claude-cli/opus`) running in nested lane with webchat as the delivery channel were only logging output but not broadcasting to webchat clients. This caused blank message bubbles in webchat while the TUI displayed messages correctly.
## Changes
- Import `emitAgentEvent` from `../../infra/agent-events.js` in `delivery.ts`
- After processing payloads for nested lane agents, emit an "assistant" stream agent event when:
- The agent is running in nested lane (`opts.lane === AGENT_LANE_NESTED`)
- The delivery channel is webchat (`isInternalMessageChannel(deliveryChannel)`)
- Both `runId` and `sessionKey` are available
This allows the gateway's chat event handler to pick up the event and broadcast it to webchat clients.
## Test plan
- [x] Added test: emits agent events for nested lane with webchat channel
- [x] Added test: does not emit agent events for nested lane with non-webchat channel
- [x] Added test: does not emit agent events without runId or sessionKey
- [x] Added test: combines multiple payload texts for webchat broadcast
- [x] All existing tests pass
```bash
pnpm vitest run src/commands/agent.delivery.test.ts
# ✓ src/commands/agent.delivery.test.ts (11 tests)
```
🤖 Generated with [Claude Code](https://claude.ai/code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR fixes missing webchat broadcasts for nested-lane CLI agents by emitting an `assistant` agent-event after payload normalization, allowing the gateway chat event handler to relay the combined text to connected webchat clients. It also adds focused unit tests that verify the emit behavior (webchat vs non-webchat, missing identifiers, and multi-payload concatenation).
<h3>Confidence Score: 4/5</h3>
- This PR is likely safe to merge, with one logic guard worth tightening to avoid emitting events for unintended internal channels.
- Changes are small and covered by new tests; main risk is the use of `isInternalMessageChannel(...)` (broader than “webchat”) which could cause unexpected event emission if other internal channels exist.
- src/commands/agent/delivery.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#14309: fix(ui): resolve chat event session key mismatch
by justonlyforyou · 2026-02-11
78.9%
#6611: fix(webchat): persist assistant messages for CLI backends
by JorgeAlan · 2026-02-01
78.9%
#16949: fix(gateway): deliver chat:final even when sessionKey is unresolved (…
by ekleziast · 2026-02-15
78.1%
#12240: fix: suppress heartbeat agent events from webchat broadcast
by Yida-Dev · 2026-02-09
77.7%
#3517: fix: trigger agent response for webchat sessions after restart
by dovewars · 2026-01-28
77.6%
#4495: Fix: emit final assistant event when reply tags hide stream
by ukeate · 2026-01-30
77.5%
#3721: fix(ui): webchat not displaying chat responses
by maxmaxrouge-rgb · 2026-01-29
77.0%
#13720: fix: emit single lifecycle start/end pair for model fallback chain
by gitsual · 2026-02-10
76.6%
#11216: Fix nightly failures: cron webchat delivery result + media cleanup ...
by DeanoC · 2026-02-07
76.6%
#13104: fix: persist user command message in chat transcript
by mcaxtr · 2026-02-10
76.4%