Repository navigation
fix(auto-improvement): stop a junction widening the do-not-pollute snapshot - #8871
Conversation
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Analysis complete. The fix routes the link predicate through the repo's own Design-Verdict: PASS Root-cause fix at the repo's own platform_compat seam, both failure directions pinned by tests that fail on main and run on the affected platform. Suggestions
[DESIGN-REVIEWED] e3a9e6a |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of All claims verified. The in-package tests are collected ( First-Principles-Verdict: PASS Fail-on-base evidence exists only on Windows — verify the Windows CI shard collected and ran the three new junction tests before merging. What this change shipsIntent: FIX — make the do-not-pollute gate treat a Windows junction as a link, so clean runs stop being falsely blocked and a re-pointed junction is caught. Inventory (5 items)
[FIRST-PRINCIPLES-REVIEWED] e3a9e6a |
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsFINDING -- src/kiro_crew/apps/builtins/auto_improvement/tests/test_pollute.py:45 -- Function-local |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
c2723a4 to
d40a0e5
Compare
…apshot
_hash_path snapshots the host paths the measurement runtime may write under, and
its contract is explicit: links are "recorded by their target string (a flipped
symlink is a change) without following them (avoids escaping the snapshot
scope)".
The predicate was Path.is_symlink(), which is False for a Windows directory
junction, and both halves of that contract broke there:
* pathlib deliberately does NOT recurse into a symlink, but it DOES descend
through a junction. So the walk hashed the link target's whole tree and the
snapshot escaped its own root. Any unrelated write under that target -- by
anything on the machine -- then read as a leak by the measured runtime and
blocked the run.
* A junction was hashed as a plain directory (a "D" marker plus its relative
name), so re-pointing one to another empty directory produced an IDENTICAL
hash. A real host write the gate exists to catch passed as hermetic.
Route both the top-level and the per-child check through
platform_compat.is_link_or_junction, the shim-table row for this question, and
suppress the descendants rglob still yields under a link it has already recorded
by target. Sorting the walk by path string -- which the module already does for
determinism -- is what puts a link ahead of anything beneath it, so one pass is
enough.
readlink() resolves a junction on Windows, so the existing record-by-target
branch needed no other change.
Tests stage the plant with a local mirror of test/conftest.py::make_dir_link,
which calls _winapi.CreateJunction unconditionally on Windows. It is mirrored
rather than imported because only the test/ testpath gets that conftest, and it
is NOT platform_compat.symlink_or_junction: that tries os.symlink first, so a
runner with Developer Mode gets a symlink and the junction arm is never
exercised -- silently, while still reporting green.
Both behavioural tests fail on origin/main: the outside write blocks
("assert True is False") and the re-pointed link does not block
("assert False is True").
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
d40a0e5 to
e3a9e6a
Compare
|
Rebased onto main Clean rebase, no conflicts. Main had not touched Gates run locally on the changed files only: Please review that the rebased head still matches your intent. Note that a maintainer push makes the maintainer the last pusher, so under this repo's last-push rule a second approver is needed before merge. Reply here if anything looks wrong. |
iamwhatever
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green. Category: swaps Path.is_symlink for platform_compat.is_link_or_junction in the pollute-snapshot hasher and skips children under an already-recorded link root, so a Windows directory junction is recorded by its target string instead of being descended through by rglob -- the root cause of the snapshot hash escaping its own root and reading unrelated writes under the link target as a leak. Second file is the matching test. CodeQL is not applicable on this fork PR (default-setup emits no check-run); SAST coverage is Semgrep only, latest run success with 0 annotations.
…apshot (kirodotdev#8871) _hash_path snapshots the host paths the measurement runtime may write under, and its contract is explicit: links are "recorded by their target string (a flipped symlink is a change) without following them (avoids escaping the snapshot scope)". The predicate was Path.is_symlink(), which is False for a Windows directory junction, and both halves of that contract broke there: * pathlib deliberately does NOT recurse into a symlink, but it DOES descend through a junction. So the walk hashed the link target's whole tree and the snapshot escaped its own root. Any unrelated write under that target -- by anything on the machine -- then read as a leak by the measured runtime and blocked the run. * A junction was hashed as a plain directory (a "D" marker plus its relative name), so re-pointing one to another empty directory produced an IDENTICAL hash. A real host write the gate exists to catch passed as hermetic. Route both the top-level and the per-child check through platform_compat.is_link_or_junction, the shim-table row for this question, and suppress the descendants rglob still yields under a link it has already recorded by target. Sorting the walk by path string -- which the module already does for determinism -- is what puts a link ahead of anything beneath it, so one pass is enough. readlink() resolves a junction on Windows, so the existing record-by-target branch needed no other change. Tests stage the plant with a local mirror of test/conftest.py::make_dir_link, which calls _winapi.CreateJunction unconditionally on Windows. It is mirrored rather than imported because only the test/ testpath gets that conftest, and it is NOT platform_compat.symlink_or_junction: that tries os.symlink first, so a runner with Developer Mode gets a symlink and the junction arm is never exercised -- silently, while still reporting green. Both behavioural tests fail on origin/main: the outside write blocks ("assert True is False") and the re-pointed link does not block ("assert False is True"). Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Problem / Motivation
spine/pollute.py::_hash_pathis the blocking do-not-pollute gate: it snapshots the host paths the measurement runtime may write under, boots that runtime once, re-snapshots, and refuses the whole experiment on any diff. Its contract for links is explicit in the docstring:The predicate was
Path.is_symlink(), which isFalsefor a Windows directory junction. Both halves of that contract broke there, in opposite directions:The snapshot escaped its own root.
pathlibdeliberately does not recurse into a symlink, but it does descend through a junction — measured:So the walk hashed the link target's whole tree. Any unrelated write under that target — by anything on the machine, not the measured runtime — then read as a leak and blocked the run.
A re-pointed junction became invisible. A junction was hashed as a plain directory (a
Dmarker plus its relative name), so flipping one to another empty directory produced an identical hash. A real host write the gate exists to catch passed as hermetic.Why it matters
This gate decides whether an autonomous run may start at all. The first failure makes it refuse clean runs for a reason the operator cannot see in any diff — the changed content is outside every watched path. The second is worse in kind: it is a leak the detector was built to catch, reported as hermetic.
The file's own test module opens by noting that a detector which always answers "hermetic" "passes every test a green-path suite can write, and is worthless". That is precisely the state of the re-pointing case on Windows.
What changed (motivation → approach → change)
Root cause is the link predicate, not the walk.
Both the top-level check and the per-child check now route through
platform_compat.is_link_or_junction— the shim-table row for this exact question (AGENTS.md: "Detect/remove a dir link →is_link_or_junction(path)NOTpath.is_symlink()(misses a Windows junction)"). That alone fixes the re-pointing case, because the existing record-by-target branch then runs;readlink()resolves a junction on Windows, so nothing else in that branch needed changing.Fixing the escape needs one more step, because
rglobhas already yielded the descendants by the time the link is seen. Alink_rootslist suppresses any child that sits under a link already recorded by target. The walk is already sorted by path string for determinism, and that ordering is what puts a link ahead of everything beneath it — so a single pass is sufficient and no second traversal is introduced.Exclusion ordering is deliberately unchanged: an excluded link is skipped before it is recorded, and its descendants are still excluded because
_is_excludedresolves each child and prefix-matches against the resolved exclude set.Tests
tests/test_pollute.py. The plant is staged with a local mirror oftest/conftest.py::make_dir_link, which calls_winapi.CreateJunctionunconditionally on Windows — a plain symlink on POSIX, a real directory junction on Windows — so these run on every platform and the junction arm is the one actually exercised there.It is deliberately not
platform_compat.symlink_or_junction: that triesos.symlinkFIRST and falls back to a junction only where the privilege is missing, so a runner with Developer Mode gets a SYMLINK and the junction arm is never exercised — silently, while still reporting green. The first head of this PR shipped that mistake; a guard-the-guard test asserting the plant really was a junction is what caught it, on the Windows CI shard. It is mirrored rather than imported because only thetest/testpath gets that conftest.Both behavioural tests fail on
origin/main:test_a_write_under_a_linked_child_is_not_a_leak—assert True is False: main blocks on a write that is outside the watched root and only reachable by following the link.test_a_repointed_link_still_blocks—assert False is True: main does not notice the flip at all.Green on both sides:
test_the_staged_plant_is_really_a_junction_on_windows— guards the guard: it asserts the plant really is a junction on Windows, so the two tests above cannot quietly stop exercising the junction arm. This is the test that caught thesymlink_or_junctionmistake on the first head.Local (Windows, repo-pinned toolchain):
test_pollute.py21 passed / 4 skipped (the 4 are the pre-existing symlink tests). Fullauto_improvementsuite: 1042 passed / 64 skipped / 0 failed.flake8clean;scripts/check_black_formatting.pypasses in scope (the one file it flagged was formatted withblack --target-version py310, a three-line change confined to a line this PR added).Manual verification
N/A — unit coverage sufficient: the change is one predicate plus a descendant filter inside a single function, and the tests drive the real
run_do_not_polluteagainst a tmp fake-HOME with the real plant on the affected platform, as the module's own test conventions require.Related Issues
None — found by source review of the
is_symlink()-versus-junction seam after #8766 and #8767.Pattern harvest
Rule candidate:
semgrepPattern:
Path.is_symlink()used to decide whether a directory walk may descend. It isFalsefor a Windows junction, and — unlike a symlink, whichpathlibrefuses to recurse into — a junction is traversed, so the walk silently leaves its intended root. Two distinct failures follow from the one predicate: content from outside the root enters the result, and the link's own identity (its target) is never recorded. The repo's shim table already namesis_link_or_junction; the residual risk is any walk that predates it.Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code