Repository navigation
refactor(audit): schedule retention maintenance through its lifetime owner - #158982
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 11:54 AM ET / 15:54 UTC. ClawSweeper reviewWhat this changesMoves 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +19, Tests +106. Total +125 across 10 files. View PR surface stats
Review metricsNone. Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
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 onto785fdcaa54574186236343ccf3f98680083bf459has 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 enforcedopenclaw/ci-gatereplaces a separate Testboxcheck-changedrun.Prior proof: Blacksmith-testbox, lease
tbx_01m3egmtwwrpzy41g7v4x5807e, run 36232827179. Commands ran afterpnpm install --frozen-lockfilein isolated checkouts. Heada23974aa5034ea2b79ab21dab9ea3055fa4d5b28, verified tree45b182618a2c843441da1188cc1249804e39334f: 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, treefffd103bc2e509f5ee9c41862a09ec4c9c3ee7a4) 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.src/audit/audit-event-writer.lifecycle.test.tssrc/audit/audit-event-writer.test.tssrc/audit/audit-event-writer.worker.test.tssrc/audit/audit-recorder.test.tssrc/audit/execution-decision-work.test.tssrc/commands/agent-local-audit.test.ts(original composition)src/commands/agent-via-gateway.test.ts(original composition)src/gateway/server-runtime-subscriptions.test.ts(original composition)src/gateway/server-runtime-subscriptions.shutdown.test.ts(original composition)src/gateway/server-close.model-acquisition.test.ts(original composition)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.