Skip to content

fix(gateway): cancel run-bound approvals on abort and expose approval-park lifecycle - #110993

Merged
steipete merged 5 commits into
mainfrom
claude/approvals-lifecycle
Jul 18, 2026
Merged

steipete merged 5 commits into
mainfrom
claude/approvals-lifecycle

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Aborting a run never touched its pending exec approvals: the approval stayed pending for up to 30 minutes in every surface (modal, push, channels), a later Allow was silently consumed (authorization committed, then the aborted signal threw before execution), and in the async path the detached closure would still run the command and spawn a follow-up after the user aborted. The run-aborted terminal reason existed in the schema, DB constraint, and UI with no producer. Separately, a run parked on an inline approval is indistinguishable from a thinking run.

Why This Change Was Made

Run abort is now the single owner that also settles that run's pending approvals (cancelled/run-aborted) via the existing force-deny machinery, broadcasting resolutions so all surfaces clear. Late registrations for aborted runs are rejected via the existing abort-tombstone map; the detached closure rechecks both the terminal reason and the abort signal before authorization, spawn, and follow-up; the inline path propagates run-abort as cancellation instead of a plain denial and rechecks the signal around the authorization commit. The agent event stream emits lifecycle phases waiting-approval/approval-resolved with approvalId/toolCallId so clients can render parked runs. Approval requests now carry runId/sessionId/toolCallId (additive protocol fields).

User Impact

Aborting a run immediately clears its approval prompts everywhere; an Allow clicked after an abort can no longer be silently eaten or execute a command for a dead run; status surfaces can show "waiting on approval" instead of an opaque 30-minute "running". No behavior change for timeouts, plugin approvals, or system-agent approvals.

Evidence

  • Focused suites green: chat-abort (39), approval server methods (35), approval-shared, exec-approval-request (14), host-gateway lifecycle/abort cases; the only local failures are two known macOS path-canonicalization cases that pass on Linux CI.
  • Full node scripts/check-changed.mjs (typecheck/lint/format/import-cycle shards) green on Blacksmith Testbox.
  • Structured autoreview: clean after four rounds (admission-queue race, inline post-commit race, and inline cancellation propagation found and fixed).

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Jul 18, 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: acaf3ff938

ℹ️ 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 on lines +1946 to +1947
runId: defaults?.runId,
toolCallId,

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.

P1 Badge Propagate run ownership through node-host approvals

When tools.exec.host=node requires human approval, only the gateway-host branch receives defaults.runId and toolCallId here; ExecuteNodeHostCommandParams and registerNodeApproval never receive either field. Consequently the abort sweep cannot associate a node approval with its run, and the detached callback in bash-tools.exec-host-node.ts can still dispatch node.invoke after a later Allow because it also does not recheck the aborted signal. Pass the run/tool-call binding through the node-host path and apply the same post-approval abort checks.

Useful? React with 👍 / 👎.

@@ -113,6 +113,7 @@ export function createChatAbortOps(context: GatewayRequestContext): ChatAbortOps
getRuntimeConfig: context.getRuntimeConfig,
broadcast: context.broadcast,
nodeSendToSession: context.nodeSendToSession,
onRunAborted: context.cancelRunBoundApprovals,

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.

P2 Badge Wire approval cancellation into every abort path

When runs are aborted by full-provider logout, Talk relay shutdown, maintenance timeout, or gateway restart, those paths call abortChatRunById with operations assembled outside this factory (models-auth-status.ts, talk-realtime-relay.ts, server-maintenance.ts, and server-close.ts), so this callback is absent. Their run-bound approvals therefore remain pending and visible until resolution or the 30-minute timeout, and inline approval waiters are not released promptly. Make cancellation part of every ChatAbortOps construction path or centralize it in the shared abort owner.

Useful? React with 👍 / 👎.

@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: 18d9c824bb

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

sessionKey: params.sessionKey,
sessionId: params.sessionId,
stream: "lifecycle",
data: { phase: "approval-resolved", approvalId, toolCallId: params.toolCallId },

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.

P2 Badge Skip approval-resolved after an abort terminal

When abort cancellation releases this awaited promise, abortChatRunById synchronously emits lifecycle end and deletes the run's sequence entry before this finally executes (src/gateway/chat-abort.ts:585-610). This then emits approval-resolved after the terminal event; src/gateway/server-chat.ts:1405 treats it as an ordinary event and recreates the deleted agentRunSeq entry, while clients receive an out-of-order post-terminal lifecycle transition. Suppress this clear event when params.signal is aborted, since the terminal event already clears the parked run.

Useful? React with 👍 / 👎.

Comment on lines +20 to +24
const result = params.manager.forceDenyDetailed(
pending.id,
"run-aborted",
{ kind: "system", id: null },
"cancelled",

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.

P2 Badge Isolate persistence failures while sweeping approvals

If SQLite persistence throws while cancelling any matching approval, forceDenyDetailed settles that one local waiter and rethrows (src/gateway/exec-approval-manager.ts:532-546), which exits this entire loop; abortChatRunById then deliberately swallows the callback failure. For a run with parallel pending exec approvals, every later approval therefore remains pending until timeout, and the first receives no resolution publication. Catch failures per record, log them, and continue sweeping the remaining run-bound approvals.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the claude/approvals-lifecycle branch from 18d9c82 to 33eda2e Compare July 18, 2026 23:22

@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: 33eda2e16c

ℹ️ 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 on lines +1112 to +1114
// The commit awaits: an abort that lands during it must not admit the
// process (mirrors the detached path's post-commit check).
params.signal?.throwIfAborted();

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.

P2 Badge Check abort inside the authorization commit

When an abort arrives while commitExecAuthorizationLocked is queued on the process-local or file lock, this post-commit check prevents command execution but runs only after the authorization update has already been persisted. In particular, an allow-always decision can therefore leave a durable grant behind for an aborted run—the silent authorization consumption this change is intended to prevent. src/infra/exec-approvals.ts:1284-1307 confirms that the commit can await lock acquisition before its synchronous mutation, so the abort check must occur inside the locked update immediately before writing; the detached commit path needs the same protection.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 8853217 into main Jul 18, 2026
119 checks passed
@steipete
steipete deleted the claude/approvals-lifecycle branch July 18, 2026 23:52
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
…-park lifecycle (openclaw#110993)

* fix: harden approval abort lifecycle

* fix(gateway): recheck abort before committing detached exec authorization

* fix(gateway): recheck abort after inline exec authorization commit

* fix(gateway): propagate run-abort cancellation on the inline approval path

* fix(ci): refresh approval protocol bindings
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…-park lifecycle (openclaw#110993)

* fix: harden approval abort lifecycle

* fix(gateway): recheck abort before committing detached exec authorization

* fix(gateway): recheck abort after inline exec authorization commit

* fix(gateway): propagate run-abort cancellation on the inline approval path

* fix(ci): refresh approval protocol bindings
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 gateway Gateway runtime maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant