Skip to content

recipes: compare imported analysis code by code equality, not marshal output - #778

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-recipes-key-self-test
Oct 24, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-recipes-key-self-test

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Python 3.14 이상에서 reached-input key가 전부 거부되던 문제를 고칩니다.

What and why

On Python 3.14 and 3.15, tools/recipes-key-test.py --self-test and the recipe self-test reject every reached-input key with "analysis code changed after import", even when no file changed.

The cause is in tools/bloomery/reach_cache.py. Since 3.14 the compiler folds the constant slice in dirs[:] into the code constants, and marshal.dumps(code, 2) cannot write a slice, so it raises ValueError: unmarshallable object. _code_identity turns that error into the "changed after import" rejection. Raising the marshal version does not help: the output then depends on object sharing, so an imported code object and a fresh compile of the same bytes dump differently. The imported and the freshly compiled code objects themselves compare equal.

_code_identity now compares the two code objects with ==, which checks bytecode, constants, names, line tables and flags recursively and gives the same answer on every version. An edit to the file after import is still rejected. The identity row keeps the file path and the SHA-256 of its bytes, and the cache identity now includes sys.version, so a cache written by another interpreter is a miss.

Release notes: Fixed | Reached-input keys work again on Python 3.14 and 3.15.

Code shape

  • No second copy. The change replaces _disk_code_digest with _disk_code; no new helper.
  • Model code holds only architecture facts. Not a model change.
  • Dead code is gone. The marshal import and the second digest are removed.
  • No silent failure. Compile errors and a mismatch still raise the same rejection.
  • Comments state what is true now.
  • No relaxed gate. The comparison is not weaker: changed nested function bodies, constant types, moved lines and renamed names all still compare unequal.
  • cargo fmt and cargo clippy: no Rust is touched, so I did not run them.

Duplication found or removed (path:line), or "none": none.

What I ran

Command, on a Mac mini with Homebrew interpreters for each version:

python3.1x tools/recipes-key-test.py --self-test

Before the change, on the base commit:

  • Python 3.14.9: Ran 25 tests, FAILED (failures=45).
  • Python 3.15.0: Ran 25 tests, FAILED (failures=45).

After the change:

  • Python 3.11.17: Ran 25 tests, OK.
  • Python 3.12.15: Ran 25 tests, OK.
  • Python 3.13.17: Ran 25 tests, OK.
  • Python 3.14.9: Ran 25 tests, OK.
  • Python 3.15.0: Ran 25 tests, OK.

The existing test test_analysis_code_edited_after_import_never_emits_a_skippable_key edits each analysis file after import and expects a rejection. It passes on all five versions, which shows a changed file is still caught. I added no new test, since CI runs only one Python version and no test file can reproduce the version split.

tools/recipes.py --self-test also ends with "self-test: ok (227 gate recipes, 0 failures)" on 3.14.9 and 3.15.0.

I did not run any GPU gate or a node check; the change is Python tooling only.

Hardware (if the change is for a machine)

Not applicable. CPU-only tooling change.

AI help

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

… output

Python 3.14 folds constant slices into code constants, and marshal formats
before version 5 cannot write a slice, so every reached-input key failed
with 'analysis code changed after import'. Marshal output from the current
format also depends on object sharing, so it cannot compare imported code
with newly compiled code. Code equality compares bytecode, constants, names
and line tables recursively on 3.11 through 3.15. The interpreter version
joins the cache identity in place of the bytecode digest.
@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Oct 24, 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: The changed comparison preserves stale-import rejection and invalidates older cache identities.

Checked

  • Duplicates: 1 replacement helper checked; no existing duplicate owner found. No dryer pairs were reported.
  • Complexity: No branches added; compilation, import validation and cache identity retain their existing owners.
  • Silent failure: 2 rejection paths followed. Compilation errors and unequal code reach the caller as named errors with no key.
  • Tests: No tests changed. The existing stale-import test asserts an error with no key after each analysis module is edited. Removing the mismatch guard would defeat that assertion.
  • Gates: No pins, thresholds or test cases moved or were removed.
  • Escape catalog: No patterns matched. Older cache identities differ and are rejected before hydration.

Notes

Dryer and crapper did not run because no Rust file changed.
Tests were inspected, not executed during validation. The reported eleven local checks could not be verified from the supplied inputs; the author's Python 3.14/3.15 results were not rerun.

🔨 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 aafe24c into midagedev:main Oct 24, 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