Skip to content

Keep the traced-simulation isolation test valid without core's abolition-check reads - #11248

Merged
anth-volk merged 1 commit into
mainfrom
test-isolation-without-core-abolition-reads
Nov 25, 2026
Merged

anth-volk merged 1 commit into
mainfrom
test-isolation-without-core-abolition-reads

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

No linked issue. This test change is needed before PolicyEngine/policyengine-core#664 is released.

What and why

test_traced_simulations_record_their_own_parameter_accesses compared each traced simulation's full set of recorded parameter names with five expected names. Two of them, gov.abolitions.spm_unit_fpg and gov.abolitions.spm_unit_size, came from core's own abolition check, which core reads before each calculation. PolicyEngine/policyengine-core#664 reads that check from the untraced tree, so it is no longer recorded, and the test fails with that pull request's core for both periods.

Those two names were also the test's only reads made through the simulation's own parameter root, simulation.tax_benefit_system.parameters(period), rather than through a formula's parameters argument. The two kinds of read reach a tracer in different ways:

  • Core wraps the parameters argument for each formula call with the calculating simulation's tracer, so dated reads through it land in the right tracer whatever the root holds.
  • A dated read through the root uses the tracer stored on the root. Only isolate_parameter_tracing sets it: on the shared tree, it gives each traced simulation and branch its own copy of the root. The SSI annual-input helper reads this way.

Dropping the abolition names alone would leave the test unable to notice a private root that records nothing. So the test now:

  • leaves out only each trace node's read of its own variable's abolition switch (core's check), so one expected set holds on core master and with Record scale, child-list and undated parameter reads in the tracer policyengine-core#664, while a formula's read of another variable's switch would still count;
  • applies a variable-only test reform that adds root_read_probe, whose formula reads gov.hhs.fpg.first_person.CONTIGUOUS_US through the simulation's own root, and expects that name in each simulation's trace;
  • fills the shared root's at-instant cache for the period first, as untraced requests do in production, so a private root that reused those entries would be noticed;
  • checks each private root's branch name and that it is still marked as shared, so a later parameter reform detaches it instead of editing the imported tree;
  • checks that each traced system has its own system-level at-instant cache, so its tracing views are not cached where untraced simulations read them;
  • checks that both private roots still share the imported tree's children, so the test reform cannot change what the test exercises without the test noticing.

The docstring now describes the two kinds of read and the case the test covers: simulations that share the imported tree. It no longer says that core writes the tracer onto the root on each formula call, which core stopped doing.

Test plan

  • For policy changes: not applicable, test-only change.
  • Source-conflict register entry: not applicable.
  • make format
  • Changelog fragment in changelog.d/

Both cases of the changed test, [2033] and [2034], selected by node ID:

Core Test before this PR This PR
master 0d66b304 Pass Pass
PolicyEngine/policyengine-core#664 head c968e968 Fail: the two gov.abolitions names are missing Pass

Each breakage of isolate_parameter_tracing below was applied with a scratch pytest plugin. With only the filtered name comparison and the checks the test already had, it passed under every one of them. With this PR, it fails in both cases on both cores:

Breakage Check that fails
The private root records nothing (trace left off) The probe's read is missing
The private root starts with the shared root's cache entries The probe's read is missing, once the shared cache is filled first
The private root holds no branch name The branch-name check
The private root is marked as not shared The shared-mark check
The traced system keeps the system-level at-instant cache it shares with the imported system The system-cache check

Not covered, as before this PR: a traced simulation that owns its tree, whose root is marked in place; and reads through the root that name no instant, which neither core records.

Cost

Local macOS runs of the test before this PR (origin/main) and with it, from scratch copies with the same pytest root, two rounds each. Time is the test call per case; memory is the pytest process's peak.

Core Before this PR This PR
3.36.0, the installed release 0.13–0.15 s, 1.27 GB 0.13–0.20 s, 1.27 GB
master 0d66b304 0.01–0.03 s, 1.18 GB 0.01–0.02 s, 1.18 GB
PolicyEngine/policyengine-core#664 0.13–0.17 s, 1.27 GB (fails) 0.15–0.16 s, 1.27 GB

The differences are within the variation between runs. On Linux CI, the latest main run (45245929428, job Full Suite - SPM) shows the test at 0.28 s per case. This PR does not change which CI group runs the file (make test-other-python-spm). CI peak memory was not checked.

axiom: n/a: test-only change, no policy change

🤖 Generated with Claude Code

…ion-check reads

PolicyEngine/policyengine-core#664 stops recording core's own abolition
check, which supplied the test's only reads through a simulation's own
parameter root. The test now leaves out each trace node's read of its own
variable's abolition switch, and a variable-only test reform adds
root_read_probe, which reads a parameter through the root, so the test
still notices a private root that records nothing.

The test also fills the shared root's cache for the period first, and
checks that each private root keeps its branch name and shared-tree mark
and that each traced system has its own system-level at-instant cache.

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

@PavelMakarchuk PavelMakarchuk 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.

Review at 47659db

This PR makes test_traced_simulations_record_their_own_parameter_accesses pass with released core and with PolicyEngine/policyengine-core#664. It does not make the test weaker. With released core 3.37.2, the new test catches every breakage of isolate_parameter_tracing that I tried. The old test caught only some of them.

Verdict: APPROVE

Suggestions

1. Keep failure output short for the root identity checks. policyengine_us/tests/core/test_spm_simulation_isolation.py:342 (assert first_root is not second_root) is older than this PR, but it prints the whole parameter tree when it fails. I saw this when I made isolate_parameter_tracing trace the shared root in place: the failure message started with assert calibration:\n gov:\n aca:\n ... and filled the screen. The PR already reads branch_name into local names for this reason (lines 347-350). The same pattern, for example assert id(first_root) != id(second_root), would help at line 342.

2. Update the cost table in the PR body. The table calls 3.36.0 "the installed release". Core 3.37.2 was released on 2026-11-24 at 8:55am EST, and CI for this PR installed 3.37.2. The test passes with 3.37.2 (see below), so only the body text is out of date.

What I checked

  1. The test still checks isolation. The filter at lines 69-94 removes only gov.abolitions.<variable> from that variable's own trace node. A read of another variable's switch still counts. The expected set keeps the three spm_unit_fpg formula reads. The new root_read_probe adds one dated read through the simulation's own root. The check that the first trace does not grow (line 338) is unchanged.

  2. Pass on each core. The whole file (28 tests), on the PR head and on the PR head merged with current main (116d7ba267, which needs core 3.37.2):

    Core main before this PR This PR This PR merged with main
    3.36.0 28 passed 28 passed not run (main needs 3.37.2)
    3.37.2 (latest release, same as core master) 28 passed 28 passed 28 passed
    policyengine-core#664 head c968e968 2 failed, 26 passed 28 passed 28 passed
    3.37.2 with policyengine-core#664 merged 2 failed, 26 passed 28 passed 28 passed

    The two failures are [2033] and [2034] of this test, as reported on policyengine-core#664.

  3. Fail when isolation breaks. I changed isolate_parameter_tracing in policyengine_us/spm.py in a local copy of the PR merged with main, one change at a time, and ran both cases of the test (old version and this PR):

    Change to isolate_parameter_tracing Old test, core 3.37.2 This PR, core 3.37.2 This PR, with core#664
    No change pass pass pass
    Trace the shared root in place (no private copy) fail fail fail
    Private root keeps the shared at-instant cache fail fail fail
    trace not set on the private root fail fail fail
    Private root marked as not shared pass fail fail
    System-level at-instant cache not replaced pass fail fail
    branch_name not set pass fail fail
    Function does nothing fail fail fail

    With core#664, the old test fails in every row, so it cannot detect anything. Removing only the mark_tree_shared(private) call does not change behavior, because copy(root) already copies the shared mark. The test cannot detect that change, and it does not need to.

  4. Other core tests with core#664. policyengine_us/tests/core on this PR merged with main, with 3.37.2 plus core#664: 3,950 passed, 6 failed. No failure is in the changed file. Four of them (in test_capital_gains_response_forms.py, test_run_selective_tests.py and test_medicare_cost_part_d_premium.py) fail the same way with released 3.37.2 in my local setup, and CI passes them. A Hypothesis state-machine test passed when I ran it again.

  5. Docstring. It matches isolate_parameter_tracing in policyengine_us/spm.py. Core 3.36.0 and 3.37.2 do not write the tracer onto the root in _run_formula, as the new text says.

  6. Changelog. changelog.d/test-isolation-without-core-abolition-reads.fixed.md is at the top level and has one sentence.

  7. CI and merge. All 38 checks pass. The Full Suite - SPM job installed core 3.37.2 and ran both cases (PASSED). GitHub shows MERGEABLE. The branch merges with current main without conflict. No other open PR changes this test file or policyengine_us/spm.py.

@DTrim99 DTrim99 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.

Program review

Base repository: PolicyEngine/policyengine-us
PR number: 11248
Reviewed head SHA: 47659db
Merge base SHA: b3edc04
Mode: full
Scope: changed behavior and affected dependencies
Source manifest: /private/tmp/policyengine-command-runs/ea33c0bb2b64/pr-11248-review-sources.json
Review status: COMPLETE

Source Documents

No source documents registered; see scope and validation.

Critical

None.

Should Address

None.

Suggestions

S1 — code-1 (SUGGESTION): two comments in spm.py still describe the old core behaviour (OPEN)

  • Location: policyengine_us/spm.py:554-556 and :570-574 (docstring of
    isolate_parameter_tracing), and :895-896 (comment in apply_reform). These lines
    are not in the diff.
  • Problem: They say that core writes the tracer, trace flag and branch name onto the
    root, "in _run_formula". The PR corrects exactly this claim in the test docstring
    ("which core stopped doing"). Core 3.36.0 _run_formula now wraps the tree in a
    per-call TracingParameterNode and never assigns parameters.trace or
    parameters.tracer (checked by grep of the installed simulation.py).
  • Impact: None on behaviour. The production docstring now contradicts the corrected
    test docstring.
  • Optional fix: Reword these lines in this PR or a follow-up.

No other defects found.

Evidence Gaps

No material gaps reported.

Notes

  • This PR changes one test and no model code, so it had one code reviewer and no source review.
  • The rewritten test is not vacuous. With isolate_parameter_tracing broken in 8 ways (the 5 the PR lists, plus every root recording into the first simulation's tracer, the helper doing nothing, and the shared root traced in place), the test fails in both periods on core 3.36.0, 3.37.2 and the policyengine-core#664 head (c968e968). Unbroken, it passes on all three.
  • The filter is narrow. It drops a name only when it is the recording trace node's own gov.abolitions.{variable} switch. A formula reading other variables' switches, through its parameters argument and through the root, still has both reads counted. The check that the first trace did not grow still compares the unfiltered list.
  • The probe doesn't leak. After the test, the shared system has no root_read_probe variable or abolition child, a fresh simulation doesn't see it, the shared root is still untraced, and parameter values are unchanged. The private core attributes the test reads exist with the same meaning on all three cores; a later rename would raise rather than pass silently.

Validation Summary

Local: the changed test file passes 28/28 on core 3.36.0 and 28/28 on core 3.37.2, imports from the snapshot. Breakage and leak checks ran on 3.36.0, 3.37.2 and the policyengine-core#664 head. CI at 47659db: 38/38 succeeded.

Timing

setup seconds: 45.00s; code role seconds: 1244.00s; parallel review seconds: 1244.00s; adjudication seconds: 0.00s; elapsed seconds: 1325.00s

Review Severity

APPROVE. Open findings: 0 critical, 0 should address, 1 suggestions.

@anth-volk
anth-volk merged commit e93d9b4 into main Nov 25, 2026
38 checks passed
@anth-volk
anth-volk deleted the test-isolation-without-core-abolition-reads branch November 25, 2026 16:58
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.

3 participants