T-043 — Preserve pending Gain edits and overlapping piano note ownership

Status: done · Area: rust · Depends on: T-041

Read for that: T-041, Plugin formats.

What: Address issues #18, #19 and #20. Preserve GUI Gain values through host automation and output backpressure. Keep overlapping note addresses held independently on each physical key.

Done when: Regression tests cover the Gain interleaving, rejected output and overlapping same-key note-off and choke. Rust, Julia and plugin gates pass.

Implementation

  • Host automation and pending GUI Gain use separate atomic values. A state load discards a pending GUI value, so the loaded Gain wins. A rejected event stays pending, with gesture state advancing only after the host accepts it. Process and both kinds of flush request a main-thread callback to schedule another delivery opportunity.
  • The adapter stores up to 32 distinct addresses per physical key. A repeat strike reuses its slot and released slots can be reclaimed. At capacity, a new distinct strike is ignored while all slots are held. One resonator bank serves the key, so a choke leaves it ringing while another address holds it.
  • The demo renderer calls the engine directly. Its model, DSP and MIDI event handling stay the same.

Verification

The pinned Rust gates passed all 70 tests. The release CLAP bundle passed validation with 35 passes, zero failures and nine skips. The X11 editor smoke test passed. The Julia suite passed all 2,439 tests after Pkg resolved dependencies in its temporary test environment.

Review (2026-12-02)

Mistral Large 4 reviewed the PR against issues #18–#20; Codex (gpt-6.2-sol) reviewed the fix. Each point, whether it held, what was done:

PointHeld?Done
A state load during the audio thread’s emit of a pending GUI edit is overwritten by that edit’s write-back (Mistral)yes: state_load_wins_over_an_in_flight_gui_emit failedthe applied gain is one 64-bit word with a main-thread write count; the audio thread’s write-back is one compare-exchange that fails once the count moved
The same for host automation written back in process / active flush (found while fixing)yes: state_load_wins_over_a_concurrent_automation_write_back failedthe same word; process and flush read the count before they take the flag
A load that writes the value, then the flag, lets automation in between overwrite it (Codex)not reproduced by a test (needs a pause inside the load)removed by construction: the flag (HOST_CHANGED) is in the same word, so a load is one atomic step
An older accepted event clears a newer GUI edit with the same value (ABA) (Codex)yes: a_new_gui_edit_with_the_same_value_survives_an_older_emit failedthe pending GUI word carries an edit count; the clearing exchange matches the count too
The audio thread’s write-back retried a weak compare-exchange without bound (Codex)true in principle (try_update loops)one strong compare_exchange and a fetch_and; no loop on the audio thread
A GUI edit already pushed when a load runs reaches the host after the load (Codex)yes, and not fixable in the plugin: the host reads output events after process returns, possibly after the load’s rescanaccepted: the shared value stays the loaded one and the next block applies it
The 32-address capacity has no test (Mistral); the test written for it cannot tell 31 from 32 (Codex)yestests/note_capacity.rs: the 32nd strike is accepted, the 33rd ignored, a released slot is reused

Codex’s second pass over the reworked code:

PointHeld?Done
The block read the write count before it took the flag: a load between the two was applied, automation after it was not written back, and the DSP kept the automation value while the shared value was the loaded oneyes: the old order failed dsp_and_shared_gain_agree_after_a_load_during_a_blocktake_host_change returns the count from the same fetch_and that takes the flag; process and flush write back under that count
A GUI edit made while a load runs can win over the loadno defect: the edit came after the load began, and DSP, GUI and state all end at itnone
A save during output backpressure stores the pending GUI value, not newer automationby design (#18): the pending GUI edit is the value that will winnone
The counts wrap after 2³¹ writestrue, not reachable in practicenone
On AArch64 without LSE every atomic read-modify-write is an LL/SC looptrue of every atomic on that target, the rings includednone