Repository navigation
vdf: derive results via direct record map and decoded forward link - #508
Conversation
Fedora's Asahi spin (and presumably other distros) ships an `xdg-open` that returns 0 even when `$DISPLAY` is unset, so the strict assertion "open_browser must return false on headless Linux" is false-positive on those hosts. Probe `xdg-open` directly and skip the assertion when it succeeds; the relaxed `open_browser_does_not_panic` test continues to exercise the bool-flow contract on every Linux host.
Refactor `to_results_via_records` (Rust) and `extract_named_results` (Python xray) to use the deterministic record-to-OT chain that Vensim's writer produces, replacing the previous overlap-selection DP and within-candidate lookup-name filter. Section-1 records carry the direct map (`f[2]` -> name, `f[6]` -> shape, `f[11]` -> OT-start), and graphical-function descriptors are removed via the decoded forward link into the section-6 lookup-record array (case-insensitive alphabetical order of the lookup-def names). The `f[11]` owner/descriptor union is the only on-disk ambiguity; the field-by-field analysis in `docs/design/vdf.md` confirms no byte distinguishes the two. Descriptor identification therefore proceeds by overlap-component analysis: spans that share OT slots form connected components, and within each component the lexical lookup-def name match (or, in `Ref.vdf`'s case, the highest-`f[10]` fallback) selects the descriptor record. This avoids the slot-alignment-derived hide-set that made the xray result count depend on slot-table layout noise (#500), and the xray and Rust paths now agree on the result set. The change adds class-code constants for `0x05`/`0x16`/`0x17`/`0x18` OT codes (alongside `0x08`/`0x11`) so the class-code guard rejects records whose `f[11]`-as-OT-start would land on a non-owner slot, ports the descriptor identification to `record_results.rs`, drops the now-unused overlap-selection DP, and updates `docs/design/vdf.md` to document the direct map as the primary path. The corpus precision report moves from 31 exact-by-xray / 9 not-proven to 39 / 1 (only `Ref.vdf`, where the `f[10]` fallback is exact but flagged).
Review summaryThe PR replaces the overlap-selection DP and within-candidate lookup-name filter with a deterministic record-to-OT chain, plus a class-code guard and overlap-component descriptor identification. The corpus precision improves from 31/9 to 39/1, and Rust/Python paths now agree. Below are a few correctness-adjacent observations. [P3] tools/test_vdf_xray.py — test name and docstring reference fixtures that are no longer "not-proven" The new [P3] tools/vdf_xray.py — In [P3] Class-code guard diverges on out-of-bounds OT indices between Rust and Python In Overall correctness verdict Correct. The corpus precision results (39/1) and Rust/Python parity goals are met, and the descriptor identification logic mirrors symmetrically across the two implementations. The findings above are doc/clarity nits rather than blocking issues. |
Three doc/clarity nits flagged on PR #508: 1. Rename `NOT_PROVEN_OVERLAP_PAIRS` and the corresponding xray test to `DESCRIPTOR_CONFLICT_PAIRS` / `..._pinned_on_descriptor_conflict_fixtures`. The dict and test pin the raw descriptor/owner overlap shape produced by `decoded_record_spans` *before* `identify_descriptor_records` runs; after that step these fixtures all classify as `exact-by-xray` in the precision report, so the previous "not-proven" framing was misleading post-PR. 2. Rename `used_system_variable_fallback` to `system_variable_record_missing` (and the matching reason string to `system-variable-record-missing`). The post-PR meaning is "this system variable lacks a direct record and was silently dropped from the result set", not "we used a fallback to recover it"; the previous name still implied recovery. 3. Align the Rust class-code guard's out-of-bounds behaviour with the Python xray. Previously the Rust path treated a missing class code as `0` (which `is_owner_ot_class_code` rejects) while Python short-circuited OOB indices into "no rejection signal". Both pass today on every corpus fixture because the upstream `end > offset_table_count` gate already covers the realistic OOB case, but the symmetry goal of the PR motivates aligning them. Pick the Python rule: only in-bounds non-owner codes reject the span, and a short class-code array is treated as a parser defect rather than a span-level signal.
Review summaryLooked through the three commits: the serve Specifics I checked end-to-end:
FindingsNo correctness, performance, or security issues that meet the bar for filing. A couple of low-priority observations not worth blocking on:
Overall correctness verdictCorrect. The patch preserves existing behavior on every clean fixture, resolves the documented |
Summary
Refactors
to_results_via_records(Rust) andextract_named_results(Python xray) to use the deterministic record-to-OT chain that Vensim's writer produces, replacing the previous overlap-selection DP and within-candidate lookup-name filter. Section-1 records carry the direct map (f[2]-> name,f[6]-> shape,f[11]-> OT-start), and graphical-function descriptors are removed via the decoded forward link into the section-6 lookup-record array (case-insensitive alphabetical order of the lookup-def names).The
f[11]owner/descriptor union is the only on-disk ambiguity; the field-by-field analysis indocs/design/vdf.mdconfirms no byte distinguishes the two. Descriptor identification therefore proceeds by overlap-component analysis: spans that share OT slots form connected components, and within each component the lexical lookup-def name match (or, inRef.vdf's case, the highest-f[10]fallback) selects the descriptor record.This brings xray and Rust into agreement on the result set, replacing the slot-alignment-derived hide-set that made xray's result count depend on slot-table layout noise. Closes #500.
Notable changes
Engine (
src/simlin-engine/src/vdf.rs,src/simlin-engine/src/vdf/record_results.rs)to_results_via_recordsbecomes a thin wrapper aroundbuild_record_result_columns, which composesdecoded_record_spans->identify_descriptor_records-> name-partitioned emission.0x05/0x16/0x17/0x18alongside0x08/0x11) and anis_owner_ot_class_codepredicate so the class-code guard rejects records whosef[11]-as-OT-start would land on a non-owner slot.is_lookupish_name's docstring is updated to frame it as a model-free reader's lexical approximation of the decoded forward link, not a heuristic.test_identify_descriptor_records_uses_f10_fallback_on_ref_vdfpins theRef.vdffallback case and confirms small-model fixtures don't need it.xray (
tools/vdf_xray.py,tools/test_vdf_xray.py)extract_named_results_with_diagnosticsusesdecoded_record_spans+identify_descriptor_recordsas the primary path, with aused_descriptor_f10_fallbackdiagnostic.decoded_record_spans.Ref.vdf, exact via fallback but flagged).Docs and notes
docs/design/vdf.mdupdates the pinned-facts section to document the direct map as the primary path, the SMOOTH/macro structure, the zeroed-record decode, the absence of a version marker, theaxis_ref = 60 + 16*kformula, and the owner/descriptor reframe-confirmed status.tools/vdf_xray_notes/document the corpus survey, the heuristic audit, the helper-signature region, the model-editing diff sequence, the owner/descriptor field analysis, and the synthesis plan that drove this refactor.Pre-existing test fix (separate commit)
serve: gate headless-linux open_browser test on xdg-open behavior-- the strict assertion was false-positive on Linux distros that ship anxdg-openreturning 0 even without$DISPLAY(Fedora's Asahi spin); probexdg-openand skip the assertion when it succeeds. Pre-existing failure onmain, surfaced by the pre-commit hook on this branch's first commit.Related issues
Test plan
cargo test -p simlin-engine(3199 pass)python3 -m unittest tools.test_vdf_xray(95 pass)test_identify_descriptor_records_uses_f10_fallback_on_ref_vdfvalidates theRef.vdffallback fires and small models don't need it