Skip to content

fix(#488): element-segment items are re-resolved from the final function map - #503

Merged
avrabe merged 5 commits into
mainfrom
fix/488-elem-refresh
Oct 21, 2026
Merged

avrabe merged 5 commits into
mainfrom
fix/488-elem-refresh

Conversation

@avrabe

@avrabe avrabe commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Closes #488.

Defect

Element segment items were remapped when their module was merged. For an import that crosses a component boundary through an adapter, the function map still named the callee at that point. Adapter wiring rewrote the map entry afterwards, but rebuilt only function bodies. The result:

  • Active segment: the table slot kept the callee, so a call through the table bypassed the canonical-ABI adapter. A cross-memory string arrived uncopied: 3000 instead of 3090, at exit 0.
  • Declarative segment: the body's ref.func named the adapter, but the declaration still named the callee, so the output failed validation.

Fix

Evidence (meld-core/tests/elem_refresh_488.rs)

case before after
active segment, function index 3000 3090 (= unfused)
active segment, ref.func expression 3000 3090
declarative segment + body ref.func invalid output validates, 3090
table slot and body call name the same function (two structural tests) fail pass
direct-call control 3090 3090
  • Potency: with the element half of the refresh disabled, 5 of the 6 tests fail and the control passes.
  • Corpus: all 49 wit-bindgen fixtures are byte-identical to main. None of them places an adapted import in an element segment.
  • Traceability: SR-101 (derives from SYS-2; refines SR-10, SR-98 and SR-96) and SWV-113, with reviewed-by: avrabe.

Test plan

  • cargo fmt --all -- --check: exit 0
  • cargo clippy --workspace --all-targets -- -D warnings: exit 0, with and without --all-features
  • cargo test --workspace: exit 0, 969 passed, 0 failed
  • cargo test --workspace --all-features: exit 0, 968 passed, 0 failed
  • Mythos delta-pass (auto-merge stays off until it is clean)

🤖 Generated with Claude Code

https://claude.ai/code/session_01WrmMqf1iuTS1UBEes5TmdC

avrabe and others added 3 commits October 20, 2026 23:14
…ion map

Element items were remapped at merge time from function_index_map. For an
import crossing a component boundary through an adapter, that entry still
named the callee; wire_adapter_indices later rewrote the entry but rebuilt
only bodies. An active slot bypassed the adapter (3000 instead of 3090); an
`elem declare` no longer matched the body's ref.func (invalid output).

Each element item now records its (component, module, local func) origin.
MergedModule::refresh_out_of_body_func_refs re-resolves global ref.func
initialisers (#482) and element items from the final map, before the
dissolve analysis and again immediately before encoding. A missing origin is
an error, never identity; trap stubs (#462) carry no origin and stay stubs;
task.return shim substitution is reapplied so the refresh cannot undo it.
The #462 refusal of a pending-wired import in an elem slot is replaced by
this resolution: an import never wired now fails loudly at the refresh.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WrmMqf1iuTS1UBEes5TmdC
SR-101 derives from SYS-2 and refines SR-10 (segment reindexing), SR-98
(global ref.func refresh) and SR-96 (unmapped-import stubs). SWV-113
records the runtime tests, their potency and the byte-identical corpus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WrmMqf1iuTS1UBEes5TmdC
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WrmMqf1iuTS1UBEes5TmdC
@github-actions

Copy link
Copy Markdown

Mythos delta-pass required

This PR modifies one or more Tier-5 source files (per
scripts/mythos/rank.md):

meld-core/src/merger/index_maps.rs
meld-core/src/merger/merge_core.rs
meld-core/src/merger/mod.rs
meld-core/src/rewriter.rs
meld-core/src/segments.rs

Before merge, run the Mythos discover protocol on the
modified Tier-5 files:

  1. Follow scripts/mythos/discover.md
    — one fresh agent session per touched Tier-5 file.
  2. For each finding, the agent must produce both a Kani
    harness and a failing PoC test (per the protocol's
    "if you cannot produce both, do not report" rule).
  3. Attach a comment on this PR with either the findings
    (formatted per discover.md's output schema) or
    NO FINDINGS.
  4. Add the mythos-pass-done label to this PR.

Why this gate exists: LS-A-10
(CABI alignment padding in async-lift retptr writeback) was
found by the v0.8.0 pre-release Mythos pass — but it had
lived in the callback emitter since #128, across six
releases. A PR-time gate would have caught it at review
time instead of at the release boundary.

The gate check on this PR will pass once the label is
applied.

@avrabe

avrabe commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Mythos delta-pass: NO FINDINGS for this change

Examined and sound:

  • Element origins: comp_idx/mod_idx are threaded correctly, function-index and ref.func items both record origins, passive and declarative segments are covered, and meld creates no element segments of its own.
  • P3 ordering: the P3 shift runs before the refresh and shifts the function map consistently.
  • Trap stubs: they have no origin and stay stubs.
  • Task-return shims: their reapplication is idempotent and matches the old patch.
  • dissolve_fixups: it now sees post-wiring values.
  • Pending imports: they are resolved from the same map as bodies, or error.
  • Encoding: a single encode path, with the refresh before it.

Beyond the PR's own tests, two more shapes are fixed by this change:

  • a passive segment with table.init;
  • a table filled by one module, exported, and called through by another.

Both return 3000 on main and 3090 here, matching unfused.

Pre-existing, filed separately: an adapted import that is re-exported by one core module and imported by another bypasses the adapter in both the body call and the element slot. This happens on main and on this branch alike, so it is not introduced here.

@avrabe avrabe added the mythos-pass-done Mythos delta-pass completed on Tier-5 file changes; findings (or NO FINDINGS) attached to PR label Oct 21, 2026
@avrabe
avrabe enabled auto-merge (squash) October 21, 2026 05:06
@github-actions

Copy link
Copy Markdown

LS-N verification gate

✅ 59/59 approved LS entries verified

count
Passed (≥1 test, all green) 59
Failed (≥1 test failure) 0
Missing (no ls_*_NN_* test found) 0

Approved loss-scenarios.yaml entries are expected to have a
regression test named ls_<letter>_<num>_* (e.g. LS-A-11 →
ls_a_11_*). The gate runs each prefix via cargo test --lib --no-fail-fast and aggregates pass/fail/missing.

Failed LS entries

(none)

Missing regression tests

(none)

Updated automatically by tools/post_verification_comment.py.
Source of truth: safety/stpa/loss-scenarios.yaml.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Mythos delta-pass (auto)

❌ 1 finding(s) across 5 Tier-5 file(s)

File Verdict Hypothesis
meld-core/src/merger/index_maps.rs ✅ NO FINDINGS —
meld-core/src/merger/merge_core.rs ✅ NO FINDINGS —
meld-core/src/merger/mod.rs ❌ FINDING discover step failed before emitting structured output — see workflow logs
meld-core/src/rewriter.rs ✅ NO FINDINGS —
meld-core/src/segments.rs ✅ NO FINDINGS —

Auto-run via anthropics/claude-code-action@v1
(SHA-pinned) on the touched Tier-5 files, using the
maintainer's Max-plan OAuth token. See
.github/workflows/mythos-auto.yml and
scripts/mythos/discover.md.

@avrabe
avrabe merged commit 02fdab0 into main Oct 21, 2026
24 of 25 checks passed
@avrabe
avrabe deleted the fix/488-elem-refresh branch October 21, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mythos-pass-done Mythos delta-pass completed on Tier-5 file changes; findings (or NO FINDINGS) attached to PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Element segments are not re-indexed after adapter wiring: a table entry for an adapted import bypasses the adapter

1 participant