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

Tests share process-wide state and eight are flaky: a pull's check can go red for what another test left behind #12599

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

This pull covers part of #12569: the "who is asking" ledger was already done, and four more shared-state items, the rule test, and one flaky test are now done too. I did not run the "10 identical gate runs" check, and jobs, watch and childtime are still process-wide.

Notes

opened this

This pull covers part of #12569: the "who is asking" ledger was already done, and four more shared-state items, the rule test, and one flaky test are now done too. I did not run the "10 identical gate runs" check, and jobs, watch and child_time are still process-wide. The type check, the gate script and the files I ran pass. My full-set runs timed out in the sandbox, so I have no complete pass/fail result.

What changed

  • Shared state moved under the app:
    • The turn gate, cell-protection notes, perfRecord/loopWatch/stallBlame/lagMinutes and the lag minutes are now kept per app. These went in with the earlier commit d9c4bfd98.
    • This pull adds the /changelog "running commit" read. It was one global, so a second forge, or a test's own repository, showed as another's "This forge". It is now keyed by the forge's database, and keepLive/forgetLive take db.
    • No clear() helpers were added. The tests that called forgetLive no longer need to, because each test app has its own store.
  • Rule test: test/module-state.test.ts is in RULE_TESTS, so it runs in every pull's fast tier. It fails when a module under src/ adds a module-level Map, Set or array that code inside a function writes to. The scan is a text match, so it can miss or over-match.
  • Flaky red-main: it failed whenever snapshot-repositories ran before it in the same process, because the sentinel's repeated-error detector read the process-wide error ledger. hunt now reads the hunting forge's own ledger (findFaults takes a ledger argument), and the red-main test passes a fresh ErrorLedger.

What I chose not to do

  • The rule's allow-list is a baseline, not a short list with a reason each. The scan found 216 existing module-level collections that a function writes to, many of them caches and in-flight guards. test/module-state.baseline.txt lists them. New entries are refused, and an entry whose state is gone or fixed must be deleted from the file. They still need moving under an app or justifying.
  • jobs, watch and child_time are still process-wide and are on that baseline.
  • Flaky tests I could not isolate or prove: page-budget, checks-queue, tui-grants, perf-server-hook, first-login-words and home-flow passed here, alone and together. I did not isolate a cause or run the 50-times-in-a-shard proof. The whole-gate-10-times criterion is not shown either.
  • snapshot-repositories has two failures here that are sandbox-only: the sandbox blocks the loopback object store those tests use.

How to try it

  • Open /changelog on the preview and check that "This forge" and the pulls on their way still show.
  • Run bun test test/module-state.test.ts test/red-main.test.ts test/changelog.test.ts.

Closes #12569

2 earlier comments
commented

This pull covers part of #12569: the "who is asking" ledger was already done, and four more shared-state items, the rule test, and one flaky test are now done too. I did not run the "10 identical gate runs" check, and jobs, watch and child_time are still process-wide. The type check, the gate script and the files I ran pass. My full-set runs timed out in the sandbox, so I have no complete pass/fail result.

What changed

  • Shared state moved under the app:
    • The turn gate, cell-protection notes, perfRecord/loopWatch/stallBlame/lagMinutes and the lag minutes are now kept per app. These went in with the earlier commit d9c4bfd98.
    • This pull adds the /changelog "running commit" read. It was one global, so a second forge, or a test's own repository, showed as another's "This forge". It is now keyed by the forge's database, and keepLive/forgetLive take db.
    • No clear() helpers were added. The tests that called forgetLive no longer need to, because each test app has its own store.
  • Rule test: test/module-state.test.ts is in RULE_TESTS, so it runs in every pull's fast tier. It fails when a module under src/ adds a module-level Map, Set or array that code inside a function writes to. The scan is a text match, so it can miss or over-match.
  • Flaky red-main: it failed whenever snapshot-repositories ran before it in the same process, because the sentinel's repeated-error detector read the process-wide error ledger. hunt now reads the hunting forge's own ledger (findFaults takes a ledger argument), and the red-main test passes a fresh ErrorLedger.

What I chose not to do

  • The rule's allow-list is a baseline, not a short list with a reason each. The scan found 216 existing module-level collections that a function writes to, many of them caches and in-flight guards. test/module-state.baseline.txt lists them. New entries are refused, and an entry whose state is gone or fixed must be deleted from the file. They still need moving under an app or justifying.
  • jobs, watch and child_time are still process-wide and are on that baseline.
  • Flaky tests I could not isolate or prove: page-budget, checks-queue, tui-grants, perf-server-hook, first-login-words and home-flow passed here, alone and together. I did not isolate a cause or run the 50-times-in-a-shard proof. The whole-gate-10-times criterion is not shown either.
  • snapshot-repositories has two failures here that are sandbox-only: the sandbox blocks the loopback object store those tests use.

How to try it

  • Open /changelog on the preview and check that "This forge" and the pulls on their way still show.
  • Run bun test test/module-state.test.ts test/red-main.test.ts test/changelog.test.ts.
commented

This pull narrows #12569 to what it does: the turn gate, protection notes, traffic record, loop watch, stall blame, lag minutes and landings now belong to a forge (an app object). It does not fix the eight flaky tests. Sentinel's items 3 and 4 are done, 1 and 2 are answered by narrowing the scope and by new linked issues, and 5 is not done. tsc is clean, and the new tests plus module-state, protection and stall-in-flight pass (317, 0 fail). I did not run the whole suite. The repo has no scripts/gate.ts or scripts/fast.ts, so neither ran. The app boots.

Changed this round

  • Stall before the app exists (item 4): src/kernel/stall_relay.ts replaces the loose earlyStalls array and loopLive binding in src/main.ts. It keeps at most 64 stalls and drops the oldest. It reads them in order once the forge exists, and reads later ones directly. test/stall-relay.test.ts covers the early stall and the bound.
  • Two forges in one process (item 3): test/forge-owns-its-state.test.ts makes two apps. It feeds one a traffic sample, a stall, a protection note, a turn-gate wait count and a keepLive, and asserts the other sees none of them. It would fail if any store went back to one per process.

Answers to the rest

  1. The flakes (item 1): not fixed here, and no 10-gate-run or 50-in-a-shard proof was run. Fixing eight timing tests with proof does not fit this pull, so #12609 takes them. In this sandbox snapshot-repositories fails on loopback network access being blocked, which is the sandbox, not a flake. page-budget's median test is wall-clock and flaked once in three runs together with the others, though it passes alone. #12609 should decide whether it measures statements or CPU, or runs alone. Everything else listed in #12609 I did not reproduce or diagnose.
  2. Baseline of 216 (item 2): #12610 drains it, with jobs, watch and child_time first, as the next pull. Both issues are linked as blockers of #12569, so #12569 stays open.
  3. Scope (item 5): I did not split the 56 files. The turn gate, protection, landings and perf live were each changed the same way, and the module-state rule and its baseline refuse the old shape. I can see the case for several pulls, and I'd split them only if a person asks.

I disagree with one thing. The module-state scan is a text match and can miss, but I kept it as the guard against new process-wide state. The new two-forge test is the behavioural proof.

commented

The check's visible failures are not from this pull, but the module-state rule did have a real fault, which I fixed. I could not reproduce the etag failure ("a signed-out page showing a flash…"). The forge check has not run on the new push yet.

The fault I fixed. test/module-state.baseline.txt still listed src/main.ts:earlyStalls, which my last commit had removed. After merging main it also lacked three module-level collections main added: src/apps/egress_refused.ts:said, src/core/readme_description.ts:tips and src/release/leftover_sweep.ts:removing. Both module-state tests failed on the merge of this branch with main. I merged origin/main into the branch, dropped the stale entry and added the three. The type check and scripts/gate.ts pass. module-state, forge-owns-its-state, stall-relay, red-main, changelog and etag pass (70 tests).

Failures I left alone. These fail in this sandbox on a clean origin/main as well, with the same results as on this branch:

  • outbound-gate
  • ask-to-reach
  • apps-ws
  • apps-open-host
  • data-browser
  • boundary-tenancy-cell
  • spawn-gate-e2e
  • loop-stall ("BEGIN IMMEDIATE" is missing from the logged statements)

The etag flash test passed three times alone here and passes on the merged tree. I can't tell whether it was a flake. Only 15 of the 23 failures were visible in the log tail. If the next check still shows red outside the list above, I need its log.

How to try it. Run bun test test/module-state.test.ts.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs