From b6e992f989c9aabb0e0741a8dc215daeac0e605c Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:16:49 +0700 Subject: [PATCH 01/15] feat(wire): stable EdgeId and atomic native WIRE transaction on existing roster --- engine/core/DynamicChannelRoster.h | 169 ++++++++++++++++++++++++++++- 1 file changed, 167 insertions(+), 2 deletions(-) diff --git a/engine/core/DynamicChannelRoster.h b/engine/core/DynamicChannelRoster.h index f05736a35..4c3e7331e 100644 --- a/engine/core/DynamicChannelRoster.h +++ b/engine/core/DynamicChannelRoster.h @@ -29,6 +29,7 @@ struct ChannelSendRef final { bool preFader=false; float pan=0.f; // send-only balance: PRE mono uses equal-power coefficients bool primaryOutput=false; // OUT selector edge, not a parallel SEND + std::uint64_t edgeId=0; // stable native identity; CONTROL-only assignment }; struct ChannelStripDefinition final { ChannelId id{}; @@ -51,7 +52,8 @@ struct ChannelRosterBudget final { enum class ChannelEditFault : std::uint8_t { none, staleRevision, invalidAction, missingChannel, invalidPosition, - invalidValue, budgetExceeded, linkedDestination, idExhausted + invalidValue, budgetExceeded, linkedDestination, idExhausted, + missingEdge, duplicateSend }; struct ChannelEdit final { enum class Kind : std::uint8_t { @@ -75,9 +77,18 @@ struct ChannelEditResult final { std::size_t actionIndex=0; std::uint64_t revision=0; std::vector createdIds; + std::vector createdEdgeIds; bool ok() const noexcept {return fault==ChannelEditFault::none;} }; +struct WireChange final { + enum class Kind : std::uint8_t {connect,remove,retarget,routeOnly}; + Kind kind=Kind::connect; + ChannelId from{},to{}; + std::uint64_t edgeId=0; + float gain=1.f; +}; + class DynamicChannelRoster final { public: explicit DynamicChannelRoster(ChannelRosterBudget budget={}) : budget_(budget) {} @@ -276,14 +287,132 @@ class DynamicChannelRoster final { // Structural edits are infrequent and prepared entirely on CONTROL. // Rebuild before acceptance: rejected/failed edits cannot leave the // active stable-ID map pointing into an old reordered vector. + std::uint64_t stagedNextEdge=nextEdgeId_; + if(!assignMissingEdgeIds(candidate,stagedNextEdge)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } auto stagedIndex=buildIndex(candidate); channels_.swap(candidate); + nextEdgeId_=stagedNextEdge; index_.swap(stagedIndex); nextId_=next; result.revision=++revision_; return result; } + + // This is the only WIRE topology editor. Uses the SAME ChannelSendRef + // inventory as the native PCM compiler and existing source/FX ownership. + // The accepted session later compiles the whole DAG and publishes once. + ChannelEditResult wireTransaction( + std::uint64_t expectedRevision,std::span changes) { + ChannelEditResult result;result.revision=revision_; + if(expectedRevision!=revision_){result.fault=ChannelEditFault::staleRevision;return result;} + if(changes.empty() || revision_==std::numeric_limits::max()){ + result.fault=ChannelEditFault::invalidAction;return result; + } + auto candidate=channels_; // one CONTROL-thread batch copy + const auto main=std::find_if(candidate.begin(),candidate.end(), + [](const auto& ch){return ch.role==ChannelRole::main;}); + if(main==candidate.end()){result.fault=ChannelEditFault::invalidAction;return result;} + const ChannelId mainId=main->id; + std::uint64_t stagedNextEdge=nextEdgeId_; + if(!assignMissingEdgeIds(candidate,stagedNextEdge)){ + result.fault=ChannelEditFault::idExhausted;return result; + } + for(std::size_t i=0;irole==ChannelRole::main || source->role==ChannelRole::monitor){ + result.fault=ChannelEditFault::missingChannel;break; + } + auto& sends=source->sends; + if(op.kind==WireChange::Kind::remove || + op.kind==WireChange::Kind::retarget) { + const auto edge=std::find_if(sends.begin(),sends.end(), + [&](const auto& s){return s.edgeId==op.edgeId;}); + if(!op.edgeId || edge==sends.end()) { + result.fault=ChannelEditFault::missingEdge;break; + } + if(op.kind==WireChange::Kind::remove){sends.erase(edge);continue;} + if(!op.to.value || op.to==op.from || edge->destination==op.to){ + result.fault=ChannelEditFault::invalidValue;break; + } + edge->destination=op.to; // retain exact edgeId, gain and tap + continue; + } + if(op.kind!=WireChange::Kind::connect && + op.kind!=WireChange::Kind::routeOnly) { + result.fault=ChannelEditFault::invalidAction;break; + } + if(!op.to.value || op.to==op.from || !std::isfinite(op.gain) || + op.gain<0.f || op.gain>4.f || + (op.kind==WireChange::Kind::routeOnly && op.to==mainId)){ + result.fault=ChannelEditFault::invalidValue;break; + } + const bool already=std::any_of(sends.begin(),sends.end(), + [&](const auto& s){return s.destination==op.to;}); + if(already && op.kind==WireChange::Kind::connect){ + result.fault=ChannelEditFault::duplicateSend;break; + } + if(op.kind==WireChange::Kind::routeOnly){ + sends.erase(std::remove_if(sends.begin(),sends.end(), + [&](const auto& s){return s.destination==mainId;}), + sends.end()); + if(already)continue; // retain original edgeId/gain + } + if(sends.size()>=budget_.maximumSendsPerChannel){ + result.fault=ChannelEditFault::budgetExceeded;break; + } + const bool hasPrimary=std::any_of(sends.begin(),sends.end(), + [](const auto& s){return s.primaryOutput;}); + const bool primary=!hasPrimary && + (op.to==mainId || op.kind==WireChange::Kind::routeOnly); + sends.push_back({op.to,op.gain,false,0.f,primary,0}); + } + if(result.ok()){ + // Legacy PRE and primary edges share the same accepted graph. + // The PCM compiler also validates complete reachability/cycles. + std::unordered_map indexes; + for(std::size_t i=0;i destinations; + for(const auto& edge:row.sends){ + if(!indexes.count(edge.destination.value) || + row.id==edge.destination || + row.role==ChannelRole::main || row.role==ChannelRole::monitor){ + result.fault=ChannelEditFault::invalidValue;break; + } + if(!destinations.insert(edge.destination.value).second){ + result.fault=ChannelEditFault::duplicateSend;break; + } + } + } + if(result.ok() && !withinBudget(candidate)) + result.fault=ChannelEditFault::budgetExceeded; + } + if(!result.ok())return result; + if(!assignMissingEdgeIds(candidate,stagedNextEdge)){ + result.fault=ChannelEditFault::idExhausted;return result; + } + for(const auto& row:candidate) + for(const auto& edge:row.sends) + if(edge.edgeId>=nextEdgeId_) + result.createdEdgeIds.push_back(edge.edgeId); + auto stagedIndex=buildIndex(candidate); + channels_.swap(candidate); + index_.swap(stagedIndex); + nextEdgeId_=stagedNextEdge; + result.revision=++revision_; + return result; + } + // Studio Console Add Bus / Add FX Channel: allocate a fresh independent // stereo ChannelId, OUT -> MAIN, without borrowing an input or requiring // a selection. CONTROL only; native graph publication is separate. @@ -322,8 +451,14 @@ class DynamicChannelRoster final { // Structural edits are infrequent and prepared entirely on CONTROL. // Rebuild before acceptance: rejected/failed edits cannot leave the // active stable-ID map pointing into an old reordered vector. + std::uint64_t stagedNextEdge=nextEdgeId_; + if(!assignMissingEdgeIds(candidate,stagedNextEdge)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } auto stagedIndex=buildIndex(candidate); channels_.swap(candidate); + nextEdgeId_=stagedNextEdge; index_.swap(stagedIndex);result.createdIds.push_back({nextId_++}); result.revision=++revision_;return result; } @@ -377,8 +512,14 @@ class DynamicChannelRoster final { // Structural edits are infrequent and prepared entirely on CONTROL. // Rebuild before acceptance: rejected/failed edits cannot leave the // active stable-ID map pointing into an old reordered vector. + std::uint64_t stagedNextEdge=nextEdgeId_; + if(!assignMissingEdgeIds(candidate,stagedNextEdge)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } auto stagedIndex=buildIndex(candidate); channels_.swap(candidate); + nextEdgeId_=stagedNextEdge; index_.swap(stagedIndex); result.revision=++revision_;return result; } @@ -457,8 +598,14 @@ class DynamicChannelRoster final { // Structural edits are infrequent and prepared entirely on CONTROL. // Rebuild before acceptance: rejected/failed edits cannot leave the // active stable-ID map pointing into an old reordered vector. + std::uint64_t stagedNextEdge=nextEdgeId_; + if(!assignMissingEdgeIds(candidate,stagedNextEdge)) { + result.fault=ChannelEditFault::idExhausted; + result.createdIds.clear();return result; + } auto stagedIndex=buildIndex(candidate); channels_.swap(candidate); + nextEdgeId_=stagedNextEdge; index_.swap(stagedIndex); ++nextId_;result.revision=++revision_; result.createdIds.push_back(busId); @@ -466,6 +613,24 @@ class DynamicChannelRoster final { } private: + static bool assignMissingEdgeIds( + std::vector& rows,std::uint64_t& next) { + std::unordered_set used; + for(const auto& row:rows) + for(const auto& edge:row.sends) + if(edge.edgeId && !used.insert(edge.edgeId).second)return false; + for(auto& row:rows) + for(auto& edge:row.sends)if(!edge.edgeId){ + while(used.count(next)) { + if(next==std::numeric_limits::max())return false; + ++next; + } + if(!next || next==std::numeric_limits::max())return false; + edge.edgeId=next; + used.insert(next++); + } + return true; + } static std::unordered_map buildIndex( const std::vector& rows) { std::unordered_map index; @@ -506,6 +671,6 @@ class DynamicChannelRoster final { ChannelRosterBudget budget_; std::vector channels_; std::unordered_map index_; // CONTROL ONLY - std::uint64_t revision_=0, nextId_=1; + std::uint64_t revision_=0, nextId_=1, nextEdgeId_=1; }; } // namespace armix::mixer From 59a02b2fd22c98216235eb87ae2028bb08efc913 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:17:41 +0700 Subject: [PATCH 02/15] feat(wire): atomically publish native WIRE batch through existing accepted PCM session --- engine/core/DynamicAcceptedSession.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/engine/core/DynamicAcceptedSession.h b/engine/core/DynamicAcceptedSession.h index 64d9667d9..d7660b7a5 100644 --- a/engine/core/DynamicAcceptedSession.h +++ b/engine/core/DynamicAcceptedSession.h @@ -65,6 +65,30 @@ class DynamicAcceptedSession final { std::move(result),std::move(fx)); } + + // A single native structural operation over accepted ChannelSendRef. + // No JS DSP or independent router: same compiled PCM, routing readback, + // device epoch, revision and FX leases as all other native edit paths. + Result wireTransaction(std::uint64_t expectedRosterRevision, + std::uint64_t expectedGraphRevision, + std::span changes, + const DynamicGraphRequest& route, + std::uint64_t expectedDeviceEpoch, + std::uint64_t activeDeviceEpoch, + bool allOutputsDisarmed, + DynamicNativeSessionPublisher::FxPlan fx={}) { + Result result=preflight(expectedRosterRevision,expectedGraphRevision); + if(!result.ok())return result; + auto candidate=accepted_; + result.edit=candidate.wireTransaction(expectedRosterRevision,changes); + if(!result.edit.ok()) { + result.fault=Fault::editRejected;return result; + } + return publish(std::move(candidate),route,expectedGraphRevision, + expectedDeviceEpoch,activeDeviceEpoch,allOutputsDisarmed, + std::move(result),std::move(fx)); + } + // Studio Pro: one independent Bus ChannelId and automatic assignment of // selected primary OUTs; FX Return leaves those OUTs intact and adds sends. Result createBusForSelected(std::uint64_t expectedRosterRevision, From b359d2c3fc3ca0b5f8eccdf39d022a6c7e09fc28 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:17:44 +0700 Subject: [PATCH 03/15] feat(wire): project exact stable edge IDs from accepted native routing --- engine/core/DynamicConsoleRoutingView.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/engine/core/DynamicConsoleRoutingView.h b/engine/core/DynamicConsoleRoutingView.h index a610abbe3..29cf7b460 100644 --- a/engine/core/DynamicConsoleRoutingView.h +++ b/engine/core/DynamicConsoleRoutingView.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -18,6 +19,13 @@ struct ConsoleSendView final { ChannelId destination{}; float gain=1.f,pan=0.f; bool preFader=false; + std::uint64_t edgeId=0; +}; +struct ConsoleEdgeView final { + std::uint64_t edgeId=0; + ChannelId from{},to{}; + float gainLinear=1.f; + bool preFader=false,primaryOutput=false; }; struct ConsoleChannelView final { ChannelId id{}; @@ -40,6 +48,7 @@ class DynamicConsoleRoutingView final { public: std::uint64_t rosterRevision=0; std::vector channels; + std::vector edges; // exact native accepted graph, NOT a second graph ChannelId main{},monitor{}; const ConsoleChannelView* find(ChannelId id) const noexcept { const auto it=std::find_if(channels.begin(),channels.end(), @@ -73,11 +82,15 @@ class DynamicConsoleRoutingView final { next.channels.push_back(std::move(item)); } if(!next.main.value)return false; + std::unordered_set acceptedEdgeIds; for(std::size_t i=0;isecond]; if(link.primaryOutput) { if(sender.primaryOutput.value || link.preFader || @@ -87,7 +100,7 @@ class DynamicConsoleRoutingView final { destination.primarySources.push_back(sender.id); } else { sender.parallelSends.push_back( - {link.destination,link.gain,link.pan,link.preFader}); + {link.destination,link.gain,link.pan,link.preFader,link.edgeId}); // One source shown once in the Bus fan-in even if it has // multiple legal taps to that destination. if(std::find(destination.parallelSendSources.begin(), From a307831079ae6d05554fe590217cce4e92f0631a Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:18:24 +0700 Subject: [PATCH 04/15] test(wire): native atomic MAIN detach, fan-out, 3-hop sample alignment and rollback --- tests/dynamic_accepted_session_test.cpp | 130 ++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/tests/dynamic_accepted_session_test.cpp b/tests/dynamic_accepted_session_test.cpp index f9699bb46..15dd5fa7d 100644 --- a/tests/dynamic_accepted_session_test.cpp +++ b/tests/dynamic_accepted_session_test.cpp @@ -200,7 +200,137 @@ static void verifyConsoleWirePrimaryOutputPcm() { session.pollRetirement(); } + +// Native WIRE-first acceptance: exactly ONE immutable PCM graph owner. +// Direct, nested and reconvergent paths process within the SAME sample block; +// exact edgeId detach only affects its source, rejected DAG stays audible. +static void verifyAtomicWireTransactionAndZeroSampleHops() { + constexpr std::uint64_t epoch=9909; + constexpr float center=.7071067811865475f; + DynamicAcceptedSession session; + DynamicGraphRequest physical; + physical.physicalInputs=1;physical.maxFrames=64; + const std::array create{ + add(0,ChannelRole::input,"INPUT"), + add(1,ChannelRole::input,"SUM 1",ProcessingFormat::stereo), + add(2,ChannelRole::input,"SUM 2",ProcessingFormat::stereo), + add(3,ChannelRole::main,"MAIN",ProcessingFormat::stereo) + }; + auto a=session.edit(0,0,create,physical,epoch,epoch,true); + assert(a.ok() && a.edit.createdIds.size()==4); + const auto one=a.edit.createdIds[0],two=a.edit.createdIds[1]; + const auto three=a.edit.createdIds[2],main=a.edit.createdIds[3]; + physical.sources={{one,0,-1,false}}; + auto connect=[](ChannelId from,ChannelId to,float gain=1.f) { + WireChange w;w.kind=WireChange::Kind::connect;w.from=from; + w.to=to;w.gain=gain;return w; + }; + auto routeOnly=[](ChannelId from,ChannelId to) { + WireChange w;w.kind=WireChange::Kind::routeOnly; + w.from=from;w.to=to;return w; + }; + auto remove=[](ChannelId from,std::uint64_t id) { + WireChange w;w.kind=WireChange::Kind::remove; + w.from=from;w.edgeId=id;return w; + }; + const std::array initial{ + connect(one,main),connect(two,main),connect(three,main) + }; + a=session.wireTransaction(1,1,initial,physical,epoch,epoch,true); + assert(a.ok()&&a.graphRevision==2&&a.edit.createdEdgeIds.size()==3); + const auto* graph=session.acceptedRouting(epoch,2); + assert(graph&&graph->edges.size()==3); + const auto findEdge=[&](ChannelId from,ChannelId to, + std::uint64_t revision){ + const auto* current=session.acceptedRouting(epoch,revision); + assert(current); + const auto it=std::find_if(current->edges.begin(),current->edges.end(), + [&](const auto& edge){return edge.from==from && edge.to==to;}); + return it==current->edges.end()?std::uint64_t{0}:it->edgeId; + }; + const auto originalMain=findEdge(one,main,2); + const auto otherMain=findEdge(three,main,2); + assert(originalMain!=0 && otherMain!=0 && originalMain!=otherMain); + std::array impulse{},left{},right{}; + impulse[11]=.3f; + const float* inputs[]{impulse.data()}; + const auto noFx=+[](ChannelId,float*,float*,int) noexcept {}; + const auto render=[&]{ + return session.render(epoch,inputs,1,left.data(),right.data(),64, + false,noFx); + }; + assert(render() && near(left[11],.3f*center)); + for(int i=0;i<64;++i) + if(i!=11)assert(near(left[i],0.f)); + + const std::array hop1{routeOnly(one,two)}; + a=session.wireTransaction(2,2,hop1,physical,epoch,epoch,true); + assert(a.ok() && a.graphRevision==3); + assert(!findEdge(one,main,3) && findEdge(one,two,3)); + assert(render() && near(left[11],.3f*center)); + + const std::array hop2{routeOnly(two,three)}; + a=session.wireTransaction(3,3,hop2,physical,epoch,epoch,true); + assert(a.ok() && a.graphRevision==4); + const auto chainId=findEdge(one,two,4); + assert(chainId && !findEdge(two,main,4)); + assert(findEdge(three,main,4)==otherMain); + assert(render() && near(left[11],.3f*center)); + for(int i=0;i<64;++i) + if(i!=11)assert(near(left[i],0.f)); + + // A second real path doubles PCM only by explicit legal fan-out. + const std::array parallel{connect(one,main)}; + a=session.wireTransaction(4,4,parallel,physical,epoch,epoch,true); + assert(a.ok() && a.graphRevision==5); + const auto directId=findEdge(one,main,5); + assert(directId && directId!=originalMain); + assert(render() && near(left[11],2.f*.3f*center,1e-4f)); + const std::array unplug{remove(one,directId)}; + a=session.wireTransaction(5,5,unplug,physical,epoch,epoch,true); + assert(a.ok() && a.graphRevision==6); + assert(!findEdge(one,main,6) && findEdge(three,main,6)==otherMain); + assert(render() && near(left[11],.3f*center)); + + // Wrong edge identity cannot disconnect another source's MAIN. + const std::array wrongEdge{remove(one,otherMain)}; + auto rejected=session.wireTransaction(6,6,wrongEdge,physical,epoch,epoch,true); + assert(rejected.fault==DynamicAcceptedSession::Fault::editRejected); + assert(session.acceptedGraphRevision()==6); + assert(render() && near(left[11],.3f*center)); + const std::array duplicate{connect(one,two)}; + rejected=session.wireTransaction(6,6,duplicate,physical,epoch,epoch,true); + assert(rejected.fault==DynamicAcceptedSession::Fault::editRejected); + assert(session.acceptedGraphRevision()==6); + + // Mixed existing route cycle: whole native DAG compile must roll back. + const std::array feedback{connect(three,one)}; + rejected=session.wireTransaction(6,6,feedback,physical,epoch,epoch,true); + assert(rejected.fault==DynamicAcceptedSession::Fault::graphRejected); + assert(session.acceptedGraphRevision()==6); + assert(render() && near(left[11],.3f*center)); + rejected=session.wireTransaction(5,5,unplug,physical,epoch,epoch,true); + assert(rejected.fault==DynamicAcceptedSession::Fault::staleRoster); + assert(session.acceptedGraphRevision()==6); + rejected=session.wireTransaction(6,6,unplug,physical,epoch+1,epoch,true); + assert(rejected.fault==DynamicAcceptedSession::Fault::graphRejected); + assert(render() && near(left[11],.3f*center)); + + // RETARGET keeps identity and gain, not a new/ghost wire. + WireChange retarget; + retarget.kind=WireChange::Kind::retarget; + retarget.from=one;retarget.to=main;retarget.edgeId=chainId; + const std::array reroute{retarget}; + a=session.wireTransaction(6,6,reroute,physical,epoch,epoch,true); + assert(a.ok() && a.graphRevision==7); + assert(findEdge(one,main,7)==chainId && !findEdge(one,two,7)); + assert(render() && near(left[11],.3f*center)); + session.unpublish(); + session.pollRetirement(); +} + int main() { + verifyAtomicWireTransactionAndZeroSampleHops(); // WIRE-first regression: PRE and POST to the SAME destination are // NOT two valid edges. Reject before accepting duplicate dry PCM. From de5c4ac43bef0179c56910de90929f48bf568f54 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:24:30 +0700 Subject: [PATCH 05/15] feat(wire): apply canonical atomic WIRE to installed JUCE ChannelId PCM graph --- src/LiveDryRoutingLab.h | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 5eb0ad4ad..f20bf5874 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -1528,6 +1528,72 @@ class LiveDryRoutingLab final { } } + + // Real installed ChannelId PCM transaction. No alternate router: compile + // the accepted roster's SAME send inventory, lease the SAME native VST3 + // processors and publish once to the JUCE callback's existing publisher. + // M4 cannot represent arbitrary WIRE afterwards; never downgrade it. + NativeBusResult applyNativeWireTransaction( + std::uint64_t ep,std::uint64_t expectedPcmRev, + std::uint64_t expectedRosterRev, + std::span changes, + bool outputsDisarmed=false) { + using namespace armix::mixer; + NativeBusResult r{}; + r.pcmRevision=nativeAccepted_.pcmRevision; + r.rosterRevision=nativeAccepted_.graph.roster.revision(); + if(!outputsDisarmed){r.error="OUTPUT_MUST_BE_DISARMED";return r;} + if(!channelIdPhysicalPcmActive()||!ready()|| + ep!=epoch()||nativeAccepted_.deviceEpoch!=ep|| + !nativeAccepted_.fxOwners|| + expectedPcmRev!=nativeAccepted_.pcmRevision|| + expectedRosterRev!=nativeAccepted_.graph.roster.revision()) { + r.error="STALE_NATIVE_WIRE_GRAPH";return r; + } + if(changes.empty()||changes.size()>256){ + r.error="INVALID_NATIVE_WIRE_BATCH";return r; + } + try { + auto roster=nativeAccepted_.graph.roster; + const auto changed=roster.wireTransaction(expectedRosterRev,changes); + if(!changed.ok()){ + r.error="NATIVE_WIRE_TRANSACTION_REJECTED";return r; + } + DynamicChannelFxLeaseBank bank; + if(DynamicChannelFxLeaseBank::reuseRevision( + ep,expectedPcmRev+1,*nativeAccepted_.fxOwners,bank)!= + DynamicChannelFxLeaseBank::Fault::none){ + r.error="NATIVE_WIRE_FX_LEASE_REJECTED";return r; + } + auto owner=std::make_shared(std::move(bank)); + DynamicNativeSessionPublisher::FxPlan fx; + fx.owner=std::static_pointer_cast(owner); + fx.context=owner.get(); + fx.render=+[](void* ctx,ChannelId id,float* l,float* rr,int n) noexcept { + (*static_cast(ctx))(id,l,rr,n); + }; + fx.deviceEpoch=ep; + fx.graphRevision=expectedPcmRev+1; + const auto published=nativePublisher_.commit( + roster,nativeAccepted_.graph.request,expectedPcmRev, + ep,epoch(),true,std::move(fx)); + if(!published.ok()){ + r.error="NATIVE_WIRE_PCM_GRAPH_REJECTED";return r; + } + nativeAccepted_.graph.roster=std::move(roster); + nativeAccepted_.fxOwners=std::move(owner); + nativeAccepted_.pcmRevision=published.revision; + nativeStructureLive_=true; // never fall back to incompatible M4 + nativeMeterEpoch_.store(0,std::memory_order_release); + r.accepted=true;r.error=""; + r.pcmRevision=published.revision; + r.rosterRevision=nativeAccepted_.graph.roster.revision(); + return r; + }catch(...){ + r.error="NATIVE_WIRE_PREPARE_FAILED";return r; + } + } + // Live dynamic-input controls: one canonical ChannelId PCM callback, // no M4 ordinal alias, vendor reload or RT thread allocation. bool setNativeInputMix(std::uint64_t epochValue,std::uint64_t revision, @@ -1695,6 +1761,22 @@ class LiveDryRoutingLab final { rows.add(juce::var(row.release())); } state->setProperty("channels",juce::var(rows)); + juce::Array edges; + for(const auto& accepted:routing->edges) { + auto edge=std::make_unique(); + edge->setProperty("edgeId",juce::String( + std::to_string(accepted.edgeId))); + edge->setProperty("from",juce::String( + std::to_string(accepted.from.value))); + edge->setProperty("to",juce::String( + std::to_string(accepted.to.value))); + edge->setProperty("gainLinear", + static_cast(accepted.gainLinear)); + edge->setProperty("tap",accepted.preFader?"PRE_FADER":"POST_FADER"); + edge->setProperty("primaryOutput",accepted.primaryOutput); + edges.add(juce::var(edge.release())); + } + state->setProperty("edges",juce::var(edges)); return juce::var(state.release()); } From ca0fa075b92c8bd979daf9e112abc0c41f888014 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:25:16 +0700 Subject: [PATCH 06/15] feat(wire): route JUCE native intent into real ChannelId PCM publication --- src/LiveAudioEngine.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index f3cfc002a..4d90376ca 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -1387,6 +1387,24 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback return dryRoutingLab_.setNativePrimaryOutput( ep,pcmRev,rosterRev,src,dst,true); } + // JUCE control-thread gateway to the already installed ChannelId renderer. + // No callback detach or alternate route ownership. Preserve device, + // original vendor VST3 leases and physical output-arm safety gates. + LiveDryRoutingLab::NativeBusResult applyNativeWireTransaction( + std::uint64_t ep,std::uint64_t pcmRev,std::uint64_t rosterRev, + std::span changes) { + LiveDryRoutingLab::NativeBusResult fail; + fail.error="HARDWARE_NOT_DISARMED"; + if(independent_.active()||!attached_||!directFence_.permitted()|| + routeReconfiguring_.load(std::memory_order_acquire)|| + diagnosticRoute_.load(std::memory_order_acquire)!= + armix::diagnostics::Route::normal|| + !allOutputsDisarmed()||handoff_.busy()|| + fxMovePhase_.load(std::memory_order_acquire)!=0) + return fail; + return dryRoutingLab_.applyNativeWireTransaction( + ep,pcmRev,rosterRev,changes,true); + } bool setNativeInputMix(std::uint64_t epoch,std::uint64_t rev, armix::mixer::ChannelId id,float gain,float pan) noexcept { if(independent_.active()||!directFence_.permitted()|| From 5bc08077553cf5fdc2bb760f1d728a1b13c24f24 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:25:52 +0700 Subject: [PATCH 07/15] feat(wire): strict native WebView WIRE batch decoding and epoch-fenced ACK --- src/ConsoleLiveBridgeV6.h | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/ConsoleLiveBridgeV6.h b/src/ConsoleLiveBridgeV6.h index 3b5d8daa3..cd3ca4fcd 100644 --- a/src/ConsoleLiveBridgeV6.h +++ b/src/ConsoleLiveBridgeV6.h @@ -696,6 +696,71 @@ class LiveConsoleBridgeV6 final { rosterRev=response.rosterRevision;} } } + else if(operation=="NATIVE_APPLY_WIRE_TRANSACTION") { + using namespace armix::mixer; + const auto raw=payload.getProperty("changes",juce::var()); + const auto* list=raw.getArray(); + if(!list || list->isEmpty() || list->size()>256) + error="INVALID_NATIVE_WIRE_BATCH"; + else { + std::vector changes; + changes.reserve(static_cast(list->size())); + for(const auto& item:*list) { + if(!item.isObject()) { + error="INVALID_NATIVE_WIRE_CHANGE";break; + } + WireChange change; + const auto action=item.getProperty("op","").toString(); + if(action=="CONNECT")change.kind=WireChange::Kind::connect; + else if(action=="REMOVE")change.kind=WireChange::Kind::remove; + else if(action=="RETARGET")change.kind=WireChange::Kind::retarget; + else if(action=="ROUTE_ONLY")change.kind=WireChange::Kind::routeOnly; + else {error="INVALID_NATIVE_WIRE_ACTION";break;} + std::uint64_t source=0,dest=0,edge=0; + if(!decodeDecimal(item.getProperty("from",{}),source) || + source==0) { + error="INVALID_NATIVE_WIRE_SOURCE";break; + } + change.from={source}; + if(change.kind!=WireChange::Kind::remove) { + if(!decodeDecimal(item.getProperty("to",{}),dest) || + dest==0) { + error="INVALID_NATIVE_WIRE_DESTINATION";break; + } + change.to={dest}; + } + if(change.kind==WireChange::Kind::remove || + change.kind==WireChange::Kind::retarget) { + if(!decodeDecimal(item.getProperty("edgeId",{}),edge)|| + edge==0) { + error="INVALID_NATIVE_WIRE_EDGE_ID";break; + } + change.edgeId=edge; + } else { + const auto tap=item.getProperty("tap","POST_FADER").toString(); + const auto gain=item.getProperty("gainLinear",juce::var(1.)); + if(tap!="POST_FADER" || + !(gain.isDouble()||gain.isInt()) || + !std::isfinite(static_cast(gain)) || + static_cast(gain)<0. || + static_cast(gain)>4.) { + error="INVALID_NATIVE_WIRE_GAIN_OR_TAP";break; + } + change.gain=static_cast(static_cast(gain)); + } + changes.push_back(change); + } + if(error.isEmpty()) { + const auto response=engine.applyNativeWireTransaction( + requestedEpoch,nativeRev,rosterRev, + std::span(changes)); + applied=response.accepted; + if(!applied)error=response.error; + else {nativeRev=response.pcmRevision; + rosterRev=response.rosterRevision;} + } + } + } else if(operation=="NATIVE_SET_BUS_MIX") { std::uint64_t target=0; const auto rawGain=payload.getProperty("gain",juce::var()); From baeddf05853168a03810c1bcafec70fa58df7f8f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:26:13 +0700 Subject: [PATCH 08/15] feat(wire): advertise only installed scoped native WIRE transaction --- src/LiveDryRoutingLab.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index f20bf5874..8f4ae0825 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -1666,6 +1666,7 @@ class LiveDryRoutingLab final { "NATIVE_REMOVE_BUS","NATIVE_SET_BUS_MIX", "NATIVE_CREATE_CHANNEL","NATIVE_PATCH_CHANNEL", "NATIVE_SET_PRIMARY_OUT", + "NATIVE_APPLY_WIRE_TRANSACTION", "NATIVE_SET_CHANNEL_MIX", "NATIVE_SET_CHANNEL_MUTE_SOLO", "NATIVE_LOAD_INSERT","NATIVE_SET_INSERT_BYPASS", From 6ee19f7515ddaef45a1cacd5f272899decec301a Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:26:42 +0700 Subject: [PATCH 09/15] test(wire): native WebView batch ACK exact edge IDs and malformed intent rollback --- tests/live_channel_fx_graph_test.cpp | 61 +++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/live_channel_fx_graph_test.cpp b/tests/live_channel_fx_graph_test.cpp index c0483d09b..91f97c602 100644 --- a/tests/live_channel_fx_graph_test.cpp +++ b/tests/live_channel_fx_graph_test.cpp @@ -957,7 +957,7 @@ static void verifyNativeConsoleWireRejectsUnsupportedM4AndPreservesEpoch() { int liveMixes=0; int nativeInputCreates=0,nativeInputPatches=0; int nativeInputMixes=0,nativeInputToggles=0; - int nativeWireRoutes=0; + int nativeWireRoutes=0,nativeWireBatches=0; Report createNativeInputChannel(std::uint64_t ep,std::uint64_t pcm, std::uint64_t roster,const std::string& name, ProcessingFormat format){ @@ -997,6 +997,19 @@ static void verifyNativeConsoleWireRejectsUnsupportedM4AndPreservesEpoch() { assert(src.value==20&&dst.value==18); ++nativeWireRoutes;return {true,{},4,5,""}; } + Report applyNativeWireTransaction(std::uint64_t ep, + std::uint64_t pcm,std::uint64_t roster, + std::span changes) { + assert(ep==9007199254740993ULL&&pcm==3&&roster==4); + assert(changes.size()==2); + assert(changes[0].kind==WireChange::Kind::remove); + assert(changes[0].from.value==20&&changes[0].edgeId==77); + assert(changes[1].kind==WireChange::Kind::connect); + assert(changes[1].from.value==20&&changes[1].to.value==18); + assert(near(changes[1].gain,.5f)); + ++nativeWireBatches; + return {true,{},4,5,""}; + } Report editNativeBus(std::uint64_t ep,std::uint64_t pcm, std::uint64_t roster,ChannelRole role, std::span selected, @@ -1109,6 +1122,52 @@ static void verifyNativeConsoleWireRejectsUnsupportedM4AndPreservesEpoch() { const auto wireAck=routeBusIntent(wireIntent); assert(wireAck.getProperty("status","").toString()=="ACCEPTED"); assert(busControl.nativeWireRoutes==1); + // Same existing native bridge -> exact batch -> post-publication ACK. + // Legacy M4 revision remains separate; no false universal LIVE claim. + auto batch=makeBusIntent("native:wire:batch:1"); + batch.getDynamicObject()->setProperty( + "operation","NATIVE_APPLY_WIRE_TRANSACTION"); + juce::Array changes; + auto unplug=std::make_unique(); + unplug->setProperty("op","REMOVE"); + unplug->setProperty("from","20"); + unplug->setProperty("edgeId","77"); + changes.add(juce::var(unplug.release())); + auto connect=std::make_unique(); + connect->setProperty("op","CONNECT"); + connect->setProperty("from","20"); + connect->setProperty("to","18"); + connect->setProperty("tap","POST_FADER"); + connect->setProperty("gainLinear",.5); + changes.add(juce::var(connect.release())); + auto transaction=std::make_unique(); + transaction->setProperty("changes",juce::var(changes)); + batch.getDynamicObject()->setProperty( + "payload",juce::var(transaction.release())); + auto batchAck=routeBusIntent(batch); + assert(batchAck.getProperty("status","").toString()=="ACCEPTED"); + assert(batchAck.getProperty("nativeGraphRevision","").toString()=="4"); + assert(batchAck.getProperty("nativeRosterRevision","").toString()=="5"); + assert(busControl.nativeWireBatches==1); + batchAck=routeBusIntent(batch); + assert(batchAck.getProperty("errorCode","").toString()=="DUPLICATE_REQUEST_ID"); + assert(busControl.nativeWireBatches==1); + auto invalidBatch=makeBusIntent("native:wire:bad:2"); + invalidBatch.getDynamicObject()->setProperty( + "operation","NATIVE_APPLY_WIRE_TRANSACTION"); + auto malformed=std::make_unique(); + juce::Array badChanges; + auto bad=std::make_unique(); + bad->setProperty("op","REMOVE");bad->setProperty("from","020"); + bad->setProperty("edgeId","77"); + badChanges.add(juce::var(bad.release())); + malformed->setProperty("changes",juce::var(badChanges)); + invalidBatch.getDynamicObject()->setProperty( + "payload",juce::var(malformed.release())); + batchAck=routeBusIntent(invalidBatch); + assert(batchAck.getProperty("status","").toString()=="REJECTED"); + assert(batchAck.getProperty("errorCode","").toString()=="INVALID_NATIVE_WIRE_SOURCE"); + assert(busControl.nativeWireBatches==1); auto liveMixIntent=makeBusIntent("native:mix:1"); liveMixIntent.getDynamicObject()->setProperty( "operation","NATIVE_SET_BUS_MIX"); From d31f7c7c14e5e236e7f847e7ee9fd19dd900cb76 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:29:36 +0700 Subject: [PATCH 10/15] feat(wire): one-transaction default MAIN edge for new native channels --- engine/core/DynamicChannelRoster.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/engine/core/DynamicChannelRoster.h b/engine/core/DynamicChannelRoster.h index 4c3e7331e..e3e669441 100644 --- a/engine/core/DynamicChannelRoster.h +++ b/engine/core/DynamicChannelRoster.h @@ -69,6 +69,7 @@ struct ChannelEdit final { bool enabled=false; // mute/solo value (or future enable operation) bool preFader=false; // send tap at construction, no hidden POST default bool primaryOutput=false; // exclusive OUT edge, independent of parallel SEND + bool connectMainOnCreate=false; // WIRE-first native creation; legacy imports unchanged float sendPan=0.f; // independent send PAN, never channel fader PAN std::string text; }; @@ -147,6 +148,7 @@ class DynamicChannelRoster final { } auto candidate=channels_; // one copy per BATCH, never in audio callback auto next=nextId_; + std::vector defaultMainOnCreate; const auto seek=[&candidate](ChannelId id){ return std::find_if(candidate.begin(),candidate.end(), [id](const auto& c){return c.id==id;}); @@ -179,6 +181,10 @@ class DynamicChannelRoster final { if(!validName(row.name)) {result.fault=ChannelEditFault::invalidValue;break;} candidate.insert(candidate.begin()+static_cast(op.position),std::move(row)); result.createdIds.push_back(candidate[op.position].id); + if(op.connectMainOnCreate && + candidate[op.position].role!=ChannelRole::main && + candidate[op.position].role!=ChannelRole::monitor) + defaultMainOnCreate.push_back(candidate[op.position].id); } else { auto it=seek(op.id); if(op.id.value==0 || it==candidate.end()) { @@ -282,6 +288,30 @@ class DynamicChannelRoster final { result.fault=ChannelEditFault::budgetExceeded;break; } } + // WIRE-first channel creation must connect MAIN exactly ONCE in the + // SAME batch/revision, even when MAIN was created later in this batch. + // Existing restored/disconnected channels are never auto-rewired. + if(result.ok() && !defaultMainOnCreate.empty()) { + const auto main=std::find_if(candidate.begin(),candidate.end(), + [](const auto& row){return row.role==ChannelRole::main;}); + if(main==candidate.end() || + std::count_if(candidate.begin(),candidate.end(), + [](const auto& row){return row.role==ChannelRole::main;})!=1) { + result.fault=ChannelEditFault::invalidValue; + } else { + const auto mainId=main->id; + for(const auto id:defaultMainOnCreate){ + auto row=seek(id); + if(row==candidate.end() || + row->sends.size()>=budget_.maximumSendsPerChannel){ + result.fault=ChannelEditFault::budgetExceeded;break; + } + const bool exists=std::any_of(row->sends.begin(),row->sends.end(), + [&](const auto& send){return send.destination==mainId;}); + if(!exists)row->sends.push_back({mainId,1.f,false,0.f,true,0}); + } + } + } if(result.ok() && !withinBudget(candidate))result.fault=ChannelEditFault::budgetExceeded; if(!result.ok()) {result.createdIds.clear();return result;} // Structural edits are infrequent and prepared entirely on CONTROL. From 7ec8c7763ab5bb9d7399241a38da7b3994a57d59 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:30:04 +0700 Subject: [PATCH 11/15] fix(wire): atomically create native input and MAIN edge in one accepted roster revision --- src/LiveDryRoutingLab.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 8f4ae0825..255b2f6d5 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -1331,23 +1331,17 @@ class LiveDryRoutingLab final { if(main==existing.end()) { reply.error="NATIVE_MAIN_NOT_FOUND";return reply; } - const ChannelId mainId=main->id; armix::mixer::ChannelEdit add; add.kind=armix::mixer::ChannelEdit::Kind::add;add.role=ChannelRole::input; add.format=format;add.text=name; + add.connectMainOnCreate=true; // exact one real POST_FADER MAIN edge add.position=static_cast(main-existing.begin()); + // One accepted roster revision and ONE prepared PCM publication, + // not create + second independent OUT routing mutation. auto created=roster.edit(expectedRosterRevision, std::span(&add,1)); if(!created.ok()||created.createdIds.size()!=1) { - reply.error="CHANNEL_ROSTER_ADMISSION_REJECTED";return reply; - } - armix::mixer::ChannelEdit primary; - primary.kind=armix::mixer::ChannelEdit::Kind::setPrimaryOutput; - primary.id=created.createdIds.front();primary.target=mainId; - const auto connected=roster.edit(roster.revision(), - std::span(&primary,1)); - if(!connected.ok()) { - reply.error="CHANNEL_MAIN_ROUTING_REJECTED";return reply; + reply.error="CHANNEL_MAIN_ADMISSION_REJECTED";return reply; } DynamicChannelFxLeaseBank bank; if(DynamicChannelFxLeaseBank::reuseRevision( From b8ebf198310cfe6b38e09180f3fe0405a66166ed Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:30:31 +0700 Subject: [PATCH 12/15] test(wire): default MAIN edge created exactly once, saved disconnected channel remains disconnected --- tests/dynamic_accepted_session_test.cpp | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/dynamic_accepted_session_test.cpp b/tests/dynamic_accepted_session_test.cpp index 15dd5fa7d..2899da1c5 100644 --- a/tests/dynamic_accepted_session_test.cpp +++ b/tests/dynamic_accepted_session_test.cpp @@ -329,7 +329,50 @@ static void verifyAtomicWireTransactionAndZeroSampleHops() { session.pollRetirement(); } + +// New native channel = exactly one CH->MAIN edge in ONE accepted revision, +// even when MAIN appears later in the same initial transaction. Restoring +// an intentionally disconnected older channel never auto-repairs its route. +static void verifyDefaultNativeMainEdgeAndDisconnectedRestore() { + constexpr std::uint64_t epoch=9910; + DynamicAcceptedSession session; + DynamicGraphRequest physical; + physical.maxFrames=64; + auto source=add(0,ChannelRole::input,"NEW WIRE"); + source.connectMainOnCreate=true; + const auto main=add(1,ChannelRole::main,"MAIN",ProcessingFormat::stereo); + const std::array first{source,main}; + auto a=session.edit(0,0,first,physical,epoch,epoch,true); + assert(a.ok() && a.edit.createdIds.size()==2); + const auto ch=a.edit.createdIds[0],master=a.edit.createdIds[1]; + const auto* routing=session.acceptedRouting(epoch,1); + assert(routing && routing->edges.size()==1); + const auto id=routing->edges.front().edgeId; + assert(id && routing->edges.front().from==ch && + routing->edges.front().to==master && + routing->edges.front().primaryOutput && + routing->edges.front().gainLinear==1.f); + WireChange unplug;unplug.kind=WireChange::Kind::remove; + unplug.from=ch;unplug.edgeId=id; + const std::array batch{unplug}; + a=session.wireTransaction(1,1,batch,physical,epoch,epoch,true); + assert(a.ok() && a.graphRevision==2); + assert(session.acceptedRouting(epoch,2)->edges.empty()); + auto newer=add(1,ChannelRole::input,"NEWER WIRE"); + newer.connectMainOnCreate=true; + const std::array append{newer}; + a=session.edit(2,2,append,physical,epoch,epoch,true); + assert(a.ok() && a.edit.createdIds.size()==1); + routing=session.acceptedRouting(epoch,3); + assert(routing && routing->edges.size()==1); + assert(routing->edges.front().from==a.edit.createdIds.front()); + assert(routing->edges.front().to==master); + assert(routing->edges.front().edgeId!=id); + session.unpublish();session.pollRetirement(); +} + int main() { + verifyDefaultNativeMainEdgeAndDisconnectedRestore(); verifyAtomicWireTransactionAndZeroSampleHops(); // WIRE-first regression: PRE and POST to the SAME destination are From af2823b5ad0a355658f432c5253f57b5da486e47 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 14:45:50 +0700 Subject: [PATCH 13/15] test(wire): expose exact native feedback rejection fault without weakening gate --- tests/dynamic_accepted_session_test.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/dynamic_accepted_session_test.cpp b/tests/dynamic_accepted_session_test.cpp index 2899da1c5..fe04e2bc2 100644 --- a/tests/dynamic_accepted_session_test.cpp +++ b/tests/dynamic_accepted_session_test.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include using namespace armix::mixer; @@ -306,6 +307,13 @@ static void verifyAtomicWireTransactionAndZeroSampleHops() { // Mixed existing route cycle: whole native DAG compile must roll back. const std::array feedback{connect(three,one)}; rejected=session.wireTransaction(6,6,feedback,physical,epoch,epoch,true); + if(rejected.fault!=DynamicAcceptedSession::Fault::graphRejected) + std::fprintf(stderr,"WIRE feedback rejection diagnostic: acceptedFault=%u rosterFault=%u nativeFault=%u graphFault=%u revision=%llu\\n", + static_cast(rejected.fault), + static_cast(rejected.edit.fault), + static_cast(rejected.native.fault), + static_cast(rejected.native.graphError.fault), + static_cast(rejected.graphRevision)); assert(rejected.fault==DynamicAcceptedSession::Fault::graphRejected); assert(session.acceptedGraphRevision()==6); assert(render() && near(left[11],.3f*center)); From 4eeac29f262bab4ffb4280ca2fc8e34c1ad09ba6 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 15:57:10 +0700 Subject: [PATCH 14/15] fix(wire): reject stale device before edits, preserve MAIN edge ID and rollback safety --- engine/core/DynamicAcceptedSession.h | 14 +++++- engine/core/DynamicChannelRoster.h | 15 +++++-- tests/dynamic_accepted_session_test.cpp | 59 +++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-) diff --git a/engine/core/DynamicAcceptedSession.h b/engine/core/DynamicAcceptedSession.h index d7660b7a5..61cca950f 100644 --- a/engine/core/DynamicAcceptedSession.h +++ b/engine/core/DynamicAcceptedSession.h @@ -79,6 +79,15 @@ class DynamicAcceptedSession final { DynamicNativeSessionPublisher::FxPlan fx={}) { Result result=preflight(expectedRosterRevision,expectedGraphRevision); if(!result.ok())return result; + // Validate the hardware generation BEFORE inspecting draft edge IDs. + // A stale request may reference an edge removed by a newer device + // epoch; return the stronger device fault without touching the graph. + if(!expectedDeviceEpoch || expectedDeviceEpoch!=activeDeviceEpoch) { + result.fault=Fault::graphRejected; + result.native.fault=DynamicNativeSessionPublisher::Fault::staleDevice; + result.native.revision=publisher_.acceptedRevision(); + return result; + } auto candidate=accepted_; result.edit=candidate.wireTransaction(expectedRosterRevision,changes); if(!result.edit.ok()) { @@ -260,6 +269,7 @@ class DynamicAcceptedSession final { result.native.fault=DynamicNativeSessionPublisher::Fault::invalidCandidate; result.native.revision=publisher_.acceptedRevision(); result.edit.createdIds.clear(); + result.edit.createdEdgeIds.clear(); return result; } // A structural OUT/GROUP/Return edit does NOT implicitly change IN. @@ -284,6 +294,7 @@ class DynamicAcceptedSession final { result.native.graphError={DynamicGraphFault::invalidSource,source.id}; result.native.revision=publisher_.acceptedRevision(); result.edit.createdIds.clear(); + result.edit.createdEdgeIds.clear(); return result; // old audible SOURCE and VST3 leases unchanged } } @@ -294,7 +305,8 @@ class DynamicAcceptedSession final { std::move(fx)); if(!result.native.ok()) { result.fault=Fault::graphRejected; - result.edit.createdIds.clear(); // NEVER advertise phantom Bus + result.edit.createdIds.clear(); + result.edit.createdEdgeIds.clear(); // NEVER advertise phantom Bus return result; // candidate destroyed; accepted state intact } static_assert(std::is_nothrow_move_assignable_v); diff --git a/engine/core/DynamicChannelRoster.h b/engine/core/DynamicChannelRoster.h index e3e669441..3b435432d 100644 --- a/engine/core/DynamicChannelRoster.h +++ b/engine/core/DynamicChannelRoster.h @@ -268,9 +268,18 @@ class DynamicChannelRoster final { result.fault=ChannelEditFault::invalidValue;break; } auto& edges=it->sends; - edges.erase(std::remove_if(edges.begin(),edges.end(), - [](const auto& x){return x.primaryOutput;}),edges.end()); - if(op.target.value) { + const auto primary=std::find_if(edges.begin(),edges.end(), + [](const auto& edge){return edge.primaryOutput;}); + if(!op.target.value) { + if(primary!=edges.end())edges.erase(primary); + } else if(primary!=edges.end()) { + // Retarget the EXACT original physical cable; preserve + // stable edgeId instead of removing/recreating it. + primary->destination=op.target; + primary->gain=1.f; + primary->preFader=false; + primary->pan=0.f; + } else { if(edges.size()>=budget_.maximumSendsPerChannel) { result.fault=ChannelEditFault::budgetExceeded;break; } diff --git a/tests/dynamic_accepted_session_test.cpp b/tests/dynamic_accepted_session_test.cpp index fe04e2bc2..d7abee868 100644 --- a/tests/dynamic_accepted_session_test.cpp +++ b/tests/dynamic_accepted_session_test.cpp @@ -315,6 +315,7 @@ static void verifyAtomicWireTransactionAndZeroSampleHops() { static_cast(rejected.native.graphError.fault), static_cast(rejected.graphRevision)); assert(rejected.fault==DynamicAcceptedSession::Fault::graphRejected); + assert(rejected.edit.createdEdgeIds.empty()); // no phantom rejected ID assert(session.acceptedGraphRevision()==6); assert(render() && near(left[11],.3f*center)); rejected=session.wireTransaction(5,5,unplug,physical,epoch,epoch,true); @@ -322,6 +323,15 @@ static void verifyAtomicWireTransactionAndZeroSampleHops() { assert(session.acceptedGraphRevision()==6); rejected=session.wireTransaction(6,6,unplug,physical,epoch+1,epoch,true); assert(rejected.fault==DynamicAcceptedSession::Fault::graphRejected); + assert(rejected.native.fault==DynamicNativeSessionPublisher::Fault::staleDevice); + assert(rejected.edit.createdEdgeIds.empty()); + // A genuinely valid edge must also reject the wrong epoch before + // publication, irrespective of the edit's own validity. + const std::array validButStale{connect(one,main)}; + rejected=session.wireTransaction(6,6,validButStale,physical,epoch+1,epoch,true); + assert(rejected.fault==DynamicAcceptedSession::Fault::graphRejected); + assert(rejected.native.fault==DynamicNativeSessionPublisher::Fault::staleDevice); + assert(session.acceptedGraphRevision()==6); assert(render() && near(left[11],.3f*center)); // RETARGET keeps identity and gain, not a new/ghost wire. @@ -379,7 +389,56 @@ static void verifyDefaultNativeMainEdgeAndDisconnectedRestore() { session.unpublish();session.pollRetirement(); } +static void verifyPrimaryOutKeepsCanonicalEdgeIdentity() { + constexpr std::uint64_t epoch=9931; + DynamicAcceptedSession session; + DynamicGraphRequest physical; + physical.physicalInputs=1;physical.maxFrames=64; + const std::array first{ + add(0,ChannelRole::input,"SOURCE"), + add(1,ChannelRole::input,"INTERMEDIATE",ProcessingFormat::stereo), + add(2,ChannelRole::main,"MAIN",ProcessingFormat::stereo) + }; + auto a=session.edit(0,0,first,physical,epoch,epoch,true); + assert(a.ok()); + const auto src=a.edit.createdIds[0],via=a.edit.createdIds[1]; + const auto main=a.edit.createdIds[2]; + const std::array initial{output(src,main),output(via,main)}; + physical.sources={{src,0,-1,false}}; + a=session.edit(1,1,initial,physical,epoch,epoch,true); + assert(a.ok()); + const auto* accepted=session.acceptedRouting(epoch,2); + assert(accepted&&accepted->edges.size()==2); + const auto edgeId=accepted->edges[0].edgeId; + const auto viaId=accepted->edges[1].edgeId; + assert(edgeId!=0&&viaId!=0&&edgeId!=viaId); + std::array impulse{},left{},right{}; + impulse[19]=.25f; + const float* pins[]{impulse.data()}; + const auto noFx=+[](ChannelId,float*,float*,int) noexcept {}; + const auto render=[&] { + return session.render(epoch,pins,1,left.data(),right.data(),64,false,noFx); + }; + assert(render() && near(left[19],.25f*.7071067811865475f)); + const std::array same{output(src,main)}; + a=session.edit(2,2,same,physical,epoch,epoch,true); + assert(a.ok()); + assert(session.acceptedRouting(epoch,3)->edges[0].edgeId==edgeId); + assert(render() && near(left[19],.25f*.7071067811865475f)); + const std::array retarget{output(src,via)}; + a=session.edit(3,3,retarget,physical,epoch,epoch,true); + assert(a.ok()); + accepted=session.acceptedRouting(epoch,4); + assert(accepted->edges[0].edgeId==edgeId); + assert(accepted->edges[0].to==via); + assert(accepted->edges[1].edgeId==viaId); + assert(render() && near(left[19],.25f*.7071067811865475f)); + session.unpublish(); + session.pollRetirement(); +} + int main() { + verifyPrimaryOutKeepsCanonicalEdgeIdentity(); verifyDefaultNativeMainEdgeAndDisconnectedRestore(); verifyAtomicWireTransactionAndZeroSampleHops(); From de347b32123ee3523f2bc7d743631b752e1ce305 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 4 Nov 2026 16:00:58 +0700 Subject: [PATCH 15/15] feat(wire): publish verified internal routing while output armed without device reconfigure --- engine/core/DynamicAcceptedSession.h | 29 ++++++++++++++++++--- engine/core/DynamicNativeSessionPublisher.h | 6 +++-- src/LiveAudioEngine.h | 6 ++--- src/LiveDryRoutingLab.h | 8 +++--- tests/dynamic_accepted_session_test.cpp | 14 +++++++++- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/engine/core/DynamicAcceptedSession.h b/engine/core/DynamicAcceptedSession.h index 61cca950f..ec901f2d3 100644 --- a/engine/core/DynamicAcceptedSession.h +++ b/engine/core/DynamicAcceptedSession.h @@ -93,9 +93,31 @@ class DynamicAcceptedSession final { if(!result.edit.ok()) { result.fault=Fault::editRejected;return result; } + // Never trust an armed GUI candidate that quietly changes capture + // pins, DSP block capacity or device admission. Only pure internal + // edges can be published while hardware output is armed. + const bool samePhysical= + route.physicalInputs==acceptedRequest_.physicalInputs && + route.maxFrames==acceptedRequest_.maxFrames && + route.maxScratchBytes==acceptedRequest_.maxScratchBytes && + route.mainMonoAfterFx==acceptedRequest_.mainMonoAfterFx && + route.sources.size()==acceptedRequest_.sources.size() && + std::equal(route.sources.begin(),route.sources.end(), + acceptedRequest_.sources.begin(), + [](const DynamicSourcePatch& lhs,const DynamicSourcePatch& rhs) { + return lhs.id==rhs.id && lhs.inputL==rhs.inputL && + lhs.inputR==rhs.inputR && lhs.stereo==rhs.stereo; + }); + if(!allOutputsDisarmed && !samePhysical) { + result.fault=Fault::graphRejected; + result.native.fault=DynamicNativeSessionPublisher::Fault::outputArmed; + result.native.revision=publisher_.acceptedRevision(); + result.edit.createdEdgeIds.clear(); + return result; + } return publish(std::move(candidate),route,expectedGraphRevision, expectedDeviceEpoch,activeDeviceEpoch,allOutputsDisarmed, - std::move(result),std::move(fx)); + std::move(result),std::move(fx),samePhysical); } // Studio Pro: one independent Bus ChannelId and automatic assignment of @@ -254,7 +276,8 @@ class DynamicAcceptedSession final { std::uint64_t previousGraphRevision, std::uint64_t requestedEpoch,std::uint64_t currentEpoch, bool outputsDisarmed,Result&& result, - DynamicNativeSessionPublisher::FxPlan fx) { + DynamicNativeSessionPublisher::FxPlan fx, + bool verifiedInternalWireOnly=false) { // Existing SOURCE targets belong to the accepted native session. // For already-patched ChannelIds with the same input format, ignore // stale physical pin ordinals supplied by an old GUI draft during @@ -302,7 +325,7 @@ class DynamicAcceptedSession final { const bool nextHasFx=static_cast(fx.owner); result.native=publisher_.commit(candidate,effective,previousGraphRevision, requestedEpoch,currentEpoch,outputsDisarmed, - std::move(fx)); + std::move(fx),verifiedInternalWireOnly); if(!result.native.ok()) { result.fault=Fault::graphRejected; result.edit.createdIds.clear(); diff --git a/engine/core/DynamicNativeSessionPublisher.h b/engine/core/DynamicNativeSessionPublisher.h index 0574f9753..c767600af 100644 --- a/engine/core/DynamicNativeSessionPublisher.h +++ b/engine/core/DynamicNativeSessionPublisher.h @@ -68,7 +68,7 @@ class DynamicNativeSessionPublisher final { std::uint64_t proposedDeviceEpoch, std::uint64_t activeDeviceEpoch, bool allOutputsDisarmed, - FxPlan fx={}) { + FxPlan fx={},bool verifiedInternalWireOnly=false) { CommitResult report;report.revision=publisher_.lastRevision(); if(!fx.valid() || (fx.owner && (fx.deviceEpoch!=proposedDeviceEpoch || @@ -83,7 +83,9 @@ class DynamicNativeSessionPublisher final { expectedRevision==std::numeric_limits::max()) { report.fault=Fault::staleRevision;return report; } - if(!allOutputsDisarmed) { + // Only the canonical native WIRE owner may attest unchanged + // physical patch / device epoch. Other structural edits disarm. + if(!allOutputsDisarmed && !verifiedInternalWireOnly) { report.fault=Fault::outputArmed;return report; } auto next=std::make_unique(); diff --git a/src/LiveAudioEngine.h b/src/LiveAudioEngine.h index 4d90376ca..20bc4039e 100644 --- a/src/LiveAudioEngine.h +++ b/src/LiveAudioEngine.h @@ -1394,16 +1394,16 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback std::uint64_t ep,std::uint64_t pcmRev,std::uint64_t rosterRev, std::span changes) { LiveDryRoutingLab::NativeBusResult fail; - fail.error="HARDWARE_NOT_DISARMED"; + fail.error="NATIVE_WIRE_DEVICE_NOT_READY"; if(independent_.active()||!attached_||!directFence_.permitted()|| routeReconfiguring_.load(std::memory_order_acquire)|| diagnosticRoute_.load(std::memory_order_acquire)!= armix::diagnostics::Route::normal|| - !allOutputsDisarmed()||handoff_.busy()|| + handoff_.busy()|| fxMovePhase_.load(std::memory_order_acquire)!=0) return fail; return dryRoutingLab_.applyNativeWireTransaction( - ep,pcmRev,rosterRev,changes,true); + ep,pcmRev,rosterRev,changes); } bool setNativeInputMix(std::uint64_t epoch,std::uint64_t rev, armix::mixer::ChannelId id,float gain,float pan) noexcept { diff --git a/src/LiveDryRoutingLab.h b/src/LiveDryRoutingLab.h index 255b2f6d5..a2b18e1ed 100644 --- a/src/LiveDryRoutingLab.h +++ b/src/LiveDryRoutingLab.h @@ -1530,13 +1530,13 @@ class LiveDryRoutingLab final { NativeBusResult applyNativeWireTransaction( std::uint64_t ep,std::uint64_t expectedPcmRev, std::uint64_t expectedRosterRev, - std::span changes, - bool outputsDisarmed=false) { + std::span changes) { using namespace armix::mixer; NativeBusResult r{}; r.pcmRevision=nativeAccepted_.pcmRevision; r.rosterRevision=nativeAccepted_.graph.roster.revision(); - if(!outputsDisarmed){r.error="OUTPUT_MUST_BE_DISARMED";return r;} + // This method has NO physical request argument. Always publish + // the previously accepted identical source/clock configuration. if(!channelIdPhysicalPcmActive()||!ready()|| ep!=epoch()||nativeAccepted_.deviceEpoch!=ep|| !nativeAccepted_.fxOwners|| @@ -1570,7 +1570,7 @@ class LiveDryRoutingLab final { fx.graphRevision=expectedPcmRev+1; const auto published=nativePublisher_.commit( roster,nativeAccepted_.graph.request,expectedPcmRev, - ep,epoch(),true,std::move(fx)); + ep,epoch(),false,std::move(fx),true); if(!published.ok()){ r.error="NATIVE_WIRE_PCM_GRAPH_REJECTED";return r; } diff --git a/tests/dynamic_accepted_session_test.cpp b/tests/dynamic_accepted_session_test.cpp index d7abee868..ac6a740de 100644 --- a/tests/dynamic_accepted_session_test.cpp +++ b/tests/dynamic_accepted_session_test.cpp @@ -265,7 +265,7 @@ static void verifyAtomicWireTransactionAndZeroSampleHops() { if(i!=11)assert(near(left[i],0.f)); const std::array hop1{routeOnly(one,two)}; - a=session.wireTransaction(2,2,hop1,physical,epoch,epoch,true); + a=session.wireTransaction(2,2,hop1,physical,epoch,epoch,false); // live PCM routing while armed assert(a.ok() && a.graphRevision==3); assert(!findEdge(one,main,3) && findEdge(one,two,3)); assert(render() && near(left[11],.3f*center)); @@ -318,6 +318,18 @@ static void verifyAtomicWireTransactionAndZeroSampleHops() { assert(rejected.edit.createdEdgeIds.empty()); // no phantom rejected ID assert(session.acceptedGraphRevision()==6); assert(render() && near(left[11],.3f*center)); + // Preserve output safety: the same WIRE edit with a changed hardware + // block budget is rejected BEFORE the native PCM graph is published. + DynamicGraphRequest changedPhysical=physical; + changedPhysical.maxFrames=128; + const std::array validTopology{connect(two,main)}; + rejected=session.wireTransaction(6,6,validTopology,changedPhysical, + epoch,epoch,false); + assert(rejected.fault==DynamicAcceptedSession::Fault::graphRejected); + assert(rejected.native.fault==DynamicNativeSessionPublisher::Fault::outputArmed); + assert(rejected.edit.createdEdgeIds.empty()); + assert(session.acceptedGraphRevision()==6); + assert(render() && near(left[11],.3f*center)); rejected=session.wireTransaction(5,5,unplug,physical,epoch,epoch,true); assert(rejected.fault==DynamicAcceptedSession::Fault::staleRoster); assert(session.acceptedGraphRevision()==6);