diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 7ef2dccf7..2fcdb13d3 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -14,6 +14,134 @@ const clone=x=>JSON.parse(JSON.stringify(x)); // GUI-4: SOURCE ONLY and physical PRIMARY OUT must not consume a parallel SEND. + +test("MV-6 SOURCE input queues bind exact native device epoch and verified pins",()=>{ + const choices=[{label:"None",mode:"NONE",left:-1,right:-1}, + {label:"Mono · IN 1",mode:"MONO",left:0,right:-1}, + {label:"Mono · IN 2",mode:"MONO",left:1,right:-1}, + {label:"Stereo · IN 1 + 2",mode:"STEREO",left:0,right:1}]; + const change=stripVM.sourceQueueSelection({choice:choices[1],choices, + epoch:"19",acceptedLabel:"None"}); + assert.deepEqual(change,{kind:"QUEUE",entry:{epoch:"19",choice:choices[1]}}); + assert.notEqual(change.entry.choice,choices[1], + "queue stores an independent transient operator draft"); + const undo=stripVM.sourceQueueSelection({choice:choices[0],choices, + epoch:"19",acceptedLabel:"None"}); + assert.equal(undo.kind,"CANCEL","return to installed PCM cancels stale queued edit"); + const compensate=stripVM.sourceQueueSelection({choice:choices[0],choices, + epoch:"19",acceptedLabel:"None",activeSameChannel:true}); + assert.equal(compensate.kind,"QUEUE", + "an already in-flight edit must be followed by explicit revert to old input"); + for(const invalid of [ + {choice:choices[1],choices,epoch:"0",acceptedLabel:"None"}, + {choice:choices[1],choices,epoch:19,acceptedLabel:"None"}, + {choice:choices[1],choices,epoch:"18446744073709551616",acceptedLabel:"None"}, + {choice:choices[1],choices:[...choices,choices[1]],epoch:"19"}, + {choice:{...choices[1],left:2},choices,epoch:"19"}, + {choice:{...choices[3],right:3},choices,epoch:"19"}, + {choice:{...choices[0],left:0},choices,epoch:"19"} + ])assert.equal(stripVM.sourceQueueSelection(invalid).kind,"UNAVAILABLE"); + assert.equal(change.entry.epoch,"19"); + const hugeEpoch="18446744073709551610"; + const huge=stripVM.sourceQueueSelection({choice:choices[1],choices, + epoch:hugeEpoch,acceptedLabel:"None"}); + assert.equal(huge.kind,"QUEUE", + "full uint64 ChannelId-era device epoch must stay exact decimal text"); + const hugeHardware={device:{epoch:hugeEpoch},raw:{ + mixerSession:{authority:"CHANNEL_ID"}}}; + const hugeNative={admitted:true,retained:false,device:{epoch:hugeEpoch}, + graph:{revision:"9223372036854775808",rosterRevision:"9223372036854775809", + channels:[{id:"9007199254740993",role:"INPUT"}]}}; + const hugePlan=stripVM.sourceDispatchPlan({authority:"CHANNEL_ID", + entry:huge.entry,hardware:hugeHardware,native:hugeNative, + channelId:"9007199254740993",choices,deviceReady:true}); + assert.equal(hugePlan.kind,"READY"); + assert.equal(hugePlan.payload.deviceEpoch,hugeEpoch); + assert.equal(hugePlan.payload.graphRevision,"9223372036854775808"); + assert.equal(stripVM.sourceDispatchPlan({authority:"M4",entry:huge.entry, + hardware:{...hugeHardware,raw:{...hugeHardware.raw, + legacyM4:{routingRevision:"9"}}},channel:0,choices, + deviceReady:true}).kind,"UNAVAILABLE", + "old M4 cannot coerce a 64-bit native epoch to a rounded JS Number"); + const hardware={device:{epoch:"19"},raw:{mixerSession:{authority:"CHANNEL_ID"}, + legacyM4:{routingRevision:"22"}}}; + const id="9007199254740993"; + const native={admitted:true,retained:false,device:{epoch:"19"}, + graph:{revision:"30",rosterRevision:"31", + channels:[{id,role:"INPUT"}]}}; + const plan=stripVM.sourceDispatchPlan({authority:"CHANNEL_ID", + entry:change.entry,hardware,native,channelId:id,choices,deviceReady:true}); + assert.deepEqual(plan,{kind:"READY",action:"routingNativeSourcePatch", + payload:{channelId:id,deviceEpoch:"19",graphRevision:"30", + rosterRevision:"31",mode:"MONO",left:0,right:-1}}); + for(const invalid of [ + {hardware:{...hardware,device:{epoch:"20"}}}, + {native:{...native,device:{epoch:"20"}}}, + {native:{...native,admitted:false}}, + {native:{...native,retained:true}}, + {native:{...native,graph:{...native.graph, + channels:[{id,role:"GROUP"}]}}}, + {native:{...native,graph:{...native.graph,revision:"0"}}}, + {channelId:Number(id)}, + {choices:choices.filter(x=>x.label!==choices[1].label)}, + {deviceReady:false} + ])assert.equal(stripVM.sourceDispatchPlan({authority:"CHANNEL_ID", + entry:change.entry,hardware,native,channelId:id,choices, + deviceReady:true,...invalid}).kind,"UNAVAILABLE",JSON.stringify(invalid)); +}); +test("MV-6 M4 SOURCE dispatch reuses fresh revision but never migrates stale device pins",()=>{ + const choices=[{label:"None",mode:"NONE",left:-1,right:-1}, + {label:"Mono · IN 1",mode:"MONO",left:0,right:-1}]; + const entry=stripVM.sourceQueueSelection({choice:choices[1],choices, + epoch:"71",acceptedLabel:"None"}).entry; + const hardware={device:{epoch:"71"},raw:{ + mixerSession:{authority:"M4"},legacyM4:{routingRevision:"29"}}}; + const plan=(override={})=>stripVM.sourceDispatchPlan({ + authority:"M4",entry,hardware,channel:4,choices,deviceReady:true,...override}); + assert.deepEqual(plan(),{kind:"READY",action:"routingSourceSwitch", + payload:{channel:4,mode:"MONO",left:0,right:-1,deviceEpoch:71,revision:29}}); + assert.equal(plan({hardware:{...hardware,raw:{...hardware.raw, + legacyM4:{routingRevision:"30"}}}}).payload.revision,30, + "M4 accepts fresh route revision only on the SAME physical epoch"); + assert.equal(plan({hardware:{...hardware,device:{epoch:"72"}}}).kind, + "UNAVAILABLE","device switch must discard the old input choice"); + assert.equal(plan({hardware:{...hardware,raw:{...hardware.raw, + mixerSession:{authority:"CHANNEL_ID"}}}}).kind,"UNAVAILABLE", + "M4 cannot seize authority from admitted ChannelId PCM"); + for(const override of [ + {channel:10},{channel:-1},{channel:"4"}, + {hardware:{...hardware,raw:{...hardware.raw,legacyM4:{routingRevision:"0"}}}}, + {choices:[choices[0]]},{deviceReady:false} + ])assert.equal(plan(override).kind,"UNAVAILABLE"); + const pending={requestId:99,channel:4,choice:entry.choice,epoch:71,revision:29}; + const ack={requestId:99,ok:true,state:{ready:true,epoch:71,revision:30, + hasAcceptedRoute:true,acceptedRoute:{channels:Array.from({length:10}, + (_,i)=>i===4?{mode:"MONO",left:0,right:-1}:null)}}}; + assert.equal(stripVM.sourceAckResult(pending,ack,"M4"),"ACKED"); + assert.equal(stripVM.sourceAckResult(pending,{...ack,requestId:100},"M4"),"IGNORE"); + assert.equal(stripVM.sourceAckResult(pending,{...ack,state:{...ack.state, + epoch:72}},"M4"),"REJECTED"); + assert.equal(stripVM.sourceAckResult(pending,{...ack,state:{...ack.state, + acceptedRoute:{channels:Array.from({length:10},(_,i)=>i===4? + {mode:"MONO",left:2,right:-1}:null)}}},"M4"),"REJECTED"); + assert.equal(stripVM.sourceAckResult({requestId:"source-native-1"}, + {requestId:"source-native-1",ok:true},"CHANNEL_ID"),"ACKED"); + assert.equal(stripVM.sourceAckResult({requestId:"source-native-1"}, + {requestId:"source-native-2",ok:true},"CHANNEL_ID"),"IGNORE"); + assert.equal(stripVM.sourceAckResult({requestId:"source-native-1"}, + {requestId:"source-native-1",ok:false},"CHANNEL_ID"),"REJECTED"); + const bridge=read("web/approved-native-bridge.js"); + assert.match(bridge,/stripVM\.sourceQueueSelection\(/); + assert.equal((bridge.match(/stripVM\.sourceDispatchPlan\(/g)||[]).length,2, + "both native ChannelId and M4 dispatch through one pure preflight policy"); + assert.equal((bridge.match(/stripVM\.sourceAckResult\(/g)||[]).length,2); + assert.match(bridge,/pendingNativeSources\.set\(id,decision\.entry\)/); + assert.match(bridge,/pendingSourceQueue\.set\(channel,decision\.entry\)/); + assert.match(bridge,/if\(decision\.kind==="CANCEL"\)pendingNativeSources\.delete/); + assert.match(bridge,/if\(decision\.kind==="CANCEL"\)pendingSourceQueue\.delete/); + assert.doesNotMatch(stripVM.sourceDispatchPlan.toString(),/backend|document|window/); +}); + test("GUI-4 Channel Strip PRIMARY OUT extracts exact native EdgeId without touching SEND",()=>{ const source="9007199254740993",bus="9007199254741001", main="18446744073709551615"; @@ -728,7 +856,8 @@ test("P0 DAW approved Windows GUI directly binds every IN to current JUCE ports, assert.match(bridge,/const m4TrackIds=Array\.isArray\(scope\?\.tracks\)/); assert.match(bridge,/const savedId = uiByNativeId\.get\(ch\.id\) \?\? m4Id/); assert.match(bridge,/action:"routingSourceSwitch"/); - assert.match(bridge,/row\?\.left===p\.choice\.left/); + assert.match(read("web/approved-channel-strip-view-model.js"), + /row\?\.left===pending\.choice\.left/); assert.match(nativeMain,/autoMainEpoch_!=engine_\.dryRoutingLabEpoch\(\)/); assert.match(bridge,/inputSelect\.hidden=true;routeBtn\.hidden=true;armBtn\.hidden=true/); assert.match(bridge,/openNativeAudioIO\(\)/); @@ -1024,9 +1153,11 @@ test("P0 post-BUS native IN routes NONE MONO STEREO via one PCM owner",()=>{ const engine=read("src/LiveAudioEngine.h"); const lab=read("src/LiveDryRoutingLab.h"); assert.match(bridge,/function dispatchNativeSource\(\)/); - assert.match(bridge,/action:"routingNativeSourcePatch"/); + assert.match(read("web/approved-channel-strip-view-model.js"), + /action:"routingNativeSourcePatch"/); + assert.match(bridge,/action:plan\.action,requestId/); assert.match(bridge,/arMixNativeSourceAck/); - assert.match(bridge,/pendingNativeSources.set\(id,choice\)/); + assert.match(bridge,/pendingNativeSources.set\(id,decision.entry\)/); assert.match(host,/if\(action=="routingNativeSourcePatch"\)/); assert.match(host,/engine_\.patchNativeInputSource\(ep,rev,roster,/); assert.match(lab,/const bool disconnect=!stereo&&physicalLeft==-1&&physicalRight==-1/); diff --git a/web/approved-channel-strip-view-model.js b/web/approved-channel-strip-view-model.js index c6ed943ea..a1a5ffa4f 100644 --- a/web/approved-channel-strip-view-model.js +++ b/web/approved-channel-strip-view-model.js @@ -191,7 +191,92 @@ requiresConfirmation:!none,confirmation,sharedCount:occupied}; } + + // MV-6: SOURCE selection/queue and native/M4 command preflight are pure + // projections of the one installed device inventory. The bridge owns the + // only pending queues and requestIds; neither VM nor UI owns accepted PCM. + const positiveCounter=v=>typeof v==="string"&&/^[1-9][0-9]*$/.test(v)&& + Number.isSafeInteger(Number(v)); + const decimalId=v=>{ + if(typeof v!=="string"||!/^[1-9][0-9]*$/.test(v))return false; + try{return BigInt(v)<=18446744073709551615n;}catch{return false;} + }; + function sourceChoiceMatches(choice,options) { + if(!choice||typeof choice.label!=="string"||!Array.isArray(options))return false; + const exact=options.filter(p=>p?.label===choice.label); + if(exact.length!==1)return false; + if(!["NONE","MONO","STEREO"].includes(choice.mode)|| + exact[0].mode!==choice.mode|| + exact[0].left!==choice.left||exact[0].right!==choice.right)return false; + if(choice.mode==="NONE")return choice.left===-1&&choice.right===-1; + if(!Number.isSafeInteger(choice.left)||choice.left<0)return false; + if(choice.mode==="MONO")return choice.right===-1; + return Number.isSafeInteger(choice.right)&& + choice.right===choice.left+1; + } + function sourceQueueSelection({choice,choices,epoch,acceptedLabel, + activeSameChannel=false}={}) { + if(!decimalId(epoch)||!sourceChoiceMatches(choice,choices)) + return {kind:"UNAVAILABLE"}; + // The operator can cancel a queued edit by returning to installed PCM. + // But when THIS channel already has an in-flight edit, queuing the old + // accepted choice is a legitimate rollback requested after its ACK. + if(choice.label===acceptedLabel&&!activeSameChannel) + return {kind:"CANCEL"}; + return {kind:"QUEUE",entry:{epoch,choice:{ + label:choice.label,mode:choice.mode,left:choice.left,right:choice.right + }}}; + } + function sourceDispatchPlan({authority,entry,hardware,native, + channelId,channel,choices,deviceReady=false}={}) { + const unavailable={kind:"UNAVAILABLE"}; + const choice=entry?.choice,epoch=hardware?.device?.epoch; + if(!deviceReady||!decimalId(epoch)||epoch!==entry?.epoch|| + !sourceChoiceMatches(choice,choices))return unavailable; + if(authority==="CHANNEL_ID"){ + const graph=native?.graph,session=hardware?.raw?.mixerSession; + if(!decimalId(channelId)||native?.admitted!==true|| + native?.retained===true||session?.authority!=="CHANNEL_ID"|| + native?.device?.epoch!==epoch|| + !Array.isArray(graph?.channels)|| + !graph.channels.some(ch=>ch.id===channelId&&ch.role==="INPUT")|| + !decimalId(graph?.revision)|| + !decimalId(graph?.rosterRevision))return unavailable; + return {kind:"READY",action:"routingNativeSourcePatch", + payload:{channelId,deviceEpoch:epoch, + graphRevision:graph.revision,rosterRevision:graph.rosterRevision, + mode:choice.mode,left:choice.left,right:choice.right}}; + } + if(authority==="M4"){ + if(hardware?.raw?.mixerSession?.authority==="CHANNEL_ID"|| + !positiveCounter(epoch)|| + !Number.isInteger(channel)||channel<0||channel>=10|| + !positiveCounter(hardware?.raw?.legacyM4?.routingRevision)) + return unavailable; + return {kind:"READY",action:"routingSourceSwitch", + payload:{channel,mode:choice.mode,left:choice.left,right:choice.right, + deviceEpoch:Number(epoch), + revision:Number(hardware.raw.legacyM4.routingRevision)}}; + } + return unavailable; + } + function sourceAckResult(pending,ack,authority) { + if(!pending||ack?.requestId!==pending.requestId)return "IGNORE"; + if(authority==="CHANNEL_ID") + return ack?.ok===true?"ACKED":"REJECTED"; + if(authority!=="M4")return "REJECTED"; + const next=ack?.state||{},row=next.acceptedRoute?.channels?.[pending.channel]; + return ack?.ok===true&&next.ready===true&& + Number(next.epoch)===Number(pending.epoch)&& + next.hasAcceptedRoute===true&& + Number(next.revision)>=Number(pending.revision)&& + row?.mode===pending.choice.mode&& + row?.left===pending.choice.left&&row?.right===pending.choice.right? + "ACKED":"REJECTED"; + } + return Object.freeze({outputTargets,inputChoices,externalChoices, primaryChoices,resolvePrimarySelection,readbackBindings,externalPending, - primaryOutMutation,externalOutputPlan}); + primaryOutMutation,externalOutputPlan,sourceQueueSelection, + sourceDispatchPlan,sourceAckResult}); }); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index a2d527508..ec79d6495 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1036,18 +1036,24 @@ if(activeNativeSource||!pendingNativeSources.size)return; const current=controller?.state()?.current; if(!current?.admitted||mixerSession()?.authority!=="CHANNEL_ID")return; - const [id,choice]=pendingNativeSources.entries().next().value; + const [id,entry]=pendingNativeSources.entries().next().value; pendingNativeSources.delete(id); - if(!current.graph.channels.some(ch=>ch.id===id&&ch.role==="INPUT")) - return nativeToast("Source identity changed · refresh native mixer"); + const plan=stripVM.sourceDispatchPlan({ + authority:"CHANNEL_ID",entry,hardware,native:current,channelId:id, + choices:inputChoicesFor(),deviceReady:deviceReady() + }); + if(plan.kind!=="READY"){ + nativeToast("Source identity or device pins changed · refresh native mixer"); + // An invalid head must never strand edits queued for other channels. + if(pendingNativeSources.size)window.queueMicrotask(dispatchNativeSource); + return; + } const requestId="source-native-"+(++nativeSourceSerial); - activeNativeSource={requestId,id,choice}; + activeNativeSource={requestId,id,choice:entry.choice,epoch:entry.epoch}; backend.emitEvent("arMixAction",{ - action:"routingNativeSourcePatch",requestId,channelId:id, - deviceEpoch:current.device.epoch,graphRevision:current.graph.revision, - rosterRevision:current.graph.rosterRevision, - mode:choice.mode,left:choice.left,right:choice.right}); - status("Input "+choice.label+" · native PCM readback pending"); + action:plan.action,requestId,...plan.payload + }); + status("Input "+entry.choice.label+" · native PCM readback pending"); window.setTimeout(()=>{ if(activeNativeSource?.requestId!==requestId)return; activeNativeSource=null; @@ -2611,22 +2617,30 @@ function dispatchQueuedSource(){ if(nativeUiSourcePending||pendingSourceQueue.size===0)return; if(!deviceReady()){pendingSourceQueue.clear();return;} - const [channel,choice]=pendingSourceQueue.entries().next().value; - pendingSourceQueue.delete(channel); - const ep=safeNativeCounter(hardware?.device?.epoch), - rev=safeNativeCounter(legacy()?.routingRevision); - if(ep===null||rev===null)return; - const requestId=++sourceSerial; - nativeUiSourcePending={requestId,channel,choice,epoch:ep,revision:rev}; - backend.emitEvent("arMixAction",{action:"routingSourceSwitch", - requestId,channel,mode:choice.mode,left:choice.left,right:choice.right, - deviceEpoch:ep,revision:rev}); - window.setTimeout(()=>{ - if(nativeUiSourcePending?.requestId!==requestId)return; - nativeUiSourcePending=null; - status("CH "+(channel+1)+" INPUT timeout · native state preserved"); - controller.subscribe(); - },8000); + while(pendingSourceQueue.size){ + const [channel,entry]=pendingSourceQueue.entries().next().value; + pendingSourceQueue.delete(channel); + const plan=stripVM.sourceDispatchPlan({ + authority:"M4",entry,hardware,channel, + choices:inputChoicesFor(),deviceReady:deviceReady() + }); + if(plan.kind!=="READY"){ + status("CH "+(channel+1)+" INPUT dropped · device or pin identity changed"); + continue; // stale first entry cannot starve the next valid source + } + const requestId=++sourceSerial; + nativeUiSourcePending={requestId,channel,choice:entry.choice, + epoch:plan.payload.deviceEpoch,revision:plan.payload.revision}; + backend.emitEvent("arMixAction",{action:plan.action,requestId, + ...plan.payload}); + window.setTimeout(()=>{ + if(nativeUiSourcePending?.requestId!==requestId)return; + nativeUiSourcePending=null; + status("CH "+(channel+1)+" INPUT timeout · native state preserved"); + controller.subscribe(); + },8000); + return; + } } function playAcceptedWireImpact(changes) { const plug=changes?.find(change=>["CONNECT","ROUTE_ONLY","RETARGET"].includes(change.op)); @@ -2963,9 +2977,10 @@ controller?.subscribe(); }); backend.addEventListener("arMixNativeSourceAck",ack=>{ - if(!activeNativeSource||activeNativeSource.requestId!==ack?.requestId)return; + const verdict=stripVM.sourceAckResult(activeNativeSource,ack,"CHANNEL_ID"); + if(verdict==="IGNORE")return; activeNativeSource=null; - if(ack.ok!==true) + if(verdict!=="ACKED") nativeToast("Native input rejected · "+(ack?.error||"stale PCM")); else status("Native input accepted · checking subsequent PCM readback"); controller?.subscribe(); @@ -3033,22 +3048,15 @@ controller.subscribe(); // later authoritative M4 snapshot required }); backend.addEventListener("arMixSourceSwitchAck", ack=>{ - if(nativeUiSourcePending && - ack?.requestId===nativeUiSourcePending.requestId) { + const verdict=stripVM.sourceAckResult(nativeUiSourcePending,ack,"M4"); + if(verdict!=="IGNORE"){ const p=nativeUiSourcePending; nativeUiSourcePending=null; - const next=ack?.state||{},row=next.acceptedRoute?.channels?.[p.channel]; - const verified=ack.ok===true && next.ready===true && - Number(next.epoch)===p.epoch && next.hasAcceptedRoute===true && - Number(next.revision)>=p.revision && - row?.mode===p.choice.mode && row?.left===p.choice.left && - row?.right===p.choice.right; - if(verified) { - // Native publisher + engine own the accepted graph; refresh the - // UI only from a subsequent authoritative snapshot. + if(verdict==="ACKED"){ + // The acceptedRoute carried in ACK is NOT subsequent callback PCM. controller.subscribe(); status("CH "+(p.channel+1)+" native input accepted"); - } else { + }else{ status("NATIVE INPUT REJECTED · "+(ack?.error||"stale routing")); controller.subscribe(); } @@ -3296,40 +3304,39 @@ // source, including the very first source in an unpatched session. if(event.type!=="change")return true; const channel=m4Index(t); - const choice=inputChoicesFor().find(x=>x.label===el.value); - // After BUS/WIRE the installed ChannelId graph is sole PCM owner. - // Original ten channels must not send source edits to stale M4. - if(mixerSession()?.authority==="CHANNEL_ID"){ - const current=controller?.state()?.current; - const id=nativeIdFor(t); - if(!choice||!id||!current?.admitted||!deviceReady()){ - nativeToast("Select a verified physical input"); - el.value=t.input;return true; - } - if(choice.label!==t.input){ - pendingNativeSources.set(id,choice); - dispatchNativeSource(); - } - el.value=t.input; // no optimistic browser patch - return true; - } - const ep=safeNativeCounter(hardware?.device?.epoch); - const rev=safeNativeCounter(legacy()?.routingRevision); - if(channel<0||channel>=10||!choice||!deviceReady()|| - ep===null||rev===null){ - status("INPUT REJECTED · refresh verified hardware pins"); + const choices=inputChoicesFor(); + const choice=choices.find(x=>x.label===el.value); + const nativeOwner=mixerSession()?.authority==="CHANNEL_ID"; + const id=nativeOwner?nativeIdFor(t):null; + if((nativeOwner&&(!id||!controller?.state()?.current?.admitted))|| + (!nativeOwner&&(channel<0||channel>=10))||!deviceReady()){ + status("INPUT REJECTED · verify native channel and hardware pins"); el.value=t.input;return true; } - if(choice.label===t.input&&!pendingSourceQueue.has(channel)){ + const decision=stripVM.sourceQueueSelection({ + choice,choices,epoch:hardware?.device?.epoch,acceptedLabel:t.input, + activeSameChannel:nativeOwner?activeNativeSource?.id===id: + nativeUiSourcePending?.channel===channel + }); + if(decision.kind==="UNAVAILABLE"){ + if(nativeOwner)nativeToast("Select a verified physical input"); + else status("INPUT REJECTED · refresh verified hardware pins"); el.value=t.input;return true; } - pendingSourceQueue.set(channel,choice); - // No browser demo optimistic patch. The selector stays operable for - // every channel during a previous JUCE routing transaction. - el.value=t.input; - if(nativeUiSourcePending) - status("CH "+(channel+1)+" input queued behind native route ACK"); - else dispatchQueuedSource(); + if(nativeOwner){ + if(decision.kind==="CANCEL")pendingNativeSources.delete(id); + else pendingNativeSources.set(id,decision.entry); + if(decision.kind==="QUEUE")dispatchNativeSource(); + }else{ + if(decision.kind==="CANCEL")pendingSourceQueue.delete(channel); + else pendingSourceQueue.set(channel,decision.entry); + if(decision.kind==="QUEUE"){ + if(nativeUiSourcePending) + status("CH "+(channel+1)+" input queued behind native route ACK"); + else dispatchQueuedSource(); + } + } + el.value=t.input; // installed readback, not an optimistic UI patch return true; } if(field==="external"){