Repository navigation
fix(gateway): stop restart drains waiting on approval-blocked runs - #15
Merged
Merged
Conversation
A restart drain refuses plugin.approval.request/waitDecision, so a run that needs approval can never finish during the drain. The tool failure went back to the model, which retried into the same refusal until the full drain budget (300s with TimeoutStopSec=330) expired, and then shutdown aborted the run into restart recovery anyway. Park a tool call whose approval the restart drain refuses on its run's abort signal and record it with the admission owner. The restart drain releases as soon as every active embedded run is parked and no independent work is active (unattributed replies, requests, and lane tasks stay within what the parked runs hold). Server close then skips its reply drain for those runs and marks/aborts them through the existing restart-recovery path, minutes earlier. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
openclaw gateway restarttook ~5 minutes whenever an agent run needed plugin approval mid-turn. Observed live on 2026-10-05 (13:54:24 → 13:59:24):plugin.approval.request/plugin.approval.waitDecision(unavailable during gateway restart), so theheimdallrSignal run'sopenhab-admin__execute_scriptcall failed with "Plugin approval required (gateway unavailable)".qwen3.8:27b), so the run could never finish.TimeoutStopSec=330, which Doctor/update refreshed from the old 30 s per fix: refresh stale Gateway shutdown budgets during updates and Doctor openclaw/openclaw#153636), then shutdown marked the session for restart recovery and aborted the run anyway.Solution
agent-tools.before-tool-call.approval.ts): when the gateway refuses an approval with the structuredgateway-restartingreason during the local one-way restart drain, park the tool call on the run's abort signal instead of failing it to the model, and record the parked session with the admission owner (gateway-work-admission.ts). The record is released when the park ends and cleared on admission reset.gateway-active-work.ts): optionalreleasepredicate.run-loop-drain.ts): release when every active embedded run is parked. Independent work (cron, background exec, ACP, media, session mutations, terminal sessions/persistence, lifecycle writes) keeps it waiting. Unattributed counts must stay within what the parked runs hold: one reply, root request, chat run, agent run and admission each, plus session-lane + global-lane tasks.run-loop.ts): when the drain released parked runs, server close getsdrainTimeoutMs: 0, so its reply drain does not wait again.prepareGatewayRunShutdownstill marks the runs for restart recovery and aborts them, exactly as on budget exhaustion.Impact
A restart with a run blocked on approval now proceeds within one 250 ms poll instead of the full stop budget. The turn resumes through restart recovery on the successor gateway, where approval can be requested again. Restarts without such runs are unchanged.
Not covered: exec approvals have the same refusal shape (follow-up). If a run's session id rotates mid-run, the drain falls back to the full wait (safe direction).
Evidence
pnpm test src/cli/gateway-cli/run-loop.test.ts: 214 passed (~68 s wall for the file). New case: a foreign pending reply blocks release, then release fires and close getsdrainTimeoutMs: 0. It fails on the prior code (noreleasepredicate).pnpm test src/agents/agent-tools.before-tool-call.approval-policy.test.ts: 4 passed. New case: a restart refusal parks until run abort and releases the record; a non-restart UNAVAILABLE does not park.src/process/gateway-work-admission.test.ts(41) andsrc/infra/gateway-active-work.test.ts(7) passed.pnpm tsgo:coreclean; oxlint and oxfmt clean on changed files.tsgo:core:testfails only onui/src/lib/nodes/index.ts(@noble/hashesnot installed in the gateway-only worktree), which this change does not touch..github/workflows/plugin-npm-release.yml, which the fork deleted. It was restored temporarily for the local test runs only.🤖 Generated with Claude Code