Skip to content

Preserve path errors in snapshot resolution - #1099

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-spd-t0-wall-2
Nov 1, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-spd-t0-wall-2

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

check-recipes의 공용 구조 분석에서 반복되던 경로 해석, edge 설명 구성, 구조 인코딩을 줄여 같은 결과를 9.2% 더 빨리 얻습니다.

What and why

The structural recipe analysis (Reach) resolves the same parent directories with os.path.realpath many times per snapshot, rebuilds the same edge descriptions for every hit, and walks scalar values recursively when it encodes the cached state. This PR resolves each parent once per snapshot and checks every shared parent again before the result is used. It also sorts and describes each site once in Reach.edges, and applies the scalar fast path of _encode to dicts and the fixed record fields. Check selection, assertions, key inputs and the cache format stay as they were. A symlinked last component, .. and invalid paths (embedded NUL, unencodable characters) still go through the original realpath and raise the same errors.

On the key-inputs self-test the median wall time goes from 131.828 s to 119.661 s (9.229% faster), the 24 existing assertions all pass, and the structural graph is identical.

Release notes: Under the hood: check-recipes spends about 9% less time in the shared structural analysis; results and cache keys are unchanged.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved to make a check pass; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none. The three snapshot callers in tools/bloomery/reach_cache.py (_corpus, _observed, _holds) share one path owner, _paths.

What I ran

Upstream base e9f238b0d53e12f8a5e75d89450b59fd0c6a2b11, PR head e051018224f7d417002067abefb3ab8f454113b3.

Speed, Reach key inputs, base against head, three rounds alternating the order (base/head, head/base, base/head), one fresh Python process per round, PYTHONHASHSEED=0. Each process runs:

r.make_side(r.ROOT)
r.key_self_test(expect, side, "inputs")

Output:

A/B key-inputs {"base": [131.7931624580524, 132.77682845795061, 131.82831916597206], "head": [119.66142604197375, 119.43773141596466, 119.96032512496458]}
A/B median base=131.828s head=119.661s gain=9.229% checks=24 nonoverlap=True
Metric Base (s) Head (s) Difference Ranges overlap
key-inputs median 131.828 119.661 9.229% faster no ([131.793, 132.777] against [119.438, 119.960])

Structural graph of both trees, dumped after r.reach_of(side.tree).prepare() (109,344 nodes, 472,379 edges), identical:

base {"nodes": 109344, "edges": 472379, "node_digest": "159d5397d816f7ac73208d0c276a6671c8254305212e0947c3170ef337087255", "edge_digest": "aa51855fd19e290dd2e76ae2c07fa415a50a0c36495f69c3b6d64bdca8817957", "state_digest": "ccf80b00cfcdc04c54476c0ca0008da97636291d128bbc0374232be6d5d35bc8"}
head {"nodes": 109344, "edges": 472379, "node_digest": "159d5397d816f7ac73208d0c276a6671c8254305212e0947c3170ef337087255", "edge_digest": "aa51855fd19e290dd2e76ae2c07fa415a50a0c36495f69c3b6d64bdca8817957", "state_digest": "ccf80b00cfcdc04c54476c0ca0008da97636291d128bbc0374232be6d5d35bc8"}
GRAPH-PROOF identical nodes, edges, first labels and complete encoded state

Tests: python3 tools/recipes-key-test.py --self-test runs the 26 existing cases plus the new test_snapshot_paths_keep_symlink_referents_and_recheck_parents.

Ran 27 tests in 65.728s
OK

The new test fails when the behaviour it protects is removed. Each mutant copy of reach_cache.py is passed with --source-root and RECIPES_KEY_TEST_FILTER=snapshot_paths:

assert actual == os.path.realpath(root / rel), (rel, actual)
AssertionError: ('leaf.rs', '<checkout>/leaf.rs')
FAIL-FIRST symlink-leaf rejected rc=1
AssertionError: parent retargeted during a snapshot was accepted
FAIL-FIRST parent-recheck rejected rc=1

Invalid paths ('bad\x00.rs') must raise like realpath does. The same test run against the version without that handling, then against the PR head:

AssertionError: invalid path accepted as a missing probe: 'bad\x00.rs'
FAIL-FIRST invalid-path previous implementation rejected rc=1
test_snapshot_paths_keep_symlink_referents_and_recheck_parents (__main__.RecipeKeyCLI.test_snapshot_paths_keep_symlink_referents_and_recheck_parents) ... ok
Ran 1 test in 0.155s
OK
Python syntax: PASS (3 files)

Clippy on the PR head, as the ratchet lint runs it (python3 tools/recipes.py box-command lint):

cargo clippy --workspace --all-targets --features gpu,bloomery-metal/pipeline-scan,bloomery-metal/encode-trace,bloomery-gpu-gates/deepseek41,... (feature list shortened)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 51.81s
chain-clippy: lint rc 0 (^warning: 0, the ratchet 0 in tools/lint-ratchet.txt)

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Nov 1, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: CLEAN: No merge-blocking defect found in the snapshot, graph-edge or encoding changes.

Non-blocking

⚠ Complete the timing conditions: tools/recipes.py:5315. The PR reports tooling speedups without the host, Python version or a runnable A/B driver. Add these beside the existing commit hashes and samples; mark card/model fields as inapplicable.

Checked

Duplicates: snapshot callers share _paths; no dryer pairs were available.
Complexity: only Python tooling changed; no Rust functions were reported.
Silent failure: 1 new exception default followed through snapshot consumers. Failed reads still raise; missing probes remain false; NUL and encoding errors propagate.
Tests: the new test asserts symlink referent parity, changed-parent rejection and invalid-path errors. The PR reports fail-first results for these cases; validator checks were static.
Gates: no existing tests, thresholds or pins moved.
Escape catalog: no C1–C4 patterns matched.

Notes

dryer and crapper did not run because no Rust file changed. The validator did not rerun the CLI suite.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 39ed53b into midagedev:main Nov 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant