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

perfRecord, loopWatch, stallBlame and lagMinutes belong to a forge, so page-budget and perf-server-hook stop failing in a full gate #12621

opened this

Closed 18d 1h ago

Each forge now keeps its own perfRecord, loopWatch, stallBlame and lagMinutes. Before, one copy of each served the whole process. perfOf(app) in src/perf/live.ts holds them in a WeakMap, following askingOf(app).

Notes

opened this

Each forge now keeps its own perfRecord, loopWatch, stallBlame and lagMinutes. Before, one copy of each served the whole process. perfOf(app) in src/perf/live.ts holds them in a WeakMap, following askingOf(app). There is no reset helper.

  • Hot path: serve looks up perfOf(app) once when it builds the handler. Each request then pays only a property read for perf.perfRecord.add and perf.loopWatch.finished.
  • main.ts: the stall watcher starts before the app exists. It now feeds a createPerf() set, which adoptPerf(app, perf) hands to the app once it is created. Handling one late wake of the loop (lag minute, stall, blame) is now a single function, noteWake(perf, late, at), used by main.ts and by the new test.
  • Callers: these now read their own forge's set: /system, /traffic, /scrapes, /security, the kpi probe, the crawler report, the MCP system tool, the TUI screens and the relay's stall naming. forgeMetrics gains an optional fourth argument, app; /metrics passes ctx.app, and a bare database reports no stalls.
  • Tests:
    • test/helpers/stall-state.ts only resets the telemetry reader counts now.
    • Tests that cleared the shared watches to protect later files now read their own forge's (pages-budget, mcp-system-routes, mcp-system-stalls and others).
    • The "wired" test in perf-loop-jobs uses a fresh createPerf().

New test: test/perf-per-forge.test.ts boots two forges in one process and sends a request to one. One wake 5 s late lands on that forge and a second closes its lag minute. The other forge's record, loop watch, stall blame and lag minutes stay empty. It fails on main.

Not done: the new test doesn't check that the slow forge's stall names /api/v1/health. A health request is too short to count as part of a 200 ms stall, so the test only checks that the stall was recorded; the existing stall tests cover naming. inFlight, gitRecord, bootStall, readLedger and captureStore are still shared by the whole process, which is outside this issue.

Checks: bun scripts/gate.ts, bun x tsc --noEmit and bun scripts/design-lint.ts all pass. I ran 42 files (the perf, stall, loop, metrics, traffic, MCP-system and page-budget tests) in one bun test process. pages-budget and perf-server-hook pass there. One test fails: "each page stays inside its first-view budget" in test/attention.test.ts, with "changelog words 18 > budget 16". It fails the same way on main in that set and passes alone, so some other shared state is leaking; it's left for a separate issue.

The pre-push hook required a "Try:" commit, so the branch ends with an empty commit telling reviewers what to open on the preview.

To try it: on this pull's preview, open /system as an admin. Its stalls and loop lag belong to that forge alone.

🤖 Generated with Claude Code

Closes #12615

4 earlier comments
commented

Each forge now keeps its own perfRecord, loopWatch, stallBlame and lagMinutes. Before, one copy of each served the whole process. perfOf(app) in src/perf/live.ts holds them in a WeakMap, following askingOf(app). There is no reset helper.

  • Hot path: serve looks up perfOf(app) once when it builds the handler. Each request then pays only a property read for perf.perfRecord.add and perf.loopWatch.finished.
  • main.ts: the stall watcher starts before the app exists. It now feeds a createPerf() set, which adoptPerf(app, perf) hands to the app once it is created. Handling one late wake of the loop (lag minute, stall, blame) is now a single function, noteWake(perf, late, at), used by main.ts and by the new test.
  • Callers: these now read their own forge's set: /system, /traffic, /scrapes, /security, the kpi probe, the crawler report, the MCP system tool, the TUI screens and the relay's stall naming. forgeMetrics gains an optional fourth argument, app; /metrics passes ctx.app, and a bare database reports no stalls.
  • Tests:
    • test/helpers/stall-state.ts only resets the telemetry reader counts now.
    • Tests that cleared the shared watches to protect later files now read their own forge's (pages-budget, mcp-system-routes, mcp-system-stalls and others).
    • The "wired" test in perf-loop-jobs uses a fresh createPerf().

New test: test/perf-per-forge.test.ts boots two forges in one process and sends a request to one. One wake 5 s late lands on that forge and a second closes its lag minute. The other forge's record, loop watch, stall blame and lag minutes stay empty. It fails on main.

Not done: the new test doesn't check that the slow forge's stall names /api/v1/health. A health request is too short to count as part of a 200 ms stall, so the test only checks that the stall was recorded; the existing stall tests cover naming. inFlight, gitRecord, bootStall, readLedger and captureStore are still shared by the whole process, which is outside this issue.

Checks: bun scripts/gate.ts, bun x tsc --noEmit and bun scripts/design-lint.ts all pass. I ran 42 files (the perf, stall, loop, metrics, traffic, MCP-system and page-budget tests) in one bun test process. pages-budget and perf-server-hook pass there. One test fails: "each page stays inside its first-view budget" in test/attention.test.ts, with "changelog words 18 > budget 16". It fails the same way on main in that set and passes alone, so some other shared state is leaking; it's left for a separate issue.

The pre-push hook required a "Try:" commit, so the branch ends with an empty commit telling reviewers what to open on the preview.

To try it: on this pull's preview, open /system as an admin. Its stalls and loop lag belong to that forge alone.

🤖 Generated with Claude Code

commented

Each forge now keeps its own perfRecord, loopWatch, stallBlame and lagMinutes. Before, one copy of each served the whole process, so in a full gate one file's requests and stalls showed up in another file's readings.

  • Storage: perfOf(app) in src/perf/live.ts holds the four per forge in a WeakMap, following askingOf(app). There is no reset helper.
  • Hot path: serve looks up perfOf(app) once when it builds the handler. Each request then pays only a property read for perf.perfRecord.add and perf.loopWatch.finished.
  • main.ts: the stall watcher starts before the app exists. It now feeds a createPerf() set, which adoptPerf(app, perf) hands to the app once it is created. Handling one late wake of the loop (lag minute, stall, blame) is now a single function, noteWake(perf, late, at), used by main.ts and by the new test.
  • Callers: these now read their own forge's set: /system, /traffic, /scrapes, /security, the kpi probe, the crawler report, the MCP system tool, the TUI screens and the relay's stall naming. forgeMetrics gains an optional fourth argument, app; /metrics passes ctx.app, and a bare database reports no stalls.
  • Tests:
    • test/helpers/stall-state.ts now only resets the telemetry reader counts.
    • Tests that cleared the shared watches to protect later files now read their own forge's (pages-budget, mcp-system-routes, mcp-system-stalls and others).
    • The "wired" test in perf-loop-jobs uses a fresh createPerf().
  • New test: test/perf-per-forge.test.ts boots two forges in one process and sends a request to one. One wake 5 s late lands on that forge and a second closes its lag minute. The other forge's record, loop watch, stall blame and lag minutes stay empty. It fails on main.
  • Pages: the commits carry a "No look:" line in place of before/after pictures, because no page looks any different.

Not done:

  • The new test doesn't check that the slow forge's stall names /api/v1/health. A health request is too short to count as part of a 200 ms stall, so the test only checks that the stall was recorded; the existing stall tests cover naming.
  • inFlight, gitRecord, bootStall, readLedger and captureStore are still shared by the whole process, which is outside this issue.

Checks:

  • bun scripts/gate.ts against origin/main and bun x tsc --noEmit pass.
  • bun scripts/design-lint.ts passed before the comment rewrap; I didn't re-run it after.
  • After the rewrap, five test files pass: perf-per-forge, perf-server-hook, pages-budget, metrics-forge and loop-stall-by-route.
  • Before it, I ran 42 files (the perf, stall, loop, metrics, traffic, MCP-system and page-budget tests) in one bun test process. pages-budget and perf-server-hook passed there.
  • One test in that run failed: "each page stays inside its first-view budget" in test/attention.test.ts, with "changelog words 18 > budget 16". It fails the same way on main in that set and passes alone, so some other shared state is leaking; it's left for a separate issue.

The pre-push hook required a "Try:" commit, so the branch includes an empty commit telling reviewers what to open on the preview.

To try it: on this pull's preview, open /system as an admin. Its stalls and loop lag belong to that forge alone.

🤖 Generated with Claude Code

commented

This pull makes perfRecord, loopWatch, stallBlame and lagMinutes belong to each forge. Every hosted forge now records its own stalls and loop lag, so on a preview /system shows only that forge's readings. The new test is test/perf-per-forge.test.ts.

This push also fixes a race behind the one red the check charged to this pull, "one tap lands a commit on the head branch and a note on the pull" in test/crew-proposal.test.ts. The cause had nothing to do with the perf work. When the head of a cross-repo pull moved, refreshPullHead in src/core/following.ts updated refs/pull/N/head first. It then waited on carryApproval and only after that wrote the new head into the pull row. A resolve run that finished in that gap saw the ref already up to date, trusted the row and read the old head. The run then recorded no commit, and the resolve page said "This pull has no conflicts" with no proposal card. The row now takes the new head before the ref moves. A new test in test/pull-head-refresh.test.ts checks what the row says at the moment git is asked to move the ref; it fails without the fix and passes with it.

How it was checked:

  • The race: it showed up about once in seven local runs of crew-proposal after merging main. With the fix, 15 runs in a row passed.
  • The other red: "the screen shows the share, the budgets that refused and the agent refused" in test/tui-crawlers.test.ts passed every time locally. It also lists as red in the check summary.
  • The rest: the six other red files fail the same way on main at dc5d1c0, and the check did not count them against this pull.
  • Gates: bun scripts/gate.ts and bun x tsc --noEmit both pass.

scripts/fast.ts named 2,730 files because of the merge with main, so instead I ran the 26 files that cover following.ts, the perf work and the two failing tests: 163 pass, 0 fail.

To try it, open /system on this pull's preview as an admin: its stalls and loop lag are this forge's alone.

🤖 Generated with Claude Code

commented

Every forge now keeps its own perfRecord, loopWatch, stallBlame and lagMinutes. Before this, they were module-level state shared by every forge in one process, so a second forge in the same run (a full gate, a test) changed the first one's readings. That is why page-budget and perf-server-hook failed in a full gate.

  • Lookup: perfOf(app) in src/perf/live.ts finds a forge's perf state the way askingOf(app) finds its asking state. The hot path looks it up once per request.
  • Boot: main.ts takes over the perf state it created at boot.
  • Call sites: the src/web changes only swap call sites; there is no new markup.
  • Metrics: forgeMetrics(db, sources, now, app?) now takes the forge optionally. Called with only a database, it reports no stall families and creates no perf state for that database. /metrics passes the forge, so its stalls are that forge's own.
  • Tests: a two-forge test shows one forge's stalls stay out of the other's readings. A new test in test/metrics-forge.test.ts checks that a scrape with no forge has no stall families and that one with a forge has them.

This pull no longer carries the refreshPullHead reorder in src/core/following.ts or its test in test/pull-head-refresh.test.ts. A revert commit (e75c7f7e3) undoes them on this branch, and they should go to a separate single-purpose pull. The empty Try: commit stays in the history, because removing it would need a force push, which is refused.

bun x tsc --noEmit and bun scripts/gate.ts pass. scripts/fast.ts found the diff too broad to name tests, so I ran the metrics, perf and stall suites instead: 106 pass, 0 fail.

To try it: open /system or /metrics on the preview as an admin. Stalls and loop lag there are that preview's own.

🤖 Generated with Claude Code

commented

Declined: already done on main in 2cdde1402 Run log: https://forge.open-platform.sh/trevato/forge/runs/01m7dhbb08916wcyrp4xg8qkye

Sign in to join this conversation.

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

Keyboard shortcuts

Docs