From 16369fc84b91de8a5fa28ac9add83ac419fd3a68 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 08:46:57 +0700 Subject: [PATCH 1/4] fix(m5): fail closed on malformed or duplicated native FX instance snapshots --- web/approved-native-contract.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/web/approved-native-contract.js b/web/approved-native-contract.js index 98ed14213..06a6a20ed 100644 --- a/web/approved-native-contract.js +++ b/web/approved-native-contract.js @@ -90,6 +90,23 @@ Number.isFinite(ch.controls.pan) && isBool(ch.controls.mute) && isBool(ch.controls.solo) && Array.isArray(ch.inserts) && Array.isArray(ch.sends)); + // Native insert instance tokens are live FX lease identities, not a + // browser slot ordinal or catalog name. A malformed slot/duplicate token + // must never enter the accepted renderer: MOVE/REMOVE and vendor editors + // dereference these entries after native ACK. + const validInsert = fx => fields(fx,["id","catalogId"]) && + typeof fx.id === "string" && fx.id.length > 0 && + typeof fx.catalogId === "string" && fx.catalogId.length > 0 && + (fx.name === undefined || typeof fx.name === "string") && + (fx.bypassed === undefined || isBool(fx.bypassed)); + if (hasAcceptedGraph) { + const tokens=[]; + for (const ch of g.channels) { + if (ch.inserts.length > 8 || !ch.inserts.every(validInsert)) return null; + for (const fx of ch.inserts) tokens.push(fx.id); + } + if (!unique(tokens)) return null; + } const retained = g.bindingState === "NEEDS_REMAP"; if (retained && (!hasAcceptedGraph || caps.callbackOwnsChannelIds || caps.supportedOps.length !== 0 || d.outputArmed || @@ -111,6 +128,9 @@ // control/route actually reached the accepted native graph. No invented UI // updates and no optimistic fader/edge commits. function readbackProvesIntent(next, pending) { + // Also exposed as a pure test/helper API. A rejected/unadmitted native + // snapshot cannot be used to prove an FX or WIRE command. + if (!next?.admitted || !pending || !object(pending.payload)) return false; const {operation,targetChannelId,payload} = pending; const ch = next.graph.channels.find(c=>c.id===targetChannelId); if (!ch) return false; From b8c3be8ab2418aabd3857c9162e676b0088bf508 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 08:47:27 +0700 Subject: [PATCH 2/4] test(m5): reject malformed/duplicate FX lease snapshots and retain pending native ACK --- tests/approved_native_m2_contract.test.cjs | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 142356cc6..2d5ee0a92 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -27,6 +27,67 @@ function acceptedFixture(){ tap:"POST",gainLinear:1,enabled:true,signalKind:"AUDIO"}]; return s; } +test("M5 native FX snapshot rejects malformed/duplicate lease tokens without losing accepted state",()=>{ + const good=acceptedFixture(),input=good.graph.channels[0].id; + good.graph.channels[0].inserts=[{ + id:"native-lease-A",catalogId:"vendor.fx.catalog",name:"Vendor FX",bypassed:false + }]; + const sent=[],statuses=[],controller=protocol.createController({ + emit:(event,payload)=>sent.push({event,payload}), + onStatus:x=>statuses.push(x) + }); + assert.equal(controller.onSnapshot(good),true); + const accepted=controller.state().current; + assert.ok(accepted.admitted); + const mutations=[ + row=>{row.graph.channels[0].inserts=[null];}, + row=>{row.graph.channels[0].inserts=[{}];}, + row=>{row.graph.channels[0].inserts=[{id:"",catalogId:"vendor.fx.catalog"}];}, + row=>{row.graph.channels[0].inserts=[{id:"native-lease-A",catalogId:""}];}, + row=>{row.graph.channels[0].inserts=[{id:"native-lease-A",catalogId:"vendor.fx.catalog",bypassed:"false"}];}, + row=>{row.graph.channels[0].inserts.push({...row.graph.channels[0].inserts[0]});}, + row=>{row.graph.channels[1].inserts.push({...row.graph.channels[0].inserts[0]});}, + row=>{row.graph.channels[0].inserts=Array.from({length:9},(_,i)=>({ + id:"lease-"+i,catalogId:"vendor.fx.catalog"}));} + ]; + for(const mutate of mutations){ + const bad=clone(good); + mutate(bad); + assert.equal(protocol.normalizeSnapshot(bad),null, + "malformed instance lease must not be accepted as native PCM graph"); + assert.equal(controller.onSnapshot(bad),false); + assert.equal(controller.state().current,accepted, + "rejected FX snapshot must preserve the latest accepted physical graph"); + assert.equal(controller.state().lastError,"INVALID_NATIVE_SNAPSHOT"); + assert.equal(controller.state().pending,null); + assert.equal(sent.length,0,"no bogus native intent or subscription"); + } + assert.equal(statuses.at(-1).lastError,"INVALID_NATIVE_SNAPSHOT"); + assert.equal(protocol.readbackProvesIntent(null,{ + operation:"REMOVE_INSERT",targetChannelId:input,payload:{slot:0} + }),false,"invalid snapshot may never prove ACK"); + + // Malformed unsolicited readback during an edit is not a reason to commit or + // lose the valid pending request; a subsequent real ACK+snapshot may recover. + const edit=controller.intent("SET_FADER",input,{valueDb:-12}); + assert.equal(edit.ok,true); + const bad=clone(good);bad.graph.channels[0].inserts=[null]; + assert.equal(controller.onSnapshot(bad),false); + assert.equal(controller.state().pending?.requestId,edit.requestId); + assert.equal(controller.state().current,accepted); + assert.equal(controller.onAck({ + requestId:edit.requestId,status:"ACCEPTED", + deviceEpoch:good.device.epoch, + graphRevision:good.graph.revision, + rosterRevision:good.graph.rosterRevision,errorCode:"NONE" + }),true); + const after=clone(good); + after.graph.channels[0].controls.faderDb=-12; + assert.equal(controller.onSnapshot(after),true); + assert.equal(controller.state().lastError,"ACCEPTED_READBACK"); + assert.equal(controller.state().pending,null); + assert.equal(controller.state().current.graph.channels[0].controls.faderDb,-12); +}); test("M5 rejected FX intents update observable native status without emitting or repainting PCM",()=>{ const s=acceptedFixture(); const ch=s.graph.channels[0]; From 02380f3a18e449d5e21ced340ea53285ebe4ffa1 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 08:48:55 +0700 Subject: [PATCH 3/4] test(m5): align sidechain lease fixture with actual installed FX id/catalog schema --- tests/m4_operator_routing.test.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/m4_operator_routing.test.mjs b/tests/m4_operator_routing.test.mjs index 834ea0516..fa26e8425 100644 --- a/tests/m4_operator_routing.test.mjs +++ b/tests/m4_operator_routing.test.mjs @@ -164,8 +164,12 @@ test('uint64 identities remain exact strings; malformed ids and stale capability 'NATIVE_WIRE_OPERATION_UNAVAILABLE'); }); test('sidechain is NEVER an audible WIRE edge and cannot claim a missing VST3 bus',()=>{ + // Public installed schema uses exact live lease token 'id' plus the + // independent catalog identity. The old instanceId-only fixture was not + // a valid native M2 snapshot and masked malformed-insert admission. const s=base();s.graph.channels[0].inserts.push({ - instanceId:'native-vst-1',name:'Compressor',bypassed:false}); + id:'native-vst-1',catalogId:'vendor.compressor', + name:'Compressor',bypassed:false}); let p=planM4OperatorIntent(accepted(s),{kind:'SIDECHAIN', sourceId:ids.kick,destinationId:ids.v,pluginInstanceId:'native-vst-1'}); assert.equal(p.error,'VST3_AUX_DETECTOR_BUS_NOT_NEGOTIATED'); From b143e59d2e09e395bdadeffc72dab7a54343d7a3 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 08:50:00 +0700 Subject: [PATCH 4/4] test(m5): distinguish invalid FX snapshot from valid-but-wrong native ACK readback --- tests/approved_native_m2_contract.test.cjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 2d5ee0a92..6dbb9c1c0 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -1666,8 +1666,17 @@ test("native FX remove/reorder/transfer requires exact token, ACK and ordered re c.onAck({requestId:request.requestId,status:'ACCEPTED',errorCode:'NONE',deviceEpoch:t.base.device.epoch,graphRevision:'6',rosterRevision:'8'}); const wrong=clone(t.base);wrong.graph.revision='6';wrong.graph.rosterRevision='8'; wrong.graph.channels[1].inserts.push(clone(wrong.graph.channels[0].inserts[0])); - assert.equal(c.onSnapshot(wrong),false,'name/token copy cannot masquerade as MOVE'); + assert.equal(c.onSnapshot(wrong),false,'duplicate live token is invalid native schema'); + assert.equal(c.state().lastError,'INVALID_NATIVE_SNAPSHOT'); + assert.equal(c.state().pending?.requestId,request.requestId, + 'invalid transport snapshot must not consume the accepted native ACK'); + const wrongEffect=clone(t.base); + wrongEffect.graph.revision='6';wrongEffect.graph.rosterRevision='8'; + wrongEffect.graph.channels[0].inserts.reverse(); + assert.equal(c.onSnapshot(wrongEffect),false, + 'valid but wrong FX order cannot masquerade as MOVE'); assert.equal(c.state().lastError,'ACK_READBACK_EFFECT_MISMATCH'); + assert.equal(c.state().pending,null); }); test("native vendor editor retention follows current PCM ownership, not inactive M4 slots",()=>{