Repository navigation
test: pin one storage location for a mirrored name's owner - #13908
Conversation
sys.modules is where a module is stored. A module that mirrors a surface and also holds a mapping to the resolved owner MODULE has a second storage location for it, and the two can disagree: purging an owner and importing it again leaves such a mapping reading and forwarding writes to the discarded module while a direct importer holds the fresh one. This pin finds the modules the rule binds by their SHAPE, read off the source tree, rather than from a list of module names, so a module that begins mirroring a surface is covered on the commit that introduces it. Five properties per module: no source-level mapping to owner modules, resolution through importlib.import_module, no live mapping holding a module object, a read that answers from the owner sys.modules holds, and no discarded owner retained across a purge and reimport. The fourth property is what separates this from the owner half alone. Resolving only the owner while the value stays bound in the mirroring module's own namespace makes a read and a write name different modules, and monkeypatch restores by reassignment, so teardown installs a pre-purge value into the fresh module. Refs #13769
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify #13727/#13933 owners know the de-list step — their in-flight conversions go red on rebase against this baseline, by design. Suggestions
[DESIGN-REVIEWED] 57fe258 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ⏭️ skippedRevision |
Auto-green re-measured against the real prerequisite PRsThe body's stage table was measured with the
So this pin needs no source change of its own: it goes green on the prerequisites as On overlap with #13933#13933 adds This pin scans the package by shape and holds all eight mirroring modules to the #13933 also carries |
410993e to
8da8053
Compare
8da8053 to
9541888
Compare
9541888 to
f1ab707
Compare
|
Disposition of the blocking finding on The finding was right, and it was the same defect this PR is about wearing a different Fixing that exposed the larger problem: the rule was a flat universal that seven Each direction is proved by mutation, hash-gated so a mutation that did not apply is
MERGE ORDER, measured rather than asserted. This PR is green on main today and waits
Whoever lands #13727 deletes its six names from |
Enforce the one-storage rule as a ratchet against an explicit seven-name baseline, asserted in both directions: a mirroring module off the list must satisfy the rule, and a module on the list must still break it, so a conversion has to de-list its module and the list can only shrink. A name whose module the shape scan does not find fails as a stale entry. A module the purge probe cannot measure fails rather than skips: an assertion that cannot fail is the same defect the rule is about. The probe runs in one bounded child process under its own directory, so a purge leaves no parent-attribute residue in the test process, and a case reads those bindings back to prove it.
f1ab707 to
57fe258
Compare
1. What is the problem?
A module that mirrors another's surface -- a module-level
__getattr__, or aModuleTypesubclass installed over itself to forward writes -- sometimes also holdsa mapping from an exported name to the resolved owner MODULE. That mapping is a
second storage location for something
sys.modulesalready stores, and the two candisagree.
The disagreement is produced by an idiom this suite uses in twenty files: purge an
owner from
sys.modules, import it again. The mapping keeps forwarding reads andwrites to the discarded module while a direct importer holds the fresh one. A test
that patches a control through the mirror then passes while exercising an object
nothing is running, and a later test in the same worker reads a value that disagrees
with its own owner -- in another file, under some shard splits and not others, with
nothing pointing back at the cause.
Eight modules in this package mirror a surface. Seven of them hold such a mapping.
2. Why this issue matters to the user
The failure is silent at the moment it is introduced and loud somewhere unrelated
later. A module that starts mirroring a surface and stores resolved owners ships
green; the cost lands on whoever has to explain a cross-file test failure that
reproduces under one shard split and not another. Nothing in the repository states
the rule, so each new mirroring module is trusted to remember it.
3. How our fix solves it
This PR adds the rule as an executable ratchet. It changes no product code.
The rule, stated once: a module that mirrors a surface MUST NOT hold a mapping whose
values are module objects. It keeps the owner's dotted NAME and resolves it per use
with
importlib.import_module, which answers fromsys.modules.The modules the rule binds are found BY THEIR SHAPE, read off the source tree, not
from a list. A module that begins mirroring a surface is covered on the commit that
introduces it, with no edit to this file.
Seven modules hold such a mapping today, so the rule is enforced as a ratchet against
an explicit baseline,
_KNOWN_RESOLVED_OWNER_MIRRORS:The baseline is asserted in BOTH directions, which is what stops it becoming standing
permission:
violator reddens on the commit that introduces it;
converted has to be de-listed, and the list can only shrink;
survive its module being deleted or rewritten.
The runtime and purge halves are tightened the same way. Inside a baseline module, a
resolved owner may be held only in a table the module's own source declares, so a
second, undeclared store reddens even in a module that is already listed.
No case skips and none is an expected failure. A module the purge probe cannot
measure -- one that does not import, or whose table spelling the discovery rule does
not recognise -- is a FAILURE, because an assertion that cannot fail is the same
defect this rule is about, worn on the test instead of the code. The remedy is to
widen the discovery rule, which has its own both-ways case.
The purge probe runs in a child process. Importing a module binds it onto its parent
package, so a purge and reimport changes three places: the
sys.modulesentry, theparent package's attribute, and any memo the mirror keeps. Restoring one of the three
leaves exactly the split-brain residue this rule forbids, and restoring all three is a
maintenance contract inside a test. A child process has no contract: its residue
leaves with it, and a case reads the parent-package bindings back afterwards to prove
the process is untouched.
4. What tests we did
The pin is green on current main: 32 passed, 0 failed, 0 skipped, no expected
failures.
Each direction of the ratchet was proved by mutation, with
git hash-objectbeforeand after showing the edit reached the file and the restore was exact. A run whose
hash does not move is reported as meaningless rather than as a pass.
sys.modulesThe in-process-purge row is the control for the teardown-cleanliness case: without it,
that case proves only that the check is blind.
The probe child's bound is DERIVED from the suite-wide
--timeoutinsetup.cfgandmust stay under it, because pytest-timeout arms at item setup -- before the fixture
spawns the child -- so a bound at that ceiling can never fire as a readable failure and
a hang costs the whole worker instead of one test. The ceiling is read out of
setup.cfgby a case rather than copied into the test file, since a second copy of onevalue is the defect this PR exists to forbid.
Style and gate checks on the two files: black, isort, flake8, mypy, the comment-history
gate, and an ASCII scan, all clean.
5. Any other suggestions on the work
MERGE ORDER, and it is the reverse of what a reader might expect. This PR is green on
main today and does not wait for anything. What it does is impose one mechanical step
on the two conversions in flight, measured here rather than asserted:
That is the shrink-only direction working. Each failure names the module and says
"Remove it from that set so the ratchet keeps tightening". Whoever lands #13727 deletes
its six names from
_KNOWN_RESOLVED_OWNER_MIRRORS; whoever lands #13933 deleteskiro_crew.security. When the baseline is empty the rule is a flat universal overevery mirroring module, and the set can be deleted with it.
#13933 also adds
test/test_security_single_storage.py, scoped tokiro_crew.securityalone with no cross-module shape scan. That is depth on one facade where this file is
breadth over eight; they do not overlap.
Fixes #13769