Repository navigation
fix(gateway): cancel run-bound approvals on abort and expose approval-park lifecycle - #110993
Conversation
There was a problem hiding this comment.
💡 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".
| runId: defaults?.runId, | ||
| toolCallId, |
There was a problem hiding this comment.
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, | |||
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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 }, |
There was a problem hiding this comment.
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 👍 / 👎.
| const result = params.manager.forceDenyDetailed( | ||
| pending.id, | ||
| "run-aborted", | ||
| { kind: "system", id: null }, | ||
| "cancelled", |
There was a problem hiding this comment.
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 👍 / 👎.
18d9c82 to
33eda2e
Compare
There was a problem hiding this comment.
💡 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".
| // 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(); |
There was a problem hiding this comment.
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 👍 / 👎.
|
Merged via squash.
|
…-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
…-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
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-abortedterminal 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 emitslifecyclephaseswaiting-approval/approval-resolvedwithapprovalId/toolCallIdso clients can render parked runs. Approval requests now carryrunId/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
node scripts/check-changed.mjs(typecheck/lint/format/import-cycle shards) green on Blacksmith Testbox.