Skip to content

[plugin sdk] Add session action gateway protocol#75578

Closed
100yenadmin wants to merge 19 commits into
openclaw:mainfrom
electricsheephq:split/plugin-sdk-session-actions
Closed

[plugin sdk] Add session action gateway protocol#75578
100yenadmin wants to merge 19 commits into
openclaw:mainfrom
electricsheephq:split/plugin-sdk-session-actions

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented May 1, 2026

Copy link
Copy Markdown
Contributor

Why this matters

OpenClaw plugins increasingly need typed actions that the host can expose and dispatch: approve a workflow, reopen a case, accept extracted data, retry a run, continue an agent after a human decision, or branch a workflow from a structured operator choice.

Without a generic seam, plugin authors end up with two bad options:

  • invent bespoke gateway methods and one-off UI contracts for every product feature; or
  • push product-specific action routers into OpenClaw core.

This PR adds the missing middle layer: plugins register typed session actions once, the Gateway exposes one stable dispatch method, and OpenClaw keeps ownership of schema validation, scope enforcement, stale-plugin safety, and client protocol/codegen.

What kinds of plugins this could support

This seam is intentionally generic. It can support many plugin families without adding plugin-specific action routes to core:

  • Approval and review plugins: approve, reject, request changes, or continue the agent with a typed reason.
  • Support and case-management plugins: escalate, close, reopen, request follow-up, or attach a structured disposition.
  • CRM and sales plugins: mark contacted, accept extracted updates, hand off ownership, or snooze the next step.
  • Task and workflow plugins: claim, retry, confirm completion, or branch the workflow from an operator choice.
  • Ops and incident plugins: suppress an alert, rerun diagnostics, confirm mitigation, or start escalation.
  • UI companion plugins: render action buttons or menus in Control UI, native Apple clients, CLI helpers, or external companion surfaces that all call back through the same Gateway seam.

The important part: the plugin defines the action semantics. OpenClaw owns dispatch, auth, and transport-level enforcement.

New SDK seam

This PR adds:

  • OpenClawPluginApi.registerSessionAction(...)
  • typed action context, payload schema, success/failure results, and optional continueAgent
  • plugins.sessionAction on the Gateway protocol plus regenerated Swift models
  • runtime scope classification that honors action-declared requiredScopes

Example plugin usage:

api.registerSessionAction({
  id: "approve",
  description: "Approve the current workflow",
  requiredScopes: ["operator.approvals"],
  schema: {
    type: "object",
    properties: {
      message: { type: "string" },
    },
  },
  handler: ({ payload, sessionKey }) => ({
    data: {
      approved: true,
      message: payload?.message,
      ...(sessionKey ? { sessionKey } : {}),
    },
    continueAgent: true,
  }),
});

Runtime architecture

flowchart LR
  Plugin["Plugin register()"] --> Registry["Typed session action registry"]
  Client["Gateway client / Control UI / native app / CLI"] --> RPC["plugins.sessionAction"]
  RPC --> Guard["Schema validation + scope classification"]
  Guard --> Dispatch["Registered plugin action handler"]
  Dispatch --> Result["Typed success or failure payload"]
  Result --> Client
Loading

The action is registered once inside the plugin runtime and can then be dispatched from any client surface that speaks the Gateway protocol.

Safety and boundaries

This stays intentionally narrow:

  • action ids, schemas, and duplicate registrations are validated at registration time
  • payloads are validated before handler execution and malformed traffic is rejected
  • dispatch enforces action-declared requiredScopes instead of treating every action like the same write lane
  • unresolved out-of-process callers fall back to the standard operator scope bundle instead of under-scoping to operator.write
  • stale or unloaded plugins are blocked instead of dispatching into dead registry state
  • the upstream ACP live-delivery / streaming defaults already on upstream/main stay preserved in this slice

This is a bounded typed action protocol, not arbitrary plugin-owned gateway method injection.

What changed

  • Added OpenClawPluginApi.registerSessionAction plus SDK exports for action registration, context, and result types.
  • Added registry storage, validation, duplicate detection, loader snapshot/restore support, and plugin test API/captured registration support.
  • Added Gateway protocol schemas/types, generated Swift models, and plugins.sessionAction dispatch.
  • Added dynamic Gateway scope classification so known actions keep their declared least-privilege scopes, while unresolved out-of-process callers fall back to the standard operator scope bundle instead of under-scoping to operator.write.
  • Fixed the shared agent-event bridge teardown so duplicate runtime.ts module instances do not double-dispatch pinned/active registry subscriptions.
  • Preserved the upstream ACP live-delivery / streaming default changes already on upstream/main; this slice stays narrowly focused on typed session-action registration, dispatch, and scope enforcement.
  • Added focused contract coverage for registration validation, payload schema validation, typed success/failure result validation, dispatch auth, stale-plugin blocking, pinned-registry event fanout, and method-scope classification.

Relationship to adjacent seams

This is narrower than attachments, scheduled turns, SessionEntry projection, or run-context lifecycle. It only adds the typed session-action registration/dispatch protocol plus the host scope enforcement that makes it safe to call.

Non-goals

  • Does not render UI on its own; clients still choose how to present actions.
  • Does not replace generic plugin gateway methods or open arbitrary new RPC namespaces.
  • Does not include host-mediated attachments, scheduled turns, derived path facts, SessionEntry projection, finalize retry/run-context lifecycle, or advanced workflow composition fixtures.
  • Does not reopen ACP streaming/live-delivery defaults; it preserves the upstream behavior already on main.

Stack context

Real behavior proof

Behavior or issue addressed:
This fixes the under-scoped least-privilege path for plugins.sessionAction without broadening the seam beyond the session-action protocol. Before this patch, out-of-process callers that could not resolve a local plugin registry entry fell back to operator.write, so actions that correctly declared scopes like operator.approvals failed before reaching the handler. After this patch, known actions still use their declared scopes, unresolved callers fall back to the standard operator scope bundle instead of under-scoping, dispatch still enforces requiredScopes, and typed payload/result validation still rejects malformed traffic.

Real environment tested:
Fresh loopback Gateway started from /Users/lume/openclaw-review-worktrees/pr-75578-rebase with a workspace-loaded proof plugin at /tmp/openclaw-pr75578-proof.4VP2Yu/workspace/.openclaw/extensions/session-action-proof. The runtime used HOME=/tmp/openclaw-pr75578-proof.4VP2Yu/home, OPENCLAW_WORKSPACE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/workspace, OPENCLAW_STATE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/state, and OPENCLAW_CONFIG_PATH=/tmp/openclaw-pr75578-proof.4VP2Yu/config/openclaw.json.

Exact steps or command run after this patch:

HOME=/tmp/openclaw-pr75578-proof.4VP2Yu/home OPENCLAW_WORKSPACE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/workspace OPENCLAW_STATE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/state OPENCLAW_CONFIG_PATH=/tmp/openclaw-pr75578-proof.4VP2Yu/config/openclaw.json pnpm openclaw plugins inspect session-action-proof --runtime --json

HOME=/tmp/openclaw-pr75578-proof.4VP2Yu/home OPENCLAW_WORKSPACE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/workspace OPENCLAW_STATE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/state OPENCLAW_CONFIG_PATH=/tmp/openclaw-pr75578-proof.4VP2Yu/config/openclaw.json pnpm openclaw gateway call plugins.sessionAction --json --params '{"pluginId":"session-action-proof","actionId":"approve","payload":{"message":"post-fix"}}'

HOME=/tmp/openclaw-pr75578-proof.4VP2Yu/home OPENCLAW_WORKSPACE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/workspace OPENCLAW_STATE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/state OPENCLAW_CONFIG_PATH=/tmp/openclaw-pr75578-proof.4VP2Yu/config/openclaw.json node --import tsx <<'NODE'
import { callGateway } from './src/gateway/call.ts';
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from './src/utils/message-channel.ts';
const result = await callGateway({
  method: 'plugins.sessionAction',
  params: {
    pluginId: 'session-action-proof',
    actionId: 'approve',
    payload: { message: 'post-fix' },
  },
  token: 'proof-token',
  clientName: GATEWAY_CLIENT_NAMES.GATEWAY_CLIENT,
  mode: GATEWAY_CLIENT_MODES.BACKEND,
});
console.log(JSON.stringify(result, null, 2));
NODE

HOME=/tmp/openclaw-pr75578-proof.4VP2Yu/home OPENCLAW_WORKSPACE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/workspace OPENCLAW_STATE_DIR=/tmp/openclaw-pr75578-proof.4VP2Yu/state OPENCLAW_CONFIG_PATH=/tmp/openclaw-pr75578-proof.4VP2Yu/config/openclaw.json node --import tsx <<'NODE'
import { callGateway } from './src/gateway/call.ts';
import { GATEWAY_CLIENT_MODES, GATEWAY_CLIENT_NAMES } from './src/utils/message-channel.ts';
try {
  await callGateway({
    method: 'plugins.sessionAction',
    params: {
      pluginId: 'session-action-proof',
      actionId: 'approve',
      payload: { message: 42 },
    },
    token: 'proof-token',
    clientName: GATEWAY_CLIENT_NAMES.GATEWAY_CLIENT,
    mode: GATEWAY_CLIENT_MODES.BACKEND,
  });
  console.log('unexpected success');
} catch (error) {
  console.error(String(error));
  process.exitCode = 1;
}
NODE

Evidence after fix:

$ pnpm openclaw gateway call plugins.sessionAction --json --params '{"pluginId":"session-action-proof","actionId":"approve","payload":{"message":"post-fix"}}'
gateway connect failed: GatewayClientRequestError: scope upgrade pending approval (requestId: f97fd499-4729-4cd9-b7e0-d7dc90334595)
Gateway call failed: GatewayTransportError: gateway closed (1008): pairing required: device is asking for more scopes than currently approved (requestId: f97fd499-4729-4cd9-b7e0-d7dc90334595)

$ node --import tsx <authorized backend proof>
{
  "ok": true,
  "result": {
    "approved": true,
    "message": "post-fix",
    "sessionKey": null,
    "scopes": [
      "operator.admin",
      "operator.read",
      "operator.write",
      "operator.approvals",
      "operator.pairing",
      "operator.talk.secrets"
    ]
  }
}

$ node --import tsx <invalid payload proof>
GatewayClientRequestError: plugin session action payload does not match schema: message: must be string

Observed result after fix:
The paired CLI flow no longer under-scopes plugins.sessionAction to operator.write; it now requests the broader operator scope bundle and hits the existing scope-upgrade approval gate, which preserves pairing/approval enforcement instead of failing with a misleading handler-level missing-scope error. An authorized backend/token caller successfully dispatches the typed session action and receives the typed success payload. A malformed payload is rejected before handler execution with the expected schema error.

What was not tested:
This proof did not run a full end-to-end Control UI or native Apple client invocation against the regenerated Swift models. The Swift surface was regenerated and covered at the protocol/codegen layer in this patch, but the live proof here is intentionally limited to real Gateway registration/dispatch/scope enforcement and typed payload validation.

Validation

  • pnpm protocol:gen
  • pnpm protocol:gen:swift
  • pnpm test src/gateway/method-scopes.test.ts src/gateway/call.test.ts src/agents/tools/gateway.test.ts src/plugins/contracts/session-actions.contract.test.ts
  • pnpm test src/plugins/runtime.channel-pin.test.ts
  • OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test src/plugins/runtime.test.ts src/plugins/runtime.channel-pin.test.ts
  • git diff --check

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime size: XL labels May 1, 2026
@clawsweeper

clawsweeper Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: the author explicitly moved this session-action split into the open Plugin SDK consolidation PR, and that canonical PR now owns the combined implementation, proof, and review thread.

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Review details

Best possible solution:

Consolidate review and any remaining fixes in #80229 instead of keeping this older split branch open as a parallel merge candidate.

Do we have a high-confidence way to reproduce the issue?

Not applicable. This is an additive Plugin SDK/Gateway API PR; current main does not expose plugins.sessionAction, while the PR body supplies branch-level terminal proof for the proposed behavior.

Is this the best way to solve the issue?

Yes. Closing this PR in favor of #80229 is the narrowest cleanup path because the newer open PR explicitly owns this session-action slice plus its combined proof and review context.

Security review:

Security review cleared: No concrete supply-chain or secrets-handling concern is unique to this superseded split PR; the sensitive Gateway scope behavior is now owned by the canonical consolidation review.

What I checked:

  • Author supersession comments: The author twice stated on 2026-05-10 that this PR is superseded by [plugin sdk] Phase 1: consolidate host workflow seams and media extraction runtime #80229, including that the newer branch carries the combined proof and merge-ready consolidation branch.
  • Canonical PR is open and folds this work: The live canonical PR is open, and its body says it folds together this typed session action registration/dispatch slice with related host workflow seams into the Phase 1 Plugin SDK consolidation branch. (564400622821)
  • Current main does not contain the requested Gateway method: Current main's server method list exposes plugins.uiDescriptors but not plugins.sessionAction, so the feature is not implemented on main and should be reviewed through the canonical PR rather than treated as already landed here. (src/gateway/server-methods-list.ts:54, 24edb8414662)
  • Current main plugin SDK surface lacks registerSessionAction: The current plugin API host-hook block includes session extension, UI descriptor, event subscription, run context, and scheduler-job registration, but no registerSessionAction method. (src/plugins/types.ts:2580, 24edb8414662)
  • Canonical PR diff includes the session-action files: The canonical PR file list includes the generated Gateway models, protocol schemas, method scopes, plugin host hook handler, plugin SDK type exports, registry changes, and session-action contract tests that correspond to this split PR's central change. (564400622821)
  • History/provenance pass: Local history/blame is shallow for older feature introduction, but current-main blame/log still routes recent Plugin SDK and gateway surface work through Peter Steinberger, while related merged PR context shows 100yenadmin authored the merged host-hook foundation and adjacent Plugin SDK seams. (src/plugins/host-hooks.ts:103, 24edb8414662)

Likely related people:

  • 100yenadmin: Authored the session-action split and prior merged Plugin SDK host-hook work that this PR extends, including the merged generic host-hook foundation and adjacent session projection/run-context slices in the provided related PR context. (role: feature-history contributor; confidence: high; commits: 1adaa28dc86b, cb3853587576, 8afc9ef73cb5; files: src/plugins/host-hooks.ts, src/plugins/types.ts, src/gateway/protocol/schema/plugins.ts)
  • Peter Steinberger: Recent current-main history and blame are concentrated on Plugin SDK/gateway surface refactors around the files this PR would extend, making him a likely routing candidate for API-shape and consolidation review. (role: recent area contributor; confidence: medium; commits: 24edb8414662, 4f32a32ed676, 429076525860; files: src/plugins/types.ts, src/plugins/host-hooks.ts, src/gateway/server-methods/plugin-host-hooks.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 24edb8414662.

@100yenadmin

Copy link
Copy Markdown
Contributor Author

Fixed in ce5867ca57b. Non-bundled plugins can no longer emit host-owned streams (assistant, tool, approval, error, lifecycle/model, etc.); they can still emit custom plugin-owned streams. Test: src/plugins/contracts/session-actions.contract.test.ts covers blocked assistant spoofing and allowed custom workspace streams. Validation: pnpm test src/plugins/contracts/session-actions.contract.test.ts src/gateway/method-scopes.test.ts, pnpm plugin-sdk:api:check, pnpm lint:core, git diff --check, npm run check:no-conflict-markers. pnpm check:test-types is currently blocked by unrelated fresh-main errors in src/commands/onboard-non-interactive.ts, reproduced across these split branches.

@100yenadmin
100yenadmin marked this pull request as ready for review May 1, 2026 12:39
Copilot AI review requested due to automatic review settings May 1, 2026 12:39
@100yenadmin
100yenadmin force-pushed the split/plugin-sdk-session-actions branch from ce5867c to 709c69a Compare May 1, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Plugin SDK/Gateway seam for typed session actions plus plugin-attributed agent event emission, enabling plugins to register actions that trusted Gateway clients can dispatch via plugins.sessionAction, with per-action operator-scope enforcement and payload/result validation.

Changes:

  • Extends the Plugin SDK API with registerSessionAction(...) and emitAgentEvent(...) (plus exported types) and wires these into the plugin registry/loader snapshots.
  • Implements plugins.sessionAction Gateway handler with request validation, schema validation, per-action scope checks, stale-plugin blocking, and action-result shape validation.
  • Updates Gateway protocol schemas/types (including generated Swift models) and adds focused contract + method-scope coverage.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/plugins/types.ts Exposes new SDK API surface/types (emitAgentEvent, registerSessionAction) via OpenClawPluginApi.
src/plugins/registry.ts Adds session-action registration/validation + wires emitAgentEvent into registry-built plugin APIs.
src/plugins/registry-types.ts Introduces PluginSessionActionRegistryRegistration and adds sessionActions to the registry shape.
src/plugins/registry-empty.ts Initializes sessionActions in the empty registry.
src/plugins/loader.ts Snapshots/restores sessionActions across plugin loader snapshot/restore.
src/plugins/host-hooks.ts Defines session action context/registration/result types and agent-event emit param/result types.
src/plugins/contracts/session-actions.contract.test.ts Adds contract tests for registration validation, dispatch auth/schema checks, result validation, stale plugin blocking, and event emission.
src/plugins/captured-registration.ts Captures session-action registrations and adds a stub emitAgentEvent for captured registrations.
src/plugins/api-builder.ts Extends buildPluginApi wiring with no-op defaults for emitAgentEvent and registerSessionAction.
src/plugins/agent-event-emission.ts Implements plugin-origin-aware agent event emission and reserved-stream restrictions.
src/plugin-sdk/plugin-test-api.ts Adds test API stubs for emitAgentEvent and registerSessionAction.
src/plugin-sdk/plugin-entry.ts Re-exports new session-action types from the plugin entry surface.
src/plugin-sdk/core.ts Re-exports new session-action types from the core SDK surface.
src/gateway/server-methods/plugin-host-hooks.ts Adds plugins.sessionAction Gateway method implementation with validation, auth, schema checks, and result shaping.
src/gateway/server-methods-list.ts Registers plugins.sessionAction as a supported Gateway method.
src/gateway/protocol/schema/types.ts Adds protocol schema type exports for session-action params/result.
src/gateway/protocol/schema/protocol-schemas.ts Registers the new session-action schemas in the protocol schema map.
src/gateway/protocol/schema/plugins.ts Adds session-action schemas and tightens PluginJsonValueSchema to a recursive JSON-value shape.
src/gateway/protocol/index.ts Compiles/exports validator for PluginsSessionActionParams and exports schema/types for session actions.
src/gateway/method-scopes.ts Classifies plugins.sessionAction as dynamically-scoped with a CLI-safe default.
src/gateway/method-scopes.test.ts Tests dynamic classification/authorization behavior for plugins.sessionAction.
docs/.generated/plugin-sdk-api-baseline.sha256 Updates the plugin SDK API baseline hashes to reflect the new public API surface.
apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift Adds generated Swift models for PluginsSessionActionParams/Result.
apps/macos/Sources/OpenClawProtocol/GatewayModels.swift Adds generated Swift models for PluginsSessionActionParams/Result.
CHANGELOG.md Notes the new session-action dispatch and plugin-attributed event emission feature.

Comment thread src/plugins/agent-event-emission.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new Plugin SDK ↔ Gateway “session action” seam, allowing plugins to register typed session actions that trusted clients can dispatch via plugins.sessionAction, with operator-scope enforcement at dispatch time. It also adds a plugin API for emitting plugin-attributed agent events for workflow/UI consumers, plus protocol/schema/client updates and focused contract tests.

Changes:

  • Add OpenClawPluginApi.registerSessionAction(...) and registry storage/snapshot support for session actions.
  • Add Gateway method plugins.sessionAction with request validation, payload schema validation, scope checks, and typed success/failure result handling.
  • Add OpenClawPluginApi.emitAgentEvent(...) (plugin-attributed event emission) plus supporting types/tests and generated protocol client models.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/plugins/types.ts Exports new session-action and agent-event emission types; extends OpenClawPluginApi.
src/plugins/registry.ts Adds session action registration, validation, duplicate detection, and wires emitAgentEvent into plugin API.
src/plugins/registry-types.ts Adds PluginSessionActionRegistryRegistration and registry storage field.
src/plugins/registry-empty.ts Initializes sessionActions to an empty array.
src/plugins/loader.ts Includes sessionActions in registry snapshot/restore.
src/plugins/host-hooks.ts Defines session action context/result/registration types + agent event emit types.
src/plugins/contracts/session-actions.contract.test.ts Contract tests for registration validation, dispatch, payload schema validation, scope enforcement, stale-plugin blocking, and event emission.
src/plugins/captured-registration.ts Captures registerSessionAction calls and stubs emitAgentEvent for test capture.
src/plugins/api-builder.ts Adds emitAgentEvent and registerSessionAction handlers/noops to the plugin API builder.
src/plugins/agent-event-emission.ts Implements plugin-attributed agent event emission with stream restrictions by plugin origin.
src/plugin-sdk/plugin-test-api.ts Extends test plugin API with emitAgentEvent and registerSessionAction.
src/plugin-sdk/plugin-entry.ts Re-exports new session action types from SDK entry surface.
src/plugin-sdk/core.ts Re-exports new session action types from SDK core surface.
src/gateway/server-methods/plugin-host-hooks.ts Implements plugins.sessionAction handler (validation, authZ, schema validation, result shaping).
src/gateway/server-methods-list.ts Registers plugins.sessionAction in the Gateway method list.
src/gateway/protocol/schema/types.ts Adds protocol types for PluginsSessionActionParams/Result.
src/gateway/protocol/schema/protocol-schemas.ts Registers the new session action schemas in ProtocolSchemas.
src/gateway/protocol/schema/plugins.ts Adds JSON-value schema, session action params/result schemas.
src/gateway/protocol/index.ts Exposes schemas/types and compiles validator for PluginsSessionActionParams.
src/gateway/method-scopes.ts Treats plugins.sessionAction as dynamically scoped (CLI-safe default, permissive method-level classification).
src/gateway/method-scopes.test.ts Adds coverage for dynamic classification behavior of plugins.sessionAction.
docs/.generated/plugin-sdk-api-baseline.sha256 Updates SDK API baseline hashes.
apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift Adds generated Swift models for plugins.sessionAction.
apps/macos/Sources/OpenClawProtocol/GatewayModels.swift Adds generated Swift models for plugins.sessionAction (macOS target).
CHANGELOG.md Documents the new plugins.sessionAction and emitAgentEvent support.

Comment thread src/plugins/agent-event-emission.ts
Comment thread src/plugins/contracts/session-actions.contract.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the “session action” Gateway seam for the Plugin SDK: plugins can register typed session actions, clients can dispatch them via plugins.sessionAction, and plugins can emit plugin-attributed agent events via emitAgentEvent.

Changes:

  • Extend OpenClawPluginApi with registerSessionAction(...) and emitAgentEvent(...), and plumb registrations through the plugin registry/loader (snapshot + restore).
  • Add plugins.sessionAction Gateway method with request validation, per-action payload schema validation, action-result validation, and per-action scope enforcement.
  • Add protocol schemas/types + generated Swift models, plus focused contract/unit coverage for registration, validation, auth, and stale-plugin blocking.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/plugins/types.ts Exposes new Plugin API methods and re-exports session-action / event-emission types.
src/plugins/registry.ts Adds session action registration + schema validation and wires emitAgentEvent.
src/plugins/registry-types.ts Extends registry types with sessionActions storage.
src/plugins/registry-empty.ts Initializes sessionActions in empty registries.
src/plugins/loader.ts Includes sessionActions in registry snapshot/restore.
src/plugins/host-hooks.ts Introduces session action context/result/registration types and event-emission param/result types.
src/plugins/contracts/session-actions.contract.test.ts Contract coverage for action registration, schema validation, typed results, auth, stale-plugin blocking, and event emission.
src/plugins/captured-registration.ts Captures session action registrations and stubs emitAgentEvent for captured APIs.
src/plugins/api-builder.ts Adds no-op wiring for emitAgentEvent and registerSessionAction in API builder.
src/plugins/agent-event-emission.ts Implements plugin-attributed agent-event emission with stream scoping rules.
src/plugin-sdk/plugin-test-api.ts Extends test plugin API with emitAgentEvent + registerSessionAction.
src/plugin-sdk/plugin-entry.ts Exports session action types for plugin authors via the SDK entry surface.
src/plugin-sdk/core.ts Re-exports session action types via the main plugin-sdk surface.
src/gateway/server-methods/plugin-host-hooks.ts Adds plugins.sessionAction handler: validates params, enforces scopes, validates payload/results, dispatches handler.
src/gateway/server-methods-list.ts Registers plugins.sessionAction as a gateway method.
src/gateway/protocol/schema/types.ts Adds protocol type aliases for session action params/result.
src/gateway/protocol/schema/protocol-schemas.ts Adds session action schemas to the protocol schema map.
src/gateway/protocol/schema/plugins.ts Defines PluginsSessionAction* schemas and refines PluginJsonValueSchema.
src/gateway/protocol/index.ts Compiles validator for PluginsSessionActionParams and exports new protocol types/schemas.
src/gateway/method-scopes.ts Treats plugins.sessionAction as dynamically scoped with CLI-safe defaults and runtime enforcement.
src/gateway/method-scopes.test.ts Tests dynamic classification/authorization behavior for plugins.sessionAction.
docs/.generated/plugin-sdk-api-baseline.sha256 Updates SDK API baseline hashes.
apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift Adds generated Swift models for session action params/result.
apps/macos/Sources/OpenClawProtocol/GatewayModels.swift Adds generated Swift models for session action params/result.
CHANGELOG.md Documents the new session action dispatch + emitAgentEvent capability.

Comment thread src/plugin-sdk/core.ts
Comment thread src/plugin-sdk/plugin-entry.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c59c3dad98

ℹ️ 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".

Comment thread src/gateway/method-scopes.ts Outdated
@100yenadmin
100yenadmin requested a review from Copilot May 1, 2026 14:55
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Audit follow-up fixed in f405bfd188d: restored the stale/global-side-effect guard for plugin API emitAgentEvent. Non-activating registry loads now return global side effects disabled, and captured APIs from retired/replaced plugin registries return plugin is not loaded instead of emitting events. Test: src/plugins/contracts/session-actions.contract.test.ts (blocks agent events from stale and non-activating plugin API closures). Also regenerated docs/.generated/plugin-sdk-api-baseline.sha256 for the added internal registry lifecycle module.

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 9, 2026
@100yenadmin

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Follow-up fix on head 84d38f18cd258ca0a310e2a2cf4cc75f7c94f373: the audit found a real cross-module runtime.ts listener leak that could double-dispatch pinned/active registry agent-event subscriptions. The fix moves the bridge unsubscribe handle into the shared global runtime state and adds the duplicate-import regression coverage plus the direct repro path to the test plan.

@100yenadmin

Copy link
Copy Markdown
Contributor Author

Superseded by #80229, which folds this session-action slice into the cleanup-first Plugin SDK consolidation branch tied to #80219.

@100yenadmin

Copy link
Copy Markdown
Contributor Author

Superseded by #80229, which now carries the combined proof and merge-ready consolidation branch.

@100yenadmin 100yenadmin reopened this May 10, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 10, 2026
@clawsweeper clawsweeper Bot closed this May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants