Skip to content

Shared worker pool for household-batched policyengine-us work (1.4 · 1) - #1726

Merged
anth-volk merged 16 commits into
mainfrom
claude/shared-worker-pool-2cf1b5
Nov 25, 2026
Merged

anth-volk merged 16 commits into
mainfrom
claude/shared-worker-pool-2cf1b5

Conversation

@anth-volk

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

Copy link
Copy Markdown
Contributor

Tracker task 1.4 · 1 of project 15 (US build memory, CPU and run time).

Summary

  • A shared worker pool, microcosm.build.worker_pool, for household-batched policyengine-us work. Later tasks move their callers onto it: post-export scoring (2.3 · 1), target compilation (2.3 · 3), the population-wide input runs (2.3 · 4), local-area materialize (2.5 · 1) and the planner that sizes workers from the memory budget (2.6 · 2).
  • The head-to-head scorer moves onto it (Anthony's decision), so the repository has one worker-pool implementation.
  • Post-export scoring removes each reform's policyengine-core rule modules once the reform is finished (Anthony asked for this to be part of 1.4 · 1). On the 8-household fixture they cost about 0.04 GiB per reform pass.

The pool

WorkerPool(settings, initializer=..., initargs=..., unit_function=..., describe_unit=...). pool.map(units) yields unit_function(state, unit) for each unit, in unit order.

  • Spawned workers. Each worker is a fresh Python process (spawn). The parent starts and tracks its own processes, with two one-way pipes to each, instead of using ProcessPoolExecutor. That's what lets it tell which unit a dead worker held and run that unit again.
  • Start-up data sent once per worker. initializer(*initargs) runs once in each worker, and its return value is the state every unit in that worker receives.
    • initargs are pickled and sent over the worker's own pipe once per worker start, after its process has started. So a frame passed there crosses once per worker, not once per unit.
    • Workers started together import their modules at the same time. Under ProcessPoolExecutor each start waited for the previous worker's imports: 36–44 s per start in Register the US head-to-head scorer as a Modal stage for the d844 run #1190's evidence.
    • A worker that dies while receiving its start-up data counts as a failed start. max_attempts failed starts in a row stop the run.
  • Worker replacement. max_units_per_worker replaces a worker after K units. The replacement starts only after the old worker has exited, so no more than workers processes are ever alive.
    • A worker that hasn't exited 10 s after being told to stop is killed.
    • There is no Python-version restriction: the CPython hang the scorer guarded against is in ProcessPoolExecutor, which the pool doesn't use.
  • A memory cap per worker. With memory_cap_bytes, a thread in the parent reads each worker's memory every memory_poll_seconds and kills a worker over the cap.
    • The reading is the process's footprint: on Linux, resident memory plus swapped-out pages (VmRSS + VmSwap); on macOS, the physical footprint, which counts compressed pages.
    • Resident memory alone falls when the machine is short of memory, which would let a worker slip under its cap.
    • The parent also reads a worker's memory when it returns a result. A worker over the cap then is replaced before it gets another unit, so memory one unit leaves behind isn't charged to the next.
    • A worker start doesn't hold the lock the memory thread needs, so the cap is enforced while a replacement imports its modules.
    • The memory thread records how many units a worker had been sent when it read the worker's memory. It kills the worker only if no new unit was sent since, so a reading taken during one unit can't be charged to the next.
    • A unit is assigned to a worker, and its attempt counted, under the lock before it is written, and never to a worker that has been killed. So a worker that dies while a unit is being written to it is charged for that unit, like any other death.
  • Running a failed unit again. A unit runs again in a fresh worker if its worker dies before returning a result (a crash, the operating system's out-of-memory kill, the cap), or if the unit raises MemoryError. It gets up to max_attempts attempts in all (default 2).
    • Any other exception stops the run at once, with the unit's label and the worker's traceback, because the same inputs would raise it again. So does a unit or result that can't be pickled or unpickled.
    • pool.report() lists every failed attempt and its cause, the worker starts, the most workers alive at once and the peak memory read.
  • Results in unit order. At most max_units_ahead units (default twice workers), counted from the oldest result not yet handed back, are running or waiting with a result. That bounds what the parent holds while it waits for a slow unit.
    • Before handing back a result it already holds, the parent takes in finished work and gives idle workers new units.
    • map drops each result once it has handed it back.
    • One map runs at a time. A map reads its units first, then takes its turn under the lock. Each map holds a token for its turn, so a finished map's generator closed late can't end a later map's turn, and a units iterable that raises leaves the pool usable.
  • Pipes. Each worker has two one-way pipes. Socket pairs carried a 400 MiB result in 13 s on macOS with Python 3.13, against 1.6 s for a pipe.
  • A worker environment (Anthony's decision). worker_environment sets environment variables in each worker as it starts, before it imports anything.
    • It exists so 2.6 · 2 can give workers different numeric thread counts from the parent's. This PR chooses no values; without it, workers inherit the parent's environment.
    • It's applied by holding the values in the parent's environment while each worker starts, because spawn re-imports the parent's main script before any pool code runs.
  • No orphaned workers.
    • Each worker watches a pipe that only its parent holds open, so it exits as soon as the parent dies, even in the middle of a unit. A long call into C code that holds Python's global interpreter lock delays this until the call returns.
    • Each worker also checks its parent process ID every second. A child the parent forked holds copies of that pipe, so the pipe alone would not show the parent's death.
    • A pool that is garbage-collected, or still open at interpreter exit, kills its workers.
    • A map resumed after the pool closed raises instead of starting workers.
    • A worker told to stop is killed at its deadline, even between maps.
    • The pool's lock is reentrant, and close() never waits for the memory thread, which stops at its next poll. So a garbage collection that closes an abandoned map or the pool can't deadlock, whichever thread it runs in, and even while that thread holds the lock.
  • Killing the right process. On Linux, workers are killed through a process file descriptor (pidfd), so a kill can't reach a different process that has been given the same process ID.
    • On macOS the pool checks under its lock that the worker hasn't exited, and reaps workers under the same lock.
    • But multiprocessing.Process.start reaps every exited child of the parent outside that lock, including during the pool's own worker starts, and so does multiprocessing.active_children(). That leaves a window of microseconds in which a worker's process ID could be reused before a kill lands.
    • A worker whose exit status something else collected (for example SIGCHLD set to SIG_IGN) is still noticed, through its exit pipe.
  • Sizing is the caller's. The pool takes the worker count and the cap as inputs.

The 1-vs-N byte-identity helper is test_support/microcosm_build/worker_pool_identity.py. assert_identical_across_worker_counts(run, worker_counts=(1, N)) runs run(workers) at each count and compares canonical bytes, then names the first place that differs.

  • Arrays compare by type, dtype (with byte order and fields), shape and raw bytes, and masked arrays by their mask too.
  • Structured arrays and records are encoded field by field, never by raw bytes, which would include padding and object addresses.
  • Every other value carries its type, including numpy scalar and record types. Floats compare by their IEEE 754 bits; mappings keep their key order; classes and enum members compare by name.
  • pandas objects keep their dtypes, a categorical's categories, order and codes, missing values apart from NaN, index names, attrs and a DatetimeIndex's frequency. A MultiIndex compares by each level's values, so equal ones built differently match.
  • Subclasses keep their own state: what a pandas subclass lists in _metadata (a MicroSeries' weights) and an ndarray subclass's attributes (an EnumArray's enum class).
  • So 0.0 against -0.0, NaNs with different bits, int32 against int64, True against np.True_, and two MicroSeries with different weights all count as different.
  • Types it can't encode raise TypeError, rather than being compared some approximate way.

The head-to-head scorer

  • --workers slices run on the shared pool. The scorer's ProcessPoolExecutor code and its Python-version refusal of --worker-max-slices are removed.
  • A behaviour change: a slice whose worker dies now runs once more in a fresh worker before the run stops. Before, any worker death stopped the comparison.
    • The scorer's own 20 GiB memory check stays fatal in a worker, as in one process.
    • So does any other error raised while scoring a slice, including a genuine allocation failure. Only a worker the operating system kills runs again, because the scorer sets no pool memory cap.
    • Each failed attempt is printed on stderr, beside the memory receipts.
    • A worker that fails while starting names the artifact.
  • Scorecards are unchanged. The fixture test compares 1, 2 and 3 workers, with and without worker replacement, against the sequential path. It checks the JSON and Markdown and the float64 estimate bits.
  • This worktree's Python, 3.13.13, is one of those the scorer used to refuse worker replacement on. Those test cases were skipped before and run now.
  • Draft PR Register the US head-to-head scorer as a Modal stage for the d844 run #1190 pins the scorer at 2cfe3043d, so its planned d844 run is unaffected. If Register the US head-to-head scorer as a Modal stage for the d844 run #1190 moves to a newer main, its go/no-go estimate, which models ProcessPoolExecutor's on-demand worker starts, needs re-checking: the shared pool starts its workers itself, up to the worker count.

Post-export rule modules

  • What leaks. Each reform pass builds its own reformed tax-benefit system. policyengine-core adds about 6,000 variable modules to sys.modules for every system it builds and never removes them.
    • The existing helper temporary_engine_variable_modules removes them; the head-to-head scorer already uses it.
    • A post-export reform's system is built on its first key and used until its consumer moves on, which spans several calls. Holding the helper's context manager open across calls is unsafe: if the scope is never closed, the garbage collector runs its cleanup at an arbitrary later moment, and it then removes the modules of a later reform still in use. The tests reproduced this.
  • The fix.
    • EngineVariableModuleScope is an explicit open/close form of the helper, and temporary_engine_variable_modules now uses it. A scope left unclosed does nothing when collected.
    • Scopes may close in any order. A registration belongs to the most recently opened scope that is still open when it's made. A scope that closes while a later one is still open removes only what was registered before the later one opened, and never puts back an entry the later scope has replaced.
    • The scorer keeps one reform open at a time. Handing out the next reform, finishing its consumer or closing the scorer finishes it: it drops its system and removes its modules.
    • A finished reform refuses further keys. The shipped consumers, the probe and the sweep each score one reform completely before opening the next.
  • Measured on the 8-household guard fixture (all 43 reform-coverage passes, without the removal): the footprint grew from 1.25 to 4.73 GiB. With the removal, the first 25 passes grew 1.74 GiB instead of 2.93 GiB.
    • The remaining growth is mostly one pass. salt_refund_income_neutralization leaves a whole copy of the rules and parameters alive (about 1.3 GiB). Follow-up task 1.4 · 5 investigates it.
  • Scored values are byte-identical. The engine test scores two reforms with and without the removal and compares the arrays' bytes.

Tests

Only the tests this PR adds or changes were run, each by node ID. No full suite was run.

  • engine_free/shared/test_worker_pool.py: all 52 test functions (59 cases), 59 passed.
  • engine_free/us/test_us_release_slice_memory.py: the 7 new tests, which passed.
    • I also ran, by mistake, two existing tests of the changed engine_lifecycle.py that this PR doesn't change; both passed.
  • engine_free/us/test_us_release_head_to_head_scorer.py: the 7 changed or new tests, including test_spawned_workers_score_identically_to_sequential_cli (about 11 minutes here).
  • engine_free/us/test_us_post_export_scoring.py: the 6 new tests.
  • engine_workflow/us/test_us_post_export_scoring.py::test_reform_passes_leave_no_rule_modules_behind_and_score_the_same.
  • Final run at the PR's head: the 13 scorer and post-export engine-free tests passed (16 min), and the engine test passed.
  • tools/ci_test_plan.py verify, ruff check and ruff format --check on the changed files pass, and the branch merges cleanly with origin/main at cac12ab01.
  • CI, first run: one pool test failed on both engine-free legs.
    • On the Linux runners a fresh worker holds about 0.5 GiB, so the test's fixed 512 MiB cap killed workers while they started.
    • b780d8587 sets each cap test's cap 256 MiB above an idle worker's measured peak.

Review rounds

  • Round 1: two reviewers, one on the pool and one on the scorer and post-export integration, reported 20 problems: 18 reproduced, one reasoned only (process-ID reuse) and one stale doc paragraph.
    • 16 are fixed, each with a failing test committed first.
    • Fixed without a test: the cost of scheduling, which grew with the square of the unit count, and the doc paragraph.
    • Narrowed but not removed: process-ID reuse on macOS (see "Killing the right process").
    • Left as a known limit: the import cost of each worker start.
  • Round 2: two new reviewers.
    • Pool: 11 findings, 10 reproduced, including results swapped between maps, a deadlock when garbage collection closes the pool in its memory thread, and a unit charged for an earlier unit's memory. All are fixed with a failing test committed first, except:
      • the parent-death limit for long C calls, which is now stated in the docstring;
      • the spinning wait, fixed without a test;
      • the pidfd leak at shutdown, fixed without a test.
    • Integrations: no defects in the scorer or post-export scoring. Five findings in the identity helper and the module scopes, four reproduced and one informational; the four are fixed with failing tests first.
  • Round 3: two new reviewers.
    • Pool: 8 findings, all reproduced, 4 of them only by forcing the order in which threads run. They included:

      • a unit retried for ever when its worker died while the unit was being written;
      • a units iterable that raised and blocked every later map;
      • a worker dying while reading its start-up data, which stopped the run instead of counting as a failed start;
      • a hang when close() ran under the lock;
      • a forked child keeping workers alive after the parent died.

      All are fixed. Six have a failing test committed first; two (two threads starting a map at the same moment, and a reading charged to the next unit in a microsecond gap) are fixed by holding the lock and have no test.

    • Integrations: no defects in the scorer or post-export scoring. Seven findings: three in the identity helper (subclass state, MultiIndex slices, numpy scalar types and unencodable pandas values), three module-scope edge cases no shipped code reaches, and one inaccurate changelog sentence.

      • The helper findings and two of the scope cases are fixed with failing tests first.
      • The third scope case (which scope a registration belongs to) is now stated in the docstring.
      • The changelog sentence is corrected.

Known limits

  • Every worker start imports microcosm.build, because the worker's entry point is in this module. That includes torch and pandas: about 3.6 s and 220 MiB on the Mac, before the initializer runs. Task 1.5 · 1 (import torch only where it's used) reduces this. Callers' workers import microcosm.build anyway.
  • While the caller holds a result, workers that finish get no new units. map hands out units before it yields a result, but not while the caller is working on that result. A caller that does slow work between results leaves those workers idle. The head-to-head scorer's work between results is small.

Not in this PR

  • Moving post-export scoring, target compilation, the input runs and local-area materialize onto the pool: 2.3 · 1, 2.3 · 3, 2.3 · 4 and 2.5 · 1.
  • Choosing worker counts, caps and thread counts: 2.6 · 2.
  • Holding back new units while the machine's free memory is low: 2.6 · 3.
  • No CI/CD, Docker, Terraform or Modal code changes, and no environment variables are added to deployed jobs. worker_environment only passes through values a caller supplies.

🤖 Generated with Claude Code

anth-volk and others added 14 commits November 25, 2026 02:38
…le removal

Tests for microcosm.build.worker_pool (spawned workers, the initializer's
state sent once per worker, worker replacement after a unit limit, a
per-worker memory cap, re-running a unit whose worker died, ran out of memory
or went over its cap, results in unit order, a per-worker environment) and
for a 1-vs-N byte-identity helper. The head-to-head scorer's parallel tests
now expect the shared pool and run worker replacement on every interpreter.
Post-export scoring tests expect each reform's policyengine-core rule modules
to be removed once its consumer opens the next reform or finishes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A post-export reform's rule modules must be removed when its consumer moves
on, which spans several calls. A suspended temporary_engine_variable_modules
generator would run its cleanup whenever the garbage collector closed it and
could remove a later scope's modules. These tests expect an explicit scope that
does nothing when dropped unclosed, and one open reform per post-export scorer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…post-export rule modules

microcosm.build.worker_pool runs units of household-batched work in spawned
worker processes it starts and tracks itself: the initializer's state is sent
once per worker, workers can be replaced after K units with never more than
the worker count alive, a parent thread stops a worker over its memory cap
(resident plus compressed or swapped-out pages), a unit whose worker dies,
goes over the cap or raises MemoryError runs again in a fresh worker up to
max_attempts, results come back in unit order within a bounded window, and
optional environment variables are set in each worker as it starts. The
worker_pool_identity test helper requires byte-identical results at 1 and N
workers.

The head-to-head scorer's --workers slices run on the pool, so its
ProcessPoolExecutor code and its Python-version refusal of
--worker-max-slices go away.

Post-export scoring opens an EngineVariableModuleScope (the explicit form of
temporary_engine_variable_modules) when it builds a reform's system, and
closes it when the scorer hands out its next reform, the consumer finishes or
the scorer closes, removing the ~6,000 variable modules policyengine-core
registers per system and never removes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pool: the memory cap while a worker starts, resuming a closed pool's map, a
worker that will not exit after being stopped, an unclosed pool's workers,
busy workers whose parent is killed, a map whose results were all taken,
units and results that cannot be unpickled, memory one unit leaves behind,
environment values that cannot be encoded, exit statuses collected elsewhere,
and functions defined where workers cannot import them. Scorer: its own
20 GiB check stays fatal in a worker, a failed worker start names the
artifact, and failed attempts are reported on stderr. Identity helper:
structured dtypes, masked arrays, scalar and integer subclasses, bytes types
and pandas categories and index names. Rule-module scopes may close out of
order, and closing one scorer keeps another's open reform modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pool: a worker start no longer holds the lock the memory thread needs; a map
resumed after close raises; a worker that has not exited 10 s after being
told to stop is killed; the memory thread and the finalizer share state with
the pool, not the pool itself, so an unclosed pool is collected and kills its
workers; workers exit when their parent dies; the last result finishes the
map; units and results that cannot be unpickled stop the run with their
label; a worker over its cap when it returns a result is replaced before its
next unit; environment values are checked for encoding and set inside the
restore block; dispatch no longer counts every unsent unit on each pass;
exits are seen through each worker's exit pipe, so an exit status collected
elsewhere is noticed; workers are killed through a pidfd on Linux; functions
in a __main__ that spawn cannot import are refused.

Scorer: its own 20 GiB check stays fatal in a worker, a failed worker start
names the artifact, and failed attempts are reported on stderr.

Module scopes may close out of order; the identity helper keeps dtypes with
their fields, array and scalar types, masks and pandas metadata. The h2h
memory evidence README describes worker replacement on the shared pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A finished map's generator must not end a running map's turn; the pool must
close cleanly from inside its memory thread while that thread holds the lock;
a memory reading taken before a worker's current unit must not kill it; workers
must use pipes; an idle worker must get its next unit while the caller holds a
result; a handed-back result must not be kept while map waits; a stopped
worker must be killed at its deadline between maps; a refused kill must not
raise; the memory poll interval must be one a thread can wait for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each map holds a token for its turn, so a finished map's generator closed
late cannot end a later map's turn; the shared lock is reentrant and close()
skips joining the memory thread from inside it, so a garbage collection there
can close the pool; the memory thread records how many units a worker had
been sent when it read the worker's memory and kills only if no new unit was
sent since; it also kills stopped workers at their deadline between maps;
workers use two one-way pipes instead of a socket pair; the main loop takes
in finished work and hands out units before yielding a result it holds; map
drops each result after yielding it; the poll interval must be one a thread
can wait for; a result-time cap kill no longer makes the wait spin; kills the
operating system refuses are given up on, not raised; shutdown closes pidfds
and reaps under the lock. The docstring states the interpreter-lock limit of
the parent-death exit and where process IDs can still be reused on macOS.

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

The identity helper must encode equal structured arrays with object fields
equally, keep categories beyond what a dtype's repr shows, MultiIndex level
dtypes, nullable missing values, attrs and DatetimeIndex frequencies, and
name NaN keys, frame cells and 0-d arrays. A module scope freed by a garbage
collection while another scope holds the lock in the same thread must not hang.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
canonical_result_bytes encodes structured arrays and records field by field
(never raw bytes with padding or object addresses), categoricals by their
categories, order and codes, MultiIndex levels with their codes, extension
arrays with their missing entries apart from NaN, attrs and DatetimeIndex
frequencies; _first_difference compares mapping keys by their bytes, descends
into DataFrame columns and Series positions, and names a 0-d array by its
place. The module scopes' lock is reentrant and closing iterates a copy of the
open scopes, so a scope a garbage collection frees mid-open cannot hang.

The NaN-against-missing test builds its NaN with an explicit mask: pandas 3
turns NaN into a missing value when converting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A unit whose worker dies while receiving it is charged an attempt; a worker
that dies while receiving its start-up data is a failed start, not the end of
the run; a units iterable that raises leaves the pool usable; close() returns
when its thread holds the pool's lock; handing back a result frees its place
for an idle worker at once; busy workers exit when their parent is killed even
while a child the parent forked holds copies of its pipe ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Start-up data goes over each worker's own pipe after its process starts, so a
worker that dies while reading it is an ordinary failed start (and is reaped),
and workers started together import at once. A unit is assigned and its
attempt counted under the lock before it is written, and never to a killed
worker, so a worker dying mid-send is charged and a reading taken before the
unit cannot kill for it. map() reads its units before taking its turn, takes
the turn under the lock and releases it on any failure. close() no longer
joins the memory thread, and report() builds its result outside the lock. A
held result frees its window place before units are handed out. Workers also
exit when their parent process ID changes, for a parent whose forked child
holds copies of the parent-death pipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The identity helper must keep a Series subclass's _metadata and an ndarray
subclass's attributes (such as weights and enum classes), numpy record and
scalar types, encode equal MultiIndexes equally however they were built, and
refuse pandas values it cannot encode with its own TypeError. A closing module
scope must not put back a module another scope removed, nor replace a module a
later, still-open scope registered under the same name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
canonical_result_bytes encodes what a pandas subclass lists in _metadata and
what an ndarray subclass keeps in its instance dictionary (MicroSeries weights,
an EnumArray's enum class), classes and enum members by name, numpy scalar
types and dtype character codes, a MultiIndex by each level's values, and
refuses pandas values it cannot encode with its own TypeError.

A closing module scope leaves entries from its snapshot to a later open scope,
and puts one back only while it is still registered, so it never restores a
module another scope removed or replaces one a later scope registered under a
reused name. The docstring states which scope a registration belongs to.

The scorer's changelog entry says only a worker death runs a slice again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the Linux CI runners a fresh worker holds about 0.5 GiB once it has
imported microcosm.build (torch and pandas), so the fixed 512 MiB cap killed
workers while they started and test_a_worker_over_its_memory_cap_is_stopped_
and_its_unit_run_again failed on both engine-free legs. A module fixture now
measures an idle worker's peak, and each cap test sets its cap 256 MiB above
it and allocates 768 MiB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk requested a review from juaristi22 November 25, 2026 14:21
@anth-volk
anth-volk marked this pull request as ready for review November 25, 2026 14:21
anth-volk and others added 2 commits November 25, 2026 19:42
On the engine-free (3.13) runner the test process, an hour into the run and
holding 3.2 GB, showed the same footprint before and after allocating
256 MiB: its C allocator can hand out a freed block that is already resident.
The test now reads a fresh child process before and after it allocates, and
checks the reading is None once the child has exited.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
engine-free (3.14) and engine-uk (3.14) stopped after 18 s, before any test
ran, with "No server is currently available to service your request" while
fetching a release. Jobs cannot be re-run while their workflow run is still in
progress, so this empty commit starts a new run.

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

@juaristi22 juaristi22 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at 1828a1e96. The pool does what the description says, the head-to-head scorecards and the post-export scores don't move, and the branch merges cleanly with main. One thing before merge.

What I checked

  • I probed the pool on invented units (macOS arm64, Python 3.14):
    • 40 units with random delays on 3 workers, each replaced after 2 units: the results came back in unit order and byte-identical to a sequential run, over 21 worker starts with never more than 3 alive.
    • A worker killed with SIGKILL in the middle of a unit: the unit ran again in a fresh worker, the results were unchanged, and the report named SIGKILL.
    • A unit that raised ValueError: the run stopped at once with the unit's label and the worker's traceback, and the pool closed.
    • A worker over its memory cap (idle at about 220 MiB, a cap 300 MiB above that, a unit holding 600 MiB): it was killed, the unit ran again, and the run stopped naming the cap. Units under the cap ran normally.
    • worker_environment was already set when the worker imported its modules, and the parent's environment was restored. With max_units_ahead=4 and a slow first unit, only the first 4 units started before it finished. With the parent killed in the middle of a unit, both workers were gone within 0.2 s.
  • No consumer asks a finished reform for another key. The coverage smoke and reform validation (including the stacked OBBBA states) turn each reform into totals before they open the next, the demographics and holdout consumers score only the baseline, and the probe and sweep tools call the same consumers.
  • For one scope at a time, which is how the head-to-head scorer uses it, temporary_engine_variable_modules removes and restores exactly what it did before.
  • The branch merges cleanly with current main, which hasn't changed the post-export consumers, the scorer or engine_lifecycle.py since your base. The merged release tool keeps #1697's matrix drop beside this branch's reform lifecycle.

Before merge

  1. Let CI finish on this head. engine-us passed at b780d8587, including test_reform_passes_leave_no_rule_modules_behind_and_score_the_same, and only test_worker_pool.py has changed since. engine-free failed there in test_process_memory_bytes_sees_this_process_grow, which 47bf7bb0b rewrote.

Checked

  • All 63 tests in test_worker_pool.py pass locally, and so do the first 100 of the 107 engine-free tests in test_us_post_export_scoring.py, test_us_release_slice_memory.py and test_us_release_head_to_head_scorer.py, including the five worker set-ups of test_spawned_workers_score_identically_to_sequential_cli. The last 7 scorer tests were still running when I posted.
  • I didn't rerun the engine test or the post-export memory figures.

@anth-volk
anth-volk merged commit 63e22f9 into main Nov 25, 2026
12 checks passed
@anth-volk
anth-volk deleted the claude/shared-worker-pool-2cf1b5 branch November 25, 2026 18:04
anth-volk added a commit that referenced this pull request Nov 25, 2026
Conflicts resolved by keeping both sides:
- _BatchedPostExportReform keeps main's finished-reform refusal and its
  removal of each reform's rule modules, and this branch's prefetch, which
  scores several keys of one reform in one pass;
- the scorer keeps main's open-reform tracking and this branch's registered
  baseline plans;
- the test helper _scorer takes both baseline_plans and variables_dir;
- both branches' new tests are kept. The slow pre-OBBBA test reads the
  shared pass's values before opening the next reform, since opening it now
  finishes the earlier one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Nov 25, 2026
Brings in the shared worker pool (#1726), whose post-export scorer
finishes a reform when the consumer opens the next one and refuses
further keys from it. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Nov 25, 2026
Since the shared worker pool (#1726), the post-export scorer finishes a
reformed simulation when the consumer opens the next one and refuses it
further keys. The test's consumer opened all three reformed simulations
before asking any, so the scored half of
test_reform_requests_follow_the_order_of_first_asks raised on main. Its
consumer now asks each reformed simulation for all its keys before
opening the next, and still covers a repeated key, a simulation asked
two keys, and an unasked simulation that keeps its number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Nov 25, 2026
…ext opens

The post-export scorer finishes a reformed simulation when the consumer
opens the next one and refuses it any further key (#1726). A consumer
that goes back to an earlier reformed simulation passes today's dry run
and fails only in certification's scoring, after the export. The test
expects the dry run to refuse it, for a key the simulation already asked
and for a new one, and checks that the scorer refuses the same consumer.
It fails on this commit: the dry run does not raise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Nov 25, 2026
The post-export scorer finishes a reformed simulation when the consumer
opens the next one and refuses it any further key (#1726). The dry run's
recorders now share its list of opened reforms, and a reformed
simulation's recorder raises once a later one is open, so a consumer
that goes back to an earlier reformed simulation fails the release's
plan before the export instead of certification's scoring after it. No
shipped consumer does; the recorded outputs' pinned digests are
unchanged. The docs and changelog say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
juaristi22 added a commit that referenced this pull request Nov 25, 2026
…he SPI forest release and the shared SIPP read (#931)

Main took seven pull requests since cac12ab: #1724 (each kernel reads
read-only views of its inputs instead of a deep copy), #1690 (the SPI
stage-2 forests freed before each later fit), #1686 (the SIPP person file
read once for its five donor tables), #1697 (release tools free large
objects after their last use), #1726 (a shared worker pool), #1660 (the
County Files ACS donor patch) and #1707 (New Zealand's geography layer
labels). No feed or engine pin moves, so no file is re-pinned.

Four files conflicted, all pins that both sides moved: the US spec-engine
seed map and seed protocol, the UK loader and US spec pins, and the US F0
coverage report. Each is computed on the merged tree, and the coverage
report is regenerated (--check passes; 41/41 inventory checks).

Two of main's new tests needed this branch's code reviewed.
- #1724's scan for writes into shared buffers finds np.add.at in two
  weight folds of the identity tool: _pre_split_household_weights, which
  this branch changed, and _pre_high_value_household_weights, which it
  added. Both write into the copy of the household weights that
  _pre_residential_household_weights makes and _pre_clone_fold and the
  folds pass along, so both findings are reviewed with their digests, and
  the helpers the reasons rest on take theirs, _pre_clone_fold included.
- #1690's SPI forest-release test froze origin/main's SPI output and
  receipts; this branch's keyed draws move them, as the test foresees. The
  macOS arm64 digests are recorded from this code. Linux x86_64's need a
  recording under Docker, which this machine lacks, so those two tests
  skip there and the same-run checks still run. The owner-manager rule
  rewrites owned_company_carries_on_property_business after the draw, as
  it does the trade flag, and on the synthetic fixture's draws it moves one
  drawn person, so the flag joins the targets rewritten after the draw.

Checks: main's changed tests, the pin tests and the kernel-binding test
pass (1,931, then the shared-buffer scan's 99 and the SPI forest-release
test's 48 after the two reviews), and so does the H2 clone-first test at
one and four clones (34).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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