From 2548c26b71a13a5346d82e06ea49c80343ff687f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 20 Nov 2026 08:05:11 +0700 Subject: [PATCH 1/5] refactor(native): centralize .smix save/open admission in existing session recovery owner --- src/Main.cpp | 73 +++++++++++---------- src/NativeMixerSessionRecovery.h | 77 +++++++++++++++++++++++ tests/native_mixer_session_store_test.cpp | 71 +++++++++++++++++++++ 3 files changed, 183 insertions(+), 38 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 51c1c95b4..09570638b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3431,41 +3431,37 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr bool shutdownCheckpoint=false) { const bool automatic=exportFile==juce::File{}; ensureLogicalWorkspace(); - if(mixerSessionWorker_.busy()||nativeShowBusy_||studioBackupBusy_|| - catalog_.busy()||engine_.isGraphSwitchPending()) - return "Mixer is busy. Try again after the current operation."; - if(logicalMixer_.readOnly()) - return "Saved mixer recovery required before writing a new session"; + using Recovery=armix::session::NativeMixerSessionRecovery; const auto liveState=engine_.status(); const auto live=liveState.getProperty("dryRoutingLab",{}); - const auto observed=approvedNativeSnapshot(liveState); - const auto session=observed.getProperty("mixerSession",{}); - const bool m4Active=session.getProperty("authority","").toString()=="M4"; - if(!static_cast(live.getProperty("nativeChannelIdPcmActive",false)) && - !m4Active && !engine_.secondaryArmed()) { - if(engine_.hasRetainedNativeSession()) - return "Retained native mixer still owns the session"; - // Logical edits and Open already commit HEAD before ACK. - if(automatic)return {}; + const auto session=approvedNativeSnapshot(liveState) + .getProperty("mixerSession",{}); + const auto* audio=engine_.devices().getCurrentAudioDevice(); + const auto decision=Recovery::planSave({ + automatic,mixerSessionWorker_.busy(),nativeShowBusy_, + studioBackupBusy_,catalog_.busy(),engine_.isGraphSwitchPending(), + logicalMixer_.readOnly(), + static_cast(live.getProperty("nativeChannelIdPcmActive",false)), + session.getProperty("authority","").toString()=="M4", + engine_.secondaryArmed(),engine_.hasRetainedNativeSession(), + mixerSessionRecoveryPending_,shutdownCheckpoint, + audio!=nullptr && audio->isOpen(),engine_.directRouteAuthorized(), + engine_.mainInterruptedByDevice() + }); + if(decision.action==Recovery::SaveAction::reject) + return juce::String(decision.error); + if(decision.action==Recovery::SaveAction::unchanged) + return {}; // Offline autosave: prior logical transaction already committed HEAD. + if(decision.action==Recovery::SaveAction::exportLogical) { auto safe=juce::Component::SafePointer(this); if(!logicalMixer_.exportTo(exportFile,[safe](juce::String error){ if(safe!=nullptr)safe->emitMixerSessionAck("SAVE",error); }))return "Mixer session IO worker unavailable"; return {}; } - if(automatic&&mixerSessionRecoveryPending_) - return "The retained mixer checkpoint is awaiting a verified device"; - // Auto-checkpoints must never replace an acknowledged .smix with a - // transient STOP/default/empty device state. Keep the last verified - // file on disk until the original physical route has returned. - if(automatic && !shutdownCheckpoint) { - auto* audio=engine_.devices().getCurrentAudioDevice(); - if(!audio || !audio->isOpen() || !engine_.directRouteAuthorized() || - engine_.mainInterruptedByDevice()) - return "Automatic checkpoint paused until audio device recovery"; - } + // Only a CONTROL-approved installed session reaches the temporary + // output capture fence; never move plugin capture to the audio callback. const bool monitoring=engine_.isMonitorEnabled(); - if(engine_.secondaryArmed())return "Stop STREAM before saving the mixer"; const auto epoch=engine_.dryRoutingLabEpoch(); // Temporary capture fence is NOT an operator MUTE. Keep the // persisted MAIN desire intact across device loss during Save. @@ -3537,24 +3533,25 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr std::vector states) { if(safe==nullptr)return; auto& engine=safe->engine_; - if(error.isEmpty() && (safe->nativeShowBusy_||safe->studioBackupBusy_|| - safe->catalog_.busy()||engine.isGraphSwitchPending()|| - chosenEpoch!=engine.dryRoutingLabEpoch())) - error="Mixer or audio device changed while opening the file"; - if(error.isEmpty()&&engine.secondaryArmed()) - error="Stop STREAM before opening a mixer"; + using Recovery=armix::session::NativeMixerSessionRecovery; const auto liveState=engine.status(); const auto lab=liveState.getProperty("dryRoutingLab",{}); const auto session=safe->approvedNativeSnapshot(liveState) .getProperty("mixerSession",{}); - const bool physical=static_cast(lab.getProperty( - "nativeChannelIdPcmActive",false)) || - session.getProperty("authority","").toString()=="M4"; - if(error.isEmpty()&&!physical&&engine.hasRetainedNativeSession()) - error="Retained native mixer still owns the session"; + const auto decision=Recovery::planOpen({ + safe->nativeShowBusy_ || safe->studioBackupBusy_ || + safe->catalog_.busy() || engine.isGraphSwitchPending(), + chosenEpoch!=engine.dryRoutingLabEpoch(), + engine.secondaryArmed(), + static_cast(lab.getProperty("nativeChannelIdPcmActive",false)), + session.getProperty("authority","").toString()=="M4", + engine.hasRetainedNativeSession() + }); + if(error.isEmpty() && decision.action==Recovery::OpenAction::reject) + error=decision.error; const auto importedHotkeys=doc.hotkeys; const auto importedId=doc.id; - if(error.isEmpty()&&!physical) { + if(error.isEmpty() && decision.action==Recovery::OpenAction::openLogical) { // Open the real .smix into the same stable-ID logical // document. Never demand audio hardware or instantiate VST3 // just to inspect and edit a saved mixer. diff --git a/src/NativeMixerSessionRecovery.h b/src/NativeMixerSessionRecovery.h index 162f178fd..ca0bddbe2 100644 --- a/src/NativeMixerSessionRecovery.h +++ b/src/NativeMixerSessionRecovery.h @@ -33,6 +33,83 @@ class NativeMixerSessionRecovery final { return {Source::head,std::move(error)}; } + + // One CONTROL-thread admission policy for .smix SAVE/OPEN. The host + // supplies observed native authority and keeps OS dialogs, callbacks, + // physical graph ownership and UI ACK/readback; no shadow session state. + enum class SaveAction { reject, unchanged, exportLogical, captureInstalled }; + struct SaveContext { + bool automatic = false; + bool workerBusy = false; + bool showBusy = false; + bool backupBusy = false; + bool catalogBusy = false; + bool graphPending = false; + bool readOnly = false; + bool channelIdInstalled = false; + bool m4Installed = false; + bool secondaryArmed = false; + bool retainedNative = false; + bool recoveryPending = false; + bool shutdownCheckpoint = false; + bool physicalOpen = false; + bool directAuthorized = false; + bool mainInterrupted = false; + }; + struct SavePlan { + SaveAction action; + const char* error = nullptr; + }; + static SavePlan planSave(const SaveContext& c) noexcept { + if(c.workerBusy || c.showBusy || c.backupBusy || + c.catalogBusy || c.graphPending) + return {SaveAction::reject, + "Mixer is busy. Try again after the current operation."}; + if(c.readOnly) + return {SaveAction::reject, + "Saved mixer recovery required before writing a new session"}; + if(!c.channelIdInstalled && !c.m4Installed && !c.secondaryArmed) { + if(c.retainedNative) + return {SaveAction::reject, "Retained native mixer still owns the session"}; + return {c.automatic ? SaveAction::unchanged : SaveAction::exportLogical, nullptr}; + } + if(c.automatic && c.recoveryPending) + return {SaveAction::reject, + "The retained mixer checkpoint is awaiting a verified device"}; + if(c.automatic && !c.shutdownCheckpoint && + (!c.physicalOpen || !c.directAuthorized || c.mainInterrupted)) + return {SaveAction::reject, + "Automatic checkpoint paused until audio device recovery"}; + if(c.secondaryArmed) + return {SaveAction::reject, "Stop STREAM before saving the mixer"}; + return {SaveAction::captureInstalled, nullptr}; + } + + enum class OpenAction { reject, openLogical, restoreInstalled }; + struct OpenContext { + bool operationBusy = false; + bool epochChanged = false; + bool secondaryArmed = false; + bool channelIdInstalled = false; + bool m4Installed = false; + bool retainedNative = false; + }; + struct OpenPlan { + OpenAction action; + const char* error = nullptr; + }; + static OpenPlan planOpen(const OpenContext& c) noexcept { + if(c.operationBusy || c.epochChanged) + return {OpenAction::reject, + "Mixer or audio device changed while opening the file"}; + if(c.secondaryArmed) + return {OpenAction::reject, "Stop STREAM before opening a mixer"}; + if(!c.channelIdInstalled && !c.m4Installed && c.retainedNative) + return {OpenAction::reject, "Retained native mixer still owns the session"}; + return {c.channelIdInstalled || c.m4Installed ? + OpenAction::restoreInstalled : OpenAction::openLogical, nullptr}; + } + struct Context { BindingMode bindingMode; Source source; diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index b5007085f..1a7dec5b6 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -115,6 +115,76 @@ static void checkRecoveryPlan(const MixerSessionDocument& session) { assert(plan.restoreAllowed && plan.replacePristineStartup && !plan.resumeMain); } + +static void checkSessionControlPlans() { + using Save=Recovery::SaveAction; + using Open=Recovery::OpenAction; + Recovery::SaveContext save; + save.automatic=true; + save.channelIdInstalled=true; + save.physicalOpen=true; + save.directAuthorized=true; + assert(Recovery::planSave(save).action==Save::captureInstalled); + save.workerBusy=true; + assert(Recovery::planSave(save).action==Save::reject); + save.workerBusy=false; + save.readOnly=true; + assert(Recovery::planSave(save).action==Save::reject); + save.readOnly=false; + save.channelIdInstalled=false; + assert(Recovery::planSave(save).action==Save::unchanged); + save.automatic=false; + assert(Recovery::planSave(save).action==Save::exportLogical); + save.retainedNative=true; + assert(Recovery::planSave(save).action==Save::reject); + save.retainedNative=false; + save.m4Installed=true; // Legacy M4 is installed, not an offline export. + assert(Recovery::planSave(save).action==Save::captureInstalled); + save.m4Installed=false; + save.channelIdInstalled=true; + save.automatic=true; + save.recoveryPending=true; + assert(Recovery::planSave(save).action==Save::reject); + save.recoveryPending=false; + save.physicalOpen=false; + assert(Recovery::planSave(save).action==Save::reject); + save.shutdownCheckpoint=true; // Explicit shutdown checkpoint exception. + assert(Recovery::planSave(save).action==Save::captureInstalled); + save.shutdownCheckpoint=false; + save.physicalOpen=true; + save.directAuthorized=false; + assert(Recovery::planSave(save).action==Save::reject); + save.directAuthorized=true; + save.mainInterrupted=true; + assert(Recovery::planSave(save).action==Save::reject); + save.mainInterrupted=false; + save.secondaryArmed=true; + assert(Recovery::planSave(save).action==Save::reject); + save.secondaryArmed=false; + save.graphPending=true; + assert(Recovery::planSave(save).action==Save::reject); + + Recovery::OpenContext open; + assert(Recovery::planOpen(open).action==Open::openLogical); + open.retainedNative=true; + assert(Recovery::planOpen(open).action==Open::reject); + open.channelIdInstalled=true; + assert(Recovery::planOpen(open).action==Open::restoreInstalled); + open.channelIdInstalled=false; + open.m4Installed=true; + assert(Recovery::planOpen(open).action==Open::restoreInstalled); + open.m4Installed=false; + open.retainedNative=false; + open.secondaryArmed=true; + assert(Recovery::planOpen(open).action==Open::reject); + open.secondaryArmed=false; + open.epochChanged=true; + assert(Recovery::planOpen(open).action==Open::reject); + open.epochChanged=false; + open.operationBusy=true; + assert(Recovery::planOpen(open).action==Open::reject); +} + class FixtureDevice final : public juce::AudioIODevice { public: FixtureDevice():AudioIODevice("Verified WASAPI fixture","Windows Audio") { @@ -1472,6 +1542,7 @@ int main(){ nativeDeviceRecovery(); auto d=makeSession(); checkRecoveryPlan(d); + checkSessionControlPlans(); verifyExternalOutputPortableIntent(); verifyIndependentAsioExternalRestoreProvenance(); const auto before=Codec::encode(d); From cfd19b2494e89c1685729b12c219d00ba71ed503 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 20 Nov 2026 08:08:20 +0700 Subject: [PATCH 2/5] refactor(native): put restore gate and canonical save fingerprint in session lifecycle owner --- src/Main.cpp | 24 ++++++------- src/NativeMixerSessionRecovery.h | 41 +++++++++++++++++++++++ tests/native_mixer_session_store_test.cpp | 33 ++++++++++++++++++ 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 09570638b..c5a5f2a61 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3332,10 +3332,13 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr juce::String restoreSavedMixerSession(bool startupOnSavedDevice=false, armix::session::MixerDeviceBindingPolicy::Mode bindingMode= armix::session::MixerDeviceBindingPolicy::Mode::exact) { - if(!engine_.allOutputsDisarmed() || mixerSessionWorker_.busy() || logicalVendorEditor_ || - nativeShowBusy_ || studioBackupBusy_ || engine_.isGraphSwitchPending()) - return "MUTE output and finish Studio IO before restoring mixer"; using Recovery=armix::session::NativeMixerSessionRecovery; + const auto blocked=Recovery::restoreBlocker({ + engine_.allOutputsDisarmed(),mixerSessionWorker_.busy(), + logicalVendorEditor_!=nullptr,nativeShowBusy_,studioBackupBusy_, + engine_.isGraphSwitchPending() + }); + if(blocked)return blocked; const armix::session::NativeMixerSessionStore store(settingsDirectory()); armix::session::MixerSessionDocument doc; std::vector states; @@ -3487,16 +3490,11 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // browser-provided plugin name or relocate an arbitrary VST3 path. error=resolveMixerSessionCatalog(doc,true); if(error.isNotEmpty())return error; - doc.savedMs=1; // signature excludes wall time; includes FX state hashes - const auto canonical=armix::session::Codec::encode(doc); - armix::session::MixerSessionDocument verified; - if(!armix::session::Codec::decode(canonical,verified)) - return "Mixer session document validation rejected"; - const auto fingerprint=juce::SHA256(canonical.toRawUTF8(), - canonical.getNumBytesAsUTF8()).toHexString(); - if(automatic&&fingerprint==lastMixerSessionFingerprint_) - return {}; - doc.savedMs=juce::Time::currentTimeMillis(); + const auto staged=Recovery::stageSave(doc,automatic, + lastMixerSessionFingerprint_,juce::Time::currentTimeMillis()); + if(staged.error.isNotEmpty())return staged.error; + if(staged.unchanged)return {}; + const auto fingerprint=staged.fingerprint; const auto pendingId=doc.id; auto safe=juce::Component::SafePointer(this); if(!mixerSessionWorker_.save(settingsDirectory(),std::move(doc), diff --git a/src/NativeMixerSessionRecovery.h b/src/NativeMixerSessionRecovery.h index ca0bddbe2..394a22f2d 100644 --- a/src/NativeMixerSessionRecovery.h +++ b/src/NativeMixerSessionRecovery.h @@ -34,6 +34,47 @@ class NativeMixerSessionRecovery final { } + + struct RestoreContext { + bool outputsDisarmed = false; + bool workerBusy = false; + bool vendorEditorOpen = false; + bool showBusy = false; + bool backupBusy = false; + bool graphPending = false; + }; + static const char* restoreBlocker(const RestoreContext& c) noexcept { + return (!c.outputsDisarmed || c.workerBusy || c.vendorEditorOpen || + c.showBusy || c.backupBusy || c.graphPending) ? + "MUTE output and finish Studio IO before restoring mixer" : nullptr; + } + + struct SaveStage { + juce::String error; + juce::String fingerprint; + bool unchanged = false; + }; + // Canonical fingerprint deliberately ignores savedMs. A failed worker + // never promotes it; only an accepted automatic checkpoint may dedupe. + // Disk persistence, binary blob hashing and HEAD admission remain owned + // by the existing NativeMixerSessionStore/SaveWorker. + static SaveStage stageSave(MixerSessionDocument& doc, + bool automatic, + const juce::String& acceptedFingerprint, + juce::int64 capturedAtMs) { + doc.savedMs=1; + const auto canonical=Codec::encode(doc); + MixerSessionDocument verified; + if(!Codec::decode(canonical,verified)) + return {"Mixer session document validation rejected",{},false}; + const auto fingerprint=juce::SHA256(canonical.toRawUTF8(), + canonical.getNumBytesAsUTF8()).toHexString(); + if(automatic && fingerprint==acceptedFingerprint) + return {{},fingerprint,true}; + doc.savedMs=capturedAtMs; + return {{},fingerprint,false}; + } + // One CONTROL-thread admission policy for .smix SAVE/OPEN. The host // supplies observed native authority and keeps OS dialogs, callbacks, // physical graph ownership and UI ACK/readback; no shadow session state. diff --git a/tests/native_mixer_session_store_test.cpp b/tests/native_mixer_session_store_test.cpp index 1a7dec5b6..d2db6c91a 100644 --- a/tests/native_mixer_session_store_test.cpp +++ b/tests/native_mixer_session_store_test.cpp @@ -183,6 +183,39 @@ static void checkSessionControlPlans() { open.epochChanged=false; open.operationBusy=true; assert(Recovery::planOpen(open).action==Open::reject); + + // Save deduplication only follows a prior ACCEPTED fingerprint and + // must not depend on wall clock; distinct edits always requalify. + auto doc=makeSession(); + const auto first=Recovery::stageSave(doc,true,{},1762521000000LL); + assert(first.error.isEmpty() && !first.unchanged); + assert(first.fingerprint.isNotEmpty() && doc.savedMs==1762521000000LL); + const auto again=Recovery::stageSave(doc,true,first.fingerprint,1762522000000LL); + assert(again.error.isEmpty() && again.unchanged); + const auto forced=Recovery::stageSave(doc,false,first.fingerprint,1762523000000LL); + assert(forced.error.isEmpty() && !forced.unchanged); + doc.masterGain=.4f; + const auto changed=Recovery::stageSave(doc,true,first.fingerprint,1762524000000LL); + assert(changed.error.isEmpty() && !changed.unchanged && + changed.fingerprint!=first.fingerprint); + doc.id="UNTRUSTED"; + const auto invalid=Recovery::stageSave(doc,true,{},1762525000000LL); + assert(invalid.error.isNotEmpty()); + + Recovery::RestoreContext restore; + restore.outputsDisarmed=true; + assert(Recovery::restoreBlocker(restore)==nullptr); + restore.workerBusy=true; + assert(Recovery::restoreBlocker(restore)!=nullptr); + restore.workerBusy=false; + restore.vendorEditorOpen=true; + assert(Recovery::restoreBlocker(restore)!=nullptr); + restore.vendorEditorOpen=false; + restore.graphPending=true; + assert(Recovery::restoreBlocker(restore)!=nullptr); + restore.graphPending=false; + restore.outputsDisarmed=false; + assert(Recovery::restoreBlocker(restore)!=nullptr); } class FixtureDevice final : public juce::AudioIODevice { From a60e8f6e38b24749801e8089ff724e221119853f Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 20 Nov 2026 08:10:42 +0700 Subject: [PATCH 3/5] test(native): bind STOP/checkpoint contracts to session recovery owner --- tests/audio_continuity_contract_test.mjs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/audio_continuity_contract_test.mjs b/tests/audio_continuity_contract_test.mjs index 1a9cd9783..6bae749ca 100644 --- a/tests/audio_continuity_contract_test.mjs +++ b/tests/audio_continuity_contract_test.mjs @@ -7,6 +7,7 @@ const main=read('src/Main.cpp'); const engine=read('src/LiveAudioEngine.h'); const policy=read('engine/device/AudioContinuityPolicy.h'); const coordinator=read('src/NativeDeviceApplyCoordinator.h'); +const sessionRecovery=read('src/NativeMixerSessionRecovery.h'); const cmake=read('CMakeLists.txt'); test('display sleep never changes logical mixer intent or device configuration',()=>{ @@ -69,7 +70,7 @@ test('WASAPI recovery fails closed against substituted endpoint names or pin mas test('session capture and shutdown keep requested MAIN through a device STOP',()=>{ const capture=main.split('juce::String saveMixerSession(bool resumeMain')[1] - .split('const auto canonical=')[0]; + .split('const auto pendingId=doc.id;')[0]; assert.match(capture,/if\(monitoring\)engine_\.setOutputMuted\(true\)/); assert.match(capture,/engine_\.setOutputMuted\(false\)/); assert.doesNotMatch(capture,/engine_\.setMonitorEnabled\(/); @@ -82,9 +83,16 @@ test('session capture and shutdown keep requested MAIN through a device STOP',() test('automatic checkpoints cannot overwrite saved MAIN and device binding during STOP',()=>{ const save=main.split('juce::String saveMixerSession(bool resumeMain')[1] .split('void openMixerFile(')[0]; - assert.match(save,/!audio \|\| !audio->isOpen\(\)/); - assert.match(save,/if\(automatic && !shutdownCheckpoint\)/); + // Recovery is the single SAVE admission owner; Main provides physical + // readback evidence. STOP must never be an implicit checkpoint success. + const admit=sessionRecovery.split('static SavePlan planSave(')[1] + .split('enum class OpenAction')[0]; + assert.match(save,/audio!=nullptr && audio->isOpen\(\)/); assert.match(save,/engine_\.mainInterruptedByDevice\(\)/); + assert.match(save,/Recovery::planSave\(/); + assert.match(admit,/c\.automatic && !c\.shutdownCheckpoint/); + assert.match(admit,/!c\.physicalOpen \|\| !c\.directAuthorized \|\| c\.mainInterrupted/); + assert.match(admit,/SaveAction::reject/); assert.match(save,/doc\.resumeMain=resumeMain \|\|/); assert.match(save,/engine_\.wantsMainContinuation\(\) && !operatorOutputMuted_/); const persistence=main.split('if (deviceSettingsDirty_)')[1] From 8a7c3927bbb543c09b077d196ae2d835b0e2ce47 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 20 Nov 2026 08:14:26 +0700 Subject: [PATCH 4/5] fix(native M2): respect nonconst JUCE device API and use named session admission evidence --- src/Main.cpp | 65 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index c5a5f2a61..decf7f9d9 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3333,11 +3333,14 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr armix::session::MixerDeviceBindingPolicy::Mode bindingMode= armix::session::MixerDeviceBindingPolicy::Mode::exact) { using Recovery=armix::session::NativeMixerSessionRecovery; - const auto blocked=Recovery::restoreBlocker({ - engine_.allOutputsDisarmed(),mixerSessionWorker_.busy(), - logicalVendorEditor_!=nullptr,nativeShowBusy_,studioBackupBusy_, - engine_.isGraphSwitchPending() - }); + Recovery::RestoreContext restore; + restore.outputsDisarmed=engine_.allOutputsDisarmed(); + restore.workerBusy=mixerSessionWorker_.busy(); + restore.vendorEditorOpen=logicalVendorEditor_!=nullptr; + restore.showBusy=nativeShowBusy_; + restore.backupBusy=studioBackupBusy_; + restore.graphPending=engine_.isGraphSwitchPending(); + const auto blocked=Recovery::restoreBlocker(restore); if(blocked)return blocked; const armix::session::NativeMixerSessionStore store(settingsDirectory()); armix::session::MixerSessionDocument doc; @@ -3439,18 +3442,27 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto live=liveState.getProperty("dryRoutingLab",{}); const auto session=approvedNativeSnapshot(liveState) .getProperty("mixerSession",{}); - const auto* audio=engine_.devices().getCurrentAudioDevice(); - const auto decision=Recovery::planSave({ - automatic,mixerSessionWorker_.busy(),nativeShowBusy_, - studioBackupBusy_,catalog_.busy(),engine_.isGraphSwitchPending(), - logicalMixer_.readOnly(), - static_cast(live.getProperty("nativeChannelIdPcmActive",false)), - session.getProperty("authority","").toString()=="M4", - engine_.secondaryArmed(),engine_.hasRetainedNativeSession(), - mixerSessionRecoveryPending_,shutdownCheckpoint, - audio!=nullptr && audio->isOpen(),engine_.directRouteAuthorized(), - engine_.mainInterruptedByDevice() - }); + // JUCE AudioIODevice::isOpen() is deliberately non-const. + auto* audio=engine_.devices().getCurrentAudioDevice(); + Recovery::SaveContext save; + save.automatic=automatic; + save.workerBusy=mixerSessionWorker_.busy(); + save.showBusy=nativeShowBusy_; + save.backupBusy=studioBackupBusy_; + save.catalogBusy=catalog_.busy(); + save.graphPending=engine_.isGraphSwitchPending(); + save.readOnly=logicalMixer_.readOnly(); + save.channelIdInstalled=static_cast( + live.getProperty("nativeChannelIdPcmActive",false)); + save.m4Installed=session.getProperty("authority","").toString()=="M4"; + save.secondaryArmed=engine_.secondaryArmed(); + save.retainedNative=engine_.hasRetainedNativeSession(); + save.recoveryPending=mixerSessionRecoveryPending_; + save.shutdownCheckpoint=shutdownCheckpoint; + save.physicalOpen=audio!=nullptr && audio->isOpen(); + save.directAuthorized=engine_.directRouteAuthorized(); + save.mainInterrupted=engine_.mainInterruptedByDevice(); + const auto decision=Recovery::planSave(save); if(decision.action==Recovery::SaveAction::reject) return juce::String(decision.error); if(decision.action==Recovery::SaveAction::unchanged) @@ -3536,15 +3548,16 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr const auto lab=liveState.getProperty("dryRoutingLab",{}); const auto session=safe->approvedNativeSnapshot(liveState) .getProperty("mixerSession",{}); - const auto decision=Recovery::planOpen({ - safe->nativeShowBusy_ || safe->studioBackupBusy_ || - safe->catalog_.busy() || engine.isGraphSwitchPending(), - chosenEpoch!=engine.dryRoutingLabEpoch(), - engine.secondaryArmed(), - static_cast(lab.getProperty("nativeChannelIdPcmActive",false)), - session.getProperty("authority","").toString()=="M4", - engine.hasRetainedNativeSession() - }); + Recovery::OpenContext opening; + opening.operationBusy=safe->nativeShowBusy_ || safe->studioBackupBusy_ || + safe->catalog_.busy() || engine.isGraphSwitchPending(); + opening.epochChanged=chosenEpoch!=engine.dryRoutingLabEpoch(); + opening.secondaryArmed=engine.secondaryArmed(); + opening.channelIdInstalled=static_cast( + lab.getProperty("nativeChannelIdPcmActive",false)); + opening.m4Installed=session.getProperty("authority","").toString()=="M4"; + opening.retainedNative=engine.hasRetainedNativeSession(); + const auto decision=Recovery::planOpen(opening); if(error.isEmpty() && decision.action==Recovery::OpenAction::reject) error=decision.error; const auto importedHotkeys=doc.hotkeys; From c36fc4dc948f73a931c11c18ce5305dcd0d281a0 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Fri, 20 Nov 2026 08:15:56 +0700 Subject: [PATCH 5/5] test(session): keep offline checkpoint rejection contract at true recovery owner --- tests/mixer_io_operator_contract_test.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/mixer_io_operator_contract_test.mjs b/tests/mixer_io_operator_contract_test.mjs index fc72e6c0b..e6b87165f 100644 --- a/tests/mixer_io_operator_contract_test.mjs +++ b/tests/mixer_io_operator_contract_test.mjs @@ -694,7 +694,14 @@ test('offline checkpoints stay protected until verified native restore',()=>{ assert.match(open,/if\(openError.isEmpty\(\)\)[\s\S]*?"LOGICAL_SESSION_OPENED_UNBOUND"/); const control=read('src/NativeLogicalMixerControl.h'); assert.match(control,/workspace_=std::move\(\*candidate\);[\s\S]*?checkpointSaved_\(workspace_.document\(\).id\)/); - assert.match(save,/if\(automatic&&mixerSessionRecoveryPending_\)[\s\S]*?return "[^"]+";[\s\S]*?captureNativeMixerSession/); + // Admission is now the existing NativeMixerSessionRecovery owner, not + // an inline ConsoleWindow conditional. The rejection must occur before PCM capture. + const recovery=read('src/NativeMixerSessionRecovery.h'); + const policy=recovery.slice(recovery.indexOf('static SavePlan planSave('), + recovery.indexOf('enum class OpenAction')); + assert.match(policy,/if\(c\.automatic && c\.recoveryPending\)[\s\S]*?SaveAction::reject/); + assert.match(save,/save\.recoveryPending=mixerSessionRecoveryPending_/); + assert.match(save,/Recovery::planSave\(save\)[\s\S]*?SaveAction::reject[\s\S]*?captureNativeMixerSession/); }); // Exact control-thread serialization source contract for nested JUCE modal loops.