From ce76aba824fa4ca92a69f0a0a3df75964d713276 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 19 Nov 2026 05:59:07 +0700 Subject: [PATCH 1/4] refactor(g-mv21): make ACK leases immutable and refresh I/O inventory after installed readback --- web/approved-device-view-model.js | 6 +++++- web/approved-native-bridge.js | 22 ++++++++++++++++------ web/approved-native-contract.js | 5 +++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/web/approved-device-view-model.js b/web/approved-device-view-model.js index 615dbf2af..9478887a4 100644 --- a/web/approved-device-view-model.js +++ b/web/approved-device-view-model.js @@ -258,7 +258,11 @@ remapGeneration:null}}; } function setupAck(state,ack) { - if(!state.pending||ack?.requestId!==state.pending.requestId)return state; + // G-MV21: first ACK wins while APPLYING. After a matching hardware + // acceptance, the immutable ACK lease is verified only by an installed + // v6 readback, never replaced by duplicate positive/negative ACKs. + if(state.phase!=="APPLYING"||!state.pending|| + state.pending.ack||ack?.requestId!==state.pending.requestId)return state; const active=ack.active; const accepted=ack.ok===true && (ack.state==="ACCEPTED_LIVE"||ack.state==="ACCEPTED_MUTED") && diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 77d238377..250542db2 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -2281,7 +2281,7 @@ backend.emitEvent("arMixAction",{action:"audioDeviceInventory"}); },12000); } - function finishDeviceApplyUi(){ + function finishDeviceApplyUi(verifiedSnapshot=null){ window.clearTimeout(deviceApplyTimer); deviceApplyTimer=0; if(!devicePanel)return; @@ -2289,9 +2289,12 @@ if(deviceState.phase==="ACCEPTED"){ deviceChoice=null; devicePanel.hidden=true; - const active=deviceInventory?.active; + // The confirmed schema-v6 readback, not the preceding Apply ACK, + // is the only source for the device-ready status shown to operators. + const active=verifiedSnapshot?.device; status("DEVICE READY · "+String(active?.backend||"Audio")+ - " · "+String(active?.rate||0)+" Hz / "+String(active?.buffer||0)+" samples"); + " · "+String(active?.sampleRate||0)+" Hz / "+ + String(active?.bufferFrames||0)+" samples"); nativeToast(deviceState.message); }else{ deviceChoice=null; @@ -2313,8 +2316,8 @@ const next=deviceVM.setupAck(deviceState,ack); if(next===deviceState)return; // delayed or unrelated ACK deviceState=next; - if(ack?.active && deviceInventory) - deviceInventory={...deviceInventory,active:ack.active}; + // ACK.active is unverified hardware evidence. Do not allow either + // accepted or rejected ACKs to overwrite the installed I/O inventory. if(deviceBusy()){ // ACK alone NEVER closes the dialog or announces LIVE. controller?.subscribe(); @@ -2715,7 +2718,14 @@ scope?.syncNativeWireGains?.([]); // flush accepted paint after pointer release const previousSetup=deviceState; deviceState=deviceVM.setupReadback(deviceState,next); - if(deviceState!==previousSetup && !deviceState.pending)finishDeviceApplyUi(); + if(deviceState!==previousSetup && !deviceState.pending){ + finishDeviceApplyUi(next); + // G-MV21: only after installed device verification may the UI + // request a fresh authoritative native inventory. A late ACK must + // neither poison the operator's pin choices nor close Audio I/O. + if(deviceState.phase==="ACCEPTED"&&connected) + backend.emitEvent("arMixAction",{action:"audioDeviceInventory"}); + } updateHardwarePanel(next); // The MV-18 external-output repaint must stay after the same fence. paintExternalReadback(next); diff --git a/web/approved-native-contract.js b/web/approved-native-contract.js index e5f1bbc5c..fa8553f3c 100644 --- a/web/approved-native-contract.js +++ b/web/approved-native-contract.js @@ -743,6 +743,11 @@ emit("arMixConsoleIntent",msg);notify();return {ok:true,requestId}; } function onAck(raw) { + // G-MV21: the first correlated native ACK owns this request's proof + // lease. A duplicate positive, negative or malformed ACK cannot + // overwrite its graph revision, demand another subscribe, or reject + // a command already waiting for independent installed PCM readback. + if (pending?.ack) return false; if (!pending || !fields(raw,["requestId","status","deviceEpoch","graphRevision","rosterRevision","errorCode"]) || typeof raw.requestId !== "string" || raw.requestId !== pending.requestId) return false; if ([raw.deviceEpoch,raw.graphRevision,raw.rosterRevision].some(x=>decimal(x)===null)) { From 53e83d634ebbd6945ff91cbb7eb6a2ca356412a2 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 19 Nov 2026 06:00:41 +0700 Subject: [PATCH 2/4] test(g-mv21): first ACK wins and I/O inventory remains readback-authoritative --- ...oved_device_pin_identity_contract.test.cjs | 41 +++++++++++++++++++ tests/approved_native_m2_contract.test.cjs | 30 ++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/tests/approved_device_pin_identity_contract.test.cjs b/tests/approved_device_pin_identity_contract.test.cjs index 986b93824..2e06a9c4b 100644 --- a/tests/approved_device_pin_identity_contract.test.cjs +++ b/tests/approved_device_pin_identity_contract.test.cjs @@ -68,6 +68,47 @@ test("MV-8 same-device Apply remembers explicit physical pin sets, not callback "DeviceVM cannot edit authoritative JUCE inventory"); }); +test("G-MV21 Device Setup first ACK wins even if native sends contradictory duplicates",()=>{ + const f=fixture(),begun=f.begin("ack-once"); + assert.ok(begun); + const accepted=f.ack("ack-once"),verifying=vm.setupAck(begun.state,accepted); + assert.equal(verifying.phase,"VERIFYING"); + const original=JSON.stringify(verifying); + for(const duplicate of [accepted, + {...accepted,ok:false,state:"REJECTED",error:"Late failed driver"}, + {...accepted,active:{...accepted.active,playbackDevice:"Wrong ASIO"}}, + {...accepted,active:{...accepted.active,enabledOutputs:[0,1]}}, + {...accepted,active:{...accepted.active,deviceGeneration:999}}]){ + assert.strictEqual(vm.setupAck(verifying,duplicate),verifying); + assert.equal(JSON.stringify(verifying),original); + } + assert.equal(vm.setupReadback(verifying,f.readback).phase,"ACCEPTED"); + const expired=vm.setupTimeout(verifying,"ack-once"); + assert.equal(expired.phase,"TIMEOUT"); + assert.strictEqual(vm.setupAck(expired,accepted),expired); +}); + +test("G-MV21 only verified device readback refreshes Audio I/O inventory",()=>{ + const bridge=readFileSync("web/approved-native-bridge.js","utf8"); + const a=bridge.indexOf('backend.addEventListener("arMixAudioDeviceApplyAck",ack=>'); + const b=bridge.indexOf(" function installFirstSoundMenu()",a); + assert.ok(a>0&&b>a); + const ack=bridge.slice(a,b); + assert.match(ack,/deviceVM\.setupAck\(deviceState,ack\)/); + assert.doesNotMatch(ack,/deviceInventory\s*=|inventory\.active\s*=|updateHardwarePanel/, + "unverified or rejected ACK cannot mutate native hardware inventory"); + const s=bridge.indexOf(" function onNativeReadback(next,confirmed) {"); + const e=bridge.indexOf(" if (connected) {\n controller = protocol.createController",s); + assert.ok(s>0&&e>s); + const readback=bridge.slice(s,e); + assert.match(readback,/deviceVM\.setupReadback\(deviceState,next\)/); + assert.match(readback,/finishDeviceApplyUi\(next\)/); + assert.match(readback,/deviceState\.phase==="ACCEPTED"&&connected[\s\S]*?action:"audioDeviceInventory"/); + const finish=bridge.slice(bridge.indexOf(" function finishDeviceApplyUi("),a); + assert.match(finish,/verifiedSnapshot\?\.device/); + assert.match(finish,/active\?\.sampleRate/); + assert.doesNotMatch(finish,/deviceInventory\?\.active/); +}); test("MV-8 native accepted ACK with changed output pins never claims selected hardware",()=>{ const f=fixture(),begun=f.begin("pin-2"); const acceptedDifferent=f.ack("pin-2",{active:{ diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index ce85b2011..29ef4dec3 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -2125,6 +2125,36 @@ test("SET_FADER: one exact string request, ACK then LATER same-revision native r assert.equal(c.state().pending,null); assert.equal(visible.length,2); }); +test("G-MV21 controller ACK lease is immutable until installed v6 readback",()=>{ + const snap=acceptedFixture(),events=[],paints=[]; + const c=protocol.createController({emit:(name,payload)=>events.push({name,payload}), + onAccepted:(next,confirmed)=>paints.push({next,confirmed})}); + assert.equal(c.onSnapshot(snap),true); + const issued=c.intent("SET_FADER","9007199254740993",{valueDb:-12}); + assert.equal(issued.ok,true); + const ack={requestId:issued.requestId,status:"ACCEPTED",errorCode:"NONE", + deviceEpoch:snap.device.epoch,graphRevision:"6",rosterRevision:"7"}; + assert.equal(c.onAck(ack),true); + const n=events.length; + for(const late of [ack, + {...ack,status:"REJECTED",errorCode:"STALE_GRAPH"}, + {...ack,graphRevision:"99"},{...ack,graphRevision:"broken"}, + {...ack,deviceEpoch:"18446744073709551609"}]){ + assert.equal(c.onAck(late),false); + assert.equal(c.state().pending?.requestId,issued.requestId); + assert.equal(c.state().lastError,"PENDING_ACCEPTED_SNAPSHOT"); + assert.equal(events.length,n,"duplicate ACK cannot resubscribe"); + } + assert.equal(paints.length,1,"ACK alone cannot repaint"); + const installed=clone(snap); + installed.graph.revision="6"; + installed.graph.channels[0].controls.faderDb=-12; + assert.equal(c.onSnapshot(installed),true); + assert.equal(c.state().pending,null); + assert.equal(paints.length,2); + assert.equal(paints[1].confirmed.requestId,issued.requestId); + assert.equal(c.onAck(ack),false); +}); test("STALE/REJECTED/timeout leave accepted GUI untouched and request fresh native readback",()=>{ const sent=[],c=protocol.createController({emit:(name,payload)=>sent.push({name,payload})}); const s=acceptedFixture();c.onSnapshot(s); From ff61b916acb78ab81bd88cac547d5cd61ffd9a06 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 19 Nov 2026 06:03:43 +0700 Subject: [PATCH 3/4] fix(g-mv21): refresh native inventory after rejected or NEEDS_REMAP Apply --- tests/approved_device_pin_identity_contract.test.cjs | 2 ++ web/approved-native-bridge.js | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/approved_device_pin_identity_contract.test.cjs b/tests/approved_device_pin_identity_contract.test.cjs index 2e06a9c4b..874053fd8 100644 --- a/tests/approved_device_pin_identity_contract.test.cjs +++ b/tests/approved_device_pin_identity_contract.test.cjs @@ -95,6 +95,8 @@ test("G-MV21 only verified device readback refreshes Audio I/O inventory",()=>{ assert.ok(a>0&&b>a); const ack=bridge.slice(a,b); assert.match(ack,/deviceVM\.setupAck\(deviceState,ack\)/); + assert.match(ack,/if\(deviceBusy\(\)\)[\s\S]*?else\{[\s\S]*?finishDeviceApplyUi\(\);[\s\S]*?action:"audioDeviceInventory"/, + "even rejected/NEEDS_REMAP outcomes must refresh native inventory for recovery"); assert.doesNotMatch(ack,/deviceInventory\s*=|inventory\.active\s*=|updateHardwarePanel/, "unverified or rejected ACK cannot mutate native hardware inventory"); const s=bridge.indexOf(" function onNativeReadback(next,confirmed) {"); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 250542db2..8998a82de 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -2321,7 +2321,14 @@ if(deviceBusy()){ // ACK alone NEVER closes the dialog or announces LIVE. controller?.subscribe(); - }else finishDeviceApplyUi(); + }else{ + finishDeviceApplyUi(); + // G-MV21: a negative ACK can still leave a NEW native endpoint in + // NEEDS_REMAP. Only a freshly queried native inventory may unblock + // retained-pin recovery or supply the next device generation. + // Never commit ack.active as installed hardware. + backend.emitEvent("arMixAction",{action:"audioDeviceInventory"}); + } }); } From 4431f8ce467249d54afd5126039c8a83d9ec4843 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 19 Nov 2026 06:04:39 +0700 Subject: [PATCH 4/4] test(g-mv21): prove NEEDS_REMAP recovery uses refreshed native inventory generation --- ...oved_device_pin_identity_contract.test.cjs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/approved_device_pin_identity_contract.test.cjs b/tests/approved_device_pin_identity_contract.test.cjs index 874053fd8..3361d2ffc 100644 --- a/tests/approved_device_pin_identity_contract.test.cjs +++ b/tests/approved_device_pin_identity_contract.test.cjs @@ -111,6 +111,32 @@ test("G-MV21 only verified device readback refreshes Audio I/O inventory",()=>{ assert.match(finish,/active\?\.sampleRate/); assert.doesNotMatch(finish,/deviceInventory\?\.active/); }); +test("G-MV21 NEEDS_REMAP native inventory refresh restores reuse-pins recovery",()=>{ + const f=fixture(),begin=f.begin("needs-remap"); + const newActive={...f.active,deviceGeneration:42,enabledInputs:[0,1], + enabledOutputs:[0,1]}; + const state=vm.setupAck(begin.state,{requestId:"needs-remap", + ok:false,state:"NEEDS_REMAP",error:"NEEDS_REMAP: Confirm physical pins", + canReusePins:true,active:newActive}); + assert.equal(state.phase,"REJECTED"); + assert.equal(state.remapGeneration,42); + assert.equal(vm.setupPresentation(f.inventory,f.draft,state).canReusePins,false, + "stale old endpoint generation cannot authorize a remap"); + const refreshed={...f.inventory,active:newActive}; + assert.equal(vm.setupPresentation(refreshed,f.draft,state).canReusePins,true, + "fresh native inventory unlocks explicit recovery, not ack.active"); + const retry=vm.setupBegin(state,{inventory:refreshed,draft:f.draft, + requestId:"needs-remap-retry",baselineEpoch:"42", + confirmRetainedPinMapping:true}); + assert.ok(retry,"recovery request must use fresh endpoint generation"); + assert.equal(retry.request.expectedDeviceGeneration,42); + assert.equal(retry.request.config.confirmRetainedPinMapping,true); + assert.equal(retry.request.config.sampleRate,newActive.rate); + assert.equal(retry.request.config.bufferSize,newActive.buffer); + assert.deepEqual(f.inventory.active.enabledOutputs,[0,1], + "negative Apply ACK cannot mutate old installed inventory"); +}); + test("MV-8 native accepted ACK with changed output pins never claims selected hardware",()=>{ const f=fixture(),begun=f.begin("pin-2"); const acceptedDifferent=f.ack("pin-2",{active:{