Skip to content

test(audit): event-loop probes fail on shared-runner jitter instead of real blocking [AI-assisted] - #128228

Merged
steipete merged 2 commits into
openclaw:mainfrom
8exgh:test/audit-event-loop-probe-jitter
Aug 24, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
8exgh:test/audit-event-loop-probe-jitter

Conversation

@8exgh

@8exgh 8exgh commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Related: #128223

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

Body updated 2026-08-24 to describe the shipped approach. @steipete took the branch over and replaced the original commit with a stronger fix: instead of widening the timing bound, the probes now assert the non-blocking invariant directly. The sections below describe that shipped solution, not the original proposal.

What Problem This Solves

Resolves a problem where PR CI fails on an unrelated shard when a shared runner is under load. src/audit/audit-event-writer.test.ts proved the audit writer stays non-blocking under a held SQLite write lock by scheduling a 25 ms timer and asserting it fired within 250 ms. That is a proxy for the real invariant, and it fails whenever runner scheduling jitter delays the timer — with no product regression involved.

Observed twice on #128223, both in checks-node-compact-large-6:

  • run 32640741873 — expected 275.14786399999866 to be less than 250
  • run 32643396362 — expected 278.6432880000066 to be less than 250, same test, same line

Two of three runs of that shard tripped the probe.

Why This Change Was Made

The probes now assert the invariant they actually exist to protect rather than a timing proxy. observeNonblockingSqliteTransactions wraps the state database's exec, and every BEGIN IMMEDIATE the audit writer issues is checked to run with busy_timeout = 0, throwing if it is ever non-zero. A new state-database lifecycle listener captures the busy timeout at open time, and the tests additionally assert the contender still holds its transaction (contender.isTransaction) and that at least one observed transaction was recorded — so the assertions cannot pass vacuously.

The regression this guards is a synchronous SQLite open/insert that waits out OPENCLAW_SQLITE_BUSY_TIMEOUT_MS (5 s, src/state/openclaw-state-db-contract.ts). Asserting busy_timeout === 0 at each transaction detects that failure mode directly and deterministically, with no dependence on wall-clock timing, so the test no longer has a jitter surface at all. The wrapper restores the original exec own-property descriptor (or deletes the own property when the method came from the prototype) so the observation cannot leak into sibling tests. No production code changes.

User Impact

No user-visible change. Contributor and maintainer PR CI stops going red on runner scheduling jitter in this audit test, and the test now fails for the real reason — a blocking audit write — instead of for a slow runner.

Evidence

AI-assisted (Claude Code); reviewed and understood.

  • pnpm test src/audit/audit-event-writer.test.ts on head f098cf242a7 → Test Files 1 passed (1), Tests 11 passed (11).
  • node scripts/run-oxlint.mjs src/audit/audit-event-writer.test.ts → exit 0.
  • pnpm check:changed → exit 0; git diff --check clean.
  • Both CI failure traces above establish the fault this replaces; the new assertions exercise the same production SQLite boundary under a genuinely held write lock.
  • Not a current main failure at the time of filing (recent main reds were checks-fast-baseline-ratchets); no other open issue or PR tracks this probe.

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@8exgh
8exgh marked this pull request as ready for review August 23, 2026 13:29
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 5:59 AM ET / 09:59 UTC.

ClawSweeper review

What this changes

This PR replaces two audit-writer timing probes with test-only checks that held-lock transactions run with SQLite busy waiting disabled.

Regression provenance

Possible regression — probable (failure trace; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for normal maintainer review: the deterministic SQLite-boundary assertion is a sound replacement for the flaky timer proxy, and current main does not contain this change.

Priority: P3
Reviewed head: f098cf242a75641db497d5bbd13568c3491bf69b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch replaces an infrastructure-sensitive proxy with a direct invariant check and has focused after-fix terminal evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body includes an after-fix terminal run of the changed test file on the current head; that directly demonstrates this test-only behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes an after-fix terminal run of the changed test file on the current head; that directly demonstrates this test-only behavior.
Evidence reviewed 7 items Changed test boundary: The PR observes the real cached state-database connection, records each immediate transaction, and fails if its busy timeout is nonzero; both held-lock tests also require at least one observed transaction.
Owner boundary: The writer wraps both maintenance and queued persistence through the shared-state busy-timeout owner with a zero timeout.
Transaction contract: Immediate state writes call exec with the exact BEGIN IMMEDIATE statement, which is the transaction boundary observed by the new test.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/audit/audit-event-writer.test.ts

Result: PASS (completed)

pnpm test src/audit/audit-event-writer.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128228-JIFdNJ/target$ pnpm test src/audit/audit-event-writer.test.ts
$ node --import tsx scripts/test-projects.mts src/audit/audit-event-writer.test.ts
pnpm test src/audit/audit-event-writer.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128228-JIFdNJ/target

 ✓  unit  src/audit/audit-event-writer.test.ts (11 tests) 5423ms
     ✓ keeps progress absent while disabled and routes enabled progress off audit_events  1483ms
     ✓ flushes accepted events through the canonical state connection  1103ms
     ✓ keeps fresh storage identity-free when recovery evidence is missing  763ms
     ✓ keeps a cold owner open nonblocking under a held write lock  412ms
     ✓ keeps schema and insert failures off the admission path  348ms

 Test Files  1 passed (1)
      Tests  11 passed (11)
   Start at  10:00:15
   Duration  7.61s (transform 1.61s, setup 594ms, import 1.32s, tests 5.42s, environment 0ms)

[test] passed 1 Vitest shard in 14.16s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128228-JIFdNJ/target$ pnpm test src/audit/audit-event-writer.test.ts
$ node --import tsx scripts/test-projects.mts src/audit/audit-event-writer.test.ts




























Assertions:

  • PASS expect_output: Test Files 1 passed

How this fits together

The audit event writer queues audit metadata into OpenClaw’s shared SQLite state database. Its tests hold a competing write lock and verify that audit persistence fails fast and retries instead of blocking the process.

flowchart LR
  A[Audit metadata] --> B[Audit writer queue]
  B --> C[Shared state database]
  D[Competing write lock] --> C
  C --> E[Busy-timeout policy]
  E --> F[Immediate transaction]
  F --> G[Deterministic test assertion]
Loading

Before merge

  • Resolve merge risk (P1) - This test changes CI’s regression guard; merge only after the remaining exact-head checks complete successfully, since green checks alone cannot show whether a weakened lock-contention assertion was introduced.
Agent review details

Security

None.

PR surface

Tests +54. Total +54 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 67 13 +54
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 67 13 +54

Review metrics

Metric Value Why it matters
Production vs test LOC production +0/-0; tests +67/-13 The entire diff is a focused test reliability rewrite and leaves runtime behavior unchanged.

Merge-risk options

Maintainer options:

  1. Finish exact-head CI (recommended)
    Merge after the remaining checks for f098cf2 pass, preserving the deterministic lock-contention guard.

Technical review

Best possible solution:

Keep the held-lock scenarios and their deterministic busy-timeout assertions, then land after exact-head CI confirms the test remains reliable.

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

Yes, source-reproducible: both affected tests hold a competing SQLite write transaction, and the PR body records two CI failures of the previous timer-based assertion.

Is this the best way to solve the issue?

Yes. Observing the busy-timeout value at the actual immediate-transaction boundary directly protects the non-blocking invariant while retaining held-lock and non-vacuity checks.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: The change improves internal CI reliability without changing user-visible behavior.
  • merge-risk: 🚨 automation: The PR changes the audit test’s CI regression-detection mechanism, so a bad merge could weaken or destabilize automated coverage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes an after-fix terminal run of the changed test file on the current head; that directly demonstrates this test-only behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes an after-fix terminal run of the changed test file on the current head; that directly demonstrates this test-only behavior.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current PR head and has recent substantial audit-writer history. (role: recent area contributor; confidence: high; commits: f098cf242a75, 5564671c4fe0; files: src/audit/audit-event-writer.test.ts, src/audit/audit-event-writer.ts)
  • Kaneki: Current-main blame attributes the audit writer's zero-timeout owner path and state-open path to this contributor. (role: introduced current non-blocking boundary; confidence: high; commits: 444d79aea39b; files: src/audit/audit-event-writer.ts, src/state/openclaw-state-db.ts, src/state/openclaw-state-db-open.ts)
  • Josh Avant: Recent history shows repeated audit event writer work, including execution-identity persistence coverage adjacent to these tests. (role: recent audit contributor; confidence: medium; commits: 562391b9af3c, 618fba92bf01; files: src/audit/audit-event-writer.test.ts, src/audit/audit-event-writer.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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-23T13:34:58.916Z sha 464e0954e857281e95aafa0167c9351c32044757 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T14:36:04.912Z sha eb04c7a845fa8a4a500ae8393c1828e6a9afd502 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T15:12:56.440Z sha 396f930e38a56ec050b3f0cf0dd009d59dd873f6 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Aug 23, 2026
@8exgh
8exgh force-pushed the test/audit-event-loop-probe-jitter branch from eb04c7a to 396f930 Compare August 23, 2026 15:06
@steipete
steipete force-pushed the test/audit-event-loop-probe-jitter branch from 396f930 to e6dd8fc Compare August 24, 2026 09:31
@8exgh

8exgh commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready status for head f098cf242a7 (PR author; the branch now carries @steipete's rewrite).

The latest review's remaining item was "merge only after the remaining exact-head checks complete successfully" — those have since finished:

  • Exact-head CI: run 32713362546 → success, 144 checks green, 0 failing.
  • pnpm test src/audit/audit-event-writer.test.ts on this exact head → Test Files 1 passed (1), Tests 11 passed (11).
  • node scripts/run-oxlint.mjs src/audit/audit-event-writer.test.ts → exit 0 (the three unbound-method / no-promise-executor-return errors from e6dd8fce4d8 are resolved by f098cf242a7).
  • pnpm check:changed → exit 0; git diff --check clean.

I also refreshed the PR description: it still described my original proposal (widening the probe bound to 1 s), which the rewrite replaced with the direct busy_timeout = 0 assertion on each BEGIN IMMEDIATE. The body now documents the shipped approach.

No proof gaps known. Test-only change; no production code touched.

@steipete
steipete merged commit 1bca825 into openclaw:main Aug 24, 2026
189 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 25, 2026
…f real blocking [AI-assisted] (openclaw#128228)

* test(audit): prove nonblocking writes without timer jitter

Co-authored-by: Sean Bennett <[email protected]>

* test(audit): restore observed SQLite methods without lint violations

Co-authored-by: Sean Bennett <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

2 participants