Skip to content

harness: the hardening pair: the metrics breaker, a crashed browser, the deadline across a relaunch (D19 carry) - #27

Open
mmcky wants to merge 2 commits into
mainfrom
harness/hardening
Open

mmcky wants to merge 2 commits into
mainfrom
harness/hardening

Conversation

@mmcky

@mmcky mmcky commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

The corpus hardening pair: the three defects the last review of stage 2 found, and the nits, test gaps and older items it carried, in the shared engine (byte-identical in both corpora: lib/*.mjs, run.mjs, selftest/run.mjs, harness.yml), this corpus's README and its theme.mjs (MathJax's startup wait bounded). Part of QuantEcon/project-theme-parity#15 (D19, QuantEcon/project-theme-parity#80). The twin is QuantEcon/test-lecture-theme-mystmd#28, on the same branch, harness/hardening, which the engine-drift check pairs this one with. By D19, metrics and crops are evidence only: none of this changes what a reading measures or crops, only what a run does when a reading or a browser stalls, crashes or runs out of time.

The three defects

1. A metrics-only stall on every page failed the job. Each reading given up in a step only the metrics need kept its counts but cost its worker the full reading limit, so a stall there on every page used up the run's limit, and the readings not started lost their checks and counts (exit 1), against "Warn, don't fail". Now a metrics breaker (engine.mjs, readings and pageTask): once two page readings have been given up at their own limit in a step only the metrics need (measuring a family, the body text, the fonts, the crops), every page reading after takes its checks and counts alone, with no metrics or crops. One metrics problem and one crop problem for the run say so, as do the summary ("The metrics breaker opened at …") and provenance.json (reading_limit.metrics_breaker: threshold, tripped_by, opened, skipped). Readings already in such a step when it opens may still stall to their limit, side by side, so the stall costs one or two reading limits of time, not one per page reading. A per-step budget of its own, the optional half of the suggested fix, is not added: a stalled evaluation cannot be stopped without giving up its reading, so it would only give the reading up sooner, at the price of a new cause and new wording, and the breaker already bounds the cost. Test: limitCheck's H (every long_cells reading held in its fonts step, readings 10 s, run 45 s): exit 0, the two desktop readings given up there keeping their checks, counts and metrics rows, the four after left to their checks and counts, every check run and every count taken. On main's engine (a copy of main with the branch's self-test, its new functions exported as main has them) H exits 1: four readings given up in their fonts step, one at the run's limit, one not started. The carry's own scenario (the fonts step looping on every page, readings 10 s, run 40 s, six pages): main exits 1 after 41 s in both corpora (16 readings given up, 20 not started); this branch exits 0 after 26 s here and 35 s in the twin (the first four given up side by side, no reading not started, every check run and every count taken). Also a unit case: the breaker opens on the second page reading given up in such a step, not on a feature's or a count's.

2. After a browser crash, a reading could wait out its full limit. limited raced only its timer, get() handed out a disconnected browser, and opening a context or page had no bound. Now limited also settles, as an error, when the reading's browser disconnects (or had already), and removes its listener after; get() relaunches a browser it finds disconnected before handing it out; and opening a reading's browser context or page waits 30 s at most (the reading stops on it, a late one is closed, and the browser is relaunched: "did not open a reading's … in 30 s"). Tests, in the unit cases with stand-in browsers: a reading whose browser disconnects at 100 ms stops then with "the reading stopped (the browser disconnected)", not at its 5 s limit, and one whose browser had disconnected stops at once (on main: given up at its limit, cause reading limit); a browser found disconnected as a reading is about to start is relaunched first (on main: the disconnected browser handed out); a reading the browser does not open a page for stops, and the browser is relaunched. And limitCheck's G, end to end: the browser killed with two readings at a time; the readings on it stop, the browser relaunches once, and the readings that start while it relaunches wait for it and run as on the good site. The carry's scenario on this branch (the Sphinx corpus, the browser killed at 8 s to 21.5 s in 1.5 s steps, readings 20 s): no reading reached its limit in 10 trials (the last review saw 3 of 10 on main), each run ended in 23 to 25 s with one relaunch, and one reading caught as it opened its context stopped then.

3. A reading that waited for a relaunch kept its old budget. left was computed before await b.get(), and after() relaunched past the deadline. Now a reading gets its browser first and counts the time left after the wait, so with none left it is not started, naming the deadline; no relaunch starts past the deadline; and a relaunch waits for its browser (Playwright's launch timeout) no longer than the time left. Tests, in the unit cases: a reading that waits for a relaunch slower than the time left is not started and never runs (on main: it ran, past the deadline); no relaunch past the deadline, and a relaunch's launch bounded by the time left (on main: the dead browser handed out, and the launch given no bound). The carry's scenario (the Sphinx corpus, a relaunch that takes 20 s, the browser killed at 15 s, the run 25 s): main ended after 41 s, 16 s past its deadline; this branch after 26 s, with the readings left naming the run's limit and no relaunch started for them.

The nits and gaps

Item What this pair does
streak counted readings on browsers already replaced Only readings on the current browser count towards "two in a row" (and a relaunch resets it). A unit case pins it: a reading on a replaced browser neither relaunches nor counts, and two in a row on the new one do relaunch. The relaunch still does not help a page-level stall, but now costs one launch, not a browser left open.
Replaced browsers stayed open until the end A replaced browser is closed (10 s at most) once its last reading ends; close() at the run's end waits for those already closing. A unit case pins both: open while a reading still uses it, closed after.
A deadline counted from the job's start harness.yml's first step notes the job's start (JOB_STARTED_MS, before the checkout), given to the rendered checks step alone as HARNESS_JOB_START; runDeadline takes the nearer of the run's 25 minutes from its start and 40 minutes from the job's (HARNESS_JOB_LIMIT), and names which (run_limit.deadline_by, run_limit.job, and the rows' and summary's wording). A job start that is not digits, or lies more than a minute ahead or 45 minutes back, is refused. Unit cases pin the choice and the refusals; limitCheck's J runs run.mjs with the job's deadline already passed. The self-test's own runs of run.mjs never see the job's start or limits.
The limits accepted 0x2710, 1e4 and " 20000 " HARNESS_READING_LIMIT, HARNESS_RUN_LIMIT and HARNESS_JOB_LIMIT take decimal digits alone (a sign, a point, a space, an exponent or hexadecimal refused, and recorded).
The surviving mutants All twelve of the carry's survivors are now killed: N09, N13 and L17 by a unit case of limited (a reading given up before its context opened: closed null, its body told it was given up and stopped at its next step); N14, N15 and L19 by scenario D's new reading, the renderer killed at the second shot of its crops (that reading must stop on it, keeping its rows, counts, metrics and first crop, its failed shots a crop problem each and nothing more); N16 and N17 by the stand-in unit cases and scenario G (two readings at a time: a reading that starts during a relaunch waits for it, and the browser relaunches once); L07 and L08 by unit cases of the crop step with a signal that turns at a chosen read (given up as its first crop is written: that crop removed, no further shot; given up after it: the crop kept, no further shot); C04 by a reading's own crop budget, which cropReading now takes as an argument (shortened to 1 ms); C16 by a clipped surface below the window, which must be shot with the page scrolled to it. With 27 mutants of this pair's own code, 39 in all (the shared engine, run in the Sphinx corpus, each in a process group of its own, after an unmutated run that passes): 38 killed, 1 surviving, D2f (opening a context with no bound), which no fixture forces, as no fixture stops the browser between two readings; the unit cases give a reading that error, and its browser is relaunched. N17 and F2 (readyWithin with no timer) first hung the unit cases; the settle case now races its waits against a timer of its own, and both are killed by an assertion (N17 by scenario G alone).
The self-test left its temporary directories behind Every temporary directory goes through one registry, named harness-selftest-<pid>-<what>-…: each case removes its own when it ends; whatever is left is removed as the self-test exits (an error, Ctrl-C, SIGTERM or SIGHUP, which also stop the run.mjs runs it started in the background); and those of a self-test killed outright (SIGKILL) are removed by the next, once that process has gone. After both full self-tests, no harness-selftest-* directory was left in the system's temp directory.
The Playwright install retry npx playwright install --with-deps chromium is tried three times, 30 s and then 60 s apart, with a warning for each retry and an error after the third.
Pin {in} A unit case: {select, in, text} tests the first in descendant's text (none: not counted), {select, text} the element's own, on a page where they differ.
Pin the page-level drawn.uncounted check now compares uncounted with what the expected counts imply, in order: a page reading with no count taken is one entry, family null, whose why is that reading's error rows' detail (the bad site's missing page, and its page whose dark scheme does not take effect); the selector that throws is one entry a reading, saying so.
The why label The review's own words for this nit did not survive (the log has only "a misleading why"). The one label I found that misleads: the summary's "Empty counts: N, from M reading(s) not taken", which counted uncounted entries as readings though the selector that throws is one family's count in a reading that took the rest. It now says which: "from M page reading(s) with no count taken and K count(s) of one family not taken (…)". Today's live sites have no empty counts, so their summaries are unchanged. This is my guess at the nit, for the review to confirm: if it meant another why, that one is still open.
The thrower lookup The selector that throws is the family expected-good-counts.csv leaves empty at every reading of the good site, so neither drawnCheck nor quietTable rests on the selector's text; the self-test stops unless there is exactly one.
The mystmd_native phone-dark hang Not chased. Settling's document.fonts.ready now waits 15 s at most, bounded in the page, as do MathJax's startup (30 s, in this corpus's theme.mjs). A unit case pins it with a web font that never comes (before: settling still waiting after 8 s). A page whose main thread has stopped still answers nothing, so its reading is given up at its limit in the step it was in, which reading_limit.at_limit names.
Sphinx's crop digest varies on CI Left alone, as the carry says: rasteriser noise on div.highlight's rounded edge, for stage 3's comparator to tolerate.
mystmd's Latin Modern apt step Not here: it is in mystmd's build workflow, not the shared harness, and it goes when QuantEcon/actions#353 lands.

Copilot's automatic review

Copilot reviewed both pull requests on its own, by the repositories' setting; no reviewer was requested. Its two points are taken in the second commit. The first browser is no longer launched once the deadline has passed: every reading is then not started, and provenance.json's browser build is null (scenario J now checks it). And the metrics breaker records only the readings that opened it, where it went on recording those given up after (with four workers, tripped_by and the summary named four readings, not two); a unit case gives up a third reading after it opens. A first launch with time left keeps Playwright's own 180 s limit rather than the time left: a launch that fails stops the run with exit 2 and nothing written, which is worse than a late start, and no reading starts past the deadline either way.

Outputs on today's sites

run.mjs --url from this branch's first commit against both live sites (2026-12-02; the second commit changes nothing a run with time left and no breaker does), compared with main's run on the same site (2026-11-30, both mains unchanged since, so the same builds), and, for the Sphinx site, with a second run of main's code (2026-12-02) to show the noise:

Site counts.csv metrics.csv rendered.csv crops/
Sphinx (5,088 counts, 2,478 metrics rows, 434 rows, 2,148 crops) identical identical but for sha256 (19 rows; main against main's second run: 11) 3 rows differ, all noise: launch-notebooks in light and dark is skip on main (github.com answered 429, and 503 on main's second run) and fail here (it answered); and figures phone light's console row, fail in all three, also names "Permissions policy violation: compute-pressure is not allowed in this document", which the page's embedded YouTube player logged in this run alone the same 2,148 paths; 12 files' bytes differ, all code-cell on code_cells and long_cells (main against main's second run: 7, the same kind), the rasteriser noise the carry leaves to stage 3's comparator
mystmd (5,202 counts, 2,340 metrics rows, 452 rows, 2,184 crops) identical identical, sha256 included 1 row differs, noise: main's run met a 503 from the host on admonitions (its console row fail); this run did not (pass) identical, digest 1e6e70a5… on both

Each run took as long as main's (207 s and 278 s), every reading finished, the browser was not relaunched, and the breaker did not open: reading_limit.metrics_breaker records its rule, with nothing tripped or skipped, and run_limit.job is null outside CI.

Tests

  • Both corpora's full self-tests pass locally at the first commit (Sphinx 354 s, mystmd 497 s; the new limit scenarios run beside the old ones), and leave no temporary directory behind. At the second, the unit cases and the limit scenarios pass locally (in the Sphinx corpus; the engine is shared), and both full self-tests pass on CI.
  • Before and after. The branch's self-test run against main's engine (main's code, with the functions the new unit cases call exported as main has them, and stand-ins for what main lacks that keep main's behaviour): 13 unit mismatches and 2 failing scenarios, each a case of this pair. These are: the limits' readings, the run's deadline, the reading whose browser disconnects (main: given up at its limit), the browser found disconnected (main: handed out), the relaunch waited for (main: the replaced browser never closed), the streak (main: counted a replaced browser's reading, and relaunched one reading late), the unanswered context, no relaunch past the deadline, the time left after a relaunch (main: the reading ran past the deadline), the breaker, settling's wait (main: still settling after 8 s), the crops' own budget, and scenarios H (main: exit 1) and J (main: no job deadline). The first limited case also differs on main, but only in wording: main names the module's limit, not the one it was given.
  • Mutants. See the nits table above.

CI

Green on both pull requests at their second commits, every step on the first attempt, with no warning on either run (no reading given up or not started, no metrics or crop problem); the engine-drift step found the twins' shared files the same. The rendered checks jobs' steps:

Step Sphinx (run 46885229034) mystmd (run 46885237492)
The shared engine matches the twin corpus's 7 s 5 s
Install the harness and its browser 359 s (one try) 19 s
Self-test 291 s 429 s
Rendered checks 155 s 252 s
Upload 4 s 3 s
The job 13 min 56 s 11 min 57 s

The Sphinx install took six minutes on its first and only try (no retry warning); the time is the runner's apt, not the harness.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WT8bMcHqHDAeUKbY94TYzg

…the deadline across a relaunch (D19 carry)

The items the last review of stage 2 left for a small hardening pair (the shared engine, byte-identical in both
corpora; this corpus's README and theme.mjs):

- A stall in a step only the metrics need, on every page, no longer fails the job: once two page readings are given
  up at their limit in such a step, the metrics breaker leaves every page reading after to its checks and counts, with
  one metrics problem and one crop problem for the run.
- A reading whose browser disconnects stops then, rather than wait out its limit; a reading about to start relaunches
  a browser it finds disconnected; opening a reading's context and page waits 30 s at most.
- A reading that waited for a relaunch takes the time left after the wait; no relaunch starts past the deadline, and
  one waits no longer than the time left.
- Only readings on the current browser count towards a relaunch, and a replaced browser is closed once its last
  reading ends.
- The run's deadline also counts from the job's start (HARNESS_JOB_START, noted in harness.yml's first step;
  HARNESS_JOB_LIMIT, 40 minutes), whichever comes first.
- The limits take decimal digits alone.
- Settling waits for document.fonts.ready 15 s at most, in the page (and, on the Sphinx corpus, MathJax's startup
  30 s).
- harness.yml tries `npx playwright install --with-deps chromium` three times.
- The self-test pins drawn.uncounted (the page-level entries too) and `{in}`, looks up the selector that throws from
  the expected counts, forces the surviving mutants it can, and removes its temporary directories however a case ends.

Part of QuantEcon/project-theme-parity#15 (D19, QuantEcon/project-theme-parity#80). The twin is the same change in QuantEcon/test-lecture-theme-mystmd, on the same branch, harness/hardening.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMcHqHDAeUKbY94TYzg

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The initial browser launch bypasses the job deadline, risking time reserved for results, while later timeouts incorrectly inflate breaker-opening provenance.

2 open issues
What changed in this PR

Hardens the shared harness against metrics stalls, browser crashes, and deadline overruns while preserving completed checks and counts.

Changes:

  • Adds a metrics breaker, browser recovery, and job-aware deadlines.
  • Bounds font and MathJax waits and retries browser installation.
  • Expands regression tests, cleanup, provenance, and documentation.
File Description
tests/​harness/​theme.mjs Bounds MathJax startup waits.
tests/​harness/​selftest/​run.mjs Adds hardening tests and temporary-directory cleanup.
tests/​harness/​run.mjs Reports deadlines, breaker activity, and uncounted results.
tests/​harness/​README.md Documents recovery, limits, and test coverage.
tests/​harness/​lib/​visual.mjs Makes the crop budget configurable for tests.
tests/​harness/​lib/​util.mjs Bounds page readiness waits.
tests/​harness/​lib/​engine.mjs Implements the breaker, browser recovery, and deadlines.
.github/​workflows/​harness.yml Records job start and retries browser installation.

Review effort: Balanced (adaptive)

Comment on lines +647 to +648
if (why && left <= 0) { retire(old); return Promise.resolve(); }
launching = Promise.resolve().then(() => launch(why ? Math.min(LAUNCH_LIMIT, left) : LAUNCH_LIMIT)).then(
Comment thread tests/harness/lib/engine.mjs Outdated
}
const { result, givenUp: g } = await limited(Math.min(readingLimit, left), left < readingLimit, (state) => body(browser, state), settle, { browser, words });
if (g) givenUp.push({ ...who, cause: g.cause, step: g.step, why: g.why, closed: g.closed, at: new Date().toISOString() });
if (breaker && g?.cause === "reading limit" && who.family === "page" && metricsStep(g.step)) {
…nly the readings that opened it

Two points from Copilot's automatic review of #27 and
QuantEcon/test-lecture-theme-mystmd#28:

- browsers().first() launched even when the run's deadline (the job's, above all) had already passed, which could
  spend up to Playwright's 180 s launch limit of the time left to write and upload. Now no browser is launched past
  the deadline: every reading is not started, and provenance's browser build is null. A launch with time left still
  has Playwright's own limit, as a launch that failed early would stop the run with nothing written.
- The metrics breaker went on recording readings given up after it had opened, so `tripped_by` and the summary named
  more readings than opened it. Now it records only those; later ones are in reading_limit.at_limit.

The self-test pins both: a stand-in pool with its deadline passed launches nothing, the breaker's unit case gives up a
third reading after it opens, and scenario J (the job's deadline already passed) checks no browser was launched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMcHqHDAeUKbY94TYzg
mmcky added a commit to QuantEcon/test-lecture-theme-mystmd that referenced this pull request Dec 2, 2026
…nly the readings that opened it

Two points from Copilot's automatic review of QuantEcon/test-lecture-theme-sphinx#27 and
#28:

- browsers().first() launched even when the run's deadline (the job's, above all) had already passed, which could
  spend up to Playwright's 180 s launch limit of the time left to write and upload. Now no browser is launched past
  the deadline: every reading is not started, and provenance's browser build is null. A launch with time left still
  has Playwright's own limit, as a launch that failed early would stop the run with nothing written.
- The metrics breaker went on recording readings given up after it had opened, so `tripped_by` and the summary named
  more readings than opened it. Now it records only those; later ones are in reading_limit.at_limit.

The self-test pins both: a stand-in pool with its deadline passed launches nothing, the breaker's unit case gives up a
third reading after it opens, and scenario J (the job's deadline already passed) checks no browser was launched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WT8bMcHqHDAeUKbY94TYzg

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants