Skip to content

fix(audit): keep recording after a rejected metadata event - #176608

Merged
steipete merged 5 commits into
mainfrom
dbasync/turnfuse-audit
Oct 19, 2026
Merged

steipete merged 5 commits into
mainfrom
dbasync/turnfuse-audit

Conversation

@steipete

@steipete steipete commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The audit writer permanently rejects later metadata after one record cannot be cloned, and overflow pruning uses a separate cutoff read before deleting old records.

User Impact

A rejected metadata record no longer disables later audit recording. Retention bounds, FIFO ordering, duplicate-source behavior, and shutdown settlement stay unchanged. No migration or configuration change is required.

Why This Change Was Made

Put the retention cutoff in a scalar subquery of the existing bounded DELETE. Keep the existing transaction and eager PostgreSQL lock before its authoritative work. Remove the obsolete unavailable latch, duplicate progress classification, redundant readiness state, contention-counter wrapper, and retry lower clamp. Native Promise settlement and the existing retry owner already supply those guarantees.

When the cached retention count drifts above the durable count, a zero-row overflow delete refreshes the real count and expiry once. Later inserts then use the repaired owner state without repeating DELETE/MIN queries. A successful overflow deletion still refreshes the retained expiry boundary.

The removed isOutboundMessageProgressInput guard in recordAuditEventInDatabase had no runtime caller besides src/audit/audit-event-writer.worker.ts:80–88. That worker classifies progress at line 85 and routes it to recordOutboundMessageProgressInDatabase at line 86; only terminal audit events reach recordAuditEventInDatabase at line 88. Repository reference search confirms no second runtime caller.

The cold-open contention boundary, drain reentry guard, execution binding, identity projection, and unknown-outcome no-replay behavior remain. Audit metadata is still best effort: the rejected record is reported and dropped; later valid records continue. The two ordinary per-turn audit requests remain separate because their producers straddle model execution.

Production: +22/-43 lines (net -21). Tests: +205/-32 (net +173), including one shared SQLite/PostgreSQL fixture. Documentation: +1. Test routing: +1.

Evidence

Formatting, type-aware oxlint on all six changed TypeScript files, and git diff --check pass. Two isolated Codex P0–P2 review rounds completed. The first was scoped-clean; the correction review found reused source IDs in the new count-drift fixture. Each event now has a distinct ID, so the regression reaches retention recovery rather than audit deduplication. Preparation-only interruptions did not produce additional model rounds. The prior-head run 39178651043 passed all selected jobs except PostgreSQL shard 1 and its aggregate: both new PG cases failed before assertions with Missing PostgreSQL state admission. This head adds the retention test to the database-hosted test registry, correcting that routing. The coordinator approved this exact registry addition. Final-head ordinary CI 39182445508 passes the changed-owner tests, type checks, lint, source contracts, and Madge. All three PostgreSQL shards pass in the exact-head supplemental run 39182457718, including the corrected retention-test routing. Its unrelated remaining jobs were cancelled after required evidence was collected. The mock-export ratchet failure at src/cli/program/root-help.test.ts:33 matches current main 39182492985/job/117838287257.

Head d7b064463f4c92bb2512ac726637b5efb5fbfc9f integrates main e7db41f0c8e9ab25b4a4104474054e5201c8d22e. All seven previously reviewed source/test/doc blobs remain byte-identical to PG-approved 812fbe05cbbe91703fe4f99991b6f1be275ae015; the only additional change is the registry entry. Registry formatting/type-aware lint and native commit hooks pass. Shared-semaphore frozen installs completed successfully; tsrs 0.16.0-ts7.1.0-dev.20260929 is installed, and all type checks use repository lanes. Default pinned Bun is retained for local tests.

The count-drift regression requires one recovery insert, one zero-row delete, and one count/expiry refresh, then exactly one INSERT for each subsequent event. Each PostgreSQL regression has its own database lifecycle. The shared retention regression exercises overflow with sequence gaps, the exact retained window, duplicate replay, and the next sequence. It expects four audit-table statements instead of five for a cold overflow insert. A real queue regression checks valid-before, rejected-uncloneable, valid-after, shutdown drain, and persisted FIFO order. All three baseline regressions fail at the intended assertions: overflow uses five audit-table statements instead of four; an uncloneable event disables later records; count drift causes six statements for the next two inserts instead of two. All three candidate regressions pass under the default pinned Bun runtime. Final Knip 39182457718/job/117838199069 has zero new findings: only FaceTime test exports commandResult, mutedResult, and outgoingCall (ft), identical to scheduled main 39176649118/job/117820741086.

Estimated, unmeasured workload impact: one fewer SQL statement per retention overflow; no change to ordinary warm-turn SQL, worker requests, or MAIN work. No latency claim. Combined workload counts are deferred to the coordinated SQLite/PostgreSQL census. Exact-head PostgreSQL review approved d7b064463f4c92bb2512ac726637b5efb5fbfc9f.

@clawsweeper

clawsweeper Bot commented Oct 18, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T00:52:03.052765Z d7b0644 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@clawsweeper

clawsweeper Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR isolates rejected audit metadata records and combines overflow cutoff selection with retention deletion.

Example: Record run "before", submit metadata containing a function, then record run "after".

  • Before: The malformed record permanently disables acceptance of subsequent audit records.
  • After: The malformed record is rejected while "before" and "after" remain eligible for ordered persistence.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The production change is coherent and focused, but runtime confidence is limited by the unresolved PostgreSQL admission failure.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body explicitly defers runtime proof, and the added tests describe queue recovery and retention scenarios without claiming a passing product run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After one malformed metadata record, later audit history can stop accumulating until the Gateway restarts.
Reason: The maintainer-authored direction restores best-effort collection without changing settings, retention bounds, or authorization.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this maintainer-authored PR open: it repairs a current audit-writer defect, and no definite production regression was found.

Priority: P2
Reviewed head: 51ea150827e69af9819a9d1de31acd230b60d1d0

Before merge

  • Complete next step - Investigate the new PostgreSQL retention test's state-admission failure and establish whether it is diff-caused or also occurs on the base before assigning repair work.

Findings

None.

Tests

  • Missing end-to-end proof: Baseline-red replay remains pending, and the PostgreSQL retention scenario has not reached its assertions successfully.
Agent review details

How this fits together

Trusted lifecycle producers submit metadata to a bounded process-owned FIFO, which dispatches persistence and retention operations through the shared-state worker.

flowchart LR
  A[Lifecycle producers] --> B[Audit writer]
  B --> C[Structured clone boundary]
  C --> D[Bounded FIFO]
  D --> E[Shared state worker]
  E --> F[Audit store and retention]
  F --> G[Audit queries]
Loading

Technical review

Best possible solution:

Keep per-record rejection in the existing FIFO owner and preserve retention semantics through the existing transactional store.

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

Current-main source establishes the writer-boundary sequence: an uncloneable record sets unavailable, then all later submissions return false; this review executed no target code.

Is this the best way to solve the issue?

Removing the latch fixes the owning failure without adding recovery policy; the retention rewrite preserves the existing cutoff and removes one SQL round trip.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c576536264da.

Provenance checked

  • Writer availability and readiness changes intended behavior with a stated reason (f533469: The original worker-backed writer tracked worker errors and exits; later process-owned queue refactors retained the availability state.)
  • Overflow retention keeps the original intent (6e4d1d5: Retained row-count and expiry facts reduce ordinary audit SQL while maintenance and rollback invalidate those facts.)
  • Outbound progress classification keeps the original intent (f7a8638: Nonterminal progress belongs to a companion store so the released activity ledger remains terminal-only; the production worker retains that routing.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -27, Tests +97, Docs +1. Total +71 across 7 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 2 17 44 -27
Tests 4 130 33 +97
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 148 77 +71

Review metrics

Metric Value Why it matters
Production versus test LOC Production +17/-44; tests +130/-33 Production removes obsolete state; test growth adds recovery coverage and shares a retention fixture between SQLite and PostgreSQL.

Labels

Label changes:

  • add P2: The source-proven failure suppresses subsequent diagnostic metadata, but no built-in malformed producer or urgent user incident is established.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The source-proven failure suppresses subsequent diagnostic metadata, but no built-in malformed producer or urgent user incident is established.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 18, 2026, 7:34 PM ET / 23:34 UTC.

@steipete
steipete merged commit 3a2d76f into main Oct 19, 2026
251 of 304 checks passed
@steipete
steipete deleted the dbasync/turnfuse-audit branch October 19, 2026 01:16
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…#176608)

Keep audit recording available after rejected metadata. Fold overflow cutoff selection into the bounded delete, and repair retention count drift once when no rows are deleted.

Preserve retention bounds, FIFO settlement, eager PostgreSQL writer locking, and unknown-outcome no-replay behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant