fix(ai-assistant): show activity for an RCA answer written out-of-band - #1636
Draft
ShuhaoZQGG wants to merge 1 commit into
Draft
fix(ai-assistant): show activity for an RCA answer written out-of-band#1636ShuhaoZQGG wants to merge 1 commit into
ShuhaoZQGG wants to merge 1 commit into
Conversation
Opening a detector-flagged trace pre-loads the RCA session, whose answer a worker writes after the chat is already on screen. The chat showed the prompt with no working indicator and never picked the answer up, so it looked idle until the user refreshed the page. The host that owns the opened session (TraceViewerPanel) already polls the run's authoritative status via useRca, so it now mirrors that into the chat as `initialSessionPending`: true drives the working indicator, and the flip to false re-reads the session so the finished answer appears on its own. Kept separate from `isStreaming` so the Stop button — which aborts a live stream — stays hidden for a run the chat is only waiting on. Fixes traceroot-ai#965 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #965
Summary
Opening a detector-flagged trace pre-loads the RCA session, but the answer is written by a worker after the chat is already on screen. The chat showed the prompt with no sign of activity and never picked the answer up, so the panel looked idle until the user refreshed the page.
The host that opens the session (
TraceViewerPanel) already polls the run's authoritative status viauseRca, so it now reports that to the chat asinitialSessionPending. True drives a working indicator; the flip to false re-reads the session so the finished answer appears on its own.Type of Change
Details
Why nothing showed. Normal chat streams to the browser, so
isStreamingcovers it. An RCA answer is generated out-of-band bydetector-rca-processor, and the assistant message isn't persisted until the stream completes — so mid-run the session genuinely contains only the user prompt, and the chat's one-shotGET .../messageshad no reason to look again.What changed.
useAiChatgainsinitialSessionPendingand exposesisLoadingSession. The session-load effect now also runs when that flag changes, which is what makes a worker-written answer appear without a refresh. It clears messages only when the session id itself changes, so a status-driven reload doesn't blank the list.AiAssistantPanelpassessessionStreaming={isStreaming || isLoadingSession}— a widening OR, so the existing streaming path is untouched.TraceViewerPanelmirrorsrcaData.rca.statusinto the flag while its RCA session is the one open, and reports it in the same state update as the session id. Reporting it a render later costs a second fetch of the message list on every open.isStreamingso the Stop button — which aborts a live stream that doesn't exist here — stays hidden.Nothing new polls.
useRcaalready polled this status onmain; this only consumes it.Scope. This covers a trace whose finding and RCA row already exist. A trace opened before detection has run is a separate gap (no finding yet, so no session to indicate on) — addressed in the follow-up PRs.
Screenshots / Recordings (if applicable)
Testing
Automated:
use-ai-chat.test.ts— the indicator holds while the run is pending, then the answer is reloaded on completion; and a session that is already complete on open loads exactly once.TraceViewerPanel.test.tsx— the open path reports a still-generating run in the same update as the session id (verified to fail when that line is removed).Manual. The in-flight window is short — the run finishes in tens of seconds — so the
practical way to see it (and to record it) is to drive the status directly. Local dev
database only, and note the row's original status so you can put it back:
UPDATE detector_rcas SET status='running' WHERE finding_id='<id>';UPDATE detector_rcas SET status='done' WHERE finding_id='<id>';→ within ~3s the spinner clears and the analysis appears.In DevTools, requests to
/ai/sessions/<id>/messages: one on load, one after the flip. Onmainthere is exactly one, ever, and the flip changes nothing.Set the status before the page loads —
doneis terminal, souseRcahas stopped polling and a live page cannot observe a backwards transition.Note what this does and doesn't prove. Forcing
runningon a row that already has aresultis a state the pipeline never produces, so the analysis text is already in themessage list: you're verifying the indicator and the reload, not the answer materializing.
Only a genuinely in-flight run shows that, which is what the recording below captures.
Checklist
Summary by cubic
Shows a working indicator and auto-loads the RCA answer when it’s generated out-of-band, so detector-flagged traces no longer look idle or need a refresh. Fixes #965.
TraceViewerPanelmirrorsuseRcastatus into chat viainitialSessionPending, sent with the session id and kept in sync while open.useAiChataddsinitialSessionPendingandisLoadingSession; reloads messages when pending flips to false; only clears messages on session id changes.AiAssistantPanelshows activity whenisStreaming || isLoadingSession; Stop button stays hidden for non-stream runs.AppLayouttracksaiInitialSessionPendingand resets it on navigation.useRcapolling; no new polling added. Tests cover pending→done reload and already-complete sessions.Written for commit e005b4f. Summary will update on new commits.