MIDI callback census audit: blocked by unsafe saved frame

Historical source last updated, 2026-10-20. Runtime and implementation claims below describe that dated source; see current app notes and source for subsequent changes.

Exact blocker

src/13-exports.wat:3408 exports $fire_midi_out_callback_bound, which calls $fire_audio_callback_bound at line 3414. After admission, that helper calls $save_caller_regs at line 3437, pushes five stdcall arguments and the $mm_timer_ret_thunk, then redirects EIP. The return path is CACA000A in src/09b-dispatch.wat:1542, calling $restore_caller_regs at line 1548.

The actual save/restore pair in src/03-registers.wat:1025 and line 1038 preserves EIP, EAX, ECX, EDX, flag_op, flag_res, flag_a, flag_b and flag_sign_shift in nine guest-stack words. It does not preserve saved_cf. $get_cf at line 907 uses $saved_cf whenever the restored flag_op is 4 or 5 (INC/DEC). $set_flags_inc and $set_flags_dec overwrite saved_cf with the current carry.

Concrete reachable instruction witness:

  1. The interrupted caller executes STC; INC EAX, leaving flag_op=4 and saved_cf=1. A normal slice boundary can occur after that INC.
  2. The host admits a MIDI callback and saves the nine-word frame.
  3. The callback executes an ADD with no carry, then an INC. Its saved_cf is now 0. It returns normally with the required stdcall cleanup.
  4. CACA000A restores flag_op=4 and the caller's other saved words, but leaves saved_cf=0. The caller now observes CF=0 instead of CF=1.

Neither callee-saved register discipline nor exact ESP restoration repairs this: this callback interrupts execution asynchronously, and the callback is free to change arithmetic flags. The defect predates the extraction in the wave path; it is newly reachable through this MIDI producer. The helper's comment calling the frame “invocation-owned” does not establish full saved state or token ownership. No claim is made that MIDI introduced the underlying save helper defect.

The source-only reproducer evaluates the actual parsed save, restore, get_cf and set_flags_inc forms with a strict small instruction evaluator. It observes identical ESP and EIP before/after, but carry 1 -> 0. Controls show carry remains 1 without the callback mutation, and retaining saved_cf in the evaluator state prevents this exact corruption. The latter is a diagnostic control, not a proposed or applied production repair. No WAT compilation, guest x86 execution, remote runtime, build or browser was used. Native reproduction and any production fix require a separately assigned task.

Lifetime and production-boundary review performed before stopping

This is not an exhaustive approval of other producer failure paths. The confirmed saved-frame blocker triggers the requested stop; no blanket lifetime acceptance, silent allowlist or hash refresh is appropriate.

Evidence and recovery

scratch/runs/20261020-midi-callback-census/ contains audit.js, audit-result.json, audit.log, shared-state checks and file hashes. Run node scratch/runs/20261020-midi-callback-census/audit.js from this repository. It reads immutable candidate Git blobs, loads the candidate parser in memory, records source/test SHA-256 hashes, reproduces the saved-frame witness, scans the complete production source inventory through the unchanged gate, and runs the existing census negative-mutation suite in a fresh parser context. Source files are recovered from the candidate commit, not mutable worktrees.

The complete scan reproduces the native report's eight errors: two changed host hashes, two unknown producers and four changed wave-wrapper fields. The existing unknown/stale producer, wrapper reachability, hash, ownership assertion and nonlocal-lock regression checks pass. No accepted baseline is created for the unsafe new producer, so no new acceptance regression is claimed. The initial audit harness attempts encountered a shebang-wrapper error and then the parser's 128-file location limit when running tests in the scanner's parser instance; the final harness strips shebangs for evaluation and uses a fresh parser for the separate test suite. Neither change touches production tools.

The future MIDI timing tip requires re-audit of every changed lifetime pin, especially the whole-file host-audio hash, before integration. This audit reads only a33fc31f and does not accept the concurrent timing worker's source. The coordinator must assign the saved-frame defect separately and review any resulting producer/dependency changes before census reconciliation.