Skip to content

Close the post-export scorer when an error stops US certification during scoring - #1802

Draft
anth-volk wants to merge 8 commits into
claude/pooled-post-export-scoring-605c24from
claude/post-export-smoke-first-cancel-330661
Draft

anth-volk wants to merge 8 commits into
claude/pooled-post-export-scoring-605c24from
claude/post-export-smoke-first-cancel-330661

Conversation

@anth-volk

@anth-volk anth-volk commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Tracker task 1.4 · 8 (project 15, "US build memory, CPU and run time"): "Schedule the reform-coverage passes first and cancel the rest when that check fails".

Stacked on #1775 (1.4 · 7, pooled post-export scoring as certification's default): this pull request's base is #1775's branch, so its diff shows only this task. It will be rebased onto main once #1775 merges.

What this does

Certification (_certify_us_build in tools/build_us_fiscal_refresh_release.py) now closes the post-export scorer when any error stops it during scoring, then raises that error. Before, nothing closed the scorer until every stage had finished, so on an error a pooled scorer's workers kept running the units they had started until the process exited and the pool's exit handler killed them.

  • The errors covered: any error between opening the scorer and taking its manifest block:
    • the reform-coverage smoke check's refusal at the certified tier;
    • an evidence-tier smoke failure that matches no owner;
    • a stage's own error, including a unit that failed on every attempt;
    • a SIGTERM, which certification raises as BuildTerminatedError.
  • What closing does:
    • a pooled scorer kills the workers still running a unit at once, and tells idle workers to exit, killing any that has not exited within 10 seconds;
    • every scorer, pooled or serial, removes its batch files.
  • Errors while closing (_close_post_export_scorer_after_error):
    • an Exception from closing is printed to stderr, and the first error is the one raised. This holds even when the error's text cannot be made or stderr cannot be written;
    • an interrupt while closing (Ctrl-C, or a first SIGTERM) is raised instead, with the first error as its context;
    • batch files left by a failed close are removed when the process exits.
  • A failed smoke check that certification goes on past (--allow-reform-coverage-smoke-failures, or an evidence-tier failure with an owner) cancels nothing: every later stage still runs and writes its file.

How this meets the task's finished-when text

"The reform-coverage passes run first, and the remaining passes are cancelled when that check fails."

  • Run first: Score US post-export requests in the shared worker pool by default #1775 already hands out the smoke check's reform units before any other stage's, after the merged baseline pass, which holds every stage's baseline variables. This pull request keeps that order and pins it in a test.
  • Cancelled: workers run ahead of the stages by up to twice the worker count of units.
    • With two or more workers, reform validation's first units start while the smoke check's last units are still running.
    • With one worker, reform validation's first unit is handed out as the check's last result comes back, before the check's result is decided.
    • When the check fails and that stops certification, those units are now killed as soon as the refusal is raised, and no further unit is started.

Decisions (Anthony, 27 November 2026, recorded in the tracker task's notes)

  1. Start from Score US post-export requests in the shared worker pool by default #1775's branch, with this pull request based on it.
  2. Let reform validation's units keep starting before the smoke check's result is known, and cancel them when the check fails. Holding them back would leave workers idle at the end of the check on every passing build, about 7–24 minutes (estimate).
  3. Count the check as failed only once every probe is scored, as today, so reform_coverage_smoke.json keeps every probe's result. The check function, its record and the serial scorer's outputs are unchanged. Cancelling matters only for pooled scoring; the serial path already raises before reform validation starts.
  4. Close the scorer on any error during scoring, not only on the smoke check's refusal.
    • There is no new option on the pooled scorer.
    • The export probe (tools/probe_us_post_export.py) is unchanged: it runs every stage whatever the check says, and it already closes its scorer in a finally block.
  5. Keep the merged baseline pass before the smoke check's reform units. Scoring the check's baseline variables first would add a baseline pass to every build.
  6. An interrupt while closing (Ctrl-C, or a first SIGTERM) is raised in place of the first error, which it carries as its context, so a SIGTERM still ends the run as a termination (exit code 143). An ordinary error from closing is printed, and the first error is raised.

Tests

Red-green throughout: each round's failing tests were committed before the change that makes them pass.

The new tests are at the end of packages/microcosm-build/tests/engine_free/us/test_us_post_export_pooled_scoring.py. They run _certify_us_build with a stub of the build record on the fixture plan and the fake engine, in certification's batch folder, with three of the shipped probes made to pass or fail.

  • test_a_failed_check_that_stops_certification_stops_the_pools_workers[certified|evidence_unowned]: one worker, and every reform other than the check's waits on a file nobody writes.
    • The merged baseline pass's engines are built first, then the check's reformed simulations, then reform validation's first.
    • Within 8 seconds of the check's result (the pool waits 10 seconds for a worker it has told to stop), no new child process is running.
    • The batch files and the batch folder are gone.
    • The reform-validation unit never finished, and reform_validation.json was never written.
  • test_any_error_during_scoring_closes_the_scorer[pooled|serial|pooled_sigterm]: an error, or a BuildTerminatedError, from the demographics writer leaves no worker running and no batch files.
  • test_a_stage_error_kills_the_units_still_running: reform validation fails as it builds its second reform, while the worker runs that reform's unit. The unit is killed within 8 seconds.
  • test_an_error_closing_the_scorer_does_not_replace_the_one_that_stopped_it[ordinary|unprintable] and test_a_warning_that_cannot_be_written_does_not_replace_the_error: the check's refusal is raised.
  • test_an_interrupt_while_closing_the_scorer_is_raised: the interrupt is raised, with the refusal as its context.
  • test_a_failed_check_that_does_not_stop_certification_cancels_nothing[allowed|evidence_owned]: every stage writes its file, from one pool and one worker start, with no failed attempt.
    • These two pass without the change. They pin that cancelling stops only what stops certification.

The fake engine (test_support/microcosm_build/us_post_export_pool.py) gains WAIT_FOR_OTHER_REFORMS, which makes every reformed simulation other than the listed ones wait for a file before each variable.

What was run, and what wasn't:

  • All twelve cases were run locally, each by node ID only, in the engine-free environment. They pass, in about a minute in all; the stop test has passed in every one of six runs of both its cases since round 1's fix.
  • The existing tests that inspect _certify_us_build's source (test_us_post_export_scoring.py, test_us_fiscal_refresh_builder.py, test_us_post_export_pooled_scoring.py, test_release_contract_fixture_generation.py) were read against the change, by me and by two reviewers, but not run. They use ast.walk, line order, or substrings outside the re-indented lines.

The tool's diff re-indents the scoring stages inside the new try block, so view it with whitespace ignored (?w=1).

Review

Three rounds of adversarial review (subagents) followed, each with its fixes:

  • Round 1 (two reviewers, the change and its tests): no fault in the change.
    • The main test raced with its worker. Both reviewers reproduced it, and the test now waits for the unit to start.
    • Fixed gaps: no test raised an interrupt; "killed at once" wasn't distinguished from a close that waits; live workers were found only through the engine log; the batch folder wasn't exercised.
    • Docs wording on what stops at once was corrected.
  • Round 2 (whole change): nothing serious.
    • A close error whose text cannot be made replaced the original error. Fixed, test first.
    • The pin test passed even when the busy worker was killed and its unit run again. It now checks the pool's report.
    • Tests added for an interrupt while closing, and for a stage's error killing a running unit.
  • Round 3 (round 2's changes): nothing serious.
    • A failed write of the warning to stderr replaced the original error. Fixed, test first.
    • One missing batch-folder check was added.

Not done here, and known effects

  • No CI runs on this pull request yet. The test workflow runs only on pull requests that target main, and retargeting starts no run (docs/agent-guide.md). Once Score US post-export requests in the shared worker pool by default #1775 merges, this branch is rebased onto main, which pushes, retargets and starts CI.

  • Cost figures: those in decision 2 are estimates from tracker task 1.4 · 6's per-pass figures. No run measured them.

  • Closing now happens before certify_main reports the failure to staging (telemetry.fail). The close takes about 0.05–0.2 s when measured, and up to 10 s if an idle worker is slow to exit. A second SIGTERM in that window kills the process before the failure is reported, because the first SIGTERM resets the handler.

  • A pre-existing edge case: _HouseholdBatchedPostExportScorer.close (from Score US post-export requests in the shared worker pool by default #1775 and main) has no try/finally. If finishing an open reform raises, its batch files are left until the process exits, when its finalizer removes them. This pull request leaves that code alone.

🤖 Generated with Claude Code

anth-volk and others added 8 commits November 27, 2026 21:01
…ps certification

Tracker task 1.4 · 8. Certification closes the post-export scorer only once
every stage has finished, so when the reform-coverage check fails at the
certified tier (or with a failure no evidence owner matches), or any stage
raises, the pool's workers keep running the units they had started until
the process exits.

The new tests run _certify_us_build on the fixture plan with the fake
engine, and require:

- a failed check that stops certification to leave no pool worker running
  and no batch files when the refusal leaves _certify_us_build, with the
  check's reform units run first and the reform-validation unit already
  started killed rather than finished (certified tier, and evidence tier
  with an unowned failure);
- any other error during scoring to close the scorer too, pooled or serial;
- an error from closing the scorer to be printed, with the original error
  raised.

Two pins pass already: a failed check that certification goes on past (the
allow option, or an evidence failure with an owner) cancels nothing, and
every later stage writes its file.

The fake engine gains WAIT_FOR_OTHER_REFORMS, which holds every reformed
simulation but the listed ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… scoring

Tracker task 1.4 · 8 ("Schedule the reform-coverage passes first and cancel
the rest when that check fails"). Pooled scoring already hands out the
reform-coverage smoke's reform units before any other stage's, after the
merged baseline pass. Certification now closes the scorer when any error
stops it between opening the scorer and taking its manifest block, then
raises that error:

- the smoke's refusal at the certified tier, or an evidence-tier smoke
  failure that matches no owner;
- any stage's own error, a unit that failed on every attempt, or a SIGTERM
  (BuildTerminatedError).

A pooled scorer's workers then stop at once: those still running a unit,
such as reform validation's first units, which start while the smoke's last
are running, are killed rather than left to run until the process exits.
Every scorer removes its batch files. An error from closing is printed and
the first error is the one raised (_close_post_export_scorer_after_error).
A failed smoke that certification goes on past (the allow option, or an
evidence failure with an owner) cancels nothing. The check itself, its
record and the serial scorer's outputs are unchanged.

The diff re-indents the scoring stages inside the new try block; view it
with whitespace ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 (two adversarial reviewers) found no fault in the change and
these in its tests:

- The stop test raced with its worker: the pool hands reform validation's
  first unit to the worker as the check's last result comes back, and the
  close could kill the worker before it logged that unit's first engine.
  The test now waits, after the check runs, until the worker has built it,
  so the kill always lands on a started unit.
- Nothing raised an interrupt. test_any_error_during_scoring_closes_the_scorer
  gains a pooled case where the stage raises BuildTerminatedError (a
  KeyboardInterrupt, as certification raises a SIGTERM), so a handler
  narrowed to Exception would fail it.
- "Killed at once" was not separated from a close that waits: the stop test
  now requires the refusal within 8 seconds of the check's result, below
  the pool's 10-second wait for a worker told to stop, while the started
  unit waits two minutes.
- Live workers were found only among processes that wrote to the engine
  log; the tests now require no new multiprocessing child at all.
- The opener stub dropped certification's batch parent; the scorers are now
  built in it, and the tests require the parent the scorer made to be
  removed too.
- The stop test now also checks that the merged baseline pass's engines
  were all built before any reform's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 found the wording loose. The docstring of
_close_post_export_scorer_after_error, the release-build doc and the
changelog fragment now say that:

- only workers running a unit are killed at once; idle workers are told
  to exit and killed after 10 seconds if they have not;
- with one worker, reform validation's first unit is handed out as the
  smoke's last result comes back, before the smoke's result is decided;
- an Exception from closing is printed and the first error raised, but an
  interrupt while closing (Ctrl-C, or a first SIGTERM) is raised instead;
- batch files a failed close left are removed when the process exits.

No code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 found nothing serious in the change. From its findings:

- An error from closing whose text cannot be made (its __str__ raises)
  replaces the error that stopped certification, because the warning
  formats it unguarded. New case
  test_an_error_closing_the_scorer_does_not_replace_the_one_that_stopped_it
  [unprintable] fails until the warning is guarded.
- These pass already and pin documented behaviour:
  - test_an_interrupt_while_closing_the_scorer_is_raised: an interrupt
    while closing is raised, with the first error as its context;
  - test_a_stage_error_kills_the_units_still_running: reform validation
    failing while the worker runs its next unit kills that unit at once.
- test_a_failed_check_that_does_not_stop_certification_cancels_nothing
  passed even when the busy worker was killed and its unit run again in a
  fresh one (the reviewer showed this). It now also requires one pool, one
  worker start and no failed attempts.
- The tests build their exceptions inside the test, not at collection, so
  no exception and its traceback outlives its test.
- Wording: WAIT_FOR_OTHER_REFORMS waits before each variable an engine
  computes; the module docstring lists the closing tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- _close_post_export_scorer_after_error guards making the warning's text:
  an error from closing whose __str__ raises is printed by its class name,
  and the error that stopped certification is still the one raised.
- The release-build doc and the changelog fragment say the scorer is
  closed before the error leaves certification (it has already been
  raised by then).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 3 found nothing serious. From its findings:

- When closing the scorer after an error raises, and writing the warning
  to standard error fails too (a broken pipe), the write's error replaces
  the one that stopped certification. New
  test_a_warning_that_cannot_be_written_does_not_replace_the_error fails
  until the write is guarded.
- test_a_stage_error_kills_the_units_still_running also requires the batch
  parent the scorer made to be removed, as the neighbouring tests do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_close_post_export_scorer_after_error no longer lets a failed write of its
warning (standard error's reader gone) replace the error that stopped
certification: the print is guarded, and the first error is raised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant