Public: anyone can read this; the crew can change it.
Games: host the spark profiler viewer and its uploads in the forge #18096
Merged 6h 57m 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.
-
Reviews
Changes requested — before the latest pushChanges needed, all in one round.
- HIGH, denial of service:
summarizegunzips up to 64 MiB andfieldsOfthen builds an object for every field, on the request thread, on each page view. A box owner's 8 MiB gzip bomb of tiny fields stalls the whole process, and the forge cannot go dark. Fix: decode only what is needed. Cap output near 8 MiB and the field count, stop after 200 threads, and don't materialise all fields. - The decoder is unverified. The field numbers (ThreadNode 1 and 2, SamplerData 2) were written from memory, and the test builds its bytes from the same assumption, so it cannot fail if they are wrong. Check them against spark's proto, and add a test on a real sampler profile or a fixture built from the schema.
- Both doors: the terminal's box screen lists keys only and cannot read a profile. Add the threads view under
src/tui/(reusingsummarize, with the same grant gate), or say what stops it. The doc also needs the terminal key. - The issue asks to host the spark viewer, and this is a thread list. Say plainly in the pull and the doc what the issue still lacks, and open the follow-up issue for the call tree and flame graph.
- Design principles 1 and 8: the sub line and the muted 'kept as it came' sentence say the same thing twice, in words a person has to decode. Say one plain sentence. See the line comments.
- Test:
.not.toBe(200)for the signed-out request is weak. Assert the exact status (404, or the redirect) the page gives.
The rest holds: grant gate through
boxOf("viewer"), escaped names, 404 for hidden and missing alike, and no outside fetch.ApprovedEarlier asks are met. The decode is bounded: 8 MiB unpacked, 1M fields, 200 threads, with a test for each. The page reads through the single checked decoder. The terminal reaches the same list through
sparkThreads, with a test. The thread count is the real sampled time. Signed-out is a 303, and hidden or missing is a 404. Names are escaped and tested.spark_profile.tsis off the unreached list. The doc says plainly that the viewer is not hosted and links #18208. No new finding is high.Non-blocking: on the terminal's spark screen,
j/kmoveat, butlines()draws no marker on the chosen row, so a person cannot see which profileenteropens. Mark the row with>.Non-blocking:
test/game-spark.test.tshas a stray double blank line after the bounded-profile test. - HIGH, denial of service:
-
Checks
shipped production is serving it deploy a338207
-
History
- Drop spark_profile from the unreached allow list: it is imported now 1eed7fd
- Spark profile page reads with the checked decoder, bounded; the terminal lists threads too df698d0
- games_spark: merge the duplicate layout.ts import 261c5c7
- Spark doc: the mod install now points a box at the forge 73e4a21
- Merge main into the spark profile pull (#18058) 8bef1e0
- Spark's config is installed with the mod so a profile uploads to the forge and never elsewhere (#18173) 7de2fc0
- Games survival step 3b: a sleep (night-skip) mod in the quality set (#18172) 56e2b82
- Automate a review finding as a lint or test: One high finding, then smaller ones, all for one round. (#18167) f6eb779
- A spark profile decodes to a summary: call tree, slowest ticks, per-mod time, GC and memory (#18144) e30e2b6
- Access 4b: the 'Who may do what' page, linked from settings, by person and by resource (#18131) 3ecccb5
- "asks ledger failed: database is locked" two minutes after a release (v0.7.733) (#18169) 009df15
- Merge main into the spark profile pull (#18058) 5e2a8d1
- Traces 4: a Claude Code session file imports as a trace and is listed beside the others (#18129) 68f0754
- A game box stores spark profiles in the forge: POST /post gives a Location, reads need the box's game grants (#18146) b992c0d
- Merge main into the spark profile pull (#18058) 2b791c4
- List the spark viewer routes as the seed's unfilled patterns, with why 787b30f
- Games survival step 3: quality-of-life mods tried on a copy first (graves, essential-commands, sleep, harvest, vein miner, styled-chat) (#18145) f058287
- Spend 1: a monthly budget per cloud account, one notice at 80% and one at 100% (#18121) 3382c40
- Games: a proxy plugin update can wait until nobody has been on for 30 minutes (#18039) 9a5eb31
- Traces 5: compare two traces, and share one with secrets redacted (#18017) 7a17314
12 earlier comments
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>/posttakes a gzip body typedapplication/x-spark-*. It answers 201 withLocation: <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
.envasCFG_SPARK_UPLOAD, so it is never in the repository. - Any request carrying an
OriginorSec-Fetch-Siteheader 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.
- The secret is per box, sealed like the box's other secrets, and only writes. It reaches the mod through the box's
- 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 writesconfig/spark/config.jsonwithviewerUrl(trailing slash) andbytebinUrl, plus the env that fills the secret placeholder. - Docs: a Profiles section in
docs/features/games.md. - Reused:
commitCompose,withConfigandsetServiceEnv; the sealed-secret helper instore.ts;readBoundedwith a newsparkProfilerow in the body caps;emptyLine; andsha256from 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
.protoand could not fetch the schemas here. Only the thread name (ThreadNodefield 1) and its frame count (field 2) are read. Please check those field numbers againstspark-common/src/main/protobefore 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.lookspage 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
The two failing tests came from the walk-skip list in test/no-polling.test.ts. It didn't name the two new spark profile routes. I added both with a reason each:
/games/:box/spark/:key: a kept spark profile of a game box. The seed doesn't make one, andtest/game-spark.test.tscovers it./games/:box/spark-data/:key: the same profile as raw data, not a page.
test/no-polling.test.ts now passes on its own (13 tests). I did not run the other tests. I pushed e3bae6273; the forge's check runs the full suite on it. The gate reported no problems and no change from --fix. It only noted that five files have comment lines over 100 columns, which the nightly rewrap will handle on main. I did not run bun x tsc --noEmit, since the change is a test-file edit only.
This is the final state of the pull. The spark profile store and routes from the earlier commits are unchanged.
This push fixes the check failure from the last run. The pages-budget walk found two spark profile routes with no fixture and no entry in test/budgets/unfixtured/. I added an entry for each, in the same format as the other game routes:
/games/:box/spark/:key/games/:box/spark-data/:key
Each one is listed as "no fixture holds the id this route needs". The seed makes no game boxes, so neither route can be filled. The no-polling and security-floor tests already name both routes.
The failing test, "a route the fixture cannot fill is listed in a file of its own", now passes when run alone. I did not re-run the full suite; the forge's check does that on this push. No code or app behaviour changed.
This pull adds a bytebin-compatible spark profile store to each game box, and a page listing the stored profiles. It does not yet serve the spark viewer, change spark's config, or prove outbound silence. Items 2–4 of the issue (viewer, config/spark/config.json, outbound check) remain.
What changed
- Upload:
POST …/posttakes a gzipped protobuf (application/x-spark-*) and answers 201 withLocation: <key>and no body. The upload secret sits in the path and only allows writes. - Read:
GET …/<key>returns the stored bytes with their content type and CORS headers. Reads need a forge session with the box's existing game grants; no new grant tables. - Limits: a size cap, an expiry, and a body cap in
src/kernel/body_caps.ts. - Where it lives:
src/games/spark.tsholds the store andsrc/games/protobuf.tsthe protobuf handling.src/web/pages/games_spark.tsserves the page and the key routes. The games screen insrc/tui/screens/games.tsanddocs/features/games.mdcarry the same change. There is a migration,20261204060000-game-spark. - Tests:
test/game-spark.test.ts.
Last failure on #18096
- The failing test, "a join meets the job in order > freeze at once, then stop…", is in
test/game-lend-box.test.ts. It passes here, alone and again after merging main. It asserts the run ends within 15 s, so it looks like a timing flake under load; I did not change it. - The pull was behind
main, so I mergedmaininto the branch and pushed.
The four rules the check named
- No unused exports (
test/unused-exports.test.ts), no process-wide state that requests write to (test/module-state.test.ts), no untimedduringjob (test/job-slices.test.ts) and no duplicate imports (test/dup-imports.test.ts) all pass, along withtest/game-spark.test.ts. bun x tsc --noEmitandbun scripts/design-lint.tsare clean.bun scripts/gate.ts --fixchanged nothing.- I did not run the full suite; the forge runs it on the push.
Not done
- Viewer build: hosting the spark-viewer (a static export with a basePath patch) is not done.
- Config: I did not touch
config/spark/config.json, soviewerUrlandbytebinUrlare not yet set to the forge. - Outbound check: there is no proof yet that a profiler run makes no connection to the author's hosts.
To try it: open a game box's games page, where the stored profiles are listed. Then POST a gzipped body to the box's …/post path with the upload secret and read the key from Location.
🤖 Generated with Claude Code
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.tsandtest/open-routes-floor.test.ts. The seed doesn't create a game box, so it can't fill their:key.test/game-spark.test.tscovers 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-runtest/game-spark.test.tsor 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 --fixchanged no files. It reports five files with comment lines over 100 columns, which it says the nightly rewrap handles on main.
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.
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.tsandsrc/games/spark_read.tsread 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.mddescribes the page. New test cases are intest/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,
Locationheader, 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"}
]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>.
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.
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
- Denial of service: I deleted
src/games/protobuf.tsandsrc/games/spark_read.ts. The page now usesdecodeSparkProfileinsrc/games/spark_profile.ts, through a newsparkThreads. 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.
- 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 fromspark_profile.ts, whose comment says they were checked against spark'sspark.protoandspark_sampler.proto, and whose existingspark-v2fixture 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. - Terminal: on the box screen,
popens the profiles.j/kchoose one andenterlists its threads for any grant, through the samesparkThreads. A new test intest/tui-games.test.tscovers it.docs/features/game-spark.mdhas the key and the limits. - 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.
- 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.
- 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.
profileOfnow 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"}
]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.
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
tscpass; the full suite is left to the forge's check.What changed
POST /games/<box>/spark-up/<secret>/posttakes a gzip body typedapplication/x-spark-*. It answers 201 withLocation: <key>and no body..envasCFG_SPARK_UPLOAD, so it is never in the repository.OriginorSec-Fetch-Siteheader is refused, so only the mod can write.game_spark.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./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/<box>has a Profiles block listing the stored profiles. The terminal Games screen lists each box's profiles too.<service>at the forge" is one commit by an operator. It writesconfig/spark/config.jsonwithviewerUrl(trailing slash) andbytebinUrl, plus the env that fills the secret placeholder.docs/features/games.md.commitCompose,withConfigandsetServiceEnv; the sealed-secret helper instore.ts;readBoundedwith a newsparkProfilerow in the body caps;emptyLine; andsha256from the kernel for the secret compare.Left out
.protoand could not fetch the schemas here. Only the thread name (ThreadNodefield 1) and its frame count (field 2) are read. Please check those field numbers againstspark-common/src/main/protobefore building on it.app.lookspage shows the games box.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>/postwithContent-Type: application/x-spark-sampler. The profile then appears under Profiles and opens from there.test/game-spark.test.tscovers 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