Repository navigation
fix(gateway): bound audit and Codex backlogs - #126154
Conversation
Live Gateway SQLite lock failures and process heap pressure exposed two independent queue owners. Route best-effort audit persistence through the canonical shared-state connection with bounded contention retries, and remove the per-notification Codex yield so the keyed turn queue can drain directly. Follow-up to #126033 and #126073.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 12:17 AM ET / 04:17 UTC. ClawSweeper reviewWhat this changesThis PR replaces the audit Worker with a bounded process-owned SQLite queue and removes a per-notification scheduling yield from Codex output projection. Regression provenancePossible regression — suspected (reproduction; failure trace). No predecessor PR is attributed. Merge readinessKeep open for maintainer proof review. The audit ownership refactor is source-backed, but the cited upstream Codex runtime contract could not be directly inspected and no after-fix Gateway soak is available. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherGateway audit admission records best-effort activity through the shared state database, while the Codex plugin serializes app-server notifications into each agent turn’s projected output. Both paths handle asynchronous work during active runs. flowchart LR
A[Gateway activity] --> B[Audit admission]
B --> C[Bounded audit queue]
C --> D[Shared state database]
E[Codex output notifications] --> F[Serialized turn router]
F --> G[Notification projection]
G --> H[Agent output]
Decision needed
Why: The PR explicitly grounds its Codex change in an upstream runtime contract and identifies a live soak as the source of the reported failures, neither of which is fully verifiable from this checkout. Before merge
Agent review detailsSecurityNone. PR surfaceSource +137, Tests +251, Docs +6, Other -3. Total +391 across 29 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single process-owned audit writer path, verify the exact Codex upstream contract, and add redacted after-fix Gateway evidence before landing; collapse any remaining timeout/opening duplication into the state-database owner where possible. Do we have a high-confidence way to reproduce the issue? Yes from source: current main’s audit writer creates a separate Worker-backed persistence path, and this PR adds focused contention and burst regressions; no after-fix live Gateway reproduction was supplied. Is this the best way to solve the issue? Unclear: using the process-owned shared-state connection is a coherent owner-boundary repair, but the Codex scheduling premise remains unverified against the upstream runtime cited by the PR. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8c3b3c6ea8d3. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Landing proof for The pre-fix owner regressions failed for the intended reasons: the canonical Final proof:
The live Linux Gateway soak that motivated the repair observed transient audit lock failures and drainable process-memory high-water pressure. The same process reached RSS 3.42 GiB / heap 2.88 GiB and later drained roughly 1.5+ GiB; one observed heap drain was 4.11 GiB to 2.22 GiB in about 13 minutes. This is evidence of an unbounded-but-drainable backlog, not a proven permanent leak. ClawSweeper rank-up moves:
Final LOC: production +537/-400 (net +137), tests +299/-48 (net +251), docs +27/-21 (net +6), tooling +0/-3. The production growth is the reusable fail-fast cold-open and connection-local contention boundary; the audit writer itself deletes the Worker and duplicate connection owner. There is no schema-version or protocol-version change, and no live Gateway was restarted or reconfigured. |
|
Merged via squash.
|
* fix(gateway): bound audit and Codex backlogs Live Gateway SQLite lock failures and process heap pressure exposed two independent queue owners. Route best-effort audit persistence through the canonical shared-state connection with bounded contention retries, and remove the per-notification Codex yield so the keyed turn queue can drain directly. Follow-up to openclaw#126033 and openclaw#126073. * fix(gateway): annotate raw SQLite cold-open probe * test(codex): register notification burst shard
Follow-up to #126033 and #126073.
What Problem This Solves
Fixes two independent backlog owners exposed by a live Linux Gateway soak on deployed commit
fa62fccb867f315bf4282cfc67066d5d878c598a: transientdatabase is lockedaudit failures during concurrent tool-heavy turns, and process memory high-water pressure while large Codex output bursts were draining.The same Gateway process reached RSS 3.42 GiB / heap 2.88 GiB and later similar peaks, then repeatedly drained by roughly 1.5+ GiB. One observed drain moved heap from 4.11 GiB to 2.22 GiB in about 13 minutes. That evidence identifies an unbounded-but-drainable backlog, not a proven permanent leak.
Why This Change Was Made
Audit persistence previously ran in a Worker with its own JavaScript realm and module cache, so it opened a second physical
DatabaseSyncfor the shared global state database. This change removes that Worker and its build/release surface, then uses a bounded process-ownedstructuredClonequeue that drains through the process-canonical SQLite connection. Audit attempts use a reusable connection-local timeout scope, fail fast at timeout 0, retry transient contention asynchronously with bounded 25 ms to 1 s backoff, and emit one sustained audit-specific warning. Corruption, schema, and external-ownership failures remain terminal. Retention now deletes deterministic 1,024-row batches until settled.Separately, Codex notification projection added one
setImmediateper notification even though the keyed turn router already serializes projection and the physical client already owns receive-time rate-limit merging. Exact Codexrust-v0.147.0source permits each stdout and stderr reader to emit up to 10,000 output-delta events using 8,192-byte read buffers for one native shell command. Removing the redundant yield lets that authoritative serialized queue drain directly without dropping output or changing limits.Alternatives were rejected because a transport-specific retry or larger SQLite timeout would preserve duplicate connection ownership, while output dropping or heap-threshold changes would hide rather than remove the notification backlog.
Production LOC is +537/-400 (net +137), tests +298/-48 (net +250), docs +27/-21 (net +6), and tooling +0/-3. The positive production delta is the reusable fail-fast cold-open/contention boundary; the audit writer itself deletes the Worker and duplicate connection owner.
There is no SQLite schema-version change and no Gateway protocol-version change. No live Gateway was restarted or reconfigured. #126073 independently removed idle ingress write amplification and composes with this repair.
User Impact
Gateway audit persistence no longer creates a competing SQLite writer, transient lock contention stays off the agent hot path, and bounded retention avoids oversized cleanup transactions. Codex tool-output bursts drain in order without one macrotask per notification, reducing avoidable process-memory high-water pressure while preserving output and turn ordering.
Release-note context: fixes transient audit SQLite lock failures and drainable process-memory pressure during concurrent tool-heavy Gateway turns.
Evidence
Pre-fix owner regressions failed for the intended reasons:
PRAGMA data_version: expected 2, received 3 because the Worker committed on another connectionPost-fix local proof:
node scripts/check-changed.mjs: all selected gates passedpnpm build: passedpnpm check:docs: passed with 0 broken linksgit diff --check: passedorigin/main: stable patch ID unchanged; current main includes fix(channels): stop idle ingress retention writes #126073Known gap: there has not yet been a post-fix live deployment or soak. Exact-head CI, deterministic owner regressions, and the repo-native Testbox/prepare gate are the landing proof.