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

Games: host the spark profiler viewer and its uploads in the forge #18096

opened this in answer to

Merged 5h 14m ago, live in production

This pull does the store, the forge-side config and a thin page. Most of the viewer is not built, and the box has not been checked for outbound connections. The tests and tsc pass; the full suite is left to the forge's check.

Notes

opened this

This pull does the store, the forge-side config and a thin page. Most of the viewer is not built, and the box has not been checked for outbound connections. The tests and tsc pass; the full suite is left to the forge's check.

What changed

  • Store (spark's upload contract): POST /games/<box>/spark-up/<secret>/post takes a gzip body typed application/x-spark-*. It answers 201 with Location: <key> and no body.
    • The secret is per box, sealed like the box's other secrets, and only writes. It reaches the mod through the box's .env as CFG_SPARK_UPLOAD, so it is never in the repository.
    • Any request carrying an Origin or Sec-Fetch-Site header is refused, so only the mod can write.
    • A profile is at most 8 MiB, a box keeps 30, and each expires after 7 days. The data is in a new table, game_spark.
  • Reads: GET /games/<box>/spark-data/<key> returns the bytes and their type, with CORS for the forge's own origin only. It needs a forge session with a grant on the box, using the existing game grants and no new tables. Reading with the secret is a 404.
  • Page: /games/<box>/spark/<key> decodes a sampler profile in the forge, with no outside fetch. It lists thread names and their top-level frame counts.
  • Games page and terminal: /games/<box> has a Profiles block listing the stored profiles. The terminal Games screen lists each box's profiles too.
  • Pointing spark at the forge: "Point spark on <service> at the forge" is one commit by an operator. It writes config/spark/config.json with viewerUrl (trailing slash) and bytebinUrl, plus the env that fills the secret placeholder.
  • Docs: a Profiles section in docs/features/games.md.
  • Reused: commitCompose, withConfig and setServiceEnv; the sealed-secret helper in store.ts; readBounded with a new sparkProfile row in the body caps; emptyLine; and sha256 from the kernel for the secret compare.

Left out

  • Native viewer:
    • Not built: the call tree, flame graph, slowest ticks, per-mod time, memory and GC, findings linked to a slow frame, and TPS from spark's health reports.
    • I wrote the thread-listing decoder from memory of spark's .proto and could not fetch the schemas here. Only the thread name (ThreadNode field 1) and its frame count (field 2) are read. Please check those field numbers against spark-common/src/main/proto before building on it.
  • Mod install: the spark mod is not installed together with the config, so a box could upload elsewhere before the button is pressed. The button should be pressed before the mod's first run. The mod still comes in through the existing Modrinth flow.
  • Outbound check: no check on a real box showing zero connections to the author's hosts.
  • Looks: none, because no app.looks page shows the games box.
  • Nothing was built from spark-viewer. The owner's direction change replaces it.

Try it Open /games/<box> and press "Point spark on <service> at the forge". Then POST a gzip body to the upload address. In a test it is /games/net/spark-up/<sealed secret>/post with Content-Type: application/x-spark-sampler. The profile then appears under Profiles and opens from there. test/game-spark.test.ts covers the contract, the refusals, the grants, expiry and the cap, escaping on the page, and the config and .env.

🤖 Generated with Claude Code

Closes #18058

Show 5 earlier items

7 earlier comments
commented

The check failed because two route-coverage tests didn't know about the new /games/:box/spark/:key and /games/:box/spark-data/:key routes. I fixed that and pushed.

  • What changed: both routes are now listed with a reason in test/security-floor-routes.test.ts and test/open-routes-floor.test.ts. The seed doesn't create a game box, so it can't fill their :key. test/game-spark.test.ts covers the routes themselves.
  • Tests: the two route-coverage files now pass locally, 642 tests and no failures. I didn't run tsc, and I didn't re-run test/game-spark.test.ts or the rest of the suite.
  • The third failure, test/ask-to-reach.test.ts: it failed in the check with "Failed to listen at 127.0.0.1". It passes locally (19 of 19) and the check log shows it green on main. I treated it as a port clash in the shard and changed nothing for it. If it fails again on this push, it needs a closer look.
  • Gate: bun scripts/gate.ts --fix changed no files. It reports five files with comment lines over 100 columns, which it says the nightly rewrap handles on main.
commented

I merged main into the branch and pushed it. The merge conflicted in two test files, test/no-polling.test.ts and test/open-routes-floor.test.ts.

In both, each side had added entries to the same "routes the seed can't fill" list: my spark routes, and main's game-map routes (/games/:box/:service/map and /games/:box/:service/m/:pass/*path). I kept all of them.

The four test files that cover this passed (670 of 671), and bun x tsc --noEmit was clean.

The one failure was "the owner's main pages poll nowhere, and /system streams" in no-polling, which took 5.4s in that run. It passed when I re-ran no-polling alone (13 of 13), so I'm treating it as a timing flake under load. I didn't run the full suite; the forge's check does that on this push.

commented

I merged main into the branch and pushed it. Main had landed its own spark store (#18146) on the same files as this pull. I kept main's version of everything it covered and dropped my duplicate.

What the pull now holds on top of main

  • Profile page: GET /games/<box>/spark/<key> opens a stored profile on the forge for anyone with a grant on the box.
    • A sampler profile lists its threads and their top-level frame counts, with names escaped.
    • Any other kind of profile is kept as it came and offered as a download.
    • A missing profile, or one the visitor has no grant for, is a 404.
  • Decoder: src/games/protobuf.ts and src/games/spark_read.ts read the profile bytes without a schema file.
  • Games page: the Profiles list now links to the new page, which links on to main's download at /games/<box>/@spark/<key>.
  • Docs and tests: docs/features/game-spark.md describes the page. New test cases are in test/game-spark.test.ts. There is a budget entry for the route, and the route is listed in the route-coverage tests with a reason.

What I dropped, and what I left out

  • Dropped: my own store, migration, upload route and test fixtures. Main already provides the upload address, Location header, size cap, expiry, grant-gated reads and the terminal screen.
  • Left out: the one-commit "Point spark at the forge" action. Main keeps only a hash of the upload secret, so it can't be put in the box's .env, and writing it into the repository would leak it. You set the address in spark by hand, as main already works. I also didn't build spark's full viewer (call tree, flame graph), the mod install, or the outbound check on the box.
  • No door: the commit says why there is no terminal side. The terminal's box screen already lists each profile by key.

Checks: bun x tsc --noEmit is clean, the gate and design lint pass, and the games, spark, route-coverage, no-polling and migration tests pass. I didn't run the full suite; scripts/fast.ts came back over its time budget (about 3.7 hours), so the forge's check runs everything.

To try it: post a gzipped sampler profile to a box's upload address, open /games/<box>, and follow the profile link.

[
  {"go": "/games/<box>", "look": "the Profiles block", "expect": "each stored profile links to /games/<box>/spark/<key>"},
  {"go": "/games/<box>/spark/<key>", "look": "the thread list", "expect": "thread names with top-level frame counts, escaped, and a Download the bytes link"},
  {"go": "/games/<box>/spark/<key>", "ask": "signed out, or signed in without a grant", "look": "the response", "expect": "a not-found page, not the profile"}
]
commented

I merged main into this branch and pushed it. The only conflict was docs/features/game-spark.md.

The resolution: The page now has my paragraph on the /games/<box>/spark/<key> viewer, followed by main's new "Installed with the mod (#18138)" section. I also removed one stale phrase from "Not done". It said no mod install points a box at the forge, which main's change made untrue.

Checks: tsc --noEmit is clean and the four spark test files pass (21 pass, 1 skipped). I did not run the full suite; the forge runs it on this push. scripts/fast.ts named 2733 test files, about 224 minutes, so I ran only the spark tests myself.

Gate: gate.ts --fix changed nothing. It notes two comment lines over 100 columns in src/http/games_routes.ts and src/web/pages/games.ts, which the nightly rewrap handles on main.

What this pull does (unchanged by the merge):

  • Opens a stored spark profile at /games/<box>/spark/<key> for anyone with a grant on the box.
  • Shows a sampler profile's threads and their top-level frame counts, read without a schema, with names escaped.
  • Keeps any other kind of profile and offers it as a download.
  • Does not host spark's full viewer (call tree, flame graph) and fetches nothing from elsewhere.

To try it: open a box's /games/<box> page, click a stored profile, and the viewer opens at /games/<box>/spark/<key>.

commented

Still red on current main: the repository has no duplicate import beyond the allowlist (rule duplicate-import). Fix it and push.

commented

I fixed the failing check by merging the two imports of ../layout.ts in src/web/pages/games_spark.ts into one line, import { flashTo, page } from "../layout.ts";. Nothing else changed.

test/dup-imports.test.ts passes locally (6 pass, 0 fail) and bun x tsc --noEmit printed nothing. I ran no other tests; the forge's check runs the full suite on this push. The fix is pushed as 261c5c7ca.

commented

This pull lists a stored spark sampler profile's threads on /games/<box>/spark/<key> and in the terminal. It does not host spark's viewer: no call tree or flame graph, and I opened #18208 for those. Tests I ran pass: the spark, terminal-games, dup-imports, module-state, unused-exports and both-doors files, plus tsc and the design lint. I did not run the full suite; scripts/fast.ts called it too broad, so the forge's check runs it.

What changed, against the review

  1. Denial of service: I deleted src/games/protobuf.ts and src/games/spark_read.ts. The page now uses decodeSparkProfile in src/games/spark_profile.ts, through a new sparkThreads. That decoder was already on main, and unlike my reader it has a spec-built fixture test.
    • It unpacks at most 8 MiB, down from 64 MiB.
    • It builds at most one million fields per decode. Past that it returns "too-large".
    • It reads at most 200 threads, and stops before parsing the rest.
    • Any profile that fails these limits shows "download it". That includes a real profile over 8 MiB unpacked; the old 64 MiB cap would have shown it.
  2. Field numbers: my reader's "frames" field (ThreadNode 2) was wrong. In spark's proto it is the reserved time; children are 3 and refs 5. I did not re-check the numbers against the proto myself. I took them from spark_profile.ts, whose comment says they were checked against spark's spark.proto and spark_sampler.proto, and whose existing spark-v2 fixture test is encoded from those files. The page now shows each thread's sampled time ("N ms sampled") instead of the wrong frame count. My own page test builds its bytes from the same numbers. A test builds a 9 MiB gzip bomb, a flood of fields, and 300 threads. The bomb is refused fast, the flood fails as "too-large", and the 300 threads come back as 200.
  3. Terminal: on the box screen, p opens the profiles. j/k choose one and enter lists its threads for any grant, through the same sparkThreads. A new test in test/tui-games.test.ts covers it. docs/features/game-spark.md has the key and the limits.
  4. What is still missing: this is a thread list. The doc and the page both say the call tree and flame graph are not shown, and the doc links #18208.
  5. Wording: the sub line is now one sentence: "A spark sampler profile from <box>, taken <time> UTC, N KiB." The other sentences say plainly that only sampler profiles can be listed here and that the profile can be downloaded for spark's own viewer.
  6. Test: the signed-out request now asserts a 303 to /signin, not .not.toBe(200). Hidden and missing profiles are asserted as 404.

Two things I did not do or chose

  • The field budget is a module-level number reset on each decode. It is safe because decoding is synchronous. It is not a Map, Set or array.
  • profileOf now also returns the profile's creation time.

To try it: open /games/<box>, then a stored sampler profile; or in the terminal press p, j/k, enter.

[
 {"go":"/games/<box>/spark/<key> for a sampler profile, signed in with a grant","look":"The sub line and the thread list","expect":"One plain sentence about the profile; threads busiest first with 'N ms sampled'; a note that the call tree and flame graph are not shown"},
 {"go":"The same URL for a non-sampler profile or a gzip bomb","look":"The muted line","expect":"Says it is not a readable one and to download it; the page answers quickly"},
 {"go":"The same URL signed out, or with no grant","look":"The response","expect":"Signed out is a 303 to /signin; no grant or a missing key is a 404"}
]
commented

I removed src/games/spark_profile.ts from scripts/unreached-allow.json, which fixes the failing check. Something imports that module now, so it no longer belongs on the allow list, and test/unreached.test.ts was the one test that flagged it.

I ran test/unreached.test.ts locally and all 4 tests pass. I did not run the full suite, tsc or the gate. This change only edits that JSON list, so no page or behaviour changed. The fix is pushed as 1eed7fd1f.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs