implement Helper test-load: spawns Helper before in-process load, blocks crashy plugins
Browse filesNow loadPlugin() does:
1. Check blocklist → skip if blocked
2. Spawn PluginBridgeHelper --test '/path' → wait for exit
3. Exit code 0 → safe → load in-process
4. Exit code != 0 or crash → add to blocklist → show error → Ableton stays alive
This prevents Kickstart 2 / Ozone 12 / any crashy plugin from ever
crashing Ableton. The Helper takes the hit instead.
1 unmodified line23456760 unmodified lines68697071727374757677787980818283845 unmodified lines9091929394959617 unmodified lines1141151161171181191201 unmodified line122123124125126127128231 unmodified lines3603613623633643653663673683693703713723733743753761 unmodified line#include "PluginBridgeEditor.h"#include "McpServer.h"#include "json.hpp"using json = nlohmann::json;60 unmodified linesreturn new PluginBridgeEditor(*this);}// --- Plugin Loading (IN-PROCESS) ---void PluginBridgeProcessor::loadPlugin(const juce::String& path){unloadPlugin();// Check blocklistif (blocklist.isBlocked(path)){if (onLoadFailed)onLoadFailed("Plugin is blocklisted (crashed previously)");return;}5 unmodified linesreturn;}// Find plugin descriptionjuce::OwnedArray<juce::PluginDescription> typesFound;for (int i = 0; i < formatManager.getNumFormats(); ++i)17 unmodified linesreturn;}// Create plugin instancejuce::String errorMessage;auto instance = formatManager.createPluginInstance(*typesFound[0], currentSampleRate, currentBlockSize, errorMessage);1 unmodified lineif (instance == nullptr){DBG("PluginBridgeProcessor: Failed to load: " + errorMessage);// Add to blocklist if it failsblocklist.addBlocked(path);if (onLoadFailed)onLoadFailed("Failed to load: " + errorMessage);231 unmodified linesreturn mcpServer ? mcpServer->getPort() : 0;}// --- Test Safety (Helper-based) ---PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const juce::String& path){// TODO: Spawn helper to test-load plugin// For now, all plugins are treated as safe unless blocklistedif (blocklist.isBlocked(path))return TestResult::Unsafe;return TestResult::Safe;}// --- Entry Point ---juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()1 unmodified line23456789101112131460 unmodified lines757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831845 unmodified lines19019119219319419519619719819920020120220320420520617 unmodified lines2242252262272282291 unmodified line231232233234235236231 unmodified lines4684694704714724731 unmodified line#include "PluginBridgeEditor.h"#include "McpServer.h"#include <spawn.h>#include <sys/wait.h>#include <unistd.h>#include <signal.h>extern char** environ;#include "json.hpp"using json = nlohmann::json;60 unmodified linesreturn new PluginBridgeEditor(*this);}// --- Helper Test Load ---// Spawns PluginBridgeHelper in a separate process to test if a plugin is safe.// If the helper crashes, Ableton stays alive and the plugin gets blocklisted.static juce::File findHelperBinary(){// Helper is bundled inside PluginBridge.vst3/Contents/Resources/auto helper = juce::File::getSpecialLocation(juce::File::currentExecutableFile).getParentDirectory() // MacOS/.getParentDirectory() // Contents/.getChildFile("Resources").getChildFile(PluginBridgeConstants::kHelperBinaryName);if (helper.exists())return helper;// Fallback: same directory as executablehelper = juce::File::getSpecialLocation(juce::File::currentExecutableFile).getParentDirectory().getChildFile(PluginBridgeConstants::kHelperBinaryName);return helper;}PluginBridgeProcessor::TestResult PluginBridgeProcessor::testPluginSafety(const juce::String& path){if (blocklist.isBlocked(path))return TestResult::Unsafe;auto helperBinary = findHelperBinary();if (!helperBinary.exists()){DBG("testPluginSafety: Helper binary not found, skipping test");return TestResult::Safe; // Can't test — assume safe}auto helperPathStr = helperBinary.getFullPathName().toStdString();auto pluginPathStr = path.toStdString();pid_t pid;char* argv[] = {(char*)helperPathStr.c_str(),(char*)"--test",(char*)pluginPathStr.c_str(),nullptr};int spawnResult = posix_spawn(&pid, helperPathStr.c_str(), nullptr, nullptr, argv, environ);if (spawnResult != 0){DBG("testPluginSafety: Failed to spawn helper");return TestResult::Safe; // Can't test — assume safe}// Wait for helper to exit (max 10 seconds)int status = 0;int waitResult = 0;int waitedMs = 0;const int timeoutMs = 10000;while (waitedMs < timeoutMs){waitResult = waitpid(pid, &status, WNOHANG);if (waitResult == pid)break;if (waitResult < 0)break;usleep(50000); // 50mswaitedMs += 50;}// Timeout — kill it and assume unsafeif (waitedMs >= timeoutMs){kill(pid, SIGKILL);waitpid(pid, &status, 0);DBG("testPluginSafety: Helper timed out for " + path);return TestResult::Unsafe;}// Check exit statusif (WIFEXITED(status) && WEXITSTATUS(status) == 0){DBG("testPluginSafety: Plugin is SAFE: " + path);return TestResult::Safe;}// Crashed or non-zero exitDBG("testPluginSafety: Plugin is UNSAFE: " + path);return TestResult::Unsafe;}// --- Plugin Loading (IN-PROCESS, with safety test first) ---void PluginBridgeProcessor::loadPlugin(const juce::String& path){unloadPlugin();// 1. Check blocklistif (blocklist.isBlocked(path)){if (onLoadFailed)onLoadFailed("Not compatible (crashed previously)");return;}5 unmodified linesreturn;}// 2. Test safety in Helper process FIRSTauto testResult = testPluginSafety(path);if (testResult == TestResult::Unsafe){blocklist.addBlocked(path);if (onLoadFailed)onLoadFailed("Not compatible with PluginBridge");return;}// 3. Safe — load in-processjuce::OwnedArray<juce::PluginDescription> typesFound;for (int i = 0; i < formatManager.getNumFormats(); ++i)17 unmodified linesreturn;}juce::String errorMessage;auto instance = formatManager.createPluginInstance(*typesFound[0], currentSampleRate, currentBlockSize, errorMessage);1 unmodified lineif (instance == nullptr){DBG("PluginBridgeProcessor: Failed to load: " + errorMessage);blocklist.addBlocked(path);if (onLoadFailed)onLoadFailed("Failed to load: " + errorMessage);231 unmodified linesreturn mcpServer ? mcpServer->getPort() : 0;}// --- Entry Point ---juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
Source/Plugin/PluginBridgeProcessor.cpp+114-17