Skip to content

fix(state): retain native codes in database verification errors - #138095

Merged
steipete merged 1 commit into
mainfrom
steipete/agitated-morse-2a8b30
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/agitated-morse-2a8b30

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #138067

Additional instructions

This is a same-repository maintainer branch; maintainers can update it.

What Problem This Solves

Resolves a problem where operators investigating background database-verification failures receive only the error name and message, even though Node supplied a string code and a numeric SQLite errcode. The loss happens before the worker sends its result to the Gateway, so the original native distinction is unavailable in the verification diagnostic.

Why This Change Was Made

Preserve the verifier's exact existing message prefix and append a small, I/O-free bounded code projection at the error-to-string boundary. The projection visits at most eight cause nodes, deduplicates admitted codes, limits string codes to 64 uppercase ASCII/digit/underscore characters, and admits only nonnegative signed-32-bit integer SQLite result codes. It does not serialize cause prose, stacks, SQL, aggregate members, or arbitrary metadata.

The verifier still classifies the original error before formatting. Both verification/preparation errors and close failures use the same formatter; an earlier verification failure continues to take precedence over a later close failure. Snapshot workers and all storage, schema, configuration, retention, concurrency, cleanup, serial execution, and IPC lifecycle behavior remain unchanged. No Node or dependency patch is involved.

The generic error formatter was rejected because it expands cause/structured prose, does not preserve SQLite errcode on Errors, and brings a logging-configuration dependency into this worker boundary. A dedicated pure projection keeps those concerns separate and can be reused without importing an executable worker.

User Impact

Background database-verification diagnostics retain native codes needed for troubleshooting. They do not change corruption or quarantine decisions, and they do not interpret generic disk I/O error / errcode=10 as disk exhaustion. The database integrity guide documents that distinction.

Production LOC: +28/-1 (net +27). Tests: +210/-1 (net +209). Documentation: +2/-0. The production growth is the bounded diagnostic capability; no new execution or persistence path is added.

Evidence

Before and after: real synthetic SQLite failure

A disposable non-SQLite file produces the native error code=ERR_SQLITE_ERROR, errcode=26. Before the repair, the verifier returns:

{"ok":false,"error":"Error: file is not a database","terminal":false}

After the repair, including across the real compiled child-process IPC boundary:

{"ok":false,"error":"Error: file is not a database (code=ERR_SQLITE_ERROR, errcode=26)","terminal":false}

The original source bytes remain unchanged. All data was synthetic, with isolated temporary home/state/cache roots; no operator state or Gateway was accessed. Native before/after proof ran on Node 24.20.0, with an additional candidate probe on Node 26.8.1.

Regression and contract proof

env -u LIVE -u OPENCLAW_LIVE_TEST -u OPENCLAW_LIVE_GATEWAY -u OPENCLAW_LIVE_USE_REAL_HOME node scripts/run-vitest.mjs src/state/openclaw-database-verify.test.ts src/state/openclaw-database-verify.process.test.ts src/infra/sqlite-integrity.test.ts

Tests were added before production changes: 16 expected missing-code failures and 27 passes on the original formatter. The repaired candidate passes 52 tests across the verifier and integrity suites. Coverage includes real compiled-child IPC, raw and wrapped I/O failures, extended codes, bounded/deep/cyclic causes, rejected metadata, unchanged original messages, close-error diagnostics, original-failure precedence, terminal classification, cleanup, existing WAL behavior, and quarantine behavior.

node scripts/check-changed.mjs -- docs/reference/database-schemas.md src/infra/sqlite-error-diagnostics.ts src/state/openclaw-database-verify.process.test.ts src/state/openclaw-database-verify.worker.ts

The complete changed gate passed. Its first run hit EPROCESSGROUP_CLEANUP_FAILED during core-test typecheck teardown, without TypeScript diagnostics. The process group was confirmed absent and the lock released; the unchanged retry passed without weakening any guard. Separate focused type-aware lint and the canonical verifier-test typecheck shard also passed.

Direct dependency inspection: Node v24.20.0 error construction, its backup error path, Node v22.22.3's equivalent error construction, and the installed Node SQLite types. SQLite's result-code contract distinguishes generic I/O errors from disk-full errors.

The existing formatter is present in stable v2026.9.1; introduction provenance is not established. This PR repairs the diagnostic boundary rather than attributing the bug to a particular earlier change.

Build and independent review

pnpm build qaRuntime passed: runtime/worker compilation, plugin assets, import guards, runtime postbuild validation, and build stamps completed. A separate native probe of the built dist/state/openclaw-database-verify.worker.js passed on Node 24.20.0, preserving code=ERR_SQLITE_ERROR, errcode=26, and terminal=false; the child closed, source bytes were unchanged, and operator state was untouched.

The full pnpm build did not pass. After six successful declaration compiler groups, the compiler input-stability fence detected changed ctime on a shared ancestor @types/events/index.d.ts dependency. There was no TypeScript diagnostic or task-source change. Dependencies and guards were left unchanged; the runtime profile was then selected because this patch changes no SDK/declaration API. The required exact-head CI artifact build subsequently passed, as recorded below.

Fresh pre-commit Codex autoreview completed successfully with scoped-clean and no findings; the lead accepted the unchanged candidate. Normal commit hooks passed and the committed four-file contents match that reviewed candidate.

ClawSweeper review follow-up

The exact-head review found no patch defect and accepted the native behavior proof. Its sole before-merge item was direct dependency-contract inspection, which its review environment could not complete. That item is addressed by direct maintainer inspection:

The refreshed review's Rank-up move and maintainer decision requested native-contract confirmation or explicit acceptance of the recorded inspection. That request is fulfilled by the direct inspection above and the lead's land-ready confirmation. The additional production surface remains limited to the bounded verifier diagnostic projection. No code change or contract waiver was needed; native review artifacts validated for this exact head.

Exact-head CI completion

CI run 33855067053, attempt 1 completed successfully at f12b17ab47bc6ffbc794cce4bf477858e119f8ea, including the required artifact build and final Windows test job.

node scripts/watch-pr-ci.mjs 138095 f12b17ab47bc6ffbc794cce4bf477858e119f8ea

The repository watcher exited 0 with GREEN and zero pending checks. Temporary GitHub rate-limit and pagination-snapshot errors recovered within its normal bounded retries. No CI job reruns, source changes, or gate bypasses were needed. Native review setup, main-baseline inspection, PR-head inspection, artifact validation, and hosted preparation completed without rebasing.

Landing

Merged through the native workflow as a1e8a18bb197. A pre-intent observation race stopped the first merge; the next request was rejected by GitHub with HTTP 405 because the base branch changed. After explicit operator approval, one native recovery attempt succeeded. The approved source head and landed verifier/helper/test contents match; no merge guard was weakened.

The native workflow posted merge completion, and the paired issue closed with landed proof. The task checkout is clean at the landed main commit; other checkouts and the separate snapshot-worker work were untouched.

Preserve native diagnostic codes for operators investigating background
SQLite verification failures. Keep the original message, verification
verdict, and storage behavior unchanged.

Fixes #138067.
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 08:46
@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 5:31 AM ET / 09:31 UTC.

ClawSweeper review

What this changes

The PR adds bounded Node code and SQLite errcode details to background database-verification errors, with IPC regression coverage and database-guide documentation.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep open. This is a focused candidate fix for the paired open bug and no introduced correctness defect was found; merge remains a maintainer checkpoint because this review environment could not independently retrieve the upstream Node/SQLite contract sources.

Priority: P2
Reviewed head: f12b17ab47bc6ffbc794cce4bf477858e119f8ea
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused patch and boundary coverage are solid; independent upstream contract retrieval is the remaining maintainer-facing confidence gap.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its supplied evidence nevertheless maps the changed verifier formatter to a synthetic native SQLite failure through the compiled child-process entrypoint and reports retained fields with unchanged terminal classification.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is exempt from the external-contributor proof gate; its supplied evidence nevertheless maps the changed verifier formatter to a synthetic native SQLite failure through the compiled child-process entrypoint and reports retained fields with unchanged terminal classification.
Evidence reviewed 8 items Introduced diagnostic boundary: The introduced worker first derives the existing terminal classification, then formats the same caught error; the new formatter only appends bounded diagnostic fields to the result string.
Bounded projection: The new helper admits only regex-bounded code strings and nonnegative signed-32-bit integer errcodes across at most eight cause nodes, without traversing aggregate members or serializing arbitrary fields.
Owner boundary and caller: The child-process caller logs non-terminal results as inconclusive and only uses the separately computed terminal flag to trigger owner-side reconfirmation and quarantine handling.
Findings None None.
Security None None.

How this fits together

The background database verifier prepares database files read-only, checks integrity, and sends per-database results to the Gateway. This change enriches failure diagnostics after classification, while the existing owner still decides whether a failure is inconclusive or quarantine-worthy.

flowchart LR
  A[Database file] --> B[Read-only preparation]
  B --> C[Background verifier]
  C --> D[Integrity classification]
  D --> E[Bounded diagnostic formatter]
  E --> F[Gateway verification result]
Loading

Decision needed

Question Recommendation
Should a network-enabled maintainer independently recheck the recorded Node/SQLite field contract before merge, or explicitly accept the member's recorded direct inspection? Independently confirm the contract: Review Node's SQLite error construction and SQLite result-code documentation from a network-enabled environment, then merge if they match the bounded projection.

Why: The introduced logic depends on native code and errcode field behavior, but this read-only review environment could not retrieve upstream sources to repeat that inspection.

Before merge

  • Resolve merge risk (P1) - The helper adds production code for a one-caller diagnostic capability (+27 net production lines); existing shared formatting is unsuitable because it includes cause prose, but the added surface should remain limited to this verifier boundary.
  • Resolve merge risk (P1) - This review worker could not independently inspect the Node and SQLite upstream contracts because DNS resolution failed; that is a reviewer limitation, not missing contributor proof.
  • Complete next step (P2) - Before merge, have a network-enabled maintainer recheck the Node/SQLite contract or explicitly accept the recorded direct inspection.
  • Resolve review confidence - ClawSweeper must reach high confidence before merge readiness is known.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +27, Tests +209, Docs +2. Total +238 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 28 1 +27
Tests 1 210 1 +209
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 240 2 +238

Review metrics

Metric Value Why it matters
Production versus regression coverage production +27 net, tests +209 net, docs +2 The production growth is a bounded diagnostic projection; tests cover the real child-process boundary plus edge cases, but the new helper should stay scoped to this one result path.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138067
Summary: This PR is the focused candidate repair for the open database-verification diagnostic-loss report.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Recheck the native error contract (recommended)
    Before merge, independently verify that supported Node SQLite errors expose the bounded code and numeric errcode fields the formatter projects.
  2. Accept the documented maintainer inspection
    A maintainer may explicitly accept the recorded Node and SQLite source inspection if an independent repeat is unnecessary.

Technical review

Best possible solution:

Retain the focused formatter at the verifier result boundary, preserve its existing classification and cleanup flow, and record a maintainer-confirmed Node/SQLite contract check before merge.

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

Yes—source-reproducible: current main and stable v2026.8.2 both format verifier failures as name plus message only, while the added synthetic IPC test identifies the exact missing fields. The review did not execute it because the target checkout must remain read-only.

Is this the best way to solve the issue?

Yes, subject to upstream contract confirmation: formatting after the existing classification preserves terminal behavior, while the shared formatter would emit cause prose and requires a redaction policy that this worker does not own.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This repairs operator troubleshooting output for a limited background database-verification path without evidence of data loss or availability impact.
  • add merge-risk: 🚨 other: The diagnostic behavior relies on Node/SQLite native error-field semantics that this reviewer could not independently inspect because upstream DNS retrieval failed.
  • 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: This member-authored PR is exempt from the external-contributor proof gate; its supplied evidence nevertheless maps the changed verifier formatter to a synthetic native SQLite failure through the compiled child-process entrypoint and reports retained fields with unchanged terminal classification.

Label justifications:

  • P2: This repairs operator troubleshooting output for a limited background database-verification path without evidence of data loss or availability impact.
  • merge-risk: 🚨 other: The diagnostic behavior relies on Node/SQLite native error-field semantics that this reviewer could not independently inspect because upstream DNS retrieval failed.
  • 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: This member-authored PR is exempt from the external-contributor proof gate; its supplied evidence nevertheless maps the changed verifier formatter to a synthetic native SQLite failure through the compiled child-process entrypoint and reports retained fields with unchanged terminal classification.

Evidence

What I checked:

  • Introduced diagnostic boundary: The introduced worker first derives the existing terminal classification, then formats the same caught error; the new formatter only appends bounded diagnostic fields to the result string. (src/state/openclaw-database-verify.worker.ts:57, f12b17ab47bc)
  • Bounded projection: The new helper admits only regex-bounded code strings and nonnegative signed-32-bit integer errcodes across at most eight cause nodes, without traversing aggregate members or serializing arbitrary fields. (src/infra/sqlite-error-diagnostics.ts:8, f12b17ab47bc)
  • Owner boundary and caller: The child-process caller logs non-terminal results as inconclusive and only uses the separately computed terminal flag to trigger owner-side reconfirmation and quarantine handling. (src/state/openclaw-database-verify.impl.ts:196, f12b17ab47bc)
  • Boundary regression coverage: The added test exercises the real verifier child-process route with a synthetic non-SQLite file and asserts retained native fields, unchanged terminal classification, and unchanged source bytes; the remaining added cases cover wrappers, bounds, cycles, cleanup, and prior-error precedence. (src/state/openclaw-database-verify.process.test.ts:59, f12b17ab47bc)
  • Existing formatter unsuitable for this boundary: The shared formatter deliberately traverses causes and emits cause messages, so it cannot preserve this worker's existing message-only boundary without a redaction policy. (packages/normalization-core/src/error-coercion.ts:75, f12b17ab47bc)
  • Current and shipped behavior still lack codes: Both current main and the latest supplied stable release retain the old formatter that returns only name and message, so the requested behavior is not already implemented. (src/state/openclaw-database-verify.worker.ts:30, 0965053fe6b9)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vito Cappello: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the recorded Node/SQLite contract from a network-enabled environment or explicitly accept the member's documented direct inspection.

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 (1 earlier review cycle)
  • reviewed 2026-09-04T08:58:34.647Z sha f12b17a :: blocked before merge. :: none

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer verification for exact head f12b17ab47bc6ffbc794cce4bf477858e119f8ea: ready for native preparation and merge.

The dependency-inspection item in ClawSweeper's review is resolved by direct source inspection, not waived. I personally read Node v24.20.0's error constructors, its backup error handlers, and the equivalent v22.22.3 code, plus the installed SQLite types and SQLite result-code documentation. Node stores the string code and integer errcode separately from message text. The formatter preserves those bounded fields without reclassifying the error or interpreting generic IOERR as disk exhaustion. The public v2026.9.1 tag was also rechecked and resolves to ad6fe23aecb9b833d68139b0ddc9f239b894d2f1, whose verifier retains the old lossy formatter.

Validation:

env -u LIVE -u OPENCLAW_LIVE_TEST -u OPENCLAW_LIVE_GATEWAY -u OPENCLAW_LIVE_USE_REAL_HOME node scripts/run-vitest.mjs src/state/openclaw-database-verify.test.ts src/state/openclaw-database-verify.process.test.ts src/infra/sqlite-integrity.test.ts

52 tests passed, with failing-before/passing-after regression proof. The built worker also passed a real synthetic IPC probe: native ERR_SQLITE_ERROR / errcode=26 retained, terminal=false unchanged, child closed, source bytes unchanged, and no operator state accessed.

pnpm build qaRuntime

Runtime build and normal postbuild validation passed. The full local declaration build was rejected by its unchanged dependency-input stability fence; that limitation remains documented in the PR body. The clean CI artifact build passed for this exact head.

node scripts/check-changed.mjs -- docs/reference/database-schemas.md src/infra/sqlite-error-diagnostics.ts src/state/openclaw-database-verify.process.test.ts src/state/openclaw-database-verify.worker.ts

The complete changed gate passed on an unchanged retry after the documented local process-cleanup failure. Fresh independent Codex review was scoped-clean with no findings, and normal commit hooks preserved the reviewed candidate.

CI run 33855067053, attempt 1 and the required openclaw/ci-gate succeeded without job reruns or bypasses. Native review artifacts validated as READY FOR /prepare-pr. The four-file scope remains diagnostic-only; snapshot workers and storage/schema/configuration/retention/concurrency behavior are unchanged.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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 4, 2026
@steipete
steipete merged commit a1e8a18 into main Sep 4, 2026
261 checks passed
@steipete
steipete deleted the steipete/agitated-morse-2a8b30 branch September 4, 2026 09:45
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 4, 2026
Reuse the existing SQLite error-code suffix helper in the snapshot worker while preserving its base message and every worker envelope, exit, classification, and cleanup contract. Remove the duplicated bounded extraction policy without adding API or test seams.

Related: snapshot diagnostics #137999 and verifier diagnostics #138095. Production +4/-27; tests unchanged. Focused boundary suites, byte-equivalent synthetic process captures, changed checks, full build, and Codex autoreview passed.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…claw#138095)

Preserve native diagnostic codes for operators investigating background
SQLite verification failures. Keep the original message, verification
verdict, and storage behavior unchanged.

Fixes openclaw#138067.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…8520)

Reuse the existing SQLite error-code suffix helper in the snapshot worker while preserving its base message and every worker envelope, exit, classification, and cleanup contract. Remove the duplicated bounded extraction policy without adding API or test seams.

Related: snapshot diagnostics openclaw#137999 and verifier diagnostics openclaw#138095. Production +4/-27; tests unchanged. Focused boundary suites, byte-equivalent synthetic process captures, changed checks, full build, and Codex autoreview passed.
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 maintainer Maintainer-authored PR merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: Background database verification drops native SQLite error codes

1 participant