Skip to content

fix(audit): preserve sequence range validation before numeric decoding - #139587

Merged
steipete merged 1 commit into
mainfrom
codex/test-audit-rowid-range
Sep 6, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/test-audit-rowid-range

Conversation

@steipete

@steipete steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Related: #139428

What Problem This Solves

Audit insertion can throw a native SQLite rowid-conversion error before its existing supported-integer-range check runs. The full-suite profiling run exposed this at the largest safe JavaScript integer boundary.

Why This Change Was Made

Return the inserted sequence as SQLite text, then apply the existing Number conversion and safe-integer guard inside the same transaction. Preserve duplicate no-row handling, pruning, rereading, terminal binding, and rollback order. The regression fixture binds the high-water mark as an actual SQLite INTEGER.

User Impact

Oversized audit sequences receive the existing domain-specific rejection with the insert rolled back. No schema, retention, collection, reader-scope, or generic SQLite decoding policy changes. Net two production lines added; test LOC is unchanged.

Evidence

The original audit-owner test reproduced the native conversion failure with the INTEGER fixture. The unchanged named-error and zero-row rollback assertions pass after the repair. All 198 audit/writer-family cases and 12 transaction cases pass, including deduplication and retention behavior. Full changed checks, formatting/diff checks, deslop and fresh independent P2 review pass.

No runtime reduction is claimed; this repairs a correctness blocker for the campaign baseline.

Read the inserted sequence losslessly before the existing safe-integer guard so oversized audit sequences retain the domain error and transactional rollback. Keep duplicate handling and retention unchanged.
@clawsweeper

clawsweeper Bot commented Sep 6, 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 size: XS maintainer Maintainer-authored PR labels Sep 6, 2026
@steipete
steipete marked this pull request as ready for review September 6, 2026 01:09
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 9:15 PM ET / September 6, 2026, 01:15 UTC.

ClawSweeper review

What this changes

The PR reads newly inserted audit sequence numbers as text before validating their numeric range and corrects the regression fixture to bind a SQLite integer.

Merge readiness

✅ Ready for maintainer review

The repair remains necessary: fetched main and the latest release still decode the inserted row ID before the audit range guard. No actionable defect was found in the proposed patch.

Priority: P2
Reviewed head: b96c6c4d09f84c2d09f6be2a9ef803b4498b164e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful existing regression assertions and no identified correctness or security blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from external-contributor proof requirements; its reported audit-owner regression exercises integer overflow and rollback, and the patch introduces no material authority change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from external-contributor proof requirements; its reported audit-owner regression exercises integer overflow and rollback, and the patch introduces no material authority change.
Evidence reviewed 10 items Verified introduced change: The merge-base-to-head diff contains only the audit insertion repair and integer-fixture correction; unrelated endpoint drift is not attributed to this PR.
SQLite execution boundary: Queries returning columns are fully consumed through statement.iterate(), bypassing statement.run() and its lastInsertRowid decoding. The changed query returns only a text-cast sequence; the existing range check still precedes pruning, rereading, and terminal binding.
Regression protects rejection and rollback: The existing test seeds sqlite_sequence with BigInt(Number.MAX_SAFE_INTEGER), invokes the production persistence owner, and checks both the domain-specific error and zero retained rows. Existing neighboring cases cover duplicate suppression, retention, and reopening. The PR body reports 198 audit/writer cases and 12 transaction cases passing; this review did not execute tests.
Findings None None.
Security None None.

How this fits together

OpenClaw’s audit writer stores metadata about agent, tool, and message activity in a bounded SQLite ledger. Sequence numbers order those records for operator queries and pagination.

flowchart TD
  A[Activity metadata] --> B[Audit writer]
  B --> C[Transactional ledger insert]
  C --> D{New record returned?}
  D -->|No| E[Duplicate ignored]
  D -->|Yes| F{Sequence safely representable?}
  F -->|No| G[Domain error and rollback]
  F -->|Yes| H[Prune and return audit record]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +2, Tests 0. Total +2 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 4 +2
Tests 1 1 1 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 7 5 +2

Review metrics

None.

Technical review

Best possible solution:

Keep lossless sequence decoding local to the audit insert while preserving the existing numeric contract and transactional rollback.

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

Yes, from source: seed the audit sequence high-water mark with BigInt(Number.MAX_SAFE_INTEGER) and insert through recordAuditEvent; the old helper decodes the row ID before the guard. Tests were inspected, not executed during this review.

Is this the best way to solve the issue?

Yes. Returning the sequence as SQL text uses the existing synchronous query helper and repairs decoding at its owning store without changing global SQLite behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs an established audit error-handling contract at an extreme integer boundary with limited operational blast radius.
  • 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 maintainer-authored PR is exempt from external-contributor proof requirements; its reported audit-owner regression exercises integer overflow and rollback, and the patch introduces no material authority change.

Label justifications:

  • P2: This repairs an established audit error-handling contract at an extreme integer boundary with limited operational blast radius.
  • 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 maintainer-authored PR is exempt from external-contributor proof requirements; its reported audit-owner regression exercises integer overflow and rollback, and the patch introduces no material authority change.

Evidence

What I checked:

  • Verified introduced change: The merge-base-to-head diff contains only the audit insertion repair and integer-fixture correction; unrelated endpoint drift is not attributed to this PR. (src/audit/audit-event-store.ts:627, b96c6c4d09f8)
  • SQLite execution boundary: Queries returning columns are fully consumed through statement.iterate(), bypassing statement.run() and its lastInsertRowid decoding. The changed query returns only a text-cast sequence; the existing range check still precedes pruning, rereading, and terminal binding. (src/infra/kysely-sync.ts:79, b96c6c4d09f8)
  • Regression protects rejection and rollback: The existing test seeds sqlite_sequence with BigInt(Number.MAX_SAFE_INTEGER), invokes the production persistence owner, and checks both the domain-specific error and zero retained rows. Existing neighboring cases cover duplicate suppression, retention, and reopening. The PR body reports 198 audit/writer cases and 12 transaction cases passing; this review did not execute tests. (src/audit/audit-events.test.ts:260, b96c6c4d09f8)
  • Rollback remains owned by the transaction: The synchronous transaction helper rolls back when the operation throws, including nested-savepoint rollback. The patch leaves this owner and its transaction boundary unchanged. (src/infra/sqlite-transaction.ts:209, b96c6c4d09f8)
  • Still needed on fetched main: Fetched main retains executeSqliteQuerySync followed by Number(insert.insertId), so the native decoding path still precedes the domain guard. (src/audit/audit-event-store.ts:627, 1d9ce1ac9ffa)
  • Latest release retains the old path: The supplied latest release, v2026.9.2, also uses insert.insertId before the supported-integer-range check. (src/audit/audit-event-store.ts:637, 3928bad9badf)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • 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 ae12ad0 into main Sep 6, 2026
246 checks passed
@steipete
steipete deleted the codex/test-audit-rowid-range branch September 6, 2026 01:28
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 6, 2026
* origin/main: (302 commits)
  test(gateway): preserve held-work close failures (#139593)
  refactor(exec): share package argument scanning (#139560)
  fix(audit): preserve sequence range validation before numeric decoding (#139587)
  fix(transcripts): retain capture ownership through failed cleanup (#139572)
  refactor(models): share selector reference traversal (#139571)
  perf(agents): classify allowlists without intermediate sets (#138392)
  chore(release): update appcast for 2026.9.2 (#139575)
  fix(ci): synchronize cloud retries and board widget input (#139506)
  fix(plugins): explain SDK incompatibilities after core updates (#139458)
  fix(voice-call): retain installed WebSocket behavior under Bun (#139567)
  test(text): consolidate literal sanitizer cases (#139579)
  test(gateway): observe native drain without a lint exception (#139576)
  test(memory): consolidate visibility fixtures without policy defaults (#139569)
  fix(ui): show shimmer skeletons while loading Control UI (#139525)
  test(qa): make cleanup child logging deterministic (#139566)
  test(cli): keep Unix socket fixtures within path limits (#139565)
  fix: avoid slow incognito key checks in large session stores (#139528)
  feat(macos): open Gateway windows from the Gateways menu (#139522)
  test(workshop): isolate marker casing fixture identities (#139554)
  fix(process): require cleanup evidence before releasing owned work (#139517)
  ...

# Conflicts:
#	scripts/release-check.ts
vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit '047587a542ce205ee78354fbd88ba8ec05c07844': (45 commits)
  chore(ui): refresh control ui locales (#139481)
  fix(slack): keep prototype-named emoji shortcodes intact (#136374)
  fix(gateway): deliver upgrade rejection responses under Bun (#139516)
  refactor(test): simplify catalog guards and fix native report fixture (#139496)
  fix(macos): prevent dashboard fixture loopback timeouts (#139556)
  fix(matrix): preserve selected reply targets inside threads (#139479)
  test(gateway): preserve held-work close failures (#139593)
  refactor(exec): share package argument scanning (#139560)
  fix(audit): preserve sequence range validation before numeric decoding (#139587)
  fix(transcripts): retain capture ownership through failed cleanup (#139572)
  refactor(models): share selector reference traversal (#139571)
  perf(agents): classify allowlists without intermediate sets (#138392)
  chore(release): update appcast for 2026.9.2 (#139575)
  fix(ci): synchronize cloud retries and board widget input (#139506)
  fix(plugins): explain SDK incompatibilities after core updates (#139458)
  fix(voice-call): retain installed WebSocket behavior under Bun (#139567)
  test(text): consolidate literal sanitizer cases (#139579)
  test(gateway): observe native drain without a lint exception (#139576)
  test(memory): consolidate visibility fixtures without policy defaults (#139569)
  fix(ui): show shimmer skeletons while loading Control UI (#139525)
  ...
vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit 'refs/openclaw/tasks/pr-135167-main': (2467 commits)
  refactor(ios): reuse shared integer conversion (#139581)
  fix(sessions): prevent database lock failures during reclamation (#139469)
  perf(test): reuse transforms within owned scheduler slots (#139553)
  test(agents): share sparse transcript input fixtures (#139589)
  chore(ui): refresh control ui locales (#139481)
  fix(slack): keep prototype-named emoji shortcodes intact (#136374)
  fix(gateway): deliver upgrade rejection responses under Bun (#139516)
  refactor(test): simplify catalog guards and fix native report fixture (#139496)
  fix(macos): prevent dashboard fixture loopback timeouts (#139556)
  fix(matrix): preserve selected reply targets inside threads (#139479)
  test(gateway): preserve held-work close failures (#139593)
  refactor(exec): share package argument scanning (#139560)
  fix(audit): preserve sequence range validation before numeric decoding (#139587)
  fix(transcripts): retain capture ownership through failed cleanup (#139572)
  refactor(models): share selector reference traversal (#139571)
  perf(agents): classify allowlists without intermediate sets (#138392)
  chore(release): update appcast for 2026.9.2 (#139575)
  fix(ci): synchronize cloud retries and board widget input (#139506)
  fix(plugins): explain SDK incompatibilities after core updates (#139458)
  fix(voice-call): retain installed WebSocket behavior under Bun (#139567)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
openclaw#139587)

Read the inserted sequence losslessly before the existing safe-integer guard so oversized audit sequences retain the domain error and transactional rollback. Keep duplicate handling and retention unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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