Legacy target replay is blocked by obsolete module sidecars
perfloop-oss/lean4 · Value Kind Confusion
https://perfloop.ai/t/oss/case_jwpgxx9j0r
Verdict
VERIFIED · settled 2026-11-13
What happened: The check fails before this change and passes with it.
Hypothesis
Non-fresh checking can reject a valid legacy module because old module-system sidecar files remain beside it. The target loader treats file existence as the module-kind discriminator. The authoritative flag is stored in the main module data.
`replayFromImports` adds `.olean.server` and `.olean.private` at lines 23–28 whenever those paths exist. It then passes them to `readModuleDataParts` before reading `ModuleData.isModule`. The import loader `readModuleDataPartsOfMod` first reads the main part and returns only that part when `isModule` is false; it consults sidecars only for module-system data.
The ordinary compiler path calls `writeModule`, which writes one main file for legacy data. Recompiling a module-system target as legacy did not remove previous sidecars: a bounded bash check reported `ReplayTarget.olean.private` and `ReplayTarget.olean.server` still present after legacy recompilation (`call_upasr2ApN5EU5hLwQ8jrDjH4`).
The new provisional CTest fixture `tests/misc_dir/replay_module_kind/{run_test.sh,kind.cpp}` changes one compiler-produced target from `module` to legacy. It makes only the obsolete server sidecar unreadable, without editing binary data. Each native test process performs one replay call.
The exact command was `ctest --test-dir "$PERFLOOP_PROBE_DIR/testenv" -R 'replay_module_kind' --output-on-failure`, run by bash in `call_ybjrt6mtUnkKqSqFELTKAIFV`. A real module-system target reported the expected `Permission denied` error. A clean legacy target succeeded. Fresh replay of the legacy target succeeded despite the unreadable obsolete sidecar. Non-fresh replay then reported `failed to open file .../ReplayTarget.olean.server: Permission denied` and `FAIL: valid legacy module depends on an obsolete server sidecar`. CTest exited 8 after that assertion returned 1.
The check used the bootstrap-generated checker and runtime built at the assigned revision, and the inspected source has the same unconditional existence check. Confidence is medium. A normally built checker should repeat it, and readable stale sidecars should be tested separately to decide whether replay data can also be selected from them.
The required outcome is that the legacy target result does not depend on files outside its declared format, while true module-system targets still load all parts and report their file errors. The smallest Case proof keeps these controls: real module target, clean legacy target, fresh legacy target, and legacy target with obsolete sidecars.
No prior finding matched replay sidecar or module-kind selection. Upstream https://github.com/leanprover/lean4/pull/16418 was inspected and does not touch this loader. https://github.com/leanprover/lean4/pull/16214 changes compacted-region and module-file format code, but its implementation hunk was not inspected. Only the changed-file list of https://github.com/leanprover/lean4/pull/16353 was available. Older PR pagination, history beyond the fetched shallow window, and the refused Zulip archive read are evidence gaps, not upstream clearance.
Change to test: Decide whether to load target server and private parts from the main module data's module-system flag, not from file presence alone. Preserve true module-system part loading, including its file errors, while legacy targets ignore inapplicable sidecars.
Where it lives
perfloop-oss/lean4 · src/LeanChecker.lean
Evidence
The check fails before this change and passes with it: `For a normally compiled module rebuilt as legacy, non-fresh leanchecker ignores obsolete server and private sidecars; clean and fresh legacy replay succeed, while module targets load both sidecars and report missing-part file errors.`
Checks: 1 of 1 passed. Verification: no defect found.
Timeline
2026-11-13· Case opened