Public: anyone can read this; the crew can change it.
Games: spark profile call tree and flame graph on the forge #18211
Merged 5h 35m ago, live in production
A stored spark profile now opens as a page with a flame graph and call tree per thread, and the terminal shows the same tree. The new tests, the existing spark, games-terminal and lazy-route suites, the unused-exports and module-state checks, tsc and design-lint pass.
-
Reviews
Changes requested — before the latest pushThe feature does what #18208 asked and both doors, the how-to and the tests are in place. I am asking for changes on one high finding and two design findings.
Fix first: bound how much one request draws. The page draws every thread the decoder returns, up to 200, with up to 2,000 nodes each. That is a flame SVG plus a call-tree
<pre>per thread, on the main thread, on every request, for any viewer grant. A hostile or just large 8 MiB profile can therefore make a response of tens of MB and block the process while it renders. That is the forge-goes-dark Never. Draw only the heaviest N threads (about 10 is enough), say "N more threads not drawn, download the profile" on both doors, and add a test that fails without the cap. The terminal screen recomputeslines()on every render, so it needs the same cap, and a cached result per screen.Design (docs/DESIGN.md):
- Principle 1: the page says the same sentence three times: the
pageHeadsub, the muted paragraph that explains units and pruning, and the SVG aria-label. Keep one sentence. - Principle 6: every flame box has its own stroke, which is a box around each thing. Use fill alone, or a single hairline.
Smaller: the key handler in
src/tui/screens/game_spark.tsis now a hard-to-read if/else chain with theucase folded into the final else. Write it so each key is its own branch.ApprovedEarlier asks, all met in the diff since d7b29bf: (1) thread cap, high:
heaviest()draws the 10 heaviest threads on the page and in the terminal and names the rest, and the test fails without it. (2) Principle 1: the explanation now appears once. (3) Principle 6: the per-box stroke is gone. (4) The terminal key handler has one branch per key, each with its own grant check. Output is escaped, access is gated on a viewer grant on both doors, and the work is bounded: 10 threads, at most 2,000 nodes each, 8 MiB in. The how-to is in docs/features/game-spark.md, not the README. Non-blocking:sparkHeadLinesstill builds a line for every thread (up to 200) though both doors read only the first, so build just the head line. Non-blocking: the terminal's cap and its once-built lines have no test of their own. - Principle 1: the page says the same sentence three times: the
-
Checks
shipped production is serving it deploy a338207
-
History
- Direction: draw only the 10 heaviest threads on both doors, say it once, no per-box stroke, one branch per key (#18208) 1c33dfc
- Merge the pushed spark merge (#18208) d7b29bf
- Merge main: one spark profile page at /games/<box>/spark/<key>, now drawing the call tree and flame graph (#18208) 06d1ce9
- Looks: /games (the box page lists the profiles; each opens /games/<box>/spark/<key>) (#18208) 66524f5
- Merge main: the spark call tree and flame graph take the thread list's route /games/<box>/spark/<key> (#18208) 5ac9068
- No look: the spark view needs a game box holding a stored profile, which no look fixture makes; test/games-spark-view.test.ts reads it (#18208) 0be6705
- Spend 3: the same cost reads and planned stop/delete as MCP tools and a terminal screen (#18206) c30e6bb
- Name the spark view route in the security floor's unseeded patterns (#18208) 79ee47e
- Games: host the spark profiler viewer and its uploads in the forge (#18096) beabbda
- Games: a day after a mod set is installed, the games page says whether it helped, with take-back one tap away (#18201) 2243020
- Name the spark view route in the unfixtured and no-polling lists, drop spark_profile from the unreached allowlist (#18208) 4b83999
- Games: installing the quality set ships Essential Commands' config with only /home, /spawn and /tpa on (#18199) 7b84b2c
- Connections on an account: verified identities the person controls, each with its own uses, and a lookup that answers only on opt-in (#18120) 314f4eb
- Drop decodeSparkProfile from the unused-exports allowlist: the view calls it (#18208) aa3e3c4
- Draw the spark profile view's empty thread in words, tighten exports (#18208) ab5077e
- Direction: draw a stored spark profile's call tree and flame graph on the page and in the terminal (#18208) 95ffc60
- A granted app's two-page print comes out as one sheet, printed on both sides (#18194) e2e7eb4
- Traces 5c: the trace list and one trace read through MCP tools and a terminal screen compare (#18183) cc38920
- Access 5a: a visitor principal is minted only when a visitor creates something, signed, with a role in may() and per-visitor limits (#18174) e261ee9
- Games: the forge pins forge-velocity d0635dac1654 (cannot throw into a command) (#18203) 08c4b42
7 earlier comments
<!-- look-pages aa3e3c417f09 --> Look pages for aa3e3c4, from the gate:
look pages (none): "Looks: /games/<box>/@spark/<key>/view," is not a page of app.looks in forge.json; this pull changes src/web/pages/games.ts, src/web/pages/games_spark_view.ts but the forge could not trace the route of /, /admin/telemetry, /explore and 29 more (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
The three failing tests now pass locally, and I pushed the fix. I didn't re-run the forge's full check, only the four affected test files and tsc, which came back clean.
The spark profile view is a new page, /games/:box/@spark/:key/view, and three registries of known pages hadn't been told about it:
test/budgets/unfixtured/games-box-spark-key-view.json: new file listing the route as one the page-budget fixture can't fill, because the seed stores no spark profile.test/games-spark-view.test.tscovers it instead.test/no-polling.test.ts: added the same route to the list of skipped patterns, with its reason.scripts/unreached-allow.json: removedsrc/games/spark_profile.ts. The view now imports it, so it is no longer unreached, and the test that checks for stale allowlist entries failed on it.
bun scripts/gate.ts still prints "one implementation?" notices. They cover treeLines/walk in src/games/spark_view.ts and the varint and keep helpers in test/games-spark-view.test.ts. I left them alone, since the forge's check failed only on the three tests above.
<!-- look-pages 4b839991ce74 --> Look pages for 4b83999, from the gate:
look pages (none): "Looks: /games/<box>/@spark/<key>/view," is not a page of app.looks in forge.json; this pull changes src/web/pages/games.ts, src/web/pages/games_spark_view.ts but the forge could not trace the route of /, /admin/telemetry, /explore and 29 more (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
I fixed one of the six failures and pushed it. The other five I couldn't reproduce, so I'm treating them as flakes under load.
The one I fixed: "the patterns the seed cannot fill are exactly the ones named" failed in test/security-floor-routes.test.ts. That test keeps its own list of unseeded routes, and it was missing the new /games/:box/@spark/:key/view. I added the route there, with a reason and a pointer to test/games-spark-view.test.ts. After the change, test/security-floor-routes.test.ts, test/boundary-tokens-crew.test.ts and test/game-mods.test.ts pass in isolation, and tsc is clean.
The other five:
- What I ran:
test/anonymous-deep.test.tsandtest/chaos.test.tspass in isolation.test/game-mods.test.tspasses with my changes stashed. - What I saw: in one combined run with
test/security-floor-routes.test.tsandtest/boundary-tokens-crew.test.ts, three tests failed. They were twotest/game-mods.test.tslock tests and another test with aSQLITE_IOERRin the log. A rerun of the same three files showed no failures. - Not run: the survival performance set (the tests tied to the terminal view) and the outside-agent pull-check test. I didn't run them or look at what they assert, so I haven't established that they're load flakes. They are the ones the forge's next run will tell us about.
The look-pages note was the only item that needed a change. I pushed a commit that answers it; the other three were already met.
- Look pages: I added a commit line
No look: the spark view needs a game box holding a stored profile, which no look fixture makes; test/games-spark-view.test.ts reads it (#18208). The route/games/:box/@spark/:key/viewisn't anapp.lookspage inforge.json, and no look fixture makes a game box with a stored profile. I re-ranbun scripts/gate.tsafter adding the line and its output no longer has a look-pages note. - Both doors: already done. The view has its terminal screen in
src/tui/screens/game_spark_view.ts, with a test intest/tui-games.test.ts, and the how-to is updated indocs/features/game-spark.md. - Dead code:
test/unused-exports.test.tspasses. - Issue number: the commits carry
(#18208). - Process-wide state: the view adds no module-level collection, and
test/module-state.test.tspasses.
The gate still prints "one implementation?" notes: flameRects and place in src/games/spark_view.ts, plus the earlier ones in treeLines/walk and the test helpers. They are notes, not failures, so I left the code as it is.
Merged main into the branch and pushed; tsc is clean and the spark, page-budget, unreached, unused-exports, no-polling and security-floor tests pass locally. I didn't re-run the full suite, so the forge's check will be the first to run the rest.
What changed
While this pull was open, main added its own thread-list page for a stored spark profile at /games/<box>/spark/<key> (#18058). That collided with mine, which sat at /games/<box>/@spark/<key>/view. I kept main's route and its links, and my separate route is gone.
- Page:
/games/<box>/spark/<key>now draws each thread of a sampler profile with its time sampled, a server-drawn SVG flame graph with no script, and the call tree as text (at most 12 deep and 8 wide). - Terminal:
enteron a stored profile in the box screen opens the same tree as indented lines, andj/kscroll it. The "list its threads" screen frommainis replaced by this one. - Shared code:
drawableSparkProfileinsrc/games/spark_view.tsdecides whether a profile can be drawn, and both doors call it. I removedsparkThreads, which nothing calls any more. - Fallback: an unreadable, oversized, non-sampler or thread-less profile still gets
main's message, "is not a readable one: download it", on both doors. - Tests: I changed two of
main's tests,test/game-spark.test.tsand the "Zeta thread" one intest/tui-games.test.ts. They asserted the sentence "The call tree and flame graph are not shown here", which is no longer true, so they now expect "Nothing was sampled in this thread". My own page test now uses the new route. - Docs:
docs/features/game-spark.mdsays the tree and graph are drawn here and drops the "Not done" note.
I dropped my route's entries from the no-polling and security-floor-routes lists, and the unfixtured file is now main's.
The branch now merges cleanly with main again. The does not merge into main check was failing because #18096 and #18058 landed on main and conflicted with this pull. I resolved the conflicts and pushed. The forge's check hasn't run on this push yet.
What changed
- Route and view: the call tree and flame graph now live at main's route,
/games/<box>/spark/<key>, replacing main's thread list at that address. The box page's list links there, and the old/@spark/<key>/viewroute is gone. Per thread, the page shows time sampled, an SVG flame graph drawn on the server with no script, and the call tree as text. - Terminal: on a box's Profiles screen (
p), Enter opens the same tree as indented lines. It is still gated on a viewer grant. - Decoder limits: main's limits stay in force. It unpacks at most 8 MiB and builds at most a million fields. A non-sampler, oversized or damaged profile gets "is not a readable one: download it". The unreadable-profile wording follows main's tests.
- Removed:
sparkThreadsand the old thread-list screen, which nothing calls any more. - Tests and docs: I changed main's thread-list tests where they asserted the old text, since the page now says something else. That text is "Nothing was sampled in this thread" in
test/game-spark.test.tsandtest/tui-games.test.ts. I moved the route into the budget and security-floor lists and updateddocs/features/game-spark.md.
The branch on the forge already held a similar merge (06d1ce92f) that I didn't have locally. I joined the two histories and kept my tree, so the pushed state is mine.
Checks: tsc is clean. The spark and terminal-games tests pass, as do the module-state, unused-exports, no-polling, security-floor and lazy-list tests. design-lint and the gate are clean apart from advisory "one implementation?" notes. I did not run the full suite.
Not done: the page shows the sampler profile's threads and call tree only. Spark's other viewer tabs, such as heap and slowest ticks per window, are still not drawn.
Try it: store a sampler profile on a box you hold a grant on, open /games/<box>, and click the profile under Profiles. In the terminal, open the box, press p, then Enter.
[
{"go": "/games/<box>", "look": "the Profiles list on a box that holds a sampler profile", "expect": "each row links to /games/<box>/spark/<key>"},
{"go": "/games/<box>/spark/<key>", "look": "each thread", "expect": "its time sampled, an SVG flame graph, and a collapsible call tree with shares"},
{"go": "/games/<box>/spark/<key>", "look": "a heap or damaged profile", "expect": "\"is not a readable one: download it\" with a download link"},
{"go": "/games/<box>/spark/<key>", "look": "signed in without a grant on the box", "expect": "404"}
]I've addressed all three findings and the smaller one, and pushed the branch.
What changed
- Thread cap (high): the page and the terminal now draw only the 10 heaviest threads, by time sampled. A new
heaviest()insrc/games/spark_view.tspicks them and writes the note "N more threads not drawn, download the profile." Both doors show that note, and the page links the download. - Terminal cost: the terminal profile screen builds its lines once per screen and reuses them, instead of on every render. It also stopped listing all 200 thread names in its head lines.
- Principle 1: the sentence about units and pruning now appears once, in the muted paragraph. The SVG aria-label is now just "Flame graph of <thread>".
- Principle 6: the per-box stroke is gone. Fill opacity alone shows the shape.
- Key handler:
src/tui/screens/game_spark.tsnow has one branch per key (j/down,k/up,enter,u, elsefalse). Each branch holds its own grant check. - Docs:
docs/features/game-spark.mdmentions the cap.
Test: a 13-thread profile must draw exactly 10 flame graphs and show "3 more threads not drawn". It fails without the cap. It exercises the page only; the terminal's cap and cache have no test of their own.
Checks:
tscis clean anddesign-lintis clean.- The spark and games tests pass (46 pass, 1 skipped by the sandbox).
gate --fixchanged nothing. Its remaining output flaggedtreeLines/walkand two test helpers as near-duplicates. I left them.
I did not run the full suite; the forge's check does that on the push.
Not done: the cap of 10 is a constant (MAX_THREADS) with no way to raise it from the page. I can add a query parameter if you want one.
To try it: open /games/<box>/spark/<key> for a sampler profile with more than 10 threads. In the terminal, open the box's Profiles screen (p) and press Enter on that profile.
[{"go":"/games/<box>/spark/<key> for a profile with over 10 threads","look":"10 flame graphs, no outline on the boxes, one muted explanatory line, a note naming the threads left out with a download link","expect":"3 more threads not drawn, download the profile."}]
A stored spark profile now opens as a page with a flame graph and call tree per thread, and the terminal shows the same tree. The new tests, the existing spark, games-terminal and lazy-route suites, the unused-exports and module-state checks,
tscanddesign-lintpass. I did not run the full suite, and the page was not opened on a preview.What changed
/games/<box>links to/games/<box>/@spark/<key>/view. Per thread it shows the time sampled in ms, a flame graph and the call tree with percent-of-thread. The graph is SVG drawn on the server with no script, no new CSS class and no chart library; a box is as wide as its share of the thread, with the call and time in its tooltip. A body that isn't a profile says why and links the download. Only someone with a grant on the box can read it.p),j/kpick a profile and Enter openssrc/tui/screens/game_spark_view.ts. It shows the same lines as the page's call tree, from the shared modulesrc/games/spark_view.ts.decodeSparkProfilenow has a caller, so I removed it and five other stale entries from the unused-exports allowlist. The new route is also registered insrc/http/lazy_lists.ts.docs/features/game-spark.mdis extended.test/games-spark-view.test.tschecks flame widths against a hand calculation (100/60/40/25 ms gives 1000/600/400/250), the page output, an escaped hostile name, 404 for no grant, and the unreadable-body message.test/tui-games.test.tsgets an Enter-opens-the-tree test.boxOf,pageHead,page,profileOfanddecodeSparkProfile, and the existingScreenpattern fromgame_spark.ts.similar.tsonly flagged the new code against itself, plus one test helper (varint) that I copied fromgames-spark-profile.test.tsrather than shared.What I chose not to do
/games/<box>/spark/<key>. I used@spark/<key>/viewinstead, because/games/:box/:service/...could collide with a service namedspark, and the raw bytes stay at@spark/<key>.Try it
/games/<box>on the preview.p, pick a profile, then Enter.Closes #18208