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

A first-party beacon reports each page's real load, LCP, INP, CLS and TTFB to the forge, keeping no IP #2731

Parked opened this
Closed without merging

Every forge page now links a first-party beacon that reports its real load, LCP, INP, CLS and TTFB to the forge once per page view. It keeps no IP and no user agent string. The type check passes and test/measure.test.ts passes.

Notes

stopped parked by the crew deploy 2761562

opened this

Every forge page now links a first-party beacon that reports its real load, LCP, INP, CLS and TTFB to the forge once per page view. It keeps no IP and no user agent string. The type check passes and test/measure.test.ts passes. So do the cross files from CLAUDE.md and the migration, schema and CSP-related suites. I did not run the full bun test or the forge's whole check.

What changed

  • Script: src/web/beacon.ts is one classic script of about 900 bytes, with no dependency. It is served content-hashed and immutable like the shell script (beaconAsset() in src/web/asset.ts) and linked from layout.ts with the page's nonce. The CSP is unchanged.
  • What it sends: the page path, TTFB and load time from navigation timing, LCP, INP and CLS, in one sendBeacon call. It fires when the page is hidden or left.
  • Opt-out: it sends nothing under Do-Not-Track or the forge_measure=off cookie. The server checks both again and answers 204 without storing anything.
  • POST /_measure: the handler is src/http/measure.ts, and src/web/measure.ts holds the validation and storage.
    • It requires Origin to equal the forge's origin, so a request with no Origin is refused too (403).
    • It limits each client to 30 reports a minute and the forge to 1200. The limiter is in memory only.
    • It reads at most 512 bytes (413 past that).
    • It refuses any unknown key and any non-finite, negative or over-bound number (400). Times are capped at 600 000 ms and CLS at 100.
    • It maps the path to a route pattern using the forge's router and refuses a path no route matches.
    • It answers 204 when it stores.
  • Storage: the migration 20261019140000-page-vitals.ts adds page_vital and vital_salt. The pin for it is in migration-pins.json.
    • A row stores the route pattern (for example /:owner/:name), never the path.
    • The visitor is sha256(daily salt, client address, user agent), truncated. The address and user agent go into that hash and nowhere else.
    • The salt rotates daily, and old salts are deleted when the new one is made.
    • Rows are pruned after 90 days.
  • Tests: test/measure.test.ts covers each point below.
    • A valid report is stored with no address, agent or path in the table.
    • Cross-origin, no-origin, oversized, malformed, out-of-bounds, unknown-key and unknown-route reports are refused and store nothing.
    • DNT and the cookie store nothing.
    • A client past its rate gets 429.
    • The script is under 2048 bytes, immutable and linked from /.
    • The visitor hash is stable within a day and different on the next, with one salt left.
  • README: a "Page-view beacon" section.

Left out

  • Nothing reads page_vital yet: there is no dashboard or aggregate query.
  • CLS is the plain sum of layout shifts, not session windows. INP is the worst interaction, not the 98th percentile.
  • Nothing in the UI sets the forge_measure=off cookie. It is documented, and DNT works today.

Try it: bun run src/main.ts, open a page, then switch tabs. sqlite3 $FORGE_APP_DATA/forge.db 'select * from page_vital' shows the row.

🤖 Generated with Claude Code

Closes #2711

commented

Every forge page now links a first-party beacon that reports its real load, LCP, INP, CLS and TTFB to the forge once per page view. It keeps no IP and no user agent string. The type check passes and test/measure.test.ts passes. So do the cross files from CLAUDE.md and the migration, schema and CSP-related suites. I did not run the full bun test or the forge's whole check.

What changed

  • Script: src/web/beacon.ts is one classic script of about 900 bytes, with no dependency. It is served content-hashed and immutable like the shell script (beaconAsset() in src/web/asset.ts) and linked from layout.ts with the page's nonce. The CSP is unchanged.
  • What it sends: the page path, TTFB and load time from navigation timing, LCP, INP and CLS, in one sendBeacon call. It fires when the page is hidden or left.
  • Opt-out: it sends nothing under Do-Not-Track or the forge_measure=off cookie. The server checks both again and answers 204 without storing anything.
  • POST /_measure: the handler is src/http/measure.ts, and src/web/measure.ts holds the validation and storage.
    • It requires Origin to equal the forge's origin, so a request with no Origin is refused too (403).
    • It limits each client to 30 reports a minute and the forge to 1200. The limiter is in memory only.
    • It reads at most 512 bytes (413 past that).
    • It refuses any unknown key and any non-finite, negative or over-bound number (400). Times are capped at 600 000 ms and CLS at 100.
    • It maps the path to a route pattern using the forge's router and refuses a path no route matches.
    • It answers 204 when it stores.
  • Storage: the migration 20261019140000-page-vitals.ts adds page_vital and vital_salt. The pin for it is in migration-pins.json.
    • A row stores the route pattern (for example /:owner/:name), never the path.
    • The visitor is sha256(daily salt, client address, user agent), truncated. The address and user agent go into that hash and nowhere else.
    • The salt rotates daily, and old salts are deleted when the new one is made.
    • Rows are pruned after 90 days.
  • Tests: test/measure.test.ts covers each point below.
    • A valid report is stored with no address, agent or path in the table.
    • Cross-origin, no-origin, oversized, malformed, out-of-bounds, unknown-key and unknown-route reports are refused and store nothing.
    • DNT and the cookie store nothing.
    • A client past its rate gets 429.
    • The script is under 2048 bytes, immutable and linked from /.
    • The visitor hash is stable within a day and different on the next, with one salt left.
  • README: a "Page-view beacon" section.

Left out

  • Nothing reads page_vital yet: there is no dashboard or aggregate query.
  • CLS is the plain sum of layout shifts, not session windows. INP is the worst interaction, not the 98th percentile.
  • Nothing in the UI sets the forge_measure=off cookie. It is documented, and DNT works today.

Try it: bun run src/main.ts, open a page, then switch tabs. sqlite3 $FORGE_APP_DATA/forge.db 'select * from page_vital' shows the row.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("browsing an origin repository on the web > Mirror from a browse lands on a job page with a live checklist") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs