Skip to content

Refactor channel approval capability seams#58634

Merged
gumadeiras merged 9 commits into
mainfrom
codex/approval-capability-seam
Apr 1, 2026
Merged

Refactor channel approval capability seams#58634
gumadeiras merged 9 commits into
mainfrom
codex/approval-capability-seam

Conversation

@gumadeiras

Copy link
Copy Markdown
Member

Summary

  • add a canonical approvalCapability seam with generic capability/adapter resolution and partial-migration fallback
  • move shared approval policy and native runtime helpers into the plugin SDK/core path
  • migrate Discord, Slack, and Telegram approval flows onto the shared capability/runtime seams and tighten regression coverage

Testing

  • pnpm test -- src/channels/plugins/approvals.test.ts src/infra/channel-approval-auth.test.ts src/infra/exec-approval-surface.test.ts src/auto-reply/reply/commands.test.ts extensions/slack/src/approval-native.test.ts extensions/slack/src/monitor/exec-approvals.test.ts extensions/telegram/src/channel.test.ts extensions/telegram/src/exec-approvals.test.ts
  • pnpm tsgo
  • pnpm build

Copilot AI review requested due to automatic review settings April 1, 2026 01:00
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: slack Channel integration: slack channel: telegram Channel integration: telegram size: XL maintainer Maintainer-authored PR labels Apr 1, 2026

@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: aa064c824d

ℹ️ 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 extensions/telegram/src/exec-approvals.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 canonical approvalCapability seam for channel plugins and refactors native approval delivery/auth to use shared SDK helpers, with compatibility fallbacks for partially migrated plugins.

Changes:

  • Add approvalCapability to the channel plugin contract and implement generic resolution/merging with legacy auth + approvals fields.
  • Move/shared approval helpers into plugin-sdk/approval-runtime (client profile helpers, native routing helpers, native runtime factory).
  • Migrate Discord/Slack/Telegram approval flows onto the shared capability/runtime seams and expand regression coverage + SDK docs/baselines.

Reviewed changes

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

