← Back to PRs

#4495: Fix: emit final assistant event when reply tags hide stream

by ukeate open 2026-01-30 08:23 View on GitHub →
app: macos scripts agents
## Problem When reply_to tags appear mid-stream, cleaned text can rewind and onAgentEvent never emits the final assistant text. TUI then shows no realtime reply until reconnect/history refresh. ## Fix Emit a final assistant event on message_end when the final cleaned text differs from the last streamed text. ## Testing - pnpm vitest src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.subscribeembeddedpisession.test.ts - CI: full matrix on this PR ## AI-assisted - AI-assisted: Yes (OpenAI Codex) - Testing level: lightly tested locally + CI - Prompt summary: Fix TUI realtime reply missing when reply_to tags hide stream; ensure final assistant event is emitted on message_end. - Understanding: This change compares the final cleaned text against the last streamed text and emits a final assistant event so UI consumers receive the complete reply after reply tag stripping. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes a TUI streaming edge case where `[[reply_to: …]]` directives can cause the cleaned/visible assistant text to “rewind” mid-stream and prevent downstream consumers from ever receiving the final visible assistant message. The implementation adds a `message_end` fallback in `src/agents/pi-embedded-subscribe.handlers.messages.ts` to emit one last assistant agent event when the final cleaned text differs from what was last streamed, and adds a regression test covering the reply-tag-hidden scenario. The changelog is updated to reflect the user-facing TUI behavior change. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge and addresses a real streaming/UI edge case with limited surface area. - Changes are localized and add a targeted regression test. Main remaining risk is subtle normalization differences between streaming vs final parsing that could cause an extra final event (or miss one) in some whitespace/directive-boundary scenarios; no evidence of broader behavioral breakage beyond event emission timing. - src/agents/pi-embedded-subscribe.handlers.messages.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> **Context used:** - Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8)) - Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13)) <!-- /greptile_comment -->

Most Similar PRs