Skip to content

fix: cancel aborted plugin approvals - #98577

Closed
haruaiclone-droid wants to merge 1 commit into
openclaw:mainfrom
haruaiclone-droid:codex/fix-aborted-plugin-approval-cleanup
Closed

haruaiclone-droid wants to merge 1 commit into
openclaw:mainfrom
haruaiclone-droid:codex/fix-aborted-plugin-approval-cleanup

Conversation

@haruaiclone-droid

Copy link
Copy Markdown
Contributor

Fixes #98576.

Summary

  • add plugin.approval.cancel as a requester-side terminal RPC for pending plugin approvals
  • cancel accepted plugin approval ids when the agent run aborts during waitDecision
  • broadcast nullable plugin.approval.resolved cleanup events and render cancelled plugin approvals safely
  • cover cancel routing, runtime identity, forwarder/renderer behavior, and abort cleanup

Tests

  • node scripts/run-with-env.mjs OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=300000 OPENCLAW_GATEWAY_PROJECT_SHARDS=0 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server-methods/plugin-approval.test.ts src/gateway/method-scopes.test.ts --testTimeout=30000 --reporter=dot
  • node scripts/run-with-env.mjs OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=300000 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts src/agents/agent-tools.before-tool-call.e2e.test.ts --testNamePattern="unblocks immediately when abort signal fires during waitDecision" --testTimeout=30000 --reporter=verbose
  • node scripts/run-with-env.mjs OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=300000 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.agents-tools.config.ts src/agents/tools/gateway.test.ts --testTimeout=30000 --reporter=dot
  • node scripts/run-with-env.mjs OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=300000 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.unit-fast.config.ts src/agents/tools/gateway.test.ts src/plugin-sdk/approval-renderers.test.ts --testTimeout=30000 --reporter=dot (agents file excluded by this config; renderer file ran)
  • node scripts/run-with-env.mjs OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=300000 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-slack.config.ts extensions/slack/src/approval-handler.runtime.test.ts --testTimeout=30000 --reporter=dot
  • node scripts/run-with-env.mjs OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=300000 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-messaging.config.ts extensions/googlechat/src/approval-handler.runtime.test.ts --testTimeout=30000 --reporter=dot
  • node scripts/run-with-env.mjs OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=300000 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-discord.config.ts extensions/discord/src/approval-handler.runtime.test.ts --testTimeout=30000 --reporter=dot
  • node scripts/run-with-env.mjs OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=300000 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.infra.config.ts src/infra/plugin-approval-forwarder.test.ts --testTimeout=30000 --reporter=dot
  • git diff --check
  • Attempted: node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo timed out after 240s on this Windows/OneDrive checkout; lingering tsgo processes were stopped.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: slack Channel integration: slack app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: M labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 12:30 PM ET / 16:30 UTC.

ClawSweeper review

What this changes

The PR adds a Gateway cancellation RPC and uses it when a plugin-tool approval wait is aborted, then renders cancellation as a terminal approval state across approval-card surfaces.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 11 items remain

Keep this PR open: current main still has the reported stale-pending-approval gap, but this branch is not safe to merge yet. The new cancellation RPC authorizes by general approval visibility rather than original requester identity, and it only cleans up one abort-aware waiter while another current agent path still leaves its pending approval live; it also needs real after-fix behavior proof.

Priority: P2
Reviewed head: abf31ad2c4178dab09005e869b6faeb06cde81a0

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The PR identifies a real lifecycle gap and includes useful focused tests, but requester authorization, sibling abort coverage, and real behavior proof block merge readiness.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body lists focused test runs but contains no redacted after-fix live Gateway/agent abort transcript or visible approval-card cleanup proof; add one and remove private identifiers or endpoints before posting it. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body lists focused test runs but contains no redacted after-fix live Gateway/agent abort transcript or visible approval-card cleanup proof; add one and remove private identifiers or endpoints before posting it. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Current main still lacks a plugin-approval cancellation operation: Current Gateway method descriptors list plugin approval request, wait, and resolve operations but no cancellation method, so the central requested behavior is not already implemented on main.
PR cancellation lookup is visibility-based: The proposed handler calls resolvePendingApprovalRecord, whose lookup filter is isApprovalRecordVisibleToClient rather than a requester-identity predicate.
Visibility grants broad internal approval-runtime access: Current authorization treats any client marked as an internal approval runtime with the approvals scope as able to see the record, so it is insufficient for a requester-only destructive operation.
Findings 2 actionable findings [P1] Restrict cancellation to the original requester
[P2] Cancel the native-hook approval waiter on abort
Security Needs attention Cancellation is authorized by visibility, not ownership: The proposed handler resolves pending records through isApprovalRecordVisibleToClient, which grants internal approval-runtime clients access to all approval records; a destructive cancel operation needs an explicit original-requester check.

How this fits together

Plugin tools register sensitive-action approval records with the Gateway, and agent runtimes wait for a decision. Gateway resolution events then clear pending state and drive Control UI or channel approval-card updates.

flowchart LR
  A[Plugin tool request] --> B[Gateway pending approval]
  B --> C[Agent approval waiter]
  C --> D{Agent run aborts}
  D -->|Cancel request| E[Gateway authorization check]
  E --> F[Terminal approval state]
  F --> G[Gateway resolved event]
  G --> H[Control UI and channel cards]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body lists focused test runs but contains no redacted after-fix live Gateway/agent abort transcript or visible approval-card cleanup proof; add one and remove private identifiers or endpoints before posting it. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Restrict cancellation to the original requester (P1) - resolvePendingApprovalRecord authorizes through general record visibility, and internal approval-runtime clients are visible by design. That lets another authorized approval surface cancel a pending record it did not create, contrary to the requester-side contract; add a requester-identity predicate for this destructive operation. This is a late finding on the unchanged reviewed head.
  • Cancel the native-hook approval waiter on abort (P2) - This helper only cleans up the before-tool path. Current main’s native-hook relay also creates a plugin approval and races waitDecision with an abort signal without cancelling the accepted identifier, so the same stale card and pending record survive there after a rebase; route both through one authenticated cancellation helper.
  • Resolve security concern: Cancellation is authorized by visibility, not ownership - The proposed handler resolves pending records through isApprovalRecordVisibleToClient, which grants internal approval-runtime clients access to all approval records; a destructive cancel operation needs an explicit original-requester check.
  • Resolve merge risk (P1) - The new destructive RPC can let an approval-runtime or reviewer-visible client cancel another requester’s pending security decision unless cancellation checks the record’s original requester identity.
  • Resolve merge risk (P1) - A rebased version that cancels only the before-tool waiter still leaves the native-hook relay’s abort race with an active Gateway approval.
  • Resolve merge risk (P1) - The PR provides focused tests only; maintainers do not yet have an after-fix runtime transcript or approval-card cleanup artifact proving the cross-surface behavior.
  • Complete next step (P2) - The blocking defects are concrete and mechanical: rebase to the current approval transport, enforce requester-only cancellation, and extend the canonical abort cleanup to the native-hook waiter; contributor-owned real behavior proof remains required before merge.
  • Improve patch quality - Make cancellation requester-only rather than visibility-based.
  • Improve patch quality - Cover the native-hook abort waiter through the same cleanup path.
  • Improve patch quality - Attach redacted after-fix Gateway and approval-surface proof, then update the PR body for a fresh review.

Findings

  • [P1] Restrict cancellation to the original requester — src/gateway/server-methods/approval-shared.ts:690-695
  • [P2] Cancel the native-hook approval waiter on abort — src/agents/agent-tools.before-tool-call.ts:811-813
  • [high] Cancellation is authorized by visibility, not ownership — src/gateway/server-methods/approval-shared.ts:690
Agent review details

Security

Needs attention: The new cancellation RPC crosses the approval authorization boundary and currently permits cancellation based on broad visibility rather than original requester identity.

PR surface

Source +185, Tests +120. Total +305 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 16 195 10 +185
Tests 6 121 1 +120
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 316 11 +305

Review metrics

Metric Value Why it matters
Gateway approval contract 1 RPC added; 1 resolved-event decision widened to nullable This protocol change affects agent callers and every approval renderer, so authorization and terminal-state compatibility need whole-flow proof.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #98576
Summary: This PR is the explicitly linked candidate implementation for the open aborted-plugin-approval lifecycle issue, while the other related approval PRs address distinct stale-state cases.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Repair requester authorization and abort coverage (recommended)
    Restrict cancellation to the record’s original requester, migrate both abort-aware agent waiters to the same helper, and add regression coverage before merging.
  2. Pause the protocol addition
    Leave the PR open until the permanent requester-cancellation contract is clear if a shared requester predicate cannot be defined without changing approval visibility semantics.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase onto the current approval transport; make cancellation requester-only rather than visibility-based; cover the native-hook abort waiter; add focused regression tests and redacted real behavior proof.

Technical review

Best possible solution:

Rebase onto the current extracted approval transport, add one requester-only Gateway cancellation authorization rule shared by every agent-owned abort path, preserve the existing terminal event flow, and demonstrate a cancelled approval disappearing from pending state and its visible approval surface.

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

Yes. Current main’s native-hook relay obtains a plugin approval identifier, races its wait against AbortSignal, and exits on abort without a Gateway terminal operation; the existing source directly establishes the stale-pending path.

Is this the best way to solve the issue?

No. Gateway-owned cancellation is the correct owner boundary, but this branch must use requester identity rather than reviewer visibility and cover the other current abort-aware requester before it is the best fix.

Full review comments:

  • [P1] Restrict cancellation to the original requester — src/gateway/server-methods/approval-shared.ts:690-695
    resolvePendingApprovalRecord authorizes through general record visibility, and internal approval-runtime clients are visible by design. That lets another authorized approval surface cancel a pending record it did not create, contrary to the requester-side contract; add a requester-identity predicate for this destructive operation. This is a late finding on the unchanged reviewed head.
    Confidence: 0.97
    Late finding: first raised on code an earlier review cycle already covered.
  • [P2] Cancel the native-hook approval waiter on abort — src/agents/agent-tools.before-tool-call.ts:811-813
    This helper only cleans up the before-tool path. Current main’s native-hook relay also creates a plugin approval and races waitDecision with an abort signal without cancelling the accepted identifier, so the same stale card and pending record survive there after a rebase; route both through one authenticated cancellation helper.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 19d213e7211d.

Labels

Label justifications:

  • P2: The PR addresses a bounded approval-lifecycle defect, but its current problems are pre-merge risks rather than a user-facing incident on shipped main.
  • merge-risk: 🚨 compatibility: The branch adds a Gateway RPC and changes plugin approval resolution to represent cancellation with a null decision across existing renderers and forwarders.
  • merge-risk: 🚨 security-boundary: The cancellation RPC deletes a pending security decision but currently uses broad record visibility instead of requester-only authorization.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body lists focused test runs but contains no redacted after-fix live Gateway/agent abort transcript or visible approval-card cleanup proof; add one and remove private identifiers or endpoints before posting it. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [high] Cancellation is authorized by visibility, not ownership — src/gateway/server-methods/approval-shared.ts:690
    The proposed handler resolves pending records through isApprovalRecordVisibleToClient, which grants internal approval-runtime clients access to all approval records; a destructive cancel operation needs an explicit original-requester check.
    Confidence: 0.97

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/server-methods/plugin-approval.test.ts src/gateway/method-scopes.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/agent-tools.before-tool-call.e2e.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/harness/native-hook-relay-permissions.test.ts.
  • [P1] node scripts/run-vitest.mjs src/infra/plugin-approval-forwarder.test.ts src/plugin-sdk/approval-renderers.test.ts.
  • [P1] git diff --check.

What I checked:

  • Current main still lacks a plugin-approval cancellation operation: Current Gateway method descriptors list plugin approval request, wait, and resolve operations but no cancellation method, so the central requested behavior is not already implemented on main. (src/gateway/methods/core-descriptors.ts:71, 19d213e7211d)
  • PR cancellation lookup is visibility-based: The proposed handler calls resolvePendingApprovalRecord, whose lookup filter is isApprovalRecordVisibleToClient rather than a requester-identity predicate. (src/gateway/server-methods/approval-shared.ts:690, abf31ad2c417)
  • Visibility grants broad internal approval-runtime access: Current authorization treats any client marked as an internal approval runtime with the approvals scope as able to see the record, so it is insufficient for a requester-only destructive operation. (src/gateway/server-methods/approval-shared.ts:153, 19d213e7211d)
  • A current sibling abort path remains uncovered: The native-hook relay registers a plugin approval, races waitDecision against AbortSignal, and removes the abort listener without issuing a Gateway terminal operation; merging only the proposed before-tool cleanup leaves the same stale pending state on that path. (src/agents/harness/native-hook-relay-permissions.ts:540, 19d213e7211d)
  • Current approval ownership has recent shared-agent and plugin-security work: Recent current-main commits include the extracted approval transport module and plugin hook security invariants, making their authors useful routing candidates for a rebased repair. (src/agents/agent-tools.before-tool-call.approval.ts:181, a19132e7ebc1)

Likely related people:

  • Peter Steinberger: Recent current-main work on the extracted agent approval transport includes approval behavior adjacent to the proposed abort cleanup. (role: recent agent-approval contributor; confidence: medium; commits: a19132e7ebc1; files: src/agents/agent-tools.before-tool-call.approval.ts)
  • Vincent Koc: Recent plugin-hook security work is adjacent to the requester and authorization boundary affected by the new cancellation RPC. (role: recent plugin security-invariant contributor; confidence: medium; commits: bf91a5786c87; files: src/gateway/server-methods/approval-shared.ts, src/agents/agent-tools.before-tool-call.approval.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-07-01T11:46:29.619Z sha abf31ad :: needs real behavior proof before merge. :: [P2] Cancel all abort-aware plugin approval waiters
  • reviewed 2026-07-30T20:03:56.397Z sha abf31ad :: needs real behavior proof before merge. :: [P2] Cancel approvals for every abort-aware waiter

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 1, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 23, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 30, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jul 31, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 2, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

@openclaw-barnacle openclaw-barnacle Bot closed this Sep 4, 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 channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: slack Channel integration: slack gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Aborted plugin tool approvals leave stale approval cards live

1 participant