From 904c40ce828dc7832fe6ad53f58fc9143be4a01f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 29 Oct 2026 16:31:01 +0700 Subject: [PATCH] R1 reliability: return negative routing ACK on Studio busy, unblock pending UI safely --- src/Main.cpp | 18 +++++++++++++++++- tests/live_routing_ui_contract_test.mjs | 12 ++++++++++++ tests/ui_smoke.py | 13 +++++++++++++ web/monitor.js | 13 +++---------- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index a759c09d3..a7f8a9f5b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -946,7 +946,23 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr action.startsWith ("import") || action.startsWith ("fx") || action == "addCatalog" || action == "addScanFolder" || action == "scanVst3" || action == "routingDryApply")) - return emitNotice ("Studio backup in progress. Finish backup before editing saved FX or VST library.", true); + { + const auto reason=juce::String( + "Studio backup in progress. Finish backup before editing saved FX or VST library."); + // R1 matrix must ALWAYS get a response after APPLY, including + // upstream rejection before the normal routing command handler. + // No graph or device state may be mutated while Studio IO is busy. + if(action=="routingDryApply" && browser_.loaded) + { + auto ack=std::make_unique(); + ack->setProperty("ok",false); + ack->setProperty("error",reason); + ack->setProperty("state",engine_.status().getProperty("dryRoutingLab",{})); + browser_.emitEventIfBrowserIsVisible( + "arMixRoutingLabAck",juce::var(ack.release())); + } + return emitNotice(reason,true); + } // Structural plugin operations currently detach the original callback // and must never mutate a running independent render thread. diff --git a/tests/live_routing_ui_contract_test.mjs b/tests/live_routing_ui_contract_test.mjs index 6abd48fc0..a496c9269 100644 --- a/tests/live_routing_ui_contract_test.mjs +++ b/tests/live_routing_ui_contract_test.mjs @@ -192,3 +192,15 @@ test("R1 matrix edits only device-bound draft and honors native revision ACK",() assert.doesNotMatch(ui,/filter\s*:\s*blur\(/); assert.match(ui,/document\.addEventListener\("click",event=>/); }); + +test("R1 upstream Studio-IO rejection always releases native APPLY pending state",()=>{ + const first=main.indexOf('if ((studioBackupBusy_ || nativeShowBusy_)'); + const next=main.indexOf('// Structural plugin operations',first); + assert.ok(first>=0&&next>first); + const gate=main.slice(first,next); + assert.match(gate,/action=="routingDryApply"/); + assert.match(gate,/arMixRoutingLabAck/); + assert.match(gate,/setProperty\("ok",false\)/); + assert.match(ui,/patchPending=false/); + assert.match(ui,/if\(patchPending\)return/); +}); diff --git a/tests/ui_smoke.py b/tests/ui_smoke.py index 3ee573a64..f5a77a7cc 100644 --- a/tests/ui_smoke.py +++ b/tests/ui_smoke.py @@ -1292,6 +1292,19 @@ async def image_for(selector): assert action["channels"][0]["left"]==2 and action["channels"][0]["mode"]=="MONO",action assert action["channels"][1]["left"]==2 and action["channels"][1]["right"]==5,action assert await native.locator("#arRouteApply").is_disabled() + # Busy Studio IO must reject with native ACK and unlock APPLY (no + # fake LIVE green cell or reinitialization of the user's draft). + await native.evaluate("""()=>{ + const d=window.__arPatchStatus.dryRoutingLab; + window.__arMixMockEvents.arMixRoutingLabAck({ + ok:false,error:"Studio backup in progress",state:d + }); + }""") + assert await native.locator("#arRouteApply").is_enabled() + assert "REJECTED" in await native.locator("#arRouteFeedback").inner_text() + assert await native.locator('[data-patch-row="0"][data-patch-port="2"].arPatchCell').get_attribute("data-patch-state")=="draft" + await native.locator("#arRouteApply").click() + assert await native.locator("#arRouteApply").is_disabled() await native.evaluate("""()=>{ const d=window.__arPatchStatus.dryRoutingLab; d.active=true;d.ready=true;d.revision=1; diff --git a/web/monitor.js b/web/monitor.js index 16c5fc7ac..c98a53148 100644 --- a/web/monitor.js +++ b/web/monitor.js @@ -510,18 +510,11 @@ if(failure){patchFeedback("REJECTED · "+failure);return;} if(state.monitor){patchFeedback("MUTE OUTPUT FIRST · structural routing cannot be applied while speakers are armed.");return;} syncNativeLevelsToRouteDraft(); + // patchPreflight above already checked epoch, enabled ports and stereo. + // Enter pending only after *every* synchronous rejection gate has passed. patchPending=true; renderPatchMatrix(); - if(!draftEpoch || draftEpoch!==Number(d.epoch)){ - document.getElementById("arRouteFeedback").textContent= - "DEVICE CHANGED · old channel assignments discarded. Re-select the actual physical inputs."; - drawRoutes(); - return; // must never submit old ports with a newly observed epoch - } - if(!Array.isArray(d.ports)||!d.ports.length){ - document.getElementById("arRouteFeedback").textContent="Select a real ASIO/WASAPI audio input in AUDIO SETUP first.";return; - } - document.getElementById("arRouteFeedback").textContent="Applying native route (output must be MUTED)..."; + document.getElementById("arRouteFeedback").textContent="Applying verified native route (output remains MUTED)..."; api.emitEvent("arMixAction",{action:"routingDryApply",value:{ deviceEpoch:draftEpoch,revision:Number(d.revision)||0, channels:draftRoutes.map(c=>({...c})),