Repository navigation
[Plugins|Runtime] Run a plugin in its own process - #2082
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
# Conflicts: # docs/architecture/data-model.md
Summary
run_plugin(run_id)on a newpluginsHuey queue startspython -S -m surfsense_plugin_sdk.runfrom the installed folder, and the run'splugin_runsrow goes fromqueuedtorunningtosucceeded, or tofailedwithexit <code>. It keeps the last 16 KiB of the plugin's output as the log tail. The plugin writes through the app's API while it runs, so nothing is imported afterwards.modules/plugins/:models.py(PluginRun),tasks.py,plugin_interpreter.py, andrunner/(job.pyfor the row,plugin_process.pyfor the process,plugin_environment.pyfor the environment). Migration0019addsplugin_runs.SURFSENSE_LOCAL_variable reaches it, and the API address comes from the worker's ownSURFSENSE_LOCAL_HOSTandSURFSENSE_LOCAL_PORT.worker.py pluginsdrains the queue with four threads; a fifth run waits asqueued. Electron does not start this worker yet.-Shides the packages installed beside the plugin's Python. In development that is the backend's venv, or the CLI's undersurfsense-plugins invoke. The runner,invokeand the SDK's own tests all use it, and the protocol, SDK and CLI docs say so.run_plugin(run_id):document_metadata;json.py, the app's packages, and its own pid;worker.py pluginsprocess running four at a time;plugins/exampleend to end. That test skips unlessinvokehas installed the example's dependency.plugins/core/sdk/**changes.data-model.mdlistsplugin_runsand the third queue.Follows #2081
High-level PR Summary
This PR implements the plugin runtime system that executes plugins as isolated processes. The worker spawns a plugin as
python -S -m surfsense_plugin_sdk.runin its own environment, tracks its lifecycle through a newplugin_runstable (status fromqueuedtorunningtosucceeded/failed), and captures the last 16 KiB of output. Plugins communicate with the app through the existing API during execution, with the worker committing transactions before spawn to avoid deadlocks. A newpluginsHuey queue with 4 worker threads handles concurrent runs, and-Sisolates plugins from the backend's packages in development.⏱️ Estimated Review Time: 30-90 minutes
💡 Review Order Suggestion
docs/proposals/plugins/runtime/01-process.mdsurfsense_local/backend/modules/plugins/models.pysurfsense_local/backend/alembic/versions/0019_plugin_runs.pydocs/architecture/data-model.mdsurfsense_local/backend/shared/queue.pysurfsense_local/backend/modules/plugins/plugin_interpreter.pysurfsense_local/backend/modules/plugins/runner/plugin_environment.pysurfsense_local/backend/modules/plugins/runner/plugin_process.pysurfsense_local/backend/modules/plugins/runner/job.pysurfsense_local/backend/modules/plugins/tasks.pysurfsense_local/backend/worker/consumer.pysurfsense_local/backend/worker.pysurfsense_local/backend/shared/db.pysurfsense_local/backend/shared/config.pysurfsense_local/backend/modules/plugins/__init__.pysurfsense_local/backend/modules/plugins/runner/__init__.pysurfsense_local/backend/tests/integration/conftest.pysurfsense_local/backend/tests/integration/plugins/conftest.pysurfsense_local/backend/tests/integration/plugins/test_run_plugin.pysurfsense_local/backend/tests/integration/plugins/test_plugins_worker.pysurfsense_local/backend/tests/integration/plugins/test_run_the_example.pysurfsense_local/backend/tests/conftest.pysurfsense_local/backend/tests/integration/events/test_events.pyplugins/core/sdk/surfsense_plugin_sdk/run/__main__.pyplugins/core/sdk/tests/conftest.pyplugins/core/cli/surfsense_plugin_cli/invoke/plugin/run_plugin.pyplugins/core/cli/tests/invoke/test_running.pyplugins/README.mddocs/proposals/plugins/01-protocol.mddocs/proposals/plugins/02-extending.mddocs/proposals/plugins/cli/01-author-commands.mddocs/proposals/plugins/python/01-interpreter.mddocs/proposals/plugins/sdk/01-library.md.github/workflows/desktop-tests.yml