hataa c18df580f6
feat(extensions): recover opt-in workflows unattended after restart (#8289)
* 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.
2026-11-18 10:46:20 +08:00
..

Develop an extension from an existing example

Start with the smallest example that covers your extension. Each directory is an independent Python package using the public deerflow-extension-api contract.

Start here What it demonstrates
Extension example Middleware, task lifecycle, model observations, services, and HTTP routes. Start here for backend extensions.
Conversation bookmarks A browser page, conversation action, backend actions, packaged resources, and a model tool. Start here for full-stack plugins.
Agent teams Full Agent orchestration. Use this after the basic contribution and lifecycle patterns are familiar.

Additional examples cover Office file previews, text-list classification, context pruning, advisory screening of fetched content, sectioned long-form report writing, and evidence-gated skill self-evolution.

Describe the extension

Package deerflow-extension.json beside the entrypoint's Python module (beside __init__.py for a package). Capability Center renders this public description without requiring a browser module. Use the full-stack plugin namespace as id, or a unique stable ID for a backend-only extension. A v1 document requires an ID, at least one locale, and a nonempty title, description (purpose) and usage list in every supplied locale. requirements and docs_url are optional; omit requirements when none apply. Keep secrets and deployment configuration out of this file. Names, purposes and instructions are authored by the package; loaded/enabled state and registered tools come from the host.

{
  "schema_version": 1,
  "id": "company.helper",
  "locales": {
    "en-US": {
      "title": "Task statistics",
      "description": "Collect tool-call statistics during tasks.",
      "usage": [
        {"title": "Run a task", "description": "Statistics are collected automatically after activation."}
      ]
    }
  }
}

The packaging checker validates this file when present and detects omitted wheel resources. Older packages without it remain compatible. Invalid optional copy produces a startup diagnostic while the working extension remains available. Gateway reads copy at startup only, after successful registration. Disabled and failed packages are not imported for documentation; a catalog entry alone does not prove activation. A documented backend extension with actual registrations appears in discovery even if it supplies no full-stack plugin.

For bundled examples, update their package files and run python scripts/sync_extension_documentation.py from the repository root. The generated frontend snapshot supplies descriptions before installation; installed package copy takes precedence. Backend tests check that the snapshot is current.

Edit, test, check, then install

  1. Copy the selected example outside the DeerFlow checkout. Rename its Python package, distribution and deerflow.extensions entry point. For a full-stack plugin, also choose its own namespace and browser module name.

  2. Follow the example's README to configure its dependencies and run its tests. Keep package behavior tests alongside the extension. For a bundled example with a tests/ directory, CI installs the package with its dev extra next to this checkout's deerflow-extension-api, then runs pytest, ruff check and ruff format --check.

  3. From the DeerFlow checkout root, prepare the backend environment with make -C backend install, then check the package:

    uv run --project backend --no-sync python scripts/check_extension.py /absolute/path/to/your-extension
    

    To try the checker on an unchanged example:

    uv run --project backend --no-sync python scripts/check_extension.py examples/deerflow-extension-bookmarks
    
  4. Follow that example's deployment and try-it instructions. Restart Gateway, refresh the browser when applicable, and exercise the installed feature. Use make extension-upgrade SOURCE=/absolute/path/to/your-extension to apply later source edits: local installs are snapshots.

What the checker covers

The script builds a wheel in a temporary directory, checks exactly one extension entry point and its packaged Python module, parses packaged Python syntax, and checks that the API dependency range accepts this checkout's contract version. It validates conventional ui_manifest.json resources with the same validator used by Gateway, including detecting manifests left out of the wheel in flat or src/ layouts. A custom manifest filename needs an explicit wheel-relative path:

uv run --project backend --no-sync python scripts/check_extension.py /absolute/path/to/your-extension --manifest your_package/resources.json

The build executes the package's build backend, so check trusted sources. The checker does not import the extension, call install(), install the extension, or change deployment configuration. Registration/configuration behavior and the @extension version marker are verified when loading the plugin; continue to run the package tests and the installed feature after packaging checks pass.