From 1159f84a3fbc2b7101bf6b325151fda5adfb1588 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Wed, 11 Nov 2026 06:37:58 +0700 Subject: [PATCH] fix(startup): guard manual VST3 construction before logical FX and preserve Hotkeys --- src/Main.cpp | 22 ++++++++++++++++++++++ src/StartupVst3RecoveryGuard.h | 7 +++++++ tests/live_routing_ui_contract_test.mjs | 16 ++++++++++++++++ tests/vst3_waves_identity_startup_test.cpp | 22 ++++++++++++++++++---- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index cd336646a..393ce5f05 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3161,6 +3161,20 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr }))safe->emitMixerSessionAck("OPEN","Mixer session IO worker unavailable"); return; } + // Physical Open may construct vendor DLLs inside the logical FX + // materialization step. Arm the marker BEFORE any preparation, + // not merely before the final native graph restore. + std::unique_ptr explicitRecovery; + bool hadPreviousCrashEvidence=false; + if(error.isEmpty()) { + explicitRecovery=std::make_unique( + settingsDirectory()); + hadPreviousCrashEvidence=explicitRecovery->interrupted(); + if(!explicitRecovery->armExplicitRetry()) + error="Cannot protect VST3 Open: settings folder is not writable"; + else + safe->startupFxGuard_.reset(); // old timer must not clear new marker + } if(error.isEmpty())error=safe->materializeLogicalFxForBinding(doc,states); if(error.isEmpty())error=safe->resolveMixerSessionCatalog(doc,false); if(error.isEmpty()) { @@ -3182,9 +3196,17 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr safe->mixerSessionStatus_=engine.isMonitorEnabled()?"RESTORED_MONITORING":"RESTORED_MUTED"; safe->mixerSessionError_.clear(); safe->lastMixerFile_=file; + safe->startupFxGuard_=std::move(explicitRecovery); + safe->startupFxGuardTick_=juce::Time::getMillisecondCounter(); + safe->diagnostics_.record("STARTUP_FX_EXPLICIT_RECOVERY_ACCEPTED", + "Manual FX graph restored; pending 15s stability verification"); safe->emitApprovedNativeSnapshot(); } } + // A controlled rejection is not an abnormal process crash. + // Never erase an earlier failure marker if safe recovery existed. + if(error.isNotEmpty()&&explicitRecovery&&!hadPreviousCrashEvidence) + (void)explicitRecovery->complete(); safe->emitMixerSessionAck("OPEN",error); }))emitMixerSessionAck("OPEN","Mixer file operation already in progress"); } diff --git a/src/StartupVst3RecoveryGuard.h b/src/StartupVst3RecoveryGuard.h index fe88047a4..ab2938769 100644 --- a/src/StartupVst3RecoveryGuard.h +++ b/src/StartupVst3RecoveryGuard.h @@ -20,6 +20,13 @@ class Vst3RestoreCrashGuard final { return marker_.replaceWithText("RESTORE_IN_PROGRESS\n"); } + // Manual Open is an explicit user's retry after safe recovery. Preserve + // crash evidence if the process dies again; clear only after the newly + // installed FX graph is stable. A writable marker is mandatory. + [[nodiscard]] bool armExplicitRetry() { + return marker_.replaceWithText("EXPLICIT_FX_RESTORE_IN_PROGRESS\n"); + } + [[nodiscard]] bool complete() { // Called after stable startup or graceful shutdown, never while // processor construction is still underway. diff --git a/tests/live_routing_ui_contract_test.mjs b/tests/live_routing_ui_contract_test.mjs index c23d8d57a..21f887db3 100644 --- a/tests/live_routing_ui_contract_test.mjs +++ b/tests/live_routing_ui_contract_test.mjs @@ -361,3 +361,19 @@ test("R3 routing shares approved BTN-180 cap material, has a clear console hiera assert.match(ui,/id="arPatchGrid"/); assert.doesNotMatch(ui,/arPatchCell:hover|arAuxMatrixCell:hover|filter:blur\(|backdrop-filter:/); }); + +test("P0 manual VST3 Open fences vendor preparation and retains Hotkey session",()=>{ + const enter=main.indexOf(" void openMixerFile("); + const exit=main.indexOf(" void chooseMixerFile(",enter); + assert.ok(enter>=0&&exit>enter,"native session Open must have one owner"); + const open=main.slice(enter,exit); + const arm=open.indexOf("armExplicitRetry()"); + const materialize=open.indexOf("materializeLogicalFxForBinding("); + const instantiate=open.indexOf("engine.restoreNativeMixerSession("); + assert.ok(arm>=0&&materialize>arm&&instantiate>materialize, + "crash guard must arm BEFORE logical FX and vendor graph preparation"); + assert.match(open,/hadPreviousCrashEvidence=explicitRecovery->interrupted\(\)/); + assert.match(open,/if\(error\.isNotEmpty\(\)&&explicitRecovery&&!hadPreviousCrashEvidence\)/); + assert.match(open,/startupFxGuard_=std::move\(explicitRecovery\)/); + assert.match(open,/hotkeys_\.activateSession\(id,&importedHotkeys\)/); +}); diff --git a/tests/vst3_waves_identity_startup_test.cpp b/tests/vst3_waves_identity_startup_test.cpp index bad82332d..7c92a546b 100644 --- a/tests/vst3_waves_identity_startup_test.cpp +++ b/tests/vst3_waves_identity_startup_test.cpp @@ -47,9 +47,23 @@ int main() { assert(nextLaunch.interrupted()); assert(!nextLaunch.arm()); assert(session.loadFileAsString()=="PRESERVE_USER_SESSION"); - assert(nextLaunch.complete()); - assert(!nextLaunch.interrupted()); - assert(nextLaunch.arm()); - assert(nextLaunch.complete()); + // In safe recovery, an explicit retry must keep the marker during + // potentially crashing vendor creation and for the stability window. + assert(nextLaunch.armExplicitRetry()); + assert(nextLaunch.interrupted()); + assert(session.loadFileAsString()=="PRESERVE_USER_SESSION"); + // Another simulated crash during manual Open still blocks auto replay. + armix::startup::Vst3RestoreCrashGuard retryAfterCrash(temp); + assert(retryAfterCrash.interrupted()); + assert(!retryAfterCrash.arm()); + assert(retryAfterCrash.armExplicitRetry()); + assert(retryAfterCrash.interrupted()); + // Successful manual Open plus stable timer/graceful shutdown clears it; + // next application launch can safely resume normal automatic restores. + assert(retryAfterCrash.complete()); + assert(!retryAfterCrash.interrupted()); + assert(retryAfterCrash.arm()); + assert(retryAfterCrash.complete()); + assert(session.loadFileAsString()=="PRESERVE_USER_SESSION"); assert(temp.deleteRecursively()); }