~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

Shell test: a back supersedes the shell's move still settling

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:web/story-url-flake

The shell's server test (web/shell/test/ssr.mjs, CI's web check) failed now and then on a busy machine at "a story's URL: never: back from the story linked", as on A record with no facets has its links, mentions and tags found at both its heads. The fault was the test's fake history, not the shell: a move of the shell's still settling as the test pressed back set its state over the entry gone back to, which a browser's router never does. Under load the test failed 5 of 48 full runs before, 0 of 144 after.

Claude Opus 5.5 · high

What changes

The test's history (web/shell/test/history.svelte.ts): the browser's back or forward (History.go) now comes after a move of the shell's still settling, as a browser's does: that move, once it settles, no longer sets here, so here is always the state of the entry the browser went to. Nothing the shell does changes, so no change file.

Why

A story opened from a link is two moves: the push that opens the viewer, then, as its Slides draws the story, the Pager telling it (onat), an entry in place of that one with the story shown. The fake makes an entry a microtask after it is asked for and sets here a timer later. The test polls every 20 ms and presses back once the story is drawn and the URL is its. On a busy machine its poll's timer and the fake's settle timer come due in the same turn, the poll's first, so back landed between the in-place entry and its here: the fake then set here to the story's state with the history at /, and the shell, as it must for an entry come to, opened the viewer again, and the wait never saw it close. Every failure caught had that state: at /, here the story's. The step before it, back after Next on a story opened from the strip ("the browser's back left the viewer"), fails the same way, less often.

In a browser this order cannot happen: Grain's host goes by SvelteKit 3.4's shallow goto, which makes the entry (history.replaceState) and sets page.state in the same task, with only microtasks between (resolve_intent, the onNavigate callbacks, of which Grain has none), and a back is a popstate task of its own, after it. So the shell's back from a story, opened by a link or loaded at its URL, does land; it was the fake that did not hold to that.

Considered instead: waiting in the test for each move to settle before each back (two steps patched, and every back written later needing it too); and leaving out the shell's in-place entry where the story shown is the one the viewer opened at (its URL the same), which changes the shell to suit a fake, and Next still makes one.

How it was checked

On an 8-core Mac under load (16 copies at once beside 8 to 16 yes):

  • The whole shell test (node shell/test/ssr.mjs), 16 at once: before, 5 of 48 failed, each at "back from the story linked"; after, 0 of 144.
  • A scratch harness (not committed) building the shell once and running the story's block 50 times, 16 at once: before, 13 of 800 failed (9 at "back from the story linked", 4 at "the browser's back left the viewer"); after, 0 of 800.
  • Back pressed in that window on purpose (polling by setImmediate until the in-place entry is made and its here is not set): before, 20 of 20 failed; after, 0 of 20.
  • npm run check, npm run ssr and npm run unit pass. The rest is CI's.

Shortcomings

A host whose router sets its state a task or more after the entry (SvelteKit with an onNavigate that waits, as for a view transition) could set a story's state after a back from it, and the shell would open the viewer again: it cannot tell that late state from an entry come to. Grain has no such onNavigate.

Approved

This makes the test's fake History behave as a browser's router does. go() now counts each back or forward. A move still settling when the browser goes back or forward no longer sets here over the entry gone to. That removes the stale-here state you traced to the "back from the story linked" failures.

I read only the diff, web/shell/test/history.svelte.ts and the repository's AGENTS.md. I did not run the test or read any check results.

  • Counter timing: went is read after the entry is made and just before the settle timer starts. A back pressed any time after that point suppresses the stale here.
  • Later moves: a move started after a back captures the new count, so it still sets here normally.
  • Change file: skipping one is right, since only test code changes and no app built on HUD sees it.
Merged as 31425ed