Repository navigation
feat(server): octop.extensions entry points for packages built on Octop - #3129
Conversation
|
The extension-point design looks reasonable to me. Before merging, please fix partial startup failure cleanup. If extension A starts successfully and extension B raises, Please track successfully started extensions and shut them down in reverse order on failure, restoring the failed bind to a retryable state. Simply setting the boolean earlier would also shut down extensions that never started. Please add regression tests for “A succeeds, B fails” during both normal startup and first-time binding. This finding is based on static review; I have not run a reproduction. |
Products built on Octop (for example a branded client with its own sign-in and extra tables) can only fork today: there is no way to add routes, background tasks, or public paths without patching Octop's files, and forks drift from upstream fast. A package now declares an entry point in the "octop.extensions" group. Octop loads them once per process and calls whichever optional hooks the object defines: on_startup / on_shutdown around the runtime (shutdown runs first in stop(), while the database is open), configure_app at the end of build_app but before the dashboard catch-all, and public_paths for /api/ paths that skip the JWT or stay open before setup. A broken extension is logged and skipped. Harness tools, skills and channels keep using harness plugins. docs/extensions.md describes the contract.
If extension A started and B raised in on_startup, A's on_shutdown never ran, and a failed first-run bind_control_plane() left the runtime half up with database_bound already true, so a retry did nothing. run_startup_hooks now returns the extensions whose startup finished and, when one raises, shuts the started ones down in reverse order before re-raising. stop() shuts down only those. Opening the control plane (in start() and bind_control_plane()) tears the runtime down and closes the database on failure, so the bind can be retried.
f1a7012 to
d1ec066
Compare
|
Thanks, you're right. Fixed in d1ec066 (rebased on current Startup tracks what started. A failed boot is undone. Tests (
Both tests fail on the previous commit and pass now. Full backend suite: 6257 passed, 48 skipped. |
Summary
Today a product built on Octop can only be a fork. Adding sign-in routes, background tasks, extra tables, or public endpoints means patching Octop's own files, and those forks drift from
developquickly. I maintain one (a multi-bot desktop/mobile client on top of Octop). I would like to turn it into a package that depends on theoctopwheel instead and sends generic fixes back here. This PR is the first, smallest piece: a loader plus lifecycle and HTTP hooks. I am opening it as a proposal, so feedback on the shape is very welcome before anything builds on it.Mechanism. A package declares an entry point in the
octop.extensionsgroup.octop/infra/extensions.pyloads every entry point once per process, in name order. Octop then calls each of these optional hooks only if the object defines it:async on_startup(server)OctopServer._boot_runtimeasync on_shutdown(server)OctopServer.stop, while the database is still open; runs in reverse order, and a failure in one does not stop the othersconfigure_app(app, server)build_app, after the core routers and before the dashboard catch-all, so extension routes and static mounts are not shadowedpublic_paths() -> PublicPathsis_jwt_exempt_path(exact/prefixes) and intosetup_lockdown(setup_exact/setup_prefixes); every path must start with/api/Failure handling. An extension that fails to import is logged and skipped. An exception in
on_startupfails the start, so the product cannot run half-configured.Scope. Harness tools, skills, middleware and channels keep using
octop_harness.plugins. This group is only for things in the Octop server itself.docs/extensions.mddocuments the contract.With no extension installed, nothing changes.
Possible follow-ups (separate PRs, only if this direction is acceptable):
repos(db)onRepoBundle;_build_harness_config.Target branch
develop(feature / fix — default)main(release/*orhotfix/*only)Type of change
Test plan
uv run pytest -m "not live" -n 8: 6240 passed, 46 skipped.make lintandmypyare clean.tests/unit/infra/test_extensions.pychecks that:/api/public paths are rejected;on_startupandon_shutdownrun once each, with the database open.Checklist
CHANGELOG.md(if user-facing). Happy to add one once the shape is agreed.docs/extensions.md