Frun1na opened a new pull request, #4631:
URL: https://github.com/apache/rocketmq-dashboard/pull/4631

   ### Which Issue(s) This PR Fixes
   
   ### Brief Description
   
   `useLlmRuntime.load` has no staleness guard, so a late response can 
repopulate the runtime state after the runtime was disabled:
   
   - `enabled` flipping to `false` (mock mode toggled, or an admin logging out 
into a reader account) clears the state synchronously, but the 
`getLlmConfig`/`getLlmModels` calls already in flight keep going. When they 
resolve, they write `config`, `modelOptions` and `selectedModel` back, and 
`llmReady` comes back `true` — meaning the AI page offers sending on a runtime 
it considers disabled. This directly contradicts the contract documented on the 
hook: *"`enabled === false` ... clears everything and never hits the endpoints 
— the reader-account degradation is 'no configuration visible'"*.
   - Two overlapping `reload()` calls can also finish out of order, leaving 
whichever response landed last — not the newest request.
   
   This PR tracks a monotonic load id (`loadSeqRef`); after every await the 
load checks whether it is still the current one and otherwise drops out, 
mirroring the request-sequence guards used across the other AI page hooks 
(`useConversationTimeline`, `useAgentRun`, the studio pages).
   
   ### How Did You Test This Change?
   
   New test file `web/src/pages/ai/hooks/useLlmRuntime.test.ts` (none existed 
for this hook):
   
   - `a late response for a disabled runtime never repopulates the state` — 
fails on the unfixed code (config/selectedModel/llmReady repopulated after the 
toggle), passes with the fix.
   - `keeps the last request winning when reload overlaps` — pins the 
overlapping-reload behavior.
   
   ```
   $ cd web
   $ npx vitest run src/pages/ai
    Test Files  17 passed (17)
         Tests  180 passed (180)
   $ npx tsc --noEmit            # exit 0
   $ npx eslint src/pages/ai/hooks/useLlmRuntime.ts 
src/pages/ai/hooks/useLlmRuntime.test.ts   # exit 0
   ```
   
   ### Checklist
   
   - [x] Follows the existing request-sequence guard conventions of the 
surrounding code
   - [x] Regression test added; fails before the fix
   - [x] `tsc`, `eslint` and the full AI page test suite pass locally
   


-- 
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]

Reply via email to