Skip to content

test: pin one storage location for a mirrored name's owner - #13908

Merged
chenmingwei23 merged 2 commits into
mainfrom
fix/export-owners-one-source-13769
Sep 25, 2026
Merged

chenmingwei23 merged 2 commits into
mainfrom
fix/export-owners-one-source-13769

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

1. What is the problem?

A module that mirrors another's surface -- a module-level __getattr__, or a
ModuleType subclass installed over itself to forward writes -- sometimes also holds
a mapping from an exported name to the resolved owner MODULE. That mapping is a
second storage location for something sys.modules already stores, and the two can
disagree.

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 and
writes 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 from sys.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:

kiro_crew.config
kiro_crew.crew_log
kiro_crew.dashboard
kiro_crew.diag
kiro_crew.mcp_gateway
kiro_crew.security
kiro_crew.stt

The baseline is asserted in BOTH directions, which is what stops it becoming standing
permission:

  • a mirroring module OUTSIDE the baseline must satisfy the rule -- so an eighth
    violator reddens on the commit that introduces it;
  • a module INSIDE the baseline must still break the rule -- so a module that gets
    converted has to be de-listed, and the list can only shrink;
  • every baseline name must be a module the shape scan still finds -- so a name cannot
    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.modules entry, the
parent 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-object before
and 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.

mutation result
control, unmutated 32 passed
a NEW violator appears off the baseline 1 failed, naming the module
a baseline module is converted but stays listed 1 failed, "remove it from that set"
a baseline name is not a mirroring module 1 failed, stale entry
the probe cannot measure a module 9 failed -- not skipped
the probe purges in process, restoring only sys.modules 1 failed, naming the leaked binding
the probe bound is raised to the suite ceiling 1 failed, naming both values

The 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 --timeout in setup.cfg and
must 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.cfg by a case rather than copied into the test file, since a second copy of one
value 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:

tree pin
this PR on current main 32 passed, 0 failed
plus #13727 (six modules converted) 6 failed -- one per converted module
plus #13933 (security converted) 7 failed
both, with the seven names de-listed 39 passed

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 deletes
kiro_crew.security. When the baseline is empty the rule is a flat universal over
every mirroring module, and the set can be deleted with it.

#13933 also adds test/test_security_single_storage.py, scoped to kiro_crew.security
alone 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

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
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 57fe258a0b96e014073ddb41ae158895ae289c6d — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • A compliant mirror with no table at all (single owner hardcoded in __getattr__) is unmeasurable-by-construction and thus permanently red; teaching one_reexported_pair that spelling now (read the dotted name off the function's AST) removes the one case where following the rule perfectly still fails the pin.

[DESIGN-REVIEWED] 57fe258

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 57fe258a0b96e014073ddb41ae158895ae289c6d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 57fe258

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 57fe258a0b96e014073ddb41ae158895ae289c6d: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 57fe258a0b96e014073ddb41ae158895ae289c6d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 57fe258

Verdict parsed from the review's SHA-scoped output markers for commit 57fe258a0b96e014073ddb41ae158895ae289c6d.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 57fe258a0b96e014073ddb41ae158895ae289c6d: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ⏭️ skipped

Revision 57fe258a0b96e014073ddb41ae158895ae289c6d ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Advisory — does not block merge.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Auto-green re-measured against the real prerequisite PRs

The body's stage table was measured with the kiro_crew.security conversion simulated
locally, because #13784 had no PR when this was opened. It does now -- #13933 -- so
the measurement has been redone with both prerequisites' actual source diffs applied
to 6b4afd708c, against the pin file exactly as committed (8bc15ea787), each stage
restored afterwards:

tree pin
6b4afd708c alone 14 failed, 30 passed
plus #13727's source half 5 failed, 39 passed -- every red kiro_crew.security
plus #13933's source half 44 passed, 0 failed

So this pin needs no source change of its own: it goes green on the prerequisites as
they land, and the stage-3 row is now the real conversion rather than a stand-in for it.

On overlap with #13933

#13933 adds test/test_security_single_storage.py, which is scoped to
kiro_crew.security -- one storage location for that facade's value and owner, its own
code reading through the owner, and an unresolvable gate failing closed. It performs no
cross-module scan.

This pin scans the package by shape and holds all eight mirroring modules to the
owner-storage rule. The two are complementary: #13933 is the depth on one facade, this
is the breadth that makes a ninth mirroring module fail on the commit that introduces
it. Neither subsumes the other, and neither needs narrowing for the other to land.

#13933 also carries test/test_security_facade.py (+27/-16), which is the pin that
currently asserts _EXPORT_OWNERS values are ModuleType. That was the one dependency
in this PR's body stated on #13784's word rather than measured; it is now confirmed from
#13933's own file list.

@chenmingwei23
chenmingwei23 force-pushed the fix/export-owners-one-source-13769 branch from 410993e to 8da8053 Compare September 25, 2026 20:22
@chenmingwei23
chenmingwei23 marked this pull request as draft September 25, 2026 20:23
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/export-owners-one-source-13769 branch from 8da8053 to 9541888 Compare September 25, 2026 20:55
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/export-owners-one-source-13769 branch from 9541888 to f1ab707 Compare September 25, 2026 21:41
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 25, 2026
@chenmingwei23
chenmingwei23 marked this pull request as ready for review September 25, 2026 21:41
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Disposition of the blocking finding on 9541888847 (universal ratchet converts probe
failures into skips), and the reshape it led to.

The finding was right, and it was the same defect this PR is about wearing a different
coat: a probe failure turned into a skip is an assertion that cannot fail. All three
skips are gone. There is now no pytest.skip and no expected failure anywhere in
either file -- a module the purge probe cannot measure is a FAILURE, and the remedy is
to widen the discovery rule, which has its own both-ways case.

Fixing that exposed the larger problem: the rule was a flat universal that seven
modules violate, so this PR could not go green by construction. It is now a ratchet
against an explicit baseline of those seven, asserted in both directions -- a module
off the list must satisfy the rule, a module on the list must still break it, and
every listed name must be a module the shape scan still finds. The list can only
shrink.

Each direction is proved by mutation, hash-gated so a mutation that did not apply is
reported as meaningless rather than as a pass:

mutation result
control, unmutated 31 passed
a new violator appears off the baseline 1 failed
a baseline module converted but still listed 1 failed
a baseline name is not a mirroring module 1 failed
the probe cannot measure a module 9 failed, not skipped
the probe purges in process, restoring only sys.modules 1 failed

MERGE ORDER, measured rather than asserted. This PR is green on main today and waits
for nothing. What it does is impose one mechanical step on the two conversions in
flight:

tree pin
this PR on current main 31 passed
plus #13727 at 25e0fbc0f7 6 failed, one per converted module
plus #13933 at ce39b893d9 7 failed
both, with the seven names de-listed 38 passed

Whoever lands #13727 deletes its six names from _KNOWN_RESOLVED_OWNER_MIRRORS;
whoever lands #13933 deletes kiro_crew.security. Each failure says so by name. When
the baseline is empty the rule is a flat universal and the set goes with it.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
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.
@chenmingwei23
chenmingwei23 force-pushed the fix/export-owners-one-source-13769 branch from f1ab707 to 57fe258 Compare September 25, 2026 22:55
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 merged commit 2fd66f6 into main Sep 25, 2026
94 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/export-owners-one-source-13769 branch September 25, 2026 23:51
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 25, 2026
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.

security and dev_fleet keep their own _EXPORT_OWNERS mapping, so a purged-and-reimported owner stays invisible through the module

2 participants