fix(gemini): clear activeMsgIdRef on stop to prevent message filtering bug#1354
Conversation
…g bug When clicking the stop button, the activeMsgIdRef was not being cleared. This caused subsequent messages to have their events incorrectly filtered because the ref still held the old message ID from the stopped request. Fixes iOfficeAI#1303
Code Review:fix(gemini): clear activeMsgIdRef on stop to prevent message filtering bug (#1354)变更概述此 PR 仅修改 方案评估结论:✅ 方案合理
问题清单🔵 LOW —
|
| # | 严重级别 | 文件 | 问题 |
|---|---|---|---|
| 1 | 🔵 LOW | GeminiSendBox.tsx:385 |
resetState 未同步更新 waitingResponseRef.current(已有缺陷,本 PR 更加凸显) |
| 2 | 🔵 LOW | (无测试文件) | 缺少 activeMsgIdRef 清空逻辑的回归测试 |
结论
resetState 中补齐 waitingResponseRef.current = false 并补充测试用例。
本报告由本地 /pr-review 命令生成,包含完整项目上下文,无截断限制。
… tests
- Add `waitingResponseRef.current = false` inside `resetState` to keep the
ref in sync with the state update. Previously only `setWaitingResponse(false)`
was called (async React update), leaving the ref stale until the next render.
Every other write-site for waitingResponse already performs the double-write.
- Export `useGeminiMessage` so it can be unit-tested in isolation.
- Add three regression tests in `tests/unit/useGeminiMessage.dom.test.ts`:
1. resetState() resets `running` to false
2. resetState() clears activeMsgIdRef so thought events from new messages
are no longer filtered
3. Full lifecycle: old request → resetState → new request → correct filtering
- Include GeminiSendBox.tsx in vitest coverage tracking.
Follow-up to #1354
When clicking the stop button during a CLI conversation, the \ was not being reset. This caused subsequent messages to have their events incorrectly filtered because the ref still held the old message ID from the stopped request.
The bug manifested as the AI continuing to respond to the previous (stopped) question instead of the new one, because stream events for the new message were being filtered out.
Fixes #1303