← Back to PRs

#22245: Fix responsePrefix correctness on failover + prevent duplicate prefixes

by Monkey-D-Luisi open 2026-02-20 22:58 View on GitHub →
app: web-ui gateway size: S
## Summary - **Duplicate prefix after failover (all dispatcher channels)**: `normalizeReplyPayload` prepend-only guard (`!text.startsWith(effectivePrefix)`) failed when the model changed between block and final replies, causing `[old] [new] msg`. Fixed by tracking `lastAppliedPrefix` in the dispatcher and stripping the old prefix before applying the new one, with whitespace boundary check to prevent false substring matches. - **Webchat streaming deltas missing prefix**: `emitChatDelta` broadcast raw buffer text without prefix; only `emitChatFinal` applied it. Fixed by prepending the resolved prefix in delta broadcasts (buffer stays raw for the definitive final). ## Test plan - [x] 5 unit tests in `reply-utils.test.ts` (strip-then-replace, no-strip-when-undefined, idempotency, whitespace-terminated prefix, substring edge case) - [ ] Telegram `streamMode: "partial"` with forced failover: verify single prefix `[fallback]` instead of `[primary] [fallback]` - [ ] Webchat with forced failover: verify streaming deltas and final both show fallback model prefix - [ ] No-failover regression: verify prefix behavior unchanged when primary model succeeds 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Most Similar PRs