Skip to content

Smooth answer flow: real analysis stages and a calm arrival - #28

Merged
gaffercode merged 2 commits into
mainfrom
claude/project-thread-ig9kgr
Nov 26, 2026
Merged

gaffercode merged 2 commits into
mainfrom
claude/project-thread-ig9kgr

Conversation

@gaffercode

Copy link
Copy Markdown
Owner

Requested by Gafferness · project thread

Status: REVIEW. Gaffer approved the approach on 2026-11-26 ("A + B: tahap nyata + reveal halus"). Audit with evidence: https://claude.ai/artifact/6GnsdsmB5idFhLu4CCp7NT

Why

Before this change the doctor waited up to 65 s behind a single "Menunggu jawaban AADI" line, even though the gateway already times five real stages. When the answer arrived, the chat column snapped from about 980 px to 533 px in a single frame. The section reveal also skipped AADI analyses, because the CSS selector targeted the wrong container. On phones the view jumped to the bottom of the answer, so the doctor started reading in the middle.

Model text is not streamed, on purpose. The engine returns one structured result. The gateway validates it and runs the dose evidence gate, and the browser runs the gate again. Streaming the text would show doses that have not passed the gate yet.

Commit 1: fix(ui): let an analysis arrive smoothly (client only)

  • The cascade now covers .analysis-document > *: each block fades in over 480 ms, 60 ms apart, capped at the eighth block. All content is in the DOM from the first frame.
  • Arrival now runs inside smooth(update, "arrive"), a named view transition. The chat column, composer and header tools glide to their new size over 280 ms, with snapshots pinned to the top left so text is never stretched.
  • A fresh answer scrolls to its own top. Opening an encounter or sending a question still scrolls to the bottom.
  • The wait dot pulses softly. Dead typing keyframes and comments are removed.

Commit 2: feat(aadi): show the analysis's real stages while it runs

  • Opt-in through Accept: application/x-ndjson. /api/aadi streams {"type":"stage","stage","state"} lines for retrieve_dx, aadi_dx, retrieve_tx, aadi_tx and gate. The last line is {"type":"final","status","body"}, carrying exactly the reply the plain JSON request would have returned.
  • Stage lines carry no case text, output, cost, codes or timings. The final body is validated and gated exactly as before.
  • Requests without the header are unchanged. The client falls back to plain JSON when the gateway does not stream.
  • The wait card lists only the stages the gateway actually reported.
  • Docs: docs/aadi-integration.md gains an "Analysis progress" section, and docs/sentrapedia-ui.md is updated.

Verification

  • tsc --noEmit is clean. ESLint reports 0 errors; its 3 warnings are pre-existing and in untouched files.
  • vitest run: 90 files, 888 passed, 0 failed. New tests: tests/aadi-stage-stream.test.ts, tests/ui/answer-arrival.test.tsx, plus stage cases added to tests/ui/thinking-card.test.tsx.
  • Ran Playwright against the dev server with a fixture reply and a simulated stream at 1440 and 390 px:
    • The stages appeared progressively.
    • The sections rose in over about 0.6 s.
    • Mid-transition screenshots show the glide.
    • With reduced motion, everything appeared at once.
    • On phones the answer now starts at its top.
  • CLS is not lower, because opening the pane is an intended layout change that the metric still counts. The change is in how that layout change is drawn on screen.

Not verified

  • Whether Cloudflare Access in front of the beta server passes the stream through unbuffered. If it buffers, the stages arrive together with the answer and the card behaves as it did before this change.
  • Real AADI stage latency, which needs the engine and the private index.
  • View transitions in Safari and Firefox. Browsers without support fall back to the earlier instant change.

Porting

The public repo is regenerated from the private monorepo by export-split. Both commits must be applied there as well.


Generated by Claude Code

- The fresh-answer reveal now covers an AADI analysis's sections
  (.analysis-document > *), not only a template's lines; 60 ms apart,
  capped at the eighth block, fixed nth-child delays instead of
  sibling-index().
- The answer's arrival (wait card out, answer and document pane in) runs
  in one named view transition: chat column, composer and header tools
  glide to their new width instead of snapping. CLS is unchanged because
  the layout change is intended; what changes is how it is drawn.
- A fresh answer is scrolled to its top, so on a phone its first lines
  are no longer cut off; opened encounters and new questions still go to
  the bottom.
- Soft pulse for the wait dot; removed keyframes and comments left from
  the old typing reveal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ta9C8RaPJ5eAJ3QcD1cHP
The wait card no longer shows one generic line for up to 65 s. When the
workspace asks for it (Accept: application/x-ndjson), POST /api/aadi
streams one line per gateway stage start and end (retrieve_dx, aadi_dx,
retrieve_tx, aadi_tx, gate), then the exact reply (status and body) as
its last line. Stage lines carry a stage name and state only: no case
text, model output, cost, codes or timings. The answer is still sent
once, validated and dose-gated exactly as before; model text is not
streamed, because streamed text would show ungated doses.

Without the header the route is unchanged, and the client falls back to
plain JSON when a gateway does not stream. The wait card lists only the
stages the gateway reported.

Not verified here: that Cloudflare Access in front of the beta server
passes lines through unbuffered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ta9C8RaPJ5eAJ3QcD1cHP
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentrapedia Ready Ready Preview Nov 26, 2026 10:00pm UTC

Request Review

@gaffercode gaffercode self-assigned this Nov 26, 2026
@gaffercode
gaffercode marked this pull request as ready for review November 26, 2026 22:19
@gaffercode
gaffercode merged commit 2aa9723 into main Nov 26, 2026
4 checks passed
@gaffercode
gaffercode deleted the claude/project-thread-ig9kgr branch November 26, 2026 22:19
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