Skip to content

fix(ai-assistant): show activity for an RCA answer written out-of-band - #1636

Draft
ShuhaoZQGG wants to merge 1 commit into
traceroot-ai:mainfrom
StarwatchLabs:fix/rca-session-working-indicator
Draft

fix(ai-assistant): show activity for an RCA answer written out-of-band#1636
ShuhaoZQGG wants to merge 1 commit into
traceroot-ai:mainfrom
StarwatchLabs:fix/rca-session-working-indicator

Conversation

@ShuhaoZQGG

@ShuhaoZQGG ShuhaoZQGG commented Jul 29, 2026

Copy link
Copy Markdown

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 via useRca, so it now reports that to the chat as initialSessionPending. True drives a working indicator; the flip to false re-reads the session so the finished answer appears on its own.

Type of Change

  • fix - A bug fix

Details

Why nothing showed. Normal chat streams to the browser, so isStreaming covers it. An RCA answer is generated out-of-band by detector-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-shot GET .../messages had no reason to look again.

What changed.

  • useAiChat gains initialSessionPending and exposes isLoadingSession. 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.
  • AiAssistantPanel passes sessionStreaming={isStreaming || isLoadingSession} — a widening OR, so the existing streaming path is untouched.
  • TraceViewerPanel mirrors rcaData.rca.status into 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.
  • The flag is deliberately separate from isStreaming so the Stop button — which aborts a live stream that doesn't exist here — stays hidden.

Nothing new polls. useRca already polled this status on main; 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:

  1. UPDATE detector_rcas SET status='running' WHERE finding_id='<id>';
  2. Load the trace and open the session via the Alert badge → faint spinner at the bottom of the message list, no Stop button.
  3. 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. On main there is exactly one, ever, and the flip changes nothing.

Set the status before the page loads — done is terminal, so useRca has stopped polling and a live page cannot observe a backwards transition.

Note what this does and doesn't prove. Forcing running on a row that already has a
result is a state the pipeline never produces, so the analysis text is already in the
message 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

  • I have read the CONTRIBUTING.md
  • I have added/updated tests where applicable
  • I have added screenshots or recordings for UI changes (if applicable)
  • I have updated documentation where necessary

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.

  • Bug Fixes
    • TraceViewerPanel mirrors useRca status into chat via initialSessionPending, sent with the session id and kept in sync while open.
    • useAiChat adds initialSessionPending and isLoadingSession; reloads messages when pending flips to false; only clears messages on session id changes.
    • AiAssistantPanel shows activity when isStreaming || isLoadingSession; Stop button stays hidden for non-stream runs.
    • AppLayout tracks aiInitialSessionPending and resets it on navigation.
    • Reuses existing useRca polling; no new polling added. Tests cover pending→done reload and already-complete sessions.

Written for commit e005b4f. Summary will update on new commits.

Review in cubic

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>
@CLAassistant

CLAassistant commented Jul 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants