Public: anyone can read this; the crew can change it.

A forge boots in the browser tab: wasm SQLite on OPFS and a service worker as its server #17148

opened this

Merged 26h 20m ago, live in production

A forge now starts in a browser tab at /tab. I could not run it in a real browser here, so the OPFS and service-worker half is untested. The tab test passes, as do tsc, design-lint, the gate and the cross files named in CLAUDE.md.

Notes

opened this

A forge now starts in a browser tab at /tab. I could not run it in a real browser here, so the OPFS and service-worker half is untested. The tab test passes, as do tsc, design-lint, the gate and the cross files named in CLAUDE.md. I did not run the full suite.

What it does

  • Start: /tab is server-rendered and states three facts. It lives on this device, it stops when the tab closes, and others cannot reach it. A Start it button then starts the forge.
  • Database: a dedicated worker opens vendored SQLite wasm on OPFS (src/tab/worker.ts).
  • Server: a service worker answers /tab/f/* (src/tab/sw.ts). Home, the issue list, one issue and opening an issue work (src/tab/forge.ts).
  • Forge shown in the page: the page holds the database worker and the service worker relays requests to it. The forge appears in a frame on the same page, so closing the tab stops it. With the page gone, the service worker answers "stopped".
  • Cost: everything the serving forge sends is static. That is the page, the two bundled workers, a stylesheet, and the SQLite wasm at an immutable hashed path under /tab/v/<hash>/.
  • Security: the in-tab forge's input is length-checked and its output escaped. Service-worker POSTs check the origin and a size cap. Each response sets its own CSP.
  • Terminal door: the palette entry "A forge in a browser tab" says the same words as the page (src/tab/words.ts). The how-to is docs/features/tab.md.

Things you may not expect

  • Vendored SQLite (instead of an npm dependency): @sqlite.org/[email protected] is copied unmodified into src/web/vendor/sqlite-wasm/, so package.json stays empty. I used the opfs-sahpool VFS, so no COOP/COEP headers are needed.
  • Gate fix: the "both doors" gate only read src/tui, but palette entries are opened through src/generated/screens.ts, so a new screen could never pass. scripts/gate.ts now reads that directory too.
  • Footer link: a footer link "In a tab" on every page keeps /tab from being flagged as an orphan screen, and tab joins the reserved names.
  • Style: one new class, .tab-frame (documented in docs/design/areas/tab.md).

Tests (test/tab.test.ts)

  • The same routes run over bun:sqlite and over the vendored wasm SQLite, loaded as the worker loads it but on an in-memory file, because bun has no OPFS.
  • The page's facts match the terminal's.
  • The worker, service worker and wasm are served with the right headers.

Not done

  • No headless-browser test of OPFS or the service worker. This sandbox has no automation driver, so that path was never run end to end.
  • No git, shell or installs; those wait on #16837.
  • No sign-in or multi-user, and no issue editing or comments.

Reused: bundleEntry, staticResponse, pageHead and rowList/row.

Try it: open /tab on the preview, press Start it, open an issue, reload and confirm it is still there, then close the tab and reopen /tab/f/ to see "stopped".

[
  {"go": "/tab", "look": "three plain facts, a Start it button, 'Not started.'", "expect": "says it lives on this device, stops when the tab closes, others cannot reach it"},
  {"go": "/tab", "look": "press Start it, then open an issue in the frame", "expect": "status reads 'Running in this tab.'; the issue lists and survives a reload of /tab", "ask": "does it start in your browser?"}
]

Try: open /tab on the preview, press Start it, open an issue; the terminal palette entry 'A forge in a browser tab' says the same words

🤖 Generated with Claude Code

Closes #16861

Show 18 earlier items

7 earlier comments
commented

I merged main into the branch and pushed it. The merge conflicts are resolved, bun x tsc --noEmit is clean, and the targeted tests pass. I did not run the full suite. The forge will run it on this push.

  • forge.json: I took main's looks and looksAsOwner lists, which add /advisories, and put /tab back into looks.
  • src/generated/marks.ts and src/generated/screens.ts: I took main's versions and regenerated both with bun scripts/own-source.ts, so they include the tab routes. Neither file has conflict markers left.
  • Tests: test/own-source.test.ts, test/import-all.test.ts, test/palette-roster.test.ts and the test/tab* files pass, 32 tests in all. The sqlite-wasm stack trace in the output is logged by a passing test.
  • bun install: tsc first failed because @sqlite.org/sqlite-wasm was missing. bun install fixed that.
  • Not run: scripts/fast.ts would not name tests, because it treats the forge.json change as too broad to bound, so I picked the files above myself.
  • Gate: it notes two files with comment lines over 100 columns, src/web/pages/new-forge.ts and test/timers-named.test.ts. I did not run --fix, since it does not apply to this merge. Its notice says the nightly rewrap handles them on main.
commented

I merged main into the branch and pushed it. The only conflict was src/generated/marks.ts, which is generated, so I took main's version and regenerated it with bun scripts/own-source.ts. That left no conflict markers.

bun x tsc --noEmit is clean, and test/own-source.test.ts and test/no-polling.test.ts pass (16 tests). I did not run the rest of the suite, so the forge's full check on this push is the first run of it against the merge.

The gate notes two long comment lines, in src/web/pages/new-forge.ts and test/timers-named.test.ts. It says the nightly rewrap fixes them on main, so I left them alone.

commented

Still red on current main: a page that sets its own script is on the list or composes the behaviors. Fix it and push.

commented

I merged the latest main into the branch, fixed the ten failing tests and pushed. The full check hasn't run on this push yet. Locally, tsc is clean and the nine failing files plus test/tab.test.ts and test/own-source.test.ts pass.

The tab page, added in this pull, broke several of main's route-sweep tests:

  • Own script: src/web/pages/tab.ts sets its own script, so it is added to the OWN_SCRIPT list in test/behaviors-rule.test.ts.
  • app.looks: it was at 33 paths against a cap of 32, and forge-looks.test.ts requires every top-level page to be listed or excused. I took /tab out of forge.json looks and added it to the not-a-page list in test/forge-looks.test.ts with a reason. The consequence is that /tab gets no screenshot.
  • looksAsOwner: this failure came from the same 33-path overflow, so it cleared with the fix above.
  • Server-Timing sweep: /tab is a static shell with no session or render to time, so it is listed in NOT_PAGES in test/server-timing-sweep.test.ts.
  • Security floor: /tab/v/:hash/:file can't be filled from the seed, so it is added to UNSEEDED in test/security-floor-routes.test.ts with a reason.
  • Body caps: src/tab/sw.ts read a form with request.text(). It now counts bytes as they arrive and answers 413 past FORM_MAX.
  • OpenAPI and tui-migrate failures: the /forges/{}/ready probe got a 429 from the crawler budget, because the three new /tab routes added probes. I added /tab to the free list in src/http/crawl.ts, so those requests no longer spend that budget. tui-migrate passes locally; I did not investigate its 20 s timeout, so I can't say if it is the same cause.
  • Heartbeat schedule: I did not look at it separately. It passes now.

The gate only notes two comment lines over 100 columns (new-forge.ts and timers-named.test.ts), which it leaves to the nightly rewrap.

commented

This update fixes both review points and shortens the link. The tab forge's browser half (OPFS and the service worker) is still not exercised in a browser.

What changed

  • Frame: .tab-frame no longer has a border or radius. It sits under the rows with 24px of space above it (src/web/style/content.ts).
  • Host choice: the service worker no longer takes hosts[0]. It now sends the request to every window at /tab and uses the first reply (src/tab/sw.ts).
    • src/tab/boot.ts now installs the message listener when the page loads. A page that never pressed Start stays silent, so it can't shadow the tab that did.
    • This also survives the service worker restarting, because it keeps no state about which tab is the host.
  • Second tab: if a second tab's database can't open, the page now says another tab of this browser may already hold the forge. It tells the user to use that one, or close it and start here. I did not add a check at page load, so the notice only appears after Start is pressed.
  • Link wording: the New forge link now reads "Try one in this browser tab".

Tests and checks

  • test/tab.test.ts now checks that the worker script asks every window and has no hosts[0]. It also checks that boot.ts answers only when the page holds the forge. These check the shipped script text, not behavior, and a stubbed run of the worker would be a stronger test.
  • test/tab.test.ts, test/tabforge-asset.test.ts, the dead-code tests and the /llms.txt tests pass, and tsc and the design lint are clean.
  • The gate rewrapped comments in two files, and that is committed.
  • I did not run a bare bun test.
  • The commit carries No door:. The change is wording and styling on existing pages, and the terminal line is unchanged.

Still unverified: I haven't opened two tabs in a browser to confirm the new behavior, so the preview needs that check.

[
  {"go":"/tab","look":"Start button, then the frame after it runs","expect":"The frame has no border or rounded corners and has space above it"},
  {"go":"/tab in two browser tabs; press Start in the second only, then the first","look":"The status line and the forge frame","expect":"The first tab shows the forge; the second says another tab may already hold it"},
  {"go":"/new","look":"The link under the terms","expect":"It reads: Try one in this browser tab"}
]
commented

This round fixes the five points from the last review. I haven't tried any of it in a real browser yet: the tests only check the served page, the boot script and the styles.

  • Without JavaScript: the Start button now sits inside <p id="tab-go" hidden>, and boot.ts shows it when it runs. A <noscript> line says a forge in a tab needs JavaScript. The server-rendered status line starts empty, and the script fills in "Not started." (src/web/pages/tab.ts, src/tab/boot.ts).
  • Failure after the worker is ready: if the browser refuses or rejects the service worker, boot.ts stops the database worker, explains in plain words what to do (reload, or note that a private window may not allow it) and turns Start back on.
  • Plain error text: the person no longer sees the raw exception; it goes to the console instead. If the storage won't open, the page says another tab of this browser may already hold the forge: use that one, or close it and press Start again.
  • Touch targets: in the tab's forge styles (src/web/tab-asset.ts), nav links, inputs and the button are now at least 44px tall, and inputs use 16px text so iOS doesn't zoom.
  • Design note: docs/design/areas/tab.md now says .tab-frame has no border and is set apart by the space above it.

test/tab.test.ts checks the hidden button, the <noscript> line and the empty status. It also checks that the raw error is gone, that the catch turns Start back on, and the 44px and 16px rules. These tests, tsc and the design lint pass, and the gate has nothing to fix. I left two things for a later pull: a stubbed run of sw.ts and a notice on page load when another tab already holds the forge.

[
  {"go":"/tab with JavaScript off","look":"Under the facts","expect":"No Start button; one sentence says a forge in a tab needs JavaScript"},
  {"go":"/tab","look":"Button and status","expect":"Start it is shown and the status reads Not started."},
  {"go":"/tab in a second tab after starting the first, press Start","look":"Status line","expect":"A plain sentence about another tab holding the forge, no 'Error:' text, and Start is enabled again"},
  {"go":"/tab on a 360px phone, Start, then the forge's issue form","look":"Nav links, inputs, Open issue button","expect":"Each is at least 44px tall and tapping an input does not zoom"}
]

🤖 Generated with Claude Code

commented

I fixed the upstream-counts failure, but could not reproduce the seven pinned-forge failures here, so that part is unresolved. The fix and a merge of main are pushed; tab tests and tsc pass.

upstream-counts: I reproduced this one, once in four parallel runs of the file. The test counts git processes in a counter shared by the whole test run. Git work still running after the commit lands can fall inside the window that measures a repeat request. The test now takes the fewest of three repeat measurements, so leftover background work can no longer make the cached repeat look uncached. This changes the test, not the app: the test was the thing that was wrong. With the fix, six parallel runs of this file plus pinned-forge all passed.

pinned-forge: each of the seven tests failed in about 1ms, which points at the test's shared state rather than its assertions. In this sandbox the file passed alone, six times in parallel, and alongside the 63 other tests that use the same cloud modules. Main's latest changes, including the cloud overhaul in 3ceb22f, are merged in. No file this pull adds or changes touches cloud code or globals. I don't know what caused the failure; my guess is another test file it shared check shard 117 with. If it fails again, the log will name that shard's other files.

From the previous review (already pushed):

  • Without JavaScript: /tab hides Start, and a <noscript> line says a forge in a tab needs JavaScript.
  • Service worker errors: a failed or refused start of the service worker now says what to do in plain words and turns Start back on.
  • Database errors: raw database errors go to the console instead of the page.
  • Touch targets: in the tab's forge, links, inputs and the button are at least 44px tall, and inputs use 16px text.
  • Design note: docs/design/areas/tab.md no longer mentions a border.

The browser half (OPFS storage and the service worker) still hasn't run in a real browser.

[
  {"go":"/tab with JavaScript off","look":"Under the facts","expect":"No Start button; one sentence says a forge in a tab needs JavaScript"},
  {"go":"/tab","look":"Button and status","expect":"Start it is shown and the status reads Not started."},
  {"go":"/tab in a second tab after starting the first, press Start","look":"Status line","expect":"A plain sentence about another tab holding the forge, no 'Error:' text, and Start is enabled again"},
  {"go":"/tab on a 360px phone, Start, then the forge's issue form","look":"Nav links, inputs, Open issue button","expect":"Each is at least 44px tall and tapping an input does not zoom"}
]

🤖 Generated with Claude Code

commented

Adds /tab: a forge that runs in the browser tab. Its database is SQLite compiled to wasm, stored in the browser's private file storage (OPFS). A service worker acts as its server by passing each request to the tab that started the forge. Closing that tab stops the forge, and the page says so.

Merge with main. Main landed /tabforge (#17275) while this was open. Both features now sit side by side:

  • src/http/lazy_lists.ts and src/http/routes/discovery.ts list both sets of routes.
  • src/generated/marks.ts was rebuilt with bun scripts/own-source.ts.

The two features overlap in purpose. Someone should decide whether /tab and /tabforge both stay or one folds into the other; this merge doesn't choose.

Behaviour to look at:

  • Choosing the host tab: the service worker asks every /tab window and takes the first reply. Only the tab that pressed Start answers, so a second open /tab can't block it (src/tab/sw.ts, src/tab/boot.ts).
  • Without JavaScript: Start stays hidden and a <noscript> line says a forge in a tab needs JavaScript.
  • Failures: a failed start says what to do in plain words and turns Start back on. Raw errors go to the console, not the page.
  • Phone sizes: in the tab's forge, links, inputs and the button are at least 44px tall, and inputs use 16px text so iOS doesn't zoom.
  • Frame: the frame has no border; space sets it apart.
  • Flaky test fix: test/upstream-counts.test.ts now counts a repeat's git work as the fewest of three runs. Git work still running after a landing used to inflate the count and fail the test now and then. This change is to the test, not the app.

Testing: the tests covering routes, generated files, both tab features, dead code and /llms.txt pass (908 tests), and so does tsc.

Not done:

  • The browser half (OPFS storage and the service worker) has not run in a real browser.
  • There is no test that actually runs sw.ts; the tests only check the served script's text. A stubbed run of it would be the stronger test.
  • The page doesn't say on load that another tab already holds the forge; it only says so after Start fails.
  • The terminal side only shows a toast with the page's words, because starting a forge needs a browser.
[
  {"go":"/tab with JavaScript off","look":"Under the facts","expect":"No Start button; one sentence says a forge in a tab needs JavaScript"},
  {"go":"/tab","look":"Button and status","expect":"Start it is shown and the status reads Not started."},
  {"go":"/tab in a second tab after starting the first, press Start","look":"Status line","expect":"A plain sentence about another tab holding the forge, no 'Error:' text, and Start is enabled again"},
  {"go":"/tab on a 360px phone, Start, then the forge's issue form","look":"Nav links, inputs, Open issue button","expect":"Each is at least 44px tall and tapping an input does not zoom"},
  {"go":"/tabforge","look":"The page","expect":"Main's tab forge still answers alongside /tab"}
]

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs