yyqdbngt opened a new pull request, #5328:
URL: https://github.com/apache/rocketmq-dashboard/pull/5328
### Which Issue(s) This PR Fixes
- Fixes #5288
### Brief Description
`finishStream` in `web/src/pages/ai/hooks/useAgentRun.ts` cleared the
optimistic question bubble
unconditionally as soon as the end-of-run timeline refetch succeeded
(`setPendingUserMessage(null)`).
When the run was never admitted server-side — the POST is refused
(`connection refused`) or 409s
because another tab holds the run — no `run_started` frame ever arrives and
nothing is persisted, so
the refetched transcript has no user row to replace the optimistic one: the
operator's own question
vanished from the screen and only the error banner remained.
The hook now records whether the run behind the in-flight stream was
admitted, using the only two
pieces of evidence it has: the `run_started` frame for a run it started
itself, and the run id
`attach` was handed for a run that is admitted by definition. The optimistic
bubble is dropped only
when the stream did not fail, or when the failure came after admission — so
an admitted run still
hands the question over to its persisted row exactly once, and a
never-admitted run keeps showing
what was asked.
`web/src/pages/ai/hooks/useAgentRun.test.ts` gains two regression cases: the
never-admitted failure
(fails on the unmodified tree) and the admitted-then-failed case that pins
the no-duplicate
behaviour.
### How Did You Test This Change?
Red — the new cases, written and run first, with `useAgentRun.ts` still
unmodified:
```
$ cd web && npx vitest run src/pages/ai/hooks/useAgentRun.test.ts
❯ src/pages/ai/hooks/useAgentRun.test.ts (18 tests | 1 failed) 701ms
× keepsThePendingQuestionWhenTheStreamFailsBeforeAdmissionTest 48ms
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL src/pages/ai/hooks/useAgentRun.test.ts > useAgentRun >
keepsThePendingQuestionWhenTheStreamFailsBeforeAdmissionTest
AssertionError: expected null to be '这个问题还会在吗' // Object.is equality
- Expected:
"这个问题还会在吗"
+ Received:
null
❯ src/pages/ai/hooks/useAgentRun.test.ts:364:47
Test Files 1 failed (1)
Tests 1 failed | 17 passed (18)
```
Green — the same file after the fix, and the whole hooks directory (holds
the timeline tests too):
```
$ cd web && npx vitest run src/pages/ai/hooks/useAgentRun.test.ts
Test Files 1 passed (1)
Tests 18 passed (18)
$ cd web && npx vitest run src/pages/ai/hooks
Test Files 6 passed (6)
Tests 38 passed (38)
```
Also run for the two touched files: `npx tsc -b` (exit 0) and
`npx eslint src/pages/ai/hooks/useAgentRun.ts
src/pages/ai/hooks/useAgentRun.test.ts` (exit 0).
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits
- [x] Tests added or updated for non-trivial changes
- [x] New UI text has both Chinese and English entries under `web/src/i18n/`
— not applicable: no
user-facing string is added; the bubble reuses the text already on
screen.
- [x] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks) — not applicable:
the change is web-only and touches no Java module.
- [x] New source files carry the ASF license header — no new file; both
touched files keep their
existing header.
- [x] Documentation touched where behaviour changed (README / `docs/` /
in-app help) — not
applicable: the hook's own docstring for `pendingUserMessage` still
describes the behaviour
and the fix keeps that contract, now also on the failure path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]