[plugin sdk] Consolidate workflow seams and fixtures#73384
[plugin sdk] Consolidate workflow seams and fixtures#73384100yenadmin wants to merge 97 commits intoopenclaw:mainfrom
Conversation
|
Codex review: needs changes before merge. What this changes: The PR adds generic Plugin SDK workflow host seams, Gateway Required change before merge: A narrow automated repair can add the missing changelog entry; broader API approval and unresolved CI failures still need normal maintainer review after that mechanical fix. Security review: Security review cleared: Dedicated security review found no concrete security or supply-chain regression in the diff; sensitive paths such as workflow dispatch, attachments, scheduler cleanup, CI, lockfile, and generated clients were inspected. Review findings:
Review detailsBest possible solution: Add the missing release-note entry, resolve the exact-head CI failures, and continue reviewing this PR as the implementation vehicle for the generic workflow layer while keeping the recipe documentation in the separate docs PR. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature PR, but the current-main comparison is high-confidence: current main lacks the workflow SDK methods and Is this the best way to solve the issue? Yes for the architecture direction: additive Plugin SDK/Gateway seams with contract fixtures are the maintainable path for this workflow surface. No for merge-readiness as-is because repo policy still requires a changelog entry and exact-head CI must be green. Full review comments:
Overall correctness: patch is correct Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 4eec2843cd0c. |
d0e45df to
db15c9c
Compare
Greptile SummaryThis consolidated PR builds workflow seams on top of the already-merged Confidence Score: 4/5Safe to merge; changes are additive, well-tested, and only carry a minor style nit. All findings are P2. The PR is thoroughly tested with contract tests covering validation, cleanup, scheduling, and finalize retry semantics. No logic errors, security issues, or correctness problems were found in the Gateway handler, cleanup paths, or retry budget logic. No files require special attention beyond the import style nit in src/agents/cli-runner/prepare.ts. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/cli-runner/prepare.ts
Line: 35-37
Comment:
**Duplicate imports from the same module**
Three separate import declarations reference `"../pi-embedded-runner/run/attempt.prompt-helpers.js"`. These should be collapsed into a single import to follow the module-import style used everywhere else in the file.
```suggestion
import {
forgetPromptBuildDrainCacheForRun,
resolvePromptBuildHookResult,
resolveAttemptPrependSystemContext,
} from "../pi-embedded-runner/run/attempt.prompt-helpers.js";
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "chore(plugin-sdk): refresh rebased API b..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
This PR consolidates the post-#72287 plugin host-hook follow-ups by landing workflow seams (session actions, outbound attachments, scheduling, finalize-retry), executable fixture proofs, and the companion docs/recipes together on current main.
Changes:
- Add workflow-oriented Plugin SDK seams: session action dispatch (Gateway method), host-mediated session scheduling, outbound session attachments, and plugin-attributed agent event emission.
- Harden host runtime behavior: prioritized next-turn injections, trusted policy session-state reads, bounded finalize-retry budgeting, and safer scheduler cleanup semantics.
- Expand contract tests/fixtures and publish a large recipes doc, plus regenerated protocol/Swift models and SDK API baseline.
Reviewed changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/plugins/types.ts | Exports new workflow seam types and adds SDK methods to OpenClawPluginApi. |
| src/plugins/trusted-tool-policy.ts | Adds plain-object guarding for param rewrites and injects getSessionExtension into trusted policy context. |
| src/plugins/runtime.ts | Moves agent-event bridge unsubscribe tracking into global registry state. |
| src/plugins/runtime-state.ts | Extends RegistryState to store agent event unsubscribe handle. |
| src/plugins/registry.ts | Registers session actions, wires workflow helpers (emit event / schedule turn / send attachment), validates session-action JSON schema. |
| src/plugins/registry-types.ts | Adds sessionActions registry typing. |
| src/plugins/registry-empty.ts | Initializes sessionActions array in empty registry. |
| src/plugins/host-hooks.ts | Introduces workflow types: session actions, attachments, scheduling, and agent event emit params/results. |
| src/plugins/host-hook-workflow.ts | Implements host-mediated workflow helpers (emit events, attachments via outbound, schedule session turns via cron). |
| src/plugins/host-hook-turn-types.ts | Adds priority to next-turn injections. |
| src/plugins/host-hook-state.ts | Validates/persists injection priority, sorts by priority then time, adds sync session-extension read helper, defaults config sourcing. |
| src/plugins/host-hook-runtime.ts | Adds bounded wait for terminal event handlers, improves scheduler cleanup exclusions and preserve semantics. |
| src/plugins/host-hook-cleanup.ts | Extends cleanup to also remove runtime-only scheduler jobs while avoiding registry-owned duplicates. |
| src/plugins/hooks.ts | Adds hook-runner context mapping (inject getSessionExtension) and propagates finalize-retry metadata through result merging. |
| src/plugins/hook-types.ts | Extends before_agent_finalize result with structured retry request; extends tool context with optional getSessionExtension. |
| src/plugins/contracts/host-hooks.contract.test.ts | Adds contract coverage for session actions, workflow failures being non-fatal, bounded terminal cleanup wait, priority validation, and scheduler cleanup edge cases. |
| src/plugins/contracts/advanced-workflow-fixtures.ts | Adds reusable “realistic archetype” fixture plugin registrations that exercise composed seams. |
| src/plugins/contracts/advanced-workflow-fixtures.contract.test.ts | End-to-end fixture proofs across approval/action dispatch, policy gates, scheduling + cleanup, attachments, and bounded finalize retry. |
| src/plugins/captured-registration.ts | Captures new workflow registrations in the test capture harness (actions, scheduling, attachments, event emit). |
| src/plugins/api-builder.ts | Adds no-op wiring for new SDK methods when not provided by host. |
| src/plugin-sdk/plugin-test-api.ts | Updates test API stub with new workflow methods. |
| src/plugin-sdk/plugin-entry.ts | Re-exports new workflow types from the SDK entry surface. |
| src/plugin-sdk/core.ts | Re-exports new workflow types from SDK core. |
| src/gateway/server-methods/plugin-host-hooks.ts | Adds plugins.sessionAction Gateway method with schema validation and typed success/failure responses. |
| src/gateway/server-methods-list.ts | Registers plugins.sessionAction in the server method list. |
| src/gateway/protocol/schema/types.ts | Adds protocol types for session-action params/result. |
| src/gateway/protocol/schema/protocol-schemas.ts | Registers new session-action schemas in protocol schema map. |
| src/gateway/protocol/schema/plugins.ts | Defines JSON-value schema for plugin payloads, extends UI descriptor schema, and adds session-action schemas. |
| src/gateway/protocol/index.ts | Adds AJV validator for PluginsSessionActionParams and exports schema. |
| src/gateway/method-scopes.ts | Adds plugins.sessionAction under write-scoped methods. |
| src/config/sessions/types.ts | Persists optional injection priority in session store type. |
| src/agents/pi-tools.before-tool-call.integration.e2e.test.ts | Loosens assertion to expect.objectContaining(...) for tool context shape. |
| src/agents/pi-embedded-runner/run.ts | Clears finalize-retry budget on run end alongside other per-run caches. |
| src/agents/harness/lifecycle-hook-helpers.ts | Implements bounded finalize-retry budgeting keyed by run/idempotency, with pruning and explicit clearing. |
| src/agents/harness/lifecycle-hook-helpers.test.ts | Adds tests verifying finalize-retry budget clearing by run id. |
| src/agents/cli-runner/prepare.ts | Avoids loading transcript messages unless needed by hooks; ensures prompt-drain cache cleanup in finally. |
| docs/plugins/host-hooks-examples.md | Publishes consolidated host-hook recipes/examples page. |
| docs/docs.json | Adds the new recipes page to docs navigation. |
| docs/.i18n/glossary.zh-CN.json | Adds glossary entries for the new recipes page labels. |
| docs/.generated/plugin-sdk-api-baseline.sha256 | Updates SDK API baseline checksums. |
| apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift | Regenerates Swift models for descriptor fields + session-action RPC types. |
| apps/macos/Sources/OpenClawProtocol/GatewayModels.swift | Regenerates Swift models for descriptor fields + session-action RPC types. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db15c9c0bb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d6fe5ebed
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 97f73f9c26
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Closing this consolidated stack in favor of individual hook/seam PRs. The code has been through hardening, but the combined PR became too large and brittle against fast-moving upstream main plugin sprint leading to messy additional debugging. Splitting it back into focused fresh-main PRs should reduce reviewer load, isolate CI failures, and make each generic SDK seam independently mergeable even if main shifts. |
|
Closing this consolidated stack in favor of individual hook/seam PRs. The code has been through hardening, but the combined PR became too large and brittle against fast-moving upstream main. Splitting it into focused fresh-main PRs should reduce reviewer load, isolate CI failures, and make each generic SDK seam independently mergeable. Replacement slices opened so far:
The advanced workflow fixture slice should be filed after these seams land on main; opening it now from fresh main would fail before the public seams exist, while stacking or duplicating those seams would recreate the brittle consolidated PR this split is replacing. Docs remain split in #74853; foundation remains merged #72287. |
Summary
This PR consolidates the implementation/test follow-up work that was stacked behind the now-merged generic host-hook foundation in #72287. Docs split update: the large host-hook recipe page/nav/glossary work has been moved to the separate docs-only PR #74853, so this PR now carries implementation, tests, generated protocol/API baselines, and QA hardening only (~4,542 additions / 151 deletions across 68 files).
Feature / LOC Breakdown
Approximate line counts from the current consolidated diff against
main(after #72287 merged). These are grouped by original follow-up PR / feature area so maintainers can review the stack by purpose, not just by file list. Production counts include generated client/API model updates where they are part of the shipped protocol surface; test counts include contract fixtures and QA/CI hardening tests; docs counts include recipe docs, nav, glossary, and the generated SDK API baseline hash.#72287 has merged, so keeping the remaining work split across three stale/stacked PRs now creates more review churn than clarity. This replacement keeps the original commit-level review slices, but presents them as one follow-up PR based on current
main, with the implementation and executable fixture proofs here and the docs/examples isolated in #74853.Process note: this stack went through roughly two days of GPT-5.5/Codex-assisted hardening plus maintainer, bot, and adversarial review loops. The earlier follow-ups were repeatedly tested, fixed, and restacked. Consolidating them now is meant to stop the hardening loop from scattering new feedback across stale PR diffs while preserving the original detail and review evidence.
This remains generic plugin SDK work. It does not add Plan Mode product code, prompts,
/planbehavior, Telegram-specific behavior, or product-specific UI. #71676 remains a parity oracle only; #71731 is the RFC context.Relationship To The Merged Foundation
#72287 established the generic host-hook foundation: session extension storage/projection, queued injections, trusted tool policies, tool metadata, control UI descriptors, lifecycle/event subscriptions, run-context helpers, scheduler ownership cleanup, Gateway schemas, and SDK exports.
This PR builds on that merged foundation with host-mediated workflow affordances that real plugins need after they can register hooks:
Why Consolidate Now
The old PRs were useful while #72287 was still unmerged because they separated foundation, workflow, proof fixtures, and docs. After #72287 merged, that split became counterproductive:
main, not three partially inherited views.This branch is the current comparison surface. The old PRs should be closed after this PR is opened and linked.
Review Order
The commits intentionally preserve the old review slices. Suggested review order:
feat(plugin-sdk): add workflow host seams.test(plugin-sdk): add advanced workflow fixtures.chore(plugin-sdk): refresh consolidated API baselinechore(plugin-sdk): refresh rebased API baselinetest(security): isolate windows acl os mockThe former docs/recipe commit group is now isolated in #74853.
Runtime Architecture
What Future Plugins Can Now Do
Examples that are intentionally generic, not Plan Mode-specific:
deploy.approveaction, requires operator approval scope, stores the pending deployment in plugin-owned session state, and usescontinueAgentafter an approval action.SDK And Gateway Surface Added In This PR
SDK / plugin API
Gateway / protocol
Runner / agent lifecycle
Scheduler / cron
Docs / recipes
The large recipe page, docs navigation entry, and glossary entry were split to #74853. This PR keeps the implementation/tests/generated API surface only.
File-Group Changelog
SDK/API
src/plugins/host-hooks.ts: expands the generic hook types with workflow action, outbound, scheduler, and retry concepts.src/plugins/types.ts: exposes additive plugin API types for workflow seams.src/plugin-sdk/core.ts,src/plugin-sdk/plugin-entry.ts,src/plugin-sdk/plugin-test-api.ts: project the new SDK methods into public plugin entry/test surfaces.docs/.generated/plugin-sdk-api-baseline.sha256: regenerated after the consolidated API surface was verified.Registry/runtime
src/plugins/registry.ts: captures workflow registrations, validates schemas, dispatches session actions, and wires cleanup.src/plugins/registry-types.ts,src/plugins/captured-registration.ts,src/plugins/runtime-state.ts: add durable capture/runtime typing for workflow hooks.src/plugins/host-hook-runtime.ts,src/plugins/host-hook-state.ts,src/plugins/host-hook-cleanup.ts: scope run context, side effects, lifecycle cleanup, and scheduler ownership cleanup.src/plugins/runtime.ts,src/plugins/registry-empty.ts: keep empty registries and runtime state compatible with the new surface.Workflow bridge
src/plugins/host-hook-workflow.ts: centralizes session action dispatch, attachment delivery, scheduled turn registration, and workflow helper behavior.src/agents/harness/lifecycle-hook-helpers.ts: factors finalize retry helper behavior so retry is bounded and testable.src/agents/pi-embedded-runner/run.ts: integrates finalize retry requests into the runner path.src/agents/cli-runner/prepare.ts: keeps prompt prep lazy when no prompt-consuming hooks are present.Gateway/protocol
src/gateway/server-methods/plugin-host-hooks.ts: adds Gateway methods for plugin workflow/session action calls.src/gateway/server-methods-list.ts,src/gateway/method-scopes.ts: wires method registration and scope metadata.src/gateway/protocol/schema/plugins.ts,src/gateway/protocol/schema/protocol-schemas.ts,src/gateway/protocol/schema/types.ts,src/gateway/protocol/index.ts: adds typed schemas and exported protocol entries.apps/macos/Sources/OpenClawProtocol/GatewayModels.swiftandapps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift: generated client model updates for the additive protocol surface.Policy/catalog hardening touched by workflow seams
src/plugins/trusted-tool-policy.ts: keeps policy parameter handling plain-object guarded and compatible with workflow use.src/agents/pi-tools.before-tool-call.integration.e2e.test.ts: retains coverage around intentional policy blocks as blocked results rather than generic tool execution failures.Contract tests and fixtures
src/plugins/contracts/host-hooks.contract.test.ts: expands contract coverage for workflow registration, validation, cleanup, scheduling, queued injection priority, side effects, and Gateway normalization.src/plugins/contracts/advanced-workflow-fixtures.ts: adds reusable fixture plugin archetypes.src/plugins/contracts/advanced-workflow-fixtures.contract.test.ts: proves approval, policy gate, background monitor, artifact reply, and finalize retry flows through executable fixtures.src/agents/harness/lifecycle-hook-helpers.test.ts: verifies bounded finalize retry semantics.CI stabilization
src/security/windows-acl.test.ts: adds explicit module reset before importing the Windows ACL module under test. This is not part of the plugin SDK surface; it keeps the broadcore-unit-fast-supportCI shard deterministic after currentmainstarted cachingnode:osbefore this test mock in the full shard.Docs
Hook Hardening Matrix
Before / After Examples
Scheduled turns stay cron-compatible
Before, a plugin schedule helper could produce payloads with default delivery metadata that the closed cron schema did not accept.
After, scheduled session turns only send cron-compatible fields:
Session action validation fails deterministically
Before, malformed action outputs could surface as generic runtime failures.
After, invalid action registration or invalid action results are rejected through typed plugin-action errors:
Scheduler cleanup is owner-safe
Before, stale cleanup could be too broad when old and new scheduler records shared job ids.
After, cleanup exclusions are keyed by owner and job id. A plugin reload can preserve its active jobs, while disable/reset/delete still removes plugin-owned scheduled state.
Finalize retry is bounded
Before, a plugin that wanted to repair a final reply had no generic host-mediated finalize retry seam.
After, workflow plugins can request a bounded retry through the finalize hook path, and the helper tests prove retries clear their budget rather than looping indefinitely.
Example Plugin Shapes
Deploy approval plugin
Budget guard plugin
SLA watcher plugin
Artifact responder plugin
Removed Or Refactored Code
No Plan Mode product code is added here. No Plan Mode prompts,
/plancommand behavior, Telegram routing, local installer patches, arbitrary browser JS, or Plan Mode-specific UI cards are introduced.Refactors/removals are limited to keeping the generic workflow surface production-safe:
src/plugins/host-hook-workflow.tsrather than scattering session action, attachment, and scheduling paths through Gateway/runner code. Risk: one module carries more responsibility. Mitigation: focused contract tests cover validation and output normalization.src/agents/harness/lifecycle-hook-helpers.tsto make bounded retry explicit. Risk: runner integration changes. Mitigation: lifecycle helper tests and host-hook contract coverage.Validation
Local validation on this consolidated branch:
Maintainer Checklist
mainafter [plugin sdk] Add generic plugin host-hook contracts #72287.Rollback: revert this PR. No DB migration is expected. The surfaces are additive; plugin-owned state and scheduled jobs are host-owned and cleanup/ignore paths are covered by the foundation plus this follow-up.
Issue / RFC Linkage