mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-11-28 17:50:35 +00:00
* feat(extensions): recover opt-in workflows unattended after restart Workflow launches from an authenticated browser session may opt in to unattended recovery. The launch captures the session's existing authority ceiling into a bounded, revocable grant on the workflow record; after a Gateway restart the single-Gateway SQLite store resumes recoverable records holding a usable grant through the existing journal-replay path, without a sign-in. Host: restore_delegated_authority (sibling of restore_batch_authority) plus capture_authority on bound handles; the per-operation chokepoint runs an extension-supplied grant validator so expiry and revocation fail closed on every operation, including artifact reads. Clustered stores and uncertain admissions stay on the manual path. * fix(extensions): address review findings on unattended workflow recovery - grant_validator validates the current persisted grant during locked admission, where the entry is not published yet, and switches to the live entry after publication; the previous entries-only lookup 403'd every unattended restore of a perfectly usable grant - delegated restore waits for the AgentRuns host installation signal instead of racing the rest of Gateway startup and failing the scan - cancellation defers grant revocation to the supervisor's post-cleanup save, keeping the delegated handle authorized to cancel children the recovered workflow already admitted - the per-operation delegated guard rechecks the current account disablement, which token_version does not reflect - restore stub revalidates per operation like the real host, with regression tests for all of the above; format the new fixture and condense the extension guidance within its budget * fix(tests): cancel the recovered workflow on its own service The fixture's action handlers are bound to the original service, which stop() already made unavailable; the recovered record lives on the replacement instance, so the cancel must go through replacement.cancel. * fix(extensions): let a cancelled replayed child keep its cancelled outcome The replay fence forced every errored re-dispatched step to needs_reconciliation, including the deterministic case where the error is the workflow stopping after its child was already cancelled and observed. Fence only genuinely uncertain outcomes; a clean cancel of a recovered workflow now ends cancelled like a fresh one.
6.0 KiB
6.0 KiB
Python extensions (deerflow/extensions/)
Loads operator-installed Python extensions and composes what they contribute:
middleware, lifecycle observers, Gateway services and routers, knowledge providers
and full-stack plugins. ExtensionManager (behind deerflow extensions ...)
installs, upgrades and removes them. The public contract is the separate
deerflow_extension_api package. Related docs:
full-stack plugins,
extension Agent runs,
model invocation,
knowledge contract. Authoring guide:
examples/README.md.
Verify
cd backend
python -m pytest tests -q -k "extension or plugin"
make test-blocking-io
Manager tests create temporary Git repositories with an empty repository-local hook directory, so they never run a developer's or CI's Git hooks.
Trust model
- Extension code runs with Gateway privileges. It is trusted, not sandboxed.
For that reason the
plugins:list inconfig.yamlis read at startup only and has no online write API. Everything a Gateway API can edit lives elsewhere. - Source checks prevent accidents, not attacks. Snapshot filters (credential files, Git metadata) and source-form rules protect an operator from a packaging mistake. They do not make an untrusted source safe.
- A required plugin that cannot load stops startup. An optional one fails open
with a diagnostic that names the extension.
requiredis an explicit operator opt-in. - Unsupported registration returns False. An old host must tell the extension that a contribution kind is unknown. Silently ignoring it hides a missing feature.
Install, upgrade, remove
- One transaction over four things. The manager changes
pyproject.toml,uv.lock, the managedplugins:block and the source snapshot together under.deer-flow/extension-manager.lock. A failure restores all of them, including file permission bits, and resynchronizes the environment. - A cleanup error never replaces the original error. This includes interruptions during rollback.
- Stop on a concurrent external edit. When recovery finds that someone else changed the dependency files or the config, it reports that and does not overwrite the edit.
- Local directories are installed as snapshots under
backend/extensions/sources/, not as editable links. The production image must be able to rebuild from the repository alone, so a source that only exists on the operator's machine (local wheel,file://, a path outside the project) is rejected, and the lock is audited for such references after every change. - Only the manager updates
backend/uv.lockfor extensions. Production container startup never resolves or installs an extension. - The uv version is pinned in one place (
UV_IMAGEinbackend/Dockerfile), and CI uses the same version. A newer uv elsewhere can write a lock that the production image cannot read. - Every mutation needs a Gateway restart, because plugins load once at startup.
- The
plugins:block is rewritten in place. Its boundaries come from the YAML parser, not from a text pattern, so that a neighbouring section with an unusual key is never replaced. A config with duplicate top-levelplugins:keys is rejected.
Composition
extensions/sits belowagents/in the import graph. Do not import the middleware layer here at module level. Resolve middleware classes at composition time.extensions/ordering.pyowns the ordering invariants and validates the final composed chain. Contributed middleware declares a semantic placement; it is composed at one final point.- A failing extension does not fail the run. Contributed middleware is wrapped
by
IsolatedMiddleware, and observer failures are contained per observer. - Cancellation is the exception. A genuine cancellation of the run propagates
through a contributor. A
CancelledErrorthat the contributor raised for its own reasons is contained like any other failure. - One extension snapshot per run. The run worker loads the extension set once and passes that same object to the task store and to delegated subagents, so a run never mixes two extension generations.
- The assembly descriptor is the record of what was built. It fingerprints the resolved model, prompt hash, tool list, middleware order and policies. A wrapper that hides a contribution's policy parameters makes two different assemblies look identical.
- Shutdown stops accepting detached observations before the memory flush, so an accepted observation is never registered after shutdown began.
- Search indexes are rebuildable. The Gateway rechecks each indexed hit against the current owner-visible message before returning text.
Full-stack plugins and host access
- Browser fields are allowlisted and plugin JavaScript is served by content hash. Plugin actions require an authenticated session.
- Agent run control goes through the
AgentRunshandle. The Gateway binds the principal, caps the permissions and revokes the handle before shutdown. Do not give an extension the globalRunManager, aModelInvokeras a substitute, or a user ID that the caller supplied. - Handles are scoped per plugin namespace, so idempotency keys of two plugins cannot collide.
configuration_revisionnever exposes raw configuration. It returns an HMAC. Sets hash the same way across process hash seeds; ordered lists keep their order.- Restorable authority is captured, never created. Restores revalidate it.
Extension-first exceptions
A feature that ships in core although an extension hook could express it is recorded here with the reason.
- Project-shelf summaries (
projects/summaries.py). The summary column, the<documents>index and the shelf tool output are core-owned, and a split design would have to enforce the sanitization invariants across a public write interface.