From b153e74a907c05c5820c4190da4a7a6c63065f1a Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 14:57:13 +0700 Subject: [PATCH 1/3] refactor(mv9b): fence global FX and M4 slot ACK to accepted PCM readback --- tests/approved_native_m2_contract.test.cjs | 114 +++++++++++++++++++++ web/approved-fx-rack-view-model.js | 71 ++++++++++++- web/approved-native-bridge.js | 77 +++++++------- 3 files changed, 224 insertions(+), 38 deletions(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 6bb778791..c01734079 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -3627,3 +3627,117 @@ test("MV-8 FX bridge delegates preflight and settlement to existing pure FX VM", assert.doesNotMatch(read("web/approved-fx-rack-view-model.js"), /backend\.emitEvent|document\.querySelector|setTimeout\(/); }); + +test("MV-9B Global FX requires one admitted native/M4 owner, ACK and accepted epoch readback",()=>{ + const epoch="9007199254740993",revision="9007199254740995"; + const current={admitted:true,retained:false,device:{epoch},graph:{ + revision,capabilities:{callbackOwnsChannelIds:true}},raw:{ + globalFxBypassed:false,mixerSession:{ + authority:"CHANNEL_ID",deviceEpoch:epoch}}}; + const before=JSON.stringify(current); + const context=fxRackVM.globalPowerContext(current,false,false); + assert.deepEqual(context,{authority:"CHANNEL_ID",epoch,revision}); + assert.deepEqual(fxRackVM.globalPowerPlan(current,context),{ + kind:"READY",bypassed:true,action:"routingGlobalFxBypass", + payload:{deviceEpoch:epoch,revision,value:true}}); + const pending={requestId:"global-fx-7",authority:"CHANNEL_ID", + epoch,revision,bypassed:true,acked:false}; + const settled=(p=pending,s=current,c=context)=> + fxRackVM.globalPowerSettlement(p,s,c); + assert.equal(settled(),"WAIT"); + assert.equal(settled({...pending,acked:true}),"WAIT"); + assert.equal(settled({...pending,acked:true}, + {...current,raw:{...current.raw,globalFxBypassed:true}}),"CONFIRMED"); + assert.equal(settled({...pending,acked:true},current, + {...context,epoch:"9007199254740996"}),"STALE"); + assert.equal(settled({...pending,acked:true},current, + {...context,revision:"9007199254740996"}),"STALE"); + assert.equal(settled({...pending,acked:true},current, + {...context,authority:"M4"}),"STALE"); + assert.equal(settled({...pending,acked:true},current,null),"STALE"); + assert.equal(settled(null),"NONE"); + const unavailable=(s=current,m4=false,offline=false)=> + assert.equal(fxRackVM.globalPowerContext(s,m4,offline),null); + unavailable({...current,admitted:false}); + unavailable({...current,retained:true}); + unavailable({...current,device:{epoch:"71"}}); + unavailable({...current,raw:{...current.raw,mixerSession:{ + authority:"M4",deviceEpoch:epoch}}}); + unavailable(current,false,true); + unavailable({...current,graph:{...current.graph,revision:12}}); + const m4={admitted:false,retained:false,device:{epoch:"21"},graph:{revision:"0"}, + raw:{globalFxBypassed:false,legacyM4:{routingRevision:"17"}, + mixerSession:{authority:"M4",deviceEpoch:"21",routeRevision:"17"}}}; + assert.deepEqual(fxRackVM.globalPowerContext(m4,true,false), + {authority:"M4",epoch:"21",revision:"17"}); + assert.equal(fxRackVM.globalPowerContext(m4,false,false),null); + assert.equal(fxRackVM.globalPowerContext({...m4, + raw:{...m4.raw,legacyM4:{routingRevision:"18"}}},true,false),null); + assert.equal(fxRackVM.globalPowerPlan(current,null).kind,"UNAVAILABLE"); + assert.equal(fxRackVM.globalPowerPlan(current,context,true).kind,"UNAVAILABLE"); + assert.equal(fxRackVM.globalPowerPlan({...current,raw:{...current.raw, + globalFxBypassed:"false"}},context).kind,"UNAVAILABLE"); + assert.equal(JSON.stringify(current),before,"pure selector must not mutate native state"); +}); +test("MV-9B Global FX ACK never commits without matching request and independent readback",()=>{ + const pending={requestId:"global-fx-8",bypassed:true}; + assert.equal(fxRackVM.globalPowerAckResult(null,{}),"IGNORE"); + assert.equal(fxRackVM.globalPowerAckResult(pending,{requestId:"old",ok:true, + bypassed:true}),"IGNORE"); + assert.equal(fxRackVM.globalPowerAckResult(pending,{requestId:"global-fx-8", + ok:false,bypassed:true}),"REJECTED"); + assert.equal(fxRackVM.globalPowerAckResult(pending,{requestId:"global-fx-8", + ok:true,bypassed:false}),"REJECTED"); + assert.equal(fxRackVM.globalPowerAckResult(pending,{requestId:"global-fx-8", + ok:true,bypassed:true}),"ACKED"); +}); +test("MV-9B M4 FX slot requires exact lease, route revision and independent accepted bypass",()=>{ + const snapshot={admitted:false,retained:false,device:{epoch:"31"},raw:{ + mixerSession:{authority:"M4",deviceEpoch:"31",routeRevision:"12"}, + legacyM4:{routingRevision:"12",fxInstances:[ + [{instanceId:"fx-one",bypassed:true,catalogId:"x"}]]}}}; + const pending={requestId:"fxpower-6",channel:0,slot:0,token:"fx-one", + bypass:true,epoch:"31",revision:"12",acked:false}; + const settle=(p=pending,s=snapshot)=>fxRackVM.m4SlotPowerSettlement(p,s); + assert.equal(settle(),"WAIT","ACK is required even if bypass matches"); + assert.equal(settle({...pending,acked:true}),"CONFIRMED"); + assert.equal(settle({...pending,acked:true}, + {...snapshot,raw:{...snapshot.raw,legacyM4:{...snapshot.raw.legacyM4, + fxInstances:[[{instanceId:"fx-one",bypassed:false}]]}}}),"WAIT"); + assert.equal(settle({...pending,acked:true}, + {...snapshot,raw:{...snapshot.raw,legacyM4:{...snapshot.raw.legacyM4, + fxInstances:[[{instanceId:"replaced",bypassed:true}]]}}}),"STALE"); + assert.equal(settle({...pending,acked:true}, + {...snapshot,device:{epoch:"32"}}),"STALE"); + assert.equal(settle({...pending,acked:true}, + {...snapshot,raw:{...snapshot.raw,mixerSession:{ + ...snapshot.raw.mixerSession,routeRevision:"13"}}}),"STALE"); + assert.equal(settle({...pending,acked:true}, + {...snapshot,raw:{...snapshot.raw,mixerSession:{ + ...snapshot.raw.mixerSession,authority:"CHANNEL_ID"}}}),"STALE"); + assert.equal(settle({...pending,acked:true},{...snapshot,admitted:true}),"STALE"); + assert.equal(settle(null),"NONE"); + assert.equal(fxRackVM.m4SlotPowerAckResult(null,{}),"IGNORE"); + assert.equal(fxRackVM.m4SlotPowerAckResult(pending,{requestId:"late", + channel:0,slot:0,ok:true}),"IGNORE"); + assert.equal(fxRackVM.m4SlotPowerAckResult(pending,{requestId:"fxpower-6", + channel:1,slot:0,ok:true}),"REJECTED"); + assert.equal(fxRackVM.m4SlotPowerAckResult(pending,{requestId:"fxpower-6", + channel:0,slot:1,ok:true}),"REJECTED"); + assert.equal(fxRackVM.m4SlotPowerAckResult(pending,{requestId:"fxpower-6", + channel:0,slot:0,ok:false}),"REJECTED"); + assert.equal(fxRackVM.m4SlotPowerAckResult(pending,{requestId:"fxpower-6", + channel:0,slot:0,ok:true}),"ACKED"); +}); +test("MV-9B bridge uses only accepted native snapshots for global FX, fences M4 slot ACK",()=>{ + const bridge=read("web/approved-native-bridge.js"); + const vm=read("web/approved-fx-rack-view-model.js"); + for(const name of ["globalPowerContext","globalPowerPlan","globalPowerAckResult", + "globalPowerSettlement","m4SlotPowerAckResult","m4SlotPowerSettlement"]) + assert.match(bridge,new RegExp("fxRackVM\\."+name+"\\(")); + assert.match(bridge,/const current=controller\?\.state\(\)\?\.current;\s*const button=document\.getElementById\?\.\("globalFxToggle"\)/); + assert.doesNotMatch(bridge,/const actual=snapshot\?\.globalFxBypassed;/); + assert.match(bridge,/pendingSlotPowers\.delete\(key\);\s*}\s*else pending\.acked=true;/); + assert.doesNotMatch(vm,/backend\.emitEvent|document\.querySelector|window\.setTimeout/); + assert.match(bridge,/controller = protocol\.createController\(/); +}); diff --git a/web/approved-fx-rack-view-model.js b/web/approved-fx-rack-view-model.js index b67e56c6e..fcf62787c 100644 --- a/web/approved-fx-rack-view-model.js +++ b/web/approved-fx-rack-view-model.js @@ -226,8 +226,77 @@ return "ACKED"; } + + // MV-9B: global FX is a single native atomic scalar. This ViewModel + // decides eligibility and ACK/readback settlement but never owns DSP state. + // ALWAYS use the original controller's normalized accepted snapshot. + function positiveId(value){ + if(typeof value!=="string"||!/^[1-9][0-9]*$/.test(value))return false; + try{return BigInt(value)<=18446744073709551615n;}catch{return false;} + } + function globalPowerContext(snapshot,verifiedM4=false,offline=false){ + const session=snapshot?.raw?.mixerSession,device=snapshot?.device; + if(offline||snapshot?.retained===true||!positiveId(device?.epoch)|| + session?.deviceEpoch!==device.epoch)return null; + if(snapshot.admitted===true&&session.authority==="CHANNEL_ID"&& + snapshot.graph?.capabilities?.callbackOwnsChannelIds===true&& + positiveId(snapshot.graph.revision)) + return {authority:"CHANNEL_ID",epoch:device.epoch, + revision:snapshot.graph.revision}; + if(snapshot.admitted===false&&verifiedM4===true&& + session.authority==="M4"&&positiveId(session.routeRevision)&& + session.routeRevision===snapshot.raw?.legacyM4?.routingRevision) + return {authority:"M4",epoch:device.epoch,revision:session.routeRevision}; + return null; + } + function globalPowerPlan(snapshot,context,pending=false){ + const actual=snapshot?.raw?.globalFxBypassed; + if(pending||!context||typeof actual!=="boolean")return {kind:"UNAVAILABLE"}; + return {kind:"READY",bypassed:!actual, + action:"routingGlobalFxBypass", + payload:{deviceEpoch:context.epoch,revision:context.revision,value:!actual}}; + } + function globalPowerAckResult(pending,ack){ + if(!pending||!ack||pending.requestId!==ack.requestId)return "IGNORE"; + return ack.ok===true&&ack.bypassed===pending.bypassed?"ACKED":"REJECTED"; + } + function globalPowerSettlement(pending,snapshot,context){ + if(!pending)return "NONE"; + if(!context||pending.epoch!==context.epoch|| + pending.revision!==context.revision|| + pending.authority!==context.authority)return "STALE"; + if(pending.acked!==true)return "WAIT"; + return typeof snapshot?.raw?.globalFxBypassed==="boolean"&& + snapshot.raw.globalFxBypassed===pending.bypassed?"CONFIRMED":"WAIT"; + } + // M4 compatibility FX slot ACK is NOT readback. Keep the per-slot lease + // locked until independent accepted M4 snapshot proves its exact token. + function m4SlotPowerAckResult(pending,ack){ + if(!pending||!ack||pending.requestId!==ack.requestId)return "IGNORE"; + if(ack.channel!==pending.channel||ack.slot!==pending.slot|| + ack.ok!==true)return "REJECTED"; + return "ACKED"; + } + function m4SlotPowerSettlement(pending,snapshot){ + if(!pending)return "NONE"; + const session=snapshot?.raw?.mixerSession,m=snapshot?.raw?.legacyM4; + if(snapshot?.retained===true||snapshot?.admitted===true|| + session?.authority!=="M4"|| + snapshot?.device?.epoch!==pending.epoch|| + session.deviceEpoch!==pending.epoch|| + session.routeRevision!==pending.revision|| + m?.routingRevision!==pending.revision)return "STALE"; + const slots=m.fxInstances?.[pending.channel]; + const actual=Array.isArray(slots)?slots[pending.slot]:null; + if(actual?.instanceId!==pending.token)return "STALE"; + if(pending.acked!==true)return "WAIT"; + return actual?.bypassed===pending.bypass?"CONFIRMED":"WAIT"; + } + return Object.freeze({powerReadback,mountedRackMatches, m4Presentation,nativePowerSettlement,m4RackSettlement, nativeInsertPlan,nativeEditPlan,nativeInsertSettlement, - nativePowerPlan,nativePowerAckResult}); + nativePowerPlan,nativePowerAckResult, + globalPowerContext,globalPowerPlan,globalPowerAckResult, + globalPowerSettlement,m4SlotPowerAckResult,m4SlotPowerSettlement}); }); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index d5d4c15f1..5d2759737 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1347,7 +1347,9 @@ const {lane,live}=picked,requestId="fxpower-"+(++fxRequestSerial); if(ep===null||rev===null||pendingSlotPowers.has(lane+":"+slot)) return false; - pendingSlotPowers.set(lane+":"+slot,{requestId,token:live.instanceId,bypass}); + pendingSlotPowers.set(lane+":"+slot,{ + requestId,channel:lane,slot,token:live.instanceId,bypass, + epoch:String(ep),revision:String(rev),acked:false}); backend.emitEvent("arMixAction",{action:"routingFxBypass", requestId,channel:lane,slot,instanceId:live.instanceId, deviceEpoch:ep,revision:rev,value:bypass}); @@ -1388,49 +1390,48 @@ if(decision==="STALE"||decision==="CONFIRMED") pendingM4RackPowers.delete(lane); } + // An M4 slot remains pending after ACK until its own exact instance + // lease and requested bypass are present in independently accepted PCM. + for(const [key,p] of pendingSlotPowers){ + const decision=fxRackVM.m4SlotPowerSettlement(p,next); + if(decision==="STALE"||decision==="CONFIRMED") + pendingSlotPowers.delete(key); + } } // Global A/B is a SINGLE native atomic override. Individual racks and // inserts remain untouched. Never simulate success in WebView while device // admission or a matching native ACK + subsequent readback is missing. function globalFxContext(){ - if(logicalView)return null; // an offline .smix has no audible PCM + return fxRackVM.globalPowerContext(controller?.state()?.current, + m4Verified(),!!logicalView); + } + function syncGlobalFxReadback(){ + // Ignore raw incoming events: controller may reject an invalid/stale + // snapshot and retain its previous accepted native PCM read model. const current=controller?.state()?.current; - const session=current?.raw?.mixerSession; - if(current?.admitted && session?.authority==="CHANNEL_ID") - return {epoch:String(current.device.epoch), - revision:String(current.graph.revision)}; - if(session?.authority==="M4" && m4Verified()) - return {epoch:String(session.deviceEpoch), - revision:String(session.routeRevision)}; - return null; - } - function syncGlobalFxReadback(snapshot){ const button=document.getElementById?.("globalFxToggle"); - const actual=snapshot?.globalFxBypassed; const context=globalFxContext(); - if(pendingGlobalFx?.acked && typeof actual==="boolean" && - actual===pendingGlobalFx.bypassed)pendingGlobalFx=null; - if(typeof actual==="boolean" && !pendingGlobalFx) + const decision=fxRackVM.globalPowerSettlement(pendingGlobalFx,current,context); + if(decision==="CONFIRMED"||decision==="STALE")pendingGlobalFx=null; + const actual=current?.raw?.globalFxBypassed; + if(context&&typeof actual==="boolean"&&!pendingGlobalFx) window.__ARMIX_SET_GLOBAL_FX_VIEW__?.(!actual); - if(button) { + if(button){ button.disabled=!context||!!pendingGlobalFx; button.setAttribute("aria-busy",String(!!pendingGlobalFx)); if(!context)button.title="Global FX requires admitted physical audio"; } } function toggleGlobalFx(){ - if(pendingGlobalFx)return false; - const ctx=globalFxContext(),current=controller?.state()?.current; - const actual=current?.raw?.globalFxBypassed; - if(!ctx || typeof actual!=="boolean")return false; + const current=controller?.state()?.current,ctx=globalFxContext(); + const plan=fxRackVM.globalPowerPlan(current,ctx,!!pendingGlobalFx); + if(plan.kind!=="READY")return false; const requestId="global-fx-"+(++globalFxSerial); - pendingGlobalFx={requestId,bypassed:!actual,acked:false}; + pendingGlobalFx={requestId,bypassed:plan.bypassed,acked:false, + epoch:ctx.epoch,revision:ctx.revision,authority:ctx.authority}; const button=document.getElementById?.("globalFxToggle"); if(button){button.disabled=true;button.setAttribute("aria-busy","true");} - backend.emitEvent("arMixAction",{ - action:"routingGlobalFxBypass",requestId, - deviceEpoch:ctx.epoch,revision:ctx.revision,value:!actual - }); + backend.emitEvent("arMixAction",{action:plan.action,requestId,...plan.payload}); window.setTimeout(()=>{ if(pendingGlobalFx?.requestId!==requestId)return; pendingGlobalFx=null; @@ -3015,12 +3016,12 @@ controller?.subscribe(); }); backend.addEventListener("arMixGlobalFxAck",ack=>{ - const pending=pendingGlobalFx; - if(!pending || ack?.requestId!==pending.requestId)return; - if(ack?.ok!==true || ack?.bypassed!==pending.bypassed){ + const verdict=fxRackVM.globalPowerAckResult(pendingGlobalFx,ack); + if(verdict==="IGNORE")return; + if(verdict==="REJECTED"){ pendingGlobalFx=null; status("Global FX rejected ยท "+String(ack?.error||"stale device revision")); - }else pending.acked=true; + }else pendingGlobalFx.acked=true; controller?.subscribe(); // ACK alone never establishes physical bypass. }); backend.addEventListener("arMixNativeFxPowerAck",ack=>{ @@ -3115,15 +3116,17 @@ controller.subscribe(); }); backend.addEventListener("arMixRoutingFxBypassAck",ack=>{ - const key=(Number(ack?.channel)||0)+":"+Number(ack?.slot); - // Legacy ACKs without channel/requestId can never authorize an - // arbitrary in-flight slot or paint an invented bypass state. + const key=Number(ack?.channel)+":"+Number(ack?.slot); + // The matched ACK only permits a new independently accepted M4 + // snapshot to settle the exact pending instance and bypass value. const pending=pendingSlotPowers.get(key); - if(!pending||pending.requestId!==ack?.requestId)return; - pendingSlotPowers.delete(key); - if(ack?.ok!==true) + const verdict=fxRackVM.m4SlotPowerAckResult(pending,ack); + if(verdict==="IGNORE")return; + if(verdict==="REJECTED"){ + pendingSlotPowers.delete(key); nativeToast(ack?.error||"Native VST3 bypass rejected"); - controller?.subscribe(); // real FxInstance state owns visual power + }else pending.acked=true; + controller?.subscribe(); }); backend.addEventListener("arMixRoutingFxEditorAck",ack=>{ if(ack?.ok!==true) From 1826becee91b25c0101a781e63097adbae4ee45f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 14:58:52 +0700 Subject: [PATCH 2/3] test(mv9b): assert rejected M4 slot ACK branch without assuming toast formatting --- tests/approved_native_m2_contract.test.cjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index c01734079..822104d5d 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -3737,7 +3737,8 @@ test("MV-9B bridge uses only accepted native snapshots for global FX, fences M4 assert.match(bridge,new RegExp("fxRackVM\\."+name+"\\(")); assert.match(bridge,/const current=controller\?\.state\(\)\?\.current;\s*const button=document\.getElementById\?\.\("globalFxToggle"\)/); assert.doesNotMatch(bridge,/const actual=snapshot\?\.globalFxBypassed;/); - assert.match(bridge,/pendingSlotPowers\.delete\(key\);\s*}\s*else pending\.acked=true;/); + assert.match(bridge,/if\(verdict==="REJECTED"\)\{\s*pendingSlotPowers\.delete\(key\);/); + assert.match(bridge,/}\s*else pending\.acked=true;/); assert.doesNotMatch(vm,/backend\.emitEvent|document\.querySelector|window\.setTimeout/); assert.match(bridge,/controller = protocol\.createController\(/); }); From d4eedb4e01b76d768586d161042a9b721e20ee63 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 18 Nov 2026 15:06:08 +0700 Subject: [PATCH 3/3] fix(mv9b): settle global FX only from newly accepted post-ACK snapshots --- tests/approved_native_m2_contract.test.cjs | 66 ++++++++++++++++++++++ web/approved-native-bridge.js | 15 +++-- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 822104d5d..bb7f0eb26 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -3736,9 +3736,75 @@ test("MV-9B bridge uses only accepted native snapshots for global FX, fences M4 "globalPowerSettlement","m4SlotPowerAckResult","m4SlotPowerSettlement"]) assert.match(bridge,new RegExp("fxRackVM\\."+name+"\\(")); assert.match(bridge,/const current=controller\?\.state\(\)\?\.current;\s*const button=document\.getElementById\?\.\("globalFxToggle"\)/); + assert.match(bridge,/onAccepted:\(next,confirmed\)=>\{\s*onNativeReadback\(next,confirmed\);\s*syncGlobalFxReadback\(\);/); + assert.match(bridge,/const apply=\(\)=>controller\.onSnapshot\(snapshot\);/); + assert.doesNotMatch(bridge,/controller\.onSnapshot\(snapshot\);syncGlobalFxReadback/); assert.doesNotMatch(bridge,/const actual=snapshot\?\.globalFxBypassed;/); assert.match(bridge,/if\(verdict==="REJECTED"\)\{\s*pendingSlotPowers\.delete\(key\);/); assert.match(bridge,/}\s*else pending\.acked=true;/); assert.doesNotMatch(vm,/backend\.emitEvent|document\.querySelector|window\.setTimeout/); assert.match(bridge,/controller = protocol\.createController\(/); }); + +test("MV-9B Global FX ignores rejected post-ACK snapshot after a pre-ACK value race",()=>{ + const vm=require("node:vm"),listeners=new Map(),sent=[]; + let seq=101,wire=300,viewCalls=0; + const scope={ + tracks:[],master:{id:1,name:"Master"},colors:["#456789"], + wireGraph:{validateCandidateGraph:()=>({ok:true})}, + make:(name,kind,color)=>({id:seq++,name,kind,color,selected:false}), + render(){},installGraph(tracks,master,edges){ + this.tracks=tracks;this.master=master;this.edges=edges; + },allocateWireId:()=>wire++,displayMeterDbfs(){},stopDemo(){} + }; + const backend={emitEvent:(name,payload)=>sent.push({name,payload}), + addEventListener:(name,fn)=>listeners.set(name,fn)}; + const button={disabled:false,attrs:new Map(),title:"", + setAttribute(name,val){this.attrs.set(name,String(val));}, + getAttribute(name){return this.attrs.get(name);}}; + const doc={readyState:"complete",documentElement:{dataset:{}}, + getElementById:id=>id==="globalFxToggle"?button:null, + querySelector(){return null;},addEventListener(){}}; + const win={__JUCE__:{backend}, + ArSonApprovedNativeContract:protocol, + ArSonApprovedDeviceViewModel:deviceVM, + ArSonApprovedChannelStripViewModel:stripVM, + ArSonApprovedFxRackViewModel:fxRackVM, + ArSonApprovedWireViewModel:wireVM, + __ARMIX_NATIVE_SCOPE__:scope,addEventListener(){}, + setTimeout(){return 0},clearTimeout(){}, + queueMicrotask(fn){fn();}, + __ARMIX_SET_GLOBAL_FX_VIEW__(){viewCalls++;} + }; + vm.runInNewContext(read("web/approved-native-bridge.js"), + {window:win,document:doc,performance:{now:()=>0},console},{timeout:1500}); + const initial=acceptedFixture(); + initial.globalFxBypassed=false; + initial.mixerSession={authority:"CHANNEL_ID",deviceEpoch:initial.device.epoch, + routeRevision:initial.graph.revision,rosterRevision:initial.graph.rosterRevision, + channels:initial.graph.channels,main:{db:0,mute:false}}; + listeners.get("arMixConsoleSnapshot")(initial); + assert.equal(win.__ARMIX_NATIVE_GLOBAL_FX__.toggle(),true); + const dispatched=sent.findLast(x=>x.payload?.action==="routingGlobalFxBypass"); + assert.ok(dispatched); + assert.equal(dispatched.payload.value,true); + assert.equal(button.getAttribute("aria-busy"),"true"); + // Native value has advanced before its ACK: no false completion yet. + const premature=clone(initial);premature.globalFxBypassed=true; + listeners.get("arMixConsoleSnapshot")(premature); + assert.equal(button.getAttribute("aria-busy"),"true"); + const beforeInvalid=viewCalls; + listeners.get("arMixGlobalFxAck")({requestId:dispatched.payload.requestId, + ok:true,bypassed:true}); + listeners.get("arMixConsoleSnapshot")({schemaVersion:-1, + globalFxBypassed:true}); + assert.equal(button.getAttribute("aria-busy"),"true", + "malformed post-ACK envelope must never unlock Global FX"); + assert.equal(viewCalls,beforeInvalid, + "rejected snapshot must never confirm cached pre-ACK value"); + // Only a later fully accepted native snapshot settles Global FX. + listeners.get("arMixConsoleSnapshot")(clone(premature)); + assert.equal(button.getAttribute("aria-busy"),"false"); + assert.equal(button.disabled,false); + assert.ok(viewCalls>beforeInvalid); +}); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 5d2759737..6a80750bd 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -2868,7 +2868,12 @@ if (connected) { controller = protocol.createController({ emit:(name,payload)=>backend.emitEvent(name,payload), - onAccepted:onNativeReadback, + // Global A/B must settle only on a NEW independently accepted + // post-ACK snapshot. Rejected snapshots never invoke onAccepted. + onAccepted:(next,confirmed)=>{ + onNativeReadback(next,confirmed); + syncGlobalFxReadback(); + }, onStatus:state=>{ const settledGain=pendingNativeGainIntent&&!state.pending; if(settledGain){ @@ -2931,9 +2936,11 @@ } }); backend.addEventListener("arMixConsoleSnapshot", snapshot=>{ - // First reconcile the canonical engine snapshot, then the global FX - // view gate. Never infer FX admission from a local button press. - const apply=()=>{controller.onSnapshot(snapshot);syncGlobalFxReadback(snapshot);}; + // Only the sole v6 controller may admit a PCM snapshot. Its + // onAccepted callback updates FX after validation; this listener + // must not settle an ACK using a cached pre-ACK readback if the + // incoming payload was rejected as invalid/stale. + const apply=()=>controller.onSnapshot(snapshot); const profiler=window.ArSonMixPerf; if(!profiler?.active){apply();return;} const started=performance.now();