Skip to content

fix(ui-kit): end the ghost handoff on its fades' own end (#3425) - #4065

Merged
schlessera merged 5 commits into
mainfrom
fix/3425-ghost-fade-animationend
Nov 16, 2026
Merged

schlessera merged 5 commits into
mainfrom
fix/3425-ghost-fade-animationend

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3425

What changed

The loading ghost's handoff now ends when the item's own fades end, not on a 600 ms timer started at the arrival commit. useArrival(loading, frame) takes the item's root element. After the commit it collects that frame's running ghost-in/ghost-out CSS animations and ends the handoff when they have all finished (a cancelled fade counts as finished). Where no fade runs, it keeps the HANDOFF_MS timer: reduced motion's 0s fades, animation: none, or a DOM without Web Animations (happy-dom). If no fade has started FIRST_FRAME_MS (3 s) after the commit, the document is rendering no frames and the handoff ends then. All six consumers pass their root as the frame: ActionCard, FileRow, QueueItemRow, SearchResultCard, Placeholder and StreamingAnswer. Together they cover every bk-ghost-out site, including Ghosted and GhostBand. The 600 ms fade, its easing and its keyframes are unchanged.

Why this shape

useArrival returned a boolean and owned no element, so it could not see a fade. I passed the frame as a ref rather than threading an onAnimationEnd callback through every Ghosted/GhostBand slot. That is one ref per consumer instead of a prop at roughly twenty call sites, and it keeps arriving a plain boolean. Waiting on Animation.finished rather than listening for animationend handles several slots and a cancelled layer in one place. The fade-or-timer decision comes from getAnimations() at commit, which already forces the style flush that creates the animations.

The hook waits on ghost-in as well as ghost-out. Both start in the same frame with the same 600 ms length, so in production this changes nothing. It does mean the incoming text is never cut mid-fade either. It also gives the negative controls a way to hold the ghost past its fade without touching the component, now that the timer they used to stretch is gone.

The fix is also a small change in the unloaded case. On main the ghost was always removed a frame or more before its fade ended, because the timer starts at the commit and the fade on the next frame. The existing harness comment said as much ("normally the ghost is removed before its fade ends at all").

Docs: a D53 addendum in docs/decisions/design-kit/loading.md, the ghost-handoff section of docs/process/test-waits.md (its useArrival citation is updated), and tests/visual/README.md.

Proof

bun run check:pr --base origin/main          # passed, receipt below
tsc --noEmit                                 # clean
bun run test packages/ui-kit/tests/ghost-text.test.tsx   # 54 pass
# real Chromium (Playwright chromium-1243 on the host), visual project:
vitest run --project=visual tests/visual/ghost-handoff.visual.tsx tests/visual/streaming-handoff.visual.tsx tests/visual/ghost-media.visual.tsx   # 23 passed
# LoadingToReady and Arrived stories, both theme projects:
vitest run --project=storybook --project=storybook-light stories/{decisions/ActionCard,rows/FileRow,rows/QueueItemRow,evidence/SearchResultCard,conversation/StreamingAnswer,states/Placeholder}.stories.tsx   # 154 + 34 passed

Harness. watchHandoff (stories/_handoff-clock.ts) now records fadeEnded: a ghost-out animationend arrived before removal. playHandoff and playStreamingHandoff assert it for every frame, so every LoadingToReady story checks that the ghost reached opacity 0 before it went. The #3777 frame-clock mid-fade sample, the geometry checks and the #3417 three-frame allowance are unchanged.

New control (ghost-handoff.visual.tsx and streaming-handoff.visual.tsx, both themes): a 300 ms synchronous long task right after the arrival commit, so the fades start late.

Failing first. This branch's tests were run with only packages/ui-kit/src reverted to origin/main. 13 of 15 handoff tests failed. The new controls failed at 320px: the outgoing ghost's fade ended before its removal: expected false to be true, and the streaming control at the outgoing ghost's fade ended before its removal. The unloaded input-orchestration and stall cases failed on the same assertion, because main cuts every fade short.

Mutations (each restored, then the file re-run green):

  1. In the fade path, also end at setTimeout(end, HANDOFF_MS). All four long-task controls fail at …fade ended before its removal: expected false to be true.
  2. Drop the duration > 0 filter, so the 0s fade under reduced motion is waited on. reduced motion: the handoff is instant, and ends after HANDOFF_MS fails at the outgoing ghost is laid over the arriving content: expected null not to be null: the ghost is gone before HANDOFF_MS. An earlier playState !== "finished" clause was redundant (Chrome reports a pending 0s animation as finished) and was removed, so this filter alone carries the claim.
  3. Make the no-fade timer a no-op. Both the reduced-motion and animation: none tests fail: the ghost is never removed.
  4. Remove the no-frame fallback. The unit test a fade that never starts — no rendered frames — ends the handoff after FIRST_FRAME_MS fails at FRAMELESS_DOCUMENT_ENDS.

Reduced motion and animation: none (ghost-media.visual.tsx, emulated media in Chromium): each test arrives once more, asserts the ghost is still present, waits for its removal, and asserts that a 600 ms timer was registered and no 3 s first-frame wait was. Unit tests with stand-in fades cover the timing logic: no 600 ms timer while a fade runs, a fade that started late still runs, removal on the fade's end, the no-frame fallback, and a 0s fade taking the timer.

Under CPU starvation (20 busy loops on 16 cores, load average about 30): five runs of the three visual files passed 23/23 four times. In run 3, the 720px held 200ms past its fade negative control did not reject: under that load a 200 ms hold renders as few as three frames, inside the allowance. A focused comparison of that control alone gave 5 of 8 non-rejections on this branch at 200 ms and 1 of 8 on origin/main. Both controls now hold the ghost 400 ms past its fade, and they rejected in 12 of 12 runs under the same load. The positive tests, including the new long-task controls, passed in every loaded run.

Descriptor hygiene pin. tests/dom-global-restoration.test.ts runs the ordered ghost suite under native, absent and readonly global descriptors, and pins its pass count. The three new arrival tests raise that count from 63 to 66. Candidate confirmation failed on the old pin (expected 63 pass, received 66 pass) in unit (3). The stand-in fades override getAnimations on one DOM node only, never a global, and the descriptor receipts stayed equal. After the pin change, that test and ghost-text.test.tsx pass (57), and tsc --noEmit is clean at 441d940e6 (merged with main e19300f12).

Environment-only failures. The first check:pr run, under that load, failed 11 tests in tests/ci-runner.test.ts, tests/ci-workflows.test.ts, tests/contract-gate.test.ts and tests/diagram-export-source.test.ts. All four files pass on an unmodified origin/main worktree and on this branch run directly (124 pass), and the rerun below passed.

Collisions (bun scripts/collisions.ts --json --pr 4065 at head 05a1252f2): no path or unknown reports. Only closure overlaps through shared test closures, with #3054, #3056, #3059, #3069, #3581, #3622, #3806, #4002, #4018, #4028, #4034–#4038, #4040–#4042, #4046, #4050–#4053, #4055–#4058, #4060, #4062 and #4064.

{"version":1,"kind":"brain-check-pr-receipt","head":"441d940e69347f03d0cd444047dfdb5f8321d1c7","base":"origin/main","mode":"focused","startedAt":"2026-11-16T11:05:39.037Z","finishedAt":"2026-11-16T11:06:50.271Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":13007.189888},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":114.0744709999999},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":84.52383499999996},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":18.975501000000804},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":57992.678231000005}]}

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof.
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only (docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.

Anything left open

The native runs above used the host's Playwright Chromium (chromium-1243), not the pinned mcr.microsoft.com/playwright:v1.63.0-noble image. The pinned-image browser and story proof runs on the squash's main run under the hybrid ruling. Nothing else.

🤖 Generated with Claude Code

schlessera and others added 2 commits November 15, 2026 21:29
The arrival handoff ended on a 600ms timer started at the commit, while the
fades start on the first frame rendered after it. A late first frame (a loaded
runner, a long task right after the commit) let the timer remove the ghost
part-way through its fade; even unloaded it cut the fade a frame short.

useArrival now takes the item's frame and waits for that frame's running
ghost-in/ghost-out animations to finish. Where no fade runs (reduced motion's
0s, animation: none, no Web Animations) it keeps the HANDOFF_MS timer, and a
fade that has not started FIRST_FRAME_MS after the commit (a document that
renders no frames) ends the handoff then.

The handoff clock now records whether the fade ended before removal, and the
stories assert it. New Chromium controls stall the main thread right after the
arrival commit; the 200ms-hold controls hold the incoming fade instead of the
retired timer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ntrols (#3425)

A CPU-starved browser renders a 200ms hold in as few as three frames, inside
the three-frame allowance, so the negative controls stopped rejecting under
load once the hold moved from the retired timer onto the incoming fade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: ui-kit The presentational design kit: components, tokens, Storybook, visual baselines. labels Nov 15, 2026
@uploads-sh

uploads-sh Bot commented Nov 15, 2026

Copy link
Copy Markdown

No uploads on this PR yet

This PR changes UI files (packages/ui-kit/src/conversation/StreamingAnswer.tsx, packages/ui-kit/src/decisions/ActionCard.tsx, packages/ui-kit/src/evidence/SearchResultCard.tsx and 11 more). Screenshots help reviewers see what changed.

  • From the CLI: uploads put before.png after.png --pr 4065
  • From an agent: ask it to attach screenshots with uploads.sh
  • By hand: drag images into the PR description and they're imported automatically
Tips for agents

Label each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one put per shot:

uploads put after.png --pr 4065 --meta path=/settings --state after --caption "Saved settings toast"
uploads put chat.png --pr 4065 --app ios --screen "Chat" --state after

No CLI? With the Uploads MCP, call sign_upload_url for files on disk (or put) with repo, pr: 4065 and the same screen, state and caption fields.

This comment updates with each upload, so you don't need to post the images yourself. A shot or two in the PR description is still welcome. Check what's attached with uploads list --pr 4065. More in the github-screenshots skill or the agent docs.

Workspace admins can turn this comment off in Settings → GitHub · docs

@schlessera
schlessera marked this pull request as ready for review November 16, 2026 10:36
schlessera and others added 2 commits November 16, 2026 11:05
@schlessera
schlessera marked this pull request as draft November 16, 2026 11:36
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 11:36
@schlessera
schlessera merged commit e66cf4c into main Nov 16, 2026
49 of 52 checks passed
@github-actions

Copy link
Copy Markdown

This PR's squash e66cf4c8f9d7d6b3085361902a90f8f2bda827ea landed on main while main was red at 132505f0bdacd8a69748efce2ff572cbe763e2e7 (incident #4081) without being a declared fix. Merge blocking while red is cooperative; this report is the detection.

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

Labels

area: ui-kit The presentational design kit: components, tokens, Storybook, visual baselines. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-kit: the arrival timer cuts the ghost's fade short when its first frame is late

1 participant