Skip to content

fix(database): use canonical CLI JSON failures - #183393

Merged
steipete merged 2 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-database-json-failures-20261025
Oct 26, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-database-json-failures-20261025

Conversation

@Leon-SK668

@Leon-SK668 Leon-SK668 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Database commands emit a string-valued error on operational failures, so scripts cannot use the documented CLI-wide JSON failure contract.

User Impact

Failed JSON-mode database commands return ok: false and error.type: "cli_error" with exit status 1. Successful payloads, human diagnostics, and ownership/custody checks retain their existing behavior.

Why This Change Was Made

The existing shared database error writer now uses formatCliJsonFailure, the canonical owner of CLI failure output. No second renderer, new error boundary, schema change, or config option is introduced.

Original fix and native proof by @Leon-SK668. Co-authored-by: Leon-SK668 [email protected]

Evidence

Current-main regression: the two Gateway/embedded-agent refusal cases fail with the old string-valued error; both successful claim controls pass. With the fix, the same cases assert the canonical envelope and retain database/WAL/SHM preservation and subsequent owner-write checks. The import-boundary test also verifies that database registration does not eagerly load operation/schema runtimes.

Local commands: TMPDIR=/private/tmp/oc-ct-cliinput OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/cli/database-ownership.process.test.ts src/cli/program/register.database.import-boundary.test.ts --maxWorkers=1; targeted oxlint, oxfmt, and git diff --check. Baseline 6d808362dd8a4853317fafef764b92ec2dac21bc: the intended two refusal cases fail; two claim controls and the import-boundary test pass (133.53s wrapper wall time). Integrated candidate: all five tests pass (199.55s wrapper wall time, ownership suite 163.30s including cold compilation; test bodies 8.9–12.9s each). This extends the existing process fixture because in-process helper tests would miss CLI output/exit behavior and live ownership preservation. Targeted type-aware oxlint, oxfmt, and diff check pass. Codex autoreview is scoped-clean with no actionable P0–P2 findings. Changed-file checks passed the structural/boundary ratchets, then refused local typechecking because compiler dependencies resolve to the shared worktree installation. Their later full-tree dead-export scan reported unchanged main export createScenarioCommandEnvironment in the Telegram e2e script; broad scans were stopped to respect local scope. Exact-head CI is green for f8a046ad8961d281275d770b5bf4ae59b3eea864: run 40247047096, including the CI gate and actual type/lint checks. The unrelated local dead-export finding did not fail this CI run. Final-head ClawSweeper review is clean (2026-10-26 00:02 UTC).

Contributor native proof on Linux/Node 24.22.1 used the same built-CLI driver on base f9ddc22f7a8be8d73fd88b1c24f5bf0d9348ffdd and candidate 216551373cf1c36f7f5512d0140b448d1c931417, with separate temporary home/state/config. Eight process cases covered canonical ownership, restore-path and preservation-locator refusals; byte-identical human ownership diagnostics; fresh/unmodified ownership status; and a legitimate external-manager claim with independent SQLite readback. For example, a claim without external-supervisor mode exited 1 on both: base returned {"error":"Claiming external shared-state ownership requires OPENCLAW_SUPERVISOR_MODE=external."}, candidate returned the same message inside the canonical envelope. Driver SHA-256: 4a141df00c62b4cc5793eec7db7fa1c5e9a222ac365fbfef92c4ef874963fa5e.

No fresh built-CLI live run was performed after integration on this loaded Mac; the contributor proof is retained and attributed, and the current-main process regression supplies the new boundary proof. Actual database port/restore, PostgreSQL, production services, and cross-platform behavior were not live-tested; this patch only changes failure rendering.

Production +3/-3 (net 0); tests +5/-2 (net +3). Simplification removes the private JSON envelope while retaining the existing error owner and process fixture.

@clawsweeper

clawsweeper Bot commented Oct 25, 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 cli CLI command changes size: XS labels Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Database operational failures reuse the canonical CLI JSON failure envelope.

Example: Run openclaw database ownership claim --manager supervisor --json without external-supervisor mode.

  • Before: Exit 1 with {"error":"Claiming external shared-state ownership requires OPENCLAW_SUPERVISOR_MODE=external."}.
  • After: Exit 1 with {"ok":false,"error":{"type":"cli_error","message":"Claiming external shared-state ownership requires OPENCLAW_SUPERVISOR_MODE=external."}}.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A useful, minimal contract repair with supplied built-CLI proof, focused process regressions, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Leon-SK668's supplied built-CLI trace exercises the changed database error writer on isolated Linux state and records the canonical ownership-refusal envelope with exit 1; additional refusal and success controls cover the shared writer, and integration preserves that rendering hunk while reporting passing process regressions.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Scripts parsing documented JSON failures cannot handle database commands through the same error contract.
Reason: The patch restores the documented contract and follows the previously merged CLI direction without adding configuration, state, or another rendering owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a documented CLI contract violation with a focused change; no actionable defects were found, and exact-head CI remains pending.

Priority: P2
Reviewed head: f8a046ad8961d281275d770b5bf4ae59b3eea864

Before merge

None.

Findings

None.

Agent review details

How this fits together

Database command handlers catch operational errors and send them through a shared writer that selects JSON stdout or human stderr and exits with status 1.

flowchart TD
  A[Database CLI invocation] --> B[Database operation]
  B --> C[Shared database error writer]
  C --> D[Canonical JSON formatter]
  D --> E[JSON stdout and exit 1]
  C --> F[Human stderr and exit 1]
Loading

Technical review

Best possible solution:

Merge the existing shared-writer fix once the normal exact-head checks pass.

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

Current-main source directly shows the incorrect string-valued error, and the supplied built-CLI comparison records the corresponding failure; this read-only review ran no target code.

Is this the best way to solve the issue?

This is the smallest complete fix: retain the existing database error boundary, delegate JSON formatting to its canonical owner, and strengthen the existing process regression.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Database error writer changes intended behavior with a stated reason (f31d9d8: The original ownership work established the shared local error boundary and exit behavior; the later merged CLI contract standardized failure envelopes.)
  • Lazy database runtime loading keeps the original intent (9c27ac1: Database help and ownership status should avoid loading schema and ownership-operation runtimes before selection.)
  • Existing process regression keeps the original intent (b5f30fb: The prior test consolidation removed duplication while retaining runtime contracts; this patch extends those existing assertions.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Exact introduced patch: The patch replaces the private JSON envelope with formatCliJsonFailure and extends existing process assertions without changing database operations, ownership checks, successful output, or exit status. (src/cli/program/register.database.ts:14, f8a046ad8961)
  • Current-main defect: Fetched main still emits {error: message} from writeDatabaseError, so the central problem remains unfixed upstream. (src/cli/program/register.database.ts:14, 47a88380810f)
  • Documented and approved contract: The CLI documentation requires nonzero failures to emit ok:false and a typed error object. The merged fix(cli): emit one JSON failure contract for --json invocations #124849 establishes this contract and permits local handlers with required exit behavior to use the canonical formatter. Public docs: docs/cli/index.md. (docs/cli/index.md:82, f8a046ad8961)
  • Supplied production-entry proof: The complete PR body credits Leon-SK668's isolated Linux/Node 24.22.1 built-CLI comparison, records concrete before/after ownership-refusal output and exit 1, and reports human-output, status, restore-refusal, preservation-refusal, and legitimate-claim controls. The integrated candidate additionally reports red-base/green-head process regressions. (f8a046ad8961)
  • History and ownership: Feature history identifies Peter Steinberger across the original ownership command, lazy-loading refactor, database-port work, and current integration. Database-writer blame reaches the original ownership commit. Historical blame for failure-output.ts encountered an unavailable blob; the current formatter and merged contract PR were independently inspected. (src/cli/program/register.database.ts:11, f31d9d8fa929)
  • Exact-head validation state: Production typechecking, source contracts, import boundaries, and several security checks pass; other checks and openclaw/ci-gate remain pending, with no observed failing check. (f8a046ad8961)

Likely related people:

  • Peter Steinberger: Raw commit f31d9d8 adds src/cli/program/register.database.ts:22 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f31d9d8fa929; files: src/cli/program/register.database.ts)

PR surface

Source 0, Tests +3. Total +3 across 2 files. Added test files: 0.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Database failure output violates the documented automation contract, with limited impact on scripts consuming these commands.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-25T07:40:58.857Z sha 2165513 :: needs maintainer review before merge. :: none

Reviewed October 25, 2026, 8:02 PM ET / October 26, 2026, 00:02 UTC (Revision 2).

Preserve the canonical failure renderer and existing live-owner regression
checks while integrating the current database command changes.

Co-authored-by: Leon-SK668 <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 25, 2026
@steipete
steipete merged commit e4074cb into openclaw:main Oct 26, 2026
122 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@Leon-SK668

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and landing this, @steipete! I appreciate the integration work; database scripts can now read failures through the shared CLI JSON contract.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
RomneyDa added a commit that referenced this pull request Oct 28, 2026
Co-authored-by: Leon-SK668 <[email protected]>

(cherry picked from commit e4074cb)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 6232b6321b23bf5eb8177571782c1856c9aed715)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

2 participants