Show a summary per file
File Description
src/plugin-sdk/channel-contract.ts Re-export ChannelApprovalAdapter/ChannelApprovalCapability via plugin SDK contract entrypoint.
src/plugin-sdk/approval-runtime.ts Export new approval capability builders and shared native routing/runtime helpers.
src/plugin-sdk/approval-native-helpers.ts Add SDK helpers to resolve origin targets + approver DM targets for native approval delivery.
src/plugin-sdk/approval-native-helpers.test.ts Tests for the new native routing helper factories.
src/plugin-sdk/approval-delivery-helpers.ts Introduce canonical capability builder + split/compat helpers; keep legacy adapter wrapper.
src/plugin-sdk/approval-delivery-helpers.test.ts Tests for capability builder + legacy split compatibility behavior.
src/plugin-sdk/approval-client-helpers.ts Add shared exec-approval client/profile helpers (targets matching, filters, prompt suppression).
src/plugin-sdk/approval-client-helpers.test.ts Tests for shared exec-approval client/profile helpers.
src/infra/exec-approval-surface.ts Read approval availability + DM-route state via resolved approval capability/adapter.
src/infra/exec-approval-surface.test.ts Cover approvalCapability fallback/merge behavior in initiating surface + DM route detection.
src/infra/channel-approval-auth.ts Resolve /approve authorization via approvalCapability (with legacy fallback).
src/infra/channel-approval-auth.test.ts Add test ensuring approvalCapability overrides legacy auth wiring.
src/infra/approval-native-runtime.ts Add createChannelNativeApprovalRuntime to unify native delivery hooks with shared runtime.
src/infra/approval-native-runtime.test.ts Tests for new native runtime factory behavior (kind/content propagation, expiry).
src/channels/plugins/types.ts Export ChannelApprovalCapability type from plugins types module.
src/channels/plugins/types.plugin.ts Add approvalCapability?: ChannelApprovalCapability to channel plugin type.
src/channels/plugins/types.adapters.ts Define ChannelApprovalCapability (adapter + approval-auth hooks).
src/channels/plugins/index.ts Export resolveChannelApprovalCapability from plugin registry index.
src/channels/plugins/approvals.ts Implement capability resolution/merge with legacy auth + approvals.
src/channels/plugins/approvals.test.ts Tests for capability resolution fallbacks + merging rules.
src/auto-reply/reply/commands.test.ts Add Signal /approve authorization regression and adjust Telegram denial expectations.
src/auto-reply/reply/commands-approve.ts Refactor approval method selection/fallback and centralize submit error formatting.
extensions/telegram/test-support.ts Expose approvalCapability in Telegram test plugin and keep legacy split adapter for compat.
extensions/telegram/src/exec-approvals.ts Migrate Telegram exec approval auth/profile logic to shared SDK profile helpers.
extensions/telegram/src/exec-approvals-handler.ts Switch Telegram handler to createChannelNativeApprovalRuntime and shared request handling.
extensions/telegram/src/channel.ts Replace legacy approvals/auth wiring with approvalCapability (plus render adapter).
extensions/telegram/src/channel.test.ts Add regression coverage for Telegram command conversation routing bindings.
extensions/telegram/src/approval-native.ts Migrate Telegram native approval routing + capability creation to shared SDK helpers.
extensions/slack/src/monitor/exec-approvals.ts Switch Slack handler to shared native runtime and shared request gating.
extensions/slack/src/monitor/exec-approvals.test.ts Add coverage for approvers inferred from allowFrom without explicit execApprovals.approvers.
extensions/slack/src/exec-approvals.ts Migrate Slack exec approval auth/profile logic to shared SDK profile helpers.
extensions/slack/src/channel.ts Replace legacy approvals/auth wiring with approvalCapability.
extensions/slack/src/approval-native.ts Migrate Slack native approval routing + capability creation to shared SDK helpers.
extensions/slack/src/approval-native.test.ts Update tests for optional delivery fields and updated suppression input shapes.
extensions/discord/src/monitor/exec-approvals.ts Switch Discord handler to shared native runtime and capability-driven native adapter.
extensions/discord/src/channel.ts Replace legacy approvals/auth wiring with approvalCapability.
extensions/discord/src/approval-native.ts Introduce Discord approvalCapability factory + shared native routing helpers + request gating.
docs/plugins/sdk-overview.md Update SDK overview entry for expanded approval-runtime responsibilities.
docs/plugins/sdk-migration.md Update migration doc to reflect expanded approval-runtime contents.
docs/plugins/sdk-channel-plugins.md Document the new canonical approvalCapability seam and recommended helper usage.
docs/plugins/architecture.md Add approval-runtime to recommended SDK imports and document approvalCapability guidance.
docs/.generated/plugin-sdk-api-baseline.jsonl Update generated SDK API baseline to include new exports/types.
docs/.generated/plugin-sdk-api-baseline.json Update generated SDK API baseline (JSON form) to include new exports/types.

Comment thread src/plugin-sdk/approval-client-helpers.ts
@greptile-apps

greptile-apps Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces a canonical approvalCapability seam on ChannelPlugin, consolidating the previously scattered auth.authorizeActorAction, auth.getActionAvailabilityState, and approvals.* fields into a single unified object. It also ships shared SDK helpers (createChannelExecApprovalProfile, createChannelNativeApprovalRuntime, createChannelApproverDmTargetResolver, etc.) that Discord, Slack, and Telegram now all build on, substantially reducing per-channel boilerplate.

Key changes:

  • resolveChannelApprovalCapability provides a legacy-compatible merge so plugins can migrate incrementally
  • createChannelExecApprovalProfile centralises enabled/approver/filter checks into a reusable profile object
  • createChannelNativeApprovalRuntime wraps createExecApprovalChannelRuntime and owns the buildPendingContentprepareTargetdeliverTarget lifecycle, eliminating duplicate deliverRequested implementations across three channel handlers
  • commands-approve.ts drops Telegram-specific special-casing in favour of the generic resolveApprovalMethods + retry loop

One P1 concern: the old Telegram exec-approvals-handler.ts matchesFilters function explicitly called matchesApprovalRequestFilters with fallbackAgentIdFromSessionKey: true. The new shared telegramExecApprovalProfile does not pass fallbackAgentIdFromSessionKey: true to createChannelExecApprovalProfile, silently dropping that fallback. Any user with agentFilter configured on a Telegram account where the agent ID is absent from the request but encoded in the session key will see those requests stop being handled after this change.

Confidence Score: 4/5

  • Safe to merge after verifying the fallbackAgentIdFromSessionKey omission in the Telegram profile is intentional or fixing it.
  • One P1 behavioral regression: the Telegram approval profile silently drops fallbackAgentIdFromSessionKey: true that was present in the old handler-side filter logic. This affects agentFilter matching for Telegram requests where agentId is null and must be extracted from the session key. All other changes are clean refactors with equivalent or improved behavior.
  • extensions/telegram/src/exec-approvals.ts — missing fallbackAgentIdFromSessionKey: true in telegramExecApprovalProfile
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/telegram/src/exec-approvals.ts
Line: 49-61

Comment:
**Missing `fallbackAgentIdFromSessionKey` in Telegram profile**

The old `matchesFilters` function in `exec-approvals-handler.ts` explicitly passed `fallbackAgentIdFromSessionKey: true` to `matchesApprovalRequestFilters`. The new `telegramExecApprovalProfile` does not set this flag, so it silently defaults to `false`.

This is a behavioral regression: when a Telegram approval config uses `agentFilter` and the request's `agentId` is absent (relying on extraction from the session key), filter matching will now fail where it previously succeeded.

```suggestion
const telegramExecApprovalProfile = createChannelExecApprovalProfile({
  resolveConfig: resolveTelegramExecApprovalConfig,
  resolveApprovers: getTelegramExecApprovalApprovers,
  isTargetRecipient: isTelegramExecApprovalTargetRecipient,
  matchesRequestAccount: ({ cfg, accountId, request }) => {
    const boundAccountId = resolveApprovalRequestAccountId({
      cfg,
      request,
      channel:
        request.request.turnSourceChannel?.trim().toLowerCase() === "telegram" ? null : "telegram",
    });
    return (
      !boundAccountId ||
      !accountId ||
      normalizeAccountId(boundAccountId) === normalizeAccountId(accountId)
    );
  },
  fallbackAgentIdFromSessionKey: true,
  requireClientEnabledForLocalPromptSuppression: false,
});
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/discord/src/approval-native.ts
Line: 64-69

Comment:
**`shouldHandleDiscordApprovalRequest` returns `true` when config is absent**

When both `configOverride` and the account's `execApprovals` are `null`/`undefined`, `config` is falsy and the function returns `true`. This is surprising for a predicate named `should handle` — callers reasonably expect `false` when no approval config is present.

While the downstream delivery pipeline guards against actual delivery (via `hasApprovers``enabled: false` in `describeDeliveryCapabilities`), the semantics of this exported function are misleading and could cause confusion for future consumers.

Consider returning `false` here, since an absent config means approvals are not configured:

```suggestion
  if (!config) {
    return false;
  }
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Refactor channel approval capability sea..." | Re-trigger Greptile

Comment thread extensions/telegram/src/exec-approvals.ts
Comment thread extensions/discord/src/approval-native.ts
@gumadeiras gumadeiras self-assigned this Apr 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Apr 1, 2026
@gumadeiras
gumadeiras force-pushed the codex/approval-capability-seam branch from dddda5e to 0fea432 Compare April 1, 2026 16:44
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Apr 1, 2026

@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: 23d7654a58

ℹ️ 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 extensions/discord/src/approval-native.ts Outdated
@gumadeiras
gumadeiras force-pushed the codex/approval-capability-seam branch from a24254f to 52729e1 Compare April 1, 2026 19:21
@gumadeiras
gumadeiras force-pushed the codex/approval-capability-seam branch from 52729e1 to c9ad4e4 Compare April 1, 2026 21:10
@gumadeiras
gumadeiras merged commit c87c8e6 into main Apr 1, 2026
9 checks passed
@gumadeiras

Copy link
Copy Markdown
Member Author

Merged via squash.

Thanks @gumadeiras!

@gumadeiras
gumadeiras deleted the codex/approval-capability-seam branch April 1, 2026 21:10
steipete pushed a commit to duncanita/openclaw that referenced this pull request Apr 4, 2026
Merged via squash.

Prepared head SHA: c9ad4e4
Co-authored-by: gumadeiras <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
Merged via squash.

Prepared head SHA: c9ad4e4
Co-authored-by: gumadeiras <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
Merged via squash.

Prepared head SHA: c9ad4e4
Co-authored-by: gumadeiras <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Merged via squash.

Prepared head SHA: c9ad4e4
Co-authored-by: gumadeiras <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Merged via squash.

Prepared head SHA: c9ad4e4
Co-authored-by: gumadeiras <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
Merged via squash.

Prepared head SHA: c9ad4e4
Co-authored-by: gumadeiras <[email protected]>
Co-authored-by: gumadeiras <[email protected]>
Reviewed-by: @gumadeiras
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord channel: slack Channel integration: slack channel: telegram Channel integration: telegram docs Improvements or additions to documentation maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants