Skip to content

refactor(audit): schedule retention maintenance through its lifetime owner - #158982

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

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

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The audit writer’s hourly maintenance interval is outside the Gateway scheduler’s lifetime.

User Impact

Audit behavior and retention remain unchanged. Startup and final maintenance keep their existing queue path; only hourly arming moves to the shared owner, with one maintenance pass after an overdue wake. Existing installs retain their state/config and need no migration.

Why This Change Was Made

Require the scheduler through recorder/writer construction and Gateway subscriptions; delete the private hourly interval. Direct local-agent audit explicitly creates/stops a scheduler at its existing lifetime entry point, only when no surrounding audit owner exists. The standalone QA child does the same.

One scheduler instance per Gateway process, enforced by types. No optional scheduler or fallback. Existing collection defaults and policy gates remain unchanged; message and identity collection keep their opt-in settings; maintenance still runs when collection is disabled. The 30-day cutoff, 100,000-event cap, family bounds, retained fields, reader scope, schemas, permissions, and authorization are unchanged. Writes/prunes remain on the shared state worker. FIFO, uncertain-outcome non-replay, and joining submitted mutations remain intact. Queue dispatch, per-operation retry backoff, shutdown watchdog, and per-run terminal settling are documented timer exceptions. No config, SDK, or RPC change.

Strict LOC: production +35/−16/net +19; tests +119/−13/net +106; docs +0/−0/net 0. Required dependency forwarding and explicit standalone cleanup explain production growth.

Evidence

Current publication head: 1af765860aabc761b3a731fe1917b82cb94fc56c. Current-head focused proof and exact-head CI: the rebase onto 785fdcaa54574186236343ccf3f98680083bf459 has an identical stable patch ID and no changes in the writer/local-agent owner context. Prior remote proof is reused below; CI will attach after opening. Prior evidence below is not a claim that the refreshed head has been tested. GitHub’s enforced openclaw/ci-gate replaces a separate Testbox check-changed run.

Prior proof: Blacksmith-testbox, lease tbx_01m3egmtwwrpzy41g7v4x5807e, run 36232827179. Commands ran after pnpm install --frozen-lockfile in isolated checkouts. Head a23974aa5034ea2b79ab21dab9ea3055fa4d5b28, verified tree 45b182618a2c843441da1188cc1249804e39334f: all 24 cases across five owner suites passed. Manual-clock coverage proves no early prune, one idle maintenance pass after a three-hour jump, and no periodic dispatch after stop; existing policy/FIFO/worker/shutdown tests remain.

The original pinned composition (base 2d5c68187a38db0c3bbe4cc18be77c12b0f54727, tree fffd103bc2e509f5ee9c41862a09ec4c9c3ee7a4) also passed all ten focused suites: 238 cases in 219.112s on the same lease/run, including local-agent and Gateway subscription/close callers.

Deslop and one independent Codex P2 review passed with no findings. The six-root caller census confirms required scheduler forwarding. The repeated-turn QA child’s lifecycle wiring changed, but no live-provider run is recorded here; that fixture is not counted as executed proof. The final merged-stack live proof remains pending.

Recorded commands and per-file test cost

Each test row is pnpm test <target> --maxWorkers=1; command wall includes wrapper/build setup. These are prior-run measurements, not a performance comparison.

Target Cases Wall
src/audit/audit-event-writer.lifecycle.test.ts 4 16.216s
src/audit/audit-event-writer.test.ts 11 26.105s
src/audit/audit-event-writer.worker.test.ts 2 14.657s
src/audit/audit-recorder.test.ts 3 13.887s
src/audit/execution-decision-work.test.ts 4 16.623s
src/commands/agent-local-audit.test.ts (original composition) 1 21.546s
src/commands/agent-via-gateway.test.ts (original composition) 129 18.932s
src/gateway/server-runtime-subscriptions.test.ts (original composition) 76 28.984s
src/gateway/server-runtime-subscriptions.shutdown.test.ts (original composition) 2 19.051s
src/gateway/server-close.model-acquisition.test.ts (original composition) 6 37.268s
Scheduler stack

Merged: diagnostic preparation (#157517), auth factory naming (#158275), kernel scheduler and companion sweep (#158423), event-loop health (#158531), channel health (#158537), mention expiry (#158614), upstream monitoring (#158617), worker placement (#158662), idle/prewarm (#158666), Incognito expiry (#158690), OAuth maintenance (#158717), initial lifetime maintenance (#158727).

Also merged: worker reconciliation (#158812), PR subscriptions (#158821). Publication order continues with update checks, Gmail renewal, metadata capture maintenance, and audit maintenance; this PR is audit maintenance. Links for these four: update checks (#158909) and Gmail renewal (#158913) are merged; metadata (#158959) is open.

Later reviewed slices: task maintenance, cold storage, approval/secret expiry, publication and post-ready work, diagnostic heartbeat and SDK/CLI lifetime, auth pruning, MCP idle retirement, generation/periodic/media maintenance, outbound recovery, session delivery, update watcher/campaign, and cron due/foreign-receipt/system jobs. Final cleanup removes superseded timer plumbing and records the exception census; merged-main Gateway/cron/SIGSTOP/SIGTERM proof follows the last slice.

@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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime commands Command implementations size: S labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 11:54 AM ET / 15:54 UTC.

ClawSweeper review

What this changes

Moves audit retention’s hourly wakeup to the Gateway scheduler and wires scheduler ownership through the recorder, direct local-agent command, and QA child.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main and the latest release still use the private audit timer; the merged scheduler foundation covers a different consumer. I found no concrete blocking defect in this patch.

Priority: P3
Reviewed head: 1af765860aabc761b3a731fe1917b82cb94fc56c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused cutover with relevant lifecycle coverage and a successful exact-head CI gate; no concrete correctness or security defect was found.
Proof confidence 🌊 off-meta tidepool Not applicable: The changed audit writer is reached through Gateway subscriptions and direct local audit; the added clock-driven test and reported earlier-head focused suites cover its scheduling and settlement, but no current-head live Gateway run is recorded. The author’s verified repository admin permission makes contributor live proof inapplicable. 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: The changed audit writer is reached through Gateway subscriptions and direct local audit; the added clock-driven test and reported earlier-head focused suites cover its scheduling and settlement, but no current-head live Gateway run is recorded. The author’s verified repository admin permission makes contributor live proof inapplicable. No stored-data contract changes.
Evidence reviewed 9 items Introduced timer cutover: The PR replaces the writer’s private hourly interval with a named recurring scheduler job and cancels that job when the writer stops.
Still needed on main: Fetched main still creates the private hourly audit interval, so the central cutover has not landed.
Release check: The latest identified release also retains the private interval; this PR is neither shipped nor redundant with that release.
Findings None None.
Security None None.

How this fits together

The audit recorder accepts trusted run, tool, and message events under the configured collection policy. Its writer queues accepted metadata for the shared SQLite worker, while scheduled maintenance prunes retained records.

flowchart LR
A[Trusted runtime events] --> B[Audit collection policy]
B --> C[Audit writer queue]
D[Gateway scheduler] --> C
C --> E[Shared SQLite worker]
E --> F[Audit ledger and retention]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +19, Tests +106. Total +125 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 4 35 16 +19
Tests 6 119 13 +106
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 154 29 +125

Review metrics

None.

Technical review

Best possible solution:

Use the existing Gateway scheduler for hourly audit pruning while preserving the writer’s worker-backed FIFO, startup maintenance, and shutdown drain.

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

Not applicable: this is a scheduling refactor rather than a reported failing user flow. Current main’s interval and the branch’s scheduler registration are directly visible in source.

Is this the best way to solve the issue?

Yes. The patch uses the existing scheduler, supplies it at the Gateway boundary, and gives standalone audit callers explicit lifetimes without adding another timer owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a bounded internal timer-ownership refactor with no claimed user-visible behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The changed audit writer is reached through Gateway subscriptions and direct local audit; the added clock-driven test and reported earlier-head focused suites cover its scheduling and settlement, but no current-head live Gateway run is recorded. The author’s verified repository admin permission makes contributor live proof inapplicable. No stored-data contract changes.

Label justifications:

  • P3: This is a bounded internal timer-ownership refactor with no claimed user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The changed audit writer is reached through Gateway subscriptions and direct local audit; the added clock-driven test and reported earlier-head focused suites cover its scheduling and settlement, but no current-head live Gateway run is recorded. The author’s verified repository admin permission makes contributor live proof inapplicable. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 362cee1 adds src/infra/gateway-scheduler.ts:43 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)
  • Josh Avant: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 72539a3 into main Sep 26, 2026
234 of 235 checks passed
@steipete
steipete deleted the hostneutral/scheduler-audit-0926 branch September 26, 2026 16:05
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

Labels

commands Command implementations gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant