Skip to content

refactor(gateway): schedule approval deadlines with the kernel - #159081

Merged
steipete merged 1 commit into
mainfrom
hostneutral/scheduler-approvals-0926
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
hostneutral/scheduler-approvals-0926

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Approval expiry and resolved-entry cleanup arm private timers outside the Gateway scheduler’s lifetime.

User Impact

Approval deadlines and handoff grace retain their existing decisions, persistence, and cancellation behavior. The Gateway scheduler now owns their wakes and shutdown settlement. Existing installs need no migration: prior-epoch approvals still close through the existing startup recovery path, without restoring executable authority from stored rows.

Why This Change Was Made

Require the kernel scheduler through auxiliary handlers and each approval manager. The existing pending entry owns named expiry and cleanup jobs derived from its authoritative deadline. Remove scheduleExpiryTimer, pending-entry timer handles, and their setTimeout/clearTimeout plumbing. Definite-refusal retries retain captured persistence authority; uncertain outcomes retain their existing recovery path.

One scheduler instance per Gateway process, enforced by types. No standalone constructor or hidden fallback is added. There are no schema, transaction, retention, config, SDK, RPC, or port changes. Current authority guards, durable first-answer decisions, handoff custody, and store threading remain unchanged.

Strict LOC: production +47/−43/net +4; tests +266/−150/net +116; docs +0/−0/net 0. The 506 changed lines include complete constructor closure and replacement of both bespoke timer-test fixtures with the shared scheduler clock.

Evidence

Publication head: f9f3a4fa9a50abd7a3a4851ea3a56bde15796b1a. Current-head focused proof and exact-head CI: The three changed-main fixtures passed on the refreshed composition below; exact-head GitHub CI attaches on publication. The rebase preserves the same stable patch ID and unchanged approval owners/fixtures.. The evidence below is prior candidate proof, not a claim that the refreshed head has run.

Blacksmith-testbox lease tbx_01m3er4ym3e4e69mfkcyc84m7t, run 36239456451: all 360 cases across 16 approval candidate files passed after pnpm install --frozen-lockfile. Tested base 4543ce2515ef27e460d3545ac6c2675f483ad49c, candidate tree b391a0dfadd3b080374b8ec7a5250d248192f0db, patch SHA256 bee7641ce52d33f22b6788ccc9b6502467e10cd1e0abe4b6021fa5720d91785e. These commands completed before the operator interrupted a later, unrelated post-ready baseline; no completion of that broader run is claimed.

The refresh onto be46e6966c2b52c6cde06abf965c44f9a175a47f preserves every added/deleted code line and byte-identical production files. Its only conflict combines main’s ExecApprovalRecord test-helper import with the shared scheduler import. Main’s removed redundant cases remain removed. The full six-root caller census confirms required scheduler forwarding and no remaining scheduleExpiryTimer reference. The prior Codex P2 review (one round, two passes, zero findings) remains applicable; deslop and whitespace checks passed. Refreshed proof on blacksmith-testbox lease tbx_01m3f70jxsg7e3036jppdwwv8j, run 36253776173, verified tree fb01adfddf054f671da848cc36927764cd8c676d: all three changed-main fixtures passed (104 cases, 87.41s summed command wall), using pnpm test <file> --maxWorkers=1. exec-approval-manager.test.ts: 55 cases/37.93s; server-aux-handlers.test.ts: 19/23.17s; server-methods/approval-shared.test.ts: 30/26.31s. Their upstream test pruning is preserved; no new Gateway boots were added. GitHub’s enforced openclaw/ci-gate supplies changed-file validation.

The owner tests cover expiry publication, wall-clock rollback, handoff retention, stale wakes, cancellation, captured persistence on refused writes, and uncertain outcomes. No new Gateway boot, sleep, polling loop, or per-file clock implementation was added. Final merged-stack Gateway/cron/suspend/shutdown proof follows the last slice.

Recorded per-file test costs

Each row used pnpm test <target> --maxWorkers=1. Wall time includes wrapper/build setup; no performance improvement is claimed.

Target Cases Wall
src/gateway/desktop/computer-authority.runtime.test.ts 3 26.937s
src/gateway/exec-approval-manager.expiry.test.ts 24 23.731s
src/gateway/exec-approval-manager.lifetime.test.ts 11 12.995s
src/gateway/exec-approval-manager.test.ts 61 30.722s
src/gateway/node-invoke-plugin-policy.test.ts 34 17.905s
src/gateway/operator-approval-mcp-grants.test.ts 13 18.476s
src/gateway/operator-approval-session-events.test.ts 13 14.282s
src/gateway/operator-approval-standing-grants.test.ts 31 24.909s
src/gateway/server-aux-handlers.authority.test.ts 10 15.494s
src/gateway/server-aux-handlers.test.ts 20 19.934s
src/gateway/server-aux-methods.test.ts 1 11.265s
src/gateway/server-methods/approval-shared.storage-failure.test.ts 3 11.789s
src/gateway/server-methods/approval-shared.test.ts 38 25.641s
src/gateway/server-methods/approval.request-authority.test.ts 41 11.625s
src/gateway/server-methods/approval.settlement.test.ts 30 12.779s
src/gateway/server-methods/system-agent-approval.test.ts 27 28.068s
Scheduler stack

Merged foundations: diagnostics #157517, auth naming #158275, kernel scheduler #158423, event-loop health #158531, channel health #158537, mention expiry #158614, upstream monitor #158617, worker placement #158662, idle/prewarm #158666, Incognito expiry #158690, OAuth #158717, and initial lifetime maintenance #158727.

Other published slices: worker reconciliation #158812, PR subscriptions #158821. Subsequent update/Gmail/metadata/audit links: update checks #158909, Gmail #158913, metadata #158959, and audit #158982 are merged. Task maintenance #159038 is pending; generation #159042 and post-ready #159047 are merged.. This slice migrates approval deadlines.

Later slices cover outbound recovery, session delivery, update watcher/campaign, task and cold-storage maintenance, diagnostics/auth/MCP lifetime, generation and post-ready maintenance, periodic/media cleanup, and cron due/receipt/system jobs. Final cleanup removes superseded plumbing and records timer exceptions before merged-main live proof.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: f9f3a4fa9a50abd7a3a4851ea3a56bde15796b1a
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/exec-approval-expiry.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/exec-approval-lifecycle.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/exec-approval-manager.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/gateway/exec-approval-manager.types.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L labels Sep 26, 2026
@steipete
steipete enabled auto-merge (squash) September 26, 2026 17:54
@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 1:57 PM ET / 17:57 UTC.

ClawSweeper review

What this changes

The branch moves Gateway approval expiry and resolved-entry cleanup onto the existing Gateway scheduler and updates the approval tests to use scheduler clocks.

Merge readiness

✅ Ready for maintainer review

This is a distinct, still-useful Gateway scheduler migration. Current main retains private approval timers, and the reviewed production path shows no merge-blocking defect.

Priority: P3
Reviewed head: f9f3a4fa9a50abd7a3a4851ea3a56bde15796b1a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and has substantial approval-boundary test evidence, with no discrete blocking defect found.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor proof gate. Prior-candidate Testbox approval-store and scheduler-clock tests support the timing path, but no final-head live Gateway run is claimed; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor proof gate. Prior-candidate Testbox approval-store and scheduler-clock tests support the timing path, but no final-head live Gateway run is claimed; no stored-data contract changes.
Evidence reviewed 6 items Introduced scheduler wiring: The pinned PR patch replaces private expiry timers with a scheduler job and passes the kernel scheduler through auxiliary handlers.
Current main still uses private timers: The approval expiry implementation on the fetched main branch still arms a direct timeout, so this migration has not already landed.
Scheduler ownership: The scheduler replaces jobs with matching IDs; production auxiliary-handler construction gives the three approval kinds distinct managers under one newly generated runtime epoch.
Findings None None.
Security None None.

How this fits together

The Gateway receives execution and plugin approval requests, records them in its approval store, and keeps local waiters for decisions. Scheduled wakes expire unanswered requests and clean up resolved local bindings.

flowchart LR
A[Approval request] --> B[Gateway approval manager]
B --> C[Durable approval store]
B --> D[Gateway scheduler]
D --> E{Deadline or grace wake}
E --> B
B --> F[Decision or local cleanup]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +4, Tests +116. Total +120 across 25 files.

View PR surface stats
Area Files Added Removed Net
Source 6 47 43 +4
Tests 19 266 150 +116
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 25 313 193 +120

Review metrics

Metric Value Why it matters
Production and test growth production +4 net lines; tests +116 net lines Production growth is limited to required scheduler wiring; test growth replaces timer fixtures and exercises deadline behavior.

Technical review

Best possible solution:

Keep the durable approval store responsible for decisions and deadlines while the Gateway scheduler owns wakes and shutdown joining.

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

Not applicable: this PR consolidates timer ownership rather than reporting a user bug. Current main’s private timer path is visible in source.

Is this the best way to solve the issue?

Yes. Reusing the kernel scheduler and retaining the approval store as the decision owner is a narrow fit for this refactor.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5a27fda95008.

Labels

Label changes:

  • add P3: This is an internal ownership refactor with no established user-facing regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.

Label justifications:

  • P3: This is an internal ownership refactor with no established user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

  • Introduced scheduler wiring: The pinned PR patch replaces private expiry timers with a scheduler job and passes the kernel scheduler through auxiliary handlers. (src/gateway/exec-approval-expiry.ts:48, f9f3a4fa9a50)
  • Current main still uses private timers: The approval expiry implementation on the fetched main branch still arms a direct timeout, so this migration has not already landed. (src/gateway/exec-approval-expiry.ts:40, 5a27fda95008)
  • Scheduler ownership: The scheduler replaces jobs with matching IDs; production auxiliary-handler construction gives the three approval kinds distinct managers under one newly generated runtime epoch. (src/infra/gateway-scheduler.ts:99, f9f3a4fa9a50)
  • Approval authority remains store-owned: The manager retains current-authority and persistence checks around durable approval decisions; the introduced change does not mint or transfer execution authority. (src/gateway/exec-approval-manager.ts:347, f9f3a4fa9a50)
  • Scheduler feature history: Blame ties the existing scheduler registration API to the merged scheduler-foundation commit; its raw recorded parent does not contain this file. (src/infra/gateway-scheduler.ts:99, 362cee12114d)
  • Validation described in PR: The PR body reports 360 passing approval cases on an earlier candidate and 104 focused cases on a refreshed candidate, with source identities stated; it expressly does not claim that the final pinned head ran those Testbox commands. Exact-head CI was still pending in the supplied snapshot. (f9f3a4fa9a50)

Likely related people:

  • Peter Steinberger: Raw commit 362cee1 adds src/infra/gateway-scheduler.ts:99 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 362cee12114d; files: src/infra/gateway-scheduler.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.

@steipete
steipete merged commit df50212 into main Sep 26, 2026
197 checks passed
@steipete
steipete deleted the hostneutral/scheduler-approvals-0926 branch September 26, 2026 18:09
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant