Skip to content

refactor(claws): author provenance writes with Kysely - #138932

Merged
steipete merged 1 commit into
mainfrom
codex/sqlite-goal-claw-provenance
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sqlite-goal-claw-provenance

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Claw root and package provenance writers maintained raw SQL column and placeholder lists alongside their value objects. That duplicate query definition made storage contracts harder to check against the canonical schema.

Why This Change Was Made

The seven current writers and package compare-and-swap queries now use generated-schema Kysely statements. The existing state transaction remains the write owner. Package replacement still deletes the exact expected row and inserts its replacement atomically, including nullable extension metadata and timestamps; the occupancy query remains version-independent and stops after one row. Replay integrity, relationship/origin/independent ownership, empty expected-status filters, affected-row checks, and post-commit provenance-cache publication are preserved. Legacy read projections and consent-bound schema upgrades are unchanged.

User Impact

No intended user-visible change. Consent, replay, update and removal keep their existing persisted ownership and recovery behavior.

Evidence

  • 52 tests passed across provenance, package update, schema-version handoff, runtime provenance cache, and read-only older-column compatibility.
  • Full changed gate passed, including core and test typechecks, scoped lint, database guards, and runtime import-cycle checks.
  • Native SQLite baseline/candidate proof matched stored rows and all nine expected failure messages, including rejected replacement insertion rolling back and surviving physical close/reopen. Random temporary workspace-derived digest fields were compared for within-run cache consistency and excluded from cross-run equality.
  • One qaRuntime build passed. Twelve normal built CLI commands exercised project creation, add preview, stale-consent rejection, consented add, status, update preview/apply, fresh-process status, remove preview/apply, and absent/empty status. Update retained addedAtMs and changed the package version and managed SOUL.md bytes; removal retained an unowned workspace artifact, removed the agent, and left zero Claw rows with integrity_check=ok. Synthetic state was removed and source hashes were unchanged.

Production delta: +174/-258, net -84 lines across two files. Tests/test support: unchanged. No schema, config, public API, retention, or recovery-policy changes; no new dependency, cache, or storage abstraction.

The initial native proof command invoked the TypeScript preload as an entry point and did no work. The corrected --import command ran the real owner baseline successfully; the candidate and CLI proof passed without product changes or proof retries. Remaining current-schema read cleanup is separate because nontransactional query-error ownership and legacy physical projections require their own contracts.

Independent Codex P0–P2 review completed three scoped passes with no actionable findings. Full owner/caller/sibling source, pinned compiler/parser/native binding contracts, and all native/CLI receipts were supplied. The acting maintainer also inspected these source contracts and both complete proof harnesses directly.

@clawsweeper

clawsweeper Bot commented Sep 5, 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: M maintainer Maintainer-authored PR labels Sep 5, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 5, 2026, 3:15 AM ET / 07:15 UTC.

ClawSweeper review

What this changes

Replaces handwritten SQL for Claw agent and package ownership records with schema-typed Kysely queries, preserving installation, update, and removal behavior.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains useful maintainer-owned cleanup that current main has not absorbed. No actionable correctness defects were found.

Priority: P3
Reviewed head: 32c2f7b403d41f91cd1f61f0768929e8e1075cfd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused refactor with preserved owner boundaries, existing behavioral coverage, and no actionable patch defects.
Proof confidence 🌊 off-meta tidepool Not applicable: The contributor-proof gate is exempt for this maintainer-authored internal refactor. The captured body reports native provenance equivalence and built CLI lifecycle checks; those runtime results were not independently replayed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The contributor-proof gate is exempt for this maintainer-authored internal refactor. The captured body reports native provenance equivalence and built CLI lifecycle checks; those runtime results were not independently replayed.
Evidence reviewed 11 items Verified introduced change and merge result: The complete merge-base-to-head diff changes only the two provenance modules. The test merge records the pinned main and PR head as its two parents, and its difference from main contains those same two files.
Package replacement preserves comparison semantics: The replacement retains all 20 expected-row fields, including six nullable extension fields compared with IS. The absence check remains version-independent, and deletion plus insertion remains within one write transaction.
Transaction and error ownership: The state owner retains synchronous transaction admission and rollback. The existing Kysely executor converts native affected-row counts to bigint; its registered corruption callback defers eviction while a transaction is active.
Findings None None.
Security None None.

How this fits together

Claws are versioned packages that configure an OpenClaw agent. Their provenance store records installed resources and ownership so subsequent updates, retries, status checks, and removal can distinguish managed resources from independently owned ones.

flowchart TD
  A[Claw package and operator consent] --> B[Lifecycle plan]
  B --> C[Provenance writer]
  C --> D{Expected stored state matches}
  D -->|Yes| E[Atomic SQLite write]
  D -->|No| F[Reject stale operation]
  E --> G[Ownership records and runtime cache]
  G --> H[Status, update, and removal]
Loading

Before merge

  • Resolve merge risk (P1) - Reviewer limitation: direct inspection of Kysely 0.29.5 parser/compiler source remains incomplete because local dependency sources are absent and upstream DNS access failed.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -84. Total -84 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 2 174 258 -84
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 174 258 -84

Review metrics

Metric Value Why it matters
Production versus test LOC Production net -84; tests and test support unchanged The reduction removes duplicate SQL column and placeholder definitions without adding a storage abstraction.

Stored data model

Persistent data-model change detected: database schema: src/claws/package-update-provenance.ts, database schema: src/claws/provenance.ts, serialized state: src/claws/provenance.ts, unknown-data-model-change: src/claws/provenance.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep query construction on the existing synchronous SQLite adapter while preserving exact comparisons, transaction ownership, and post-commit publication.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep query construction on the existing synchronous SQLite adapter while preserving exact comparisons, transaction ownership, and post-commit publication.

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

Not applicable: this PR proposes a behavior-preserving refactor rather than a reported runtime defect; existing tests and author-reported native/CLI results provide validation context.

Is this the best way to solve the issue?

Yes, the inspected implementation uses the established store-owned query adapter and removes duplicate SQL definitions. Converting legacy read projections or schema upgrades would introduce separate contracts outside this cleanup.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is bounded internal query-authoring cleanup with no intended user-visible behavior change.
  • 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 contributor-proof gate is exempt for this maintainer-authored internal refactor. The captured body reports native provenance equivalence and built CLI lifecycle checks; those runtime results were not independently replayed.

Label justifications:

  • P3: This is bounded internal query-authoring cleanup with no intended user-visible behavior change.
  • 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 contributor-proof gate is exempt for this maintainer-authored internal refactor. The captured body reports native provenance equivalence and built CLI lifecycle checks; those runtime results were not independently replayed.

Evidence

What I checked:

  • Verified introduced change and merge result: The complete merge-base-to-head diff changes only the two provenance modules. The test merge records the pinned main and PR head as its two parents, and its difference from main contains those same two files. (c88b7c892b08)
  • Package replacement preserves comparison semantics: The replacement retains all 20 expected-row fields, including six nullable extension fields compared with IS. The absence check remains version-independent, and deletion plus insertion remains within one write transaction. (src/claws/package-update-provenance.ts:48, 32c2f7b403d4)
  • Transaction and error ownership: The state owner retains synchronous transaction admission and rollback. The existing Kysely executor converts native affected-row counts to bigint; its registered corruption callback defers eviction while a transaction is active. (src/state/openclaw-state-db.ts:687, 32c2f7b403d4)
  • Replay and publication invariants: Replay still preserves relationship, prior Claw-introduced origin, independent ownership, and installation time. Empty expected-status lists remain unrestricted, and install-cache updates remain after successful transaction return. (src/claws/provenance.ts:483, 32c2f7b403d4)
  • Caller and product contract: The CLI passes consented plans into lifecycle owners; package updates claim expected provenance before invoking installation. Documentation defines managed versus referenced ownership, stale-plan rejection, and retained provenance after uncertain external effects. Public docs: docs/cli/claws.md. (docs/cli/claws.md:358, 32c2f7b403d4)
  • Existing regression coverage: Inspected provenance, package-update, schema-version, runtime-cache, and older-column compatibility tests. They cover stale claims, replay ownership, timestamps, consent-bound legacy handoff, and nonmutating legacy reads. Tests were inspected, not executed in this read-only review. (src/claws/provenance.test.ts, 32c2f7b403d4)

Likely related people:

  • Gio Della-Libera: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

I checked both items in the review at 32c2f7b403d41f91cd1f61f0768929e8e1075cfd.

The dependency inspection gap is resolved by direct inspection of the installed, pinned Kysely 0.29.5 SQLite/default compilers and binary-operation, value, expression, and update-set parsers, together with the native Node 24.20.0 SQLite binding and OpenClaw's synchronous executor/cache/transaction owners. The six nullable expected fields compile to IS comparisons; the fourteen other expected fields retain equality comparisons. Native execution confirmed both null and populated extension fields, version-independent occupancy, stale compare-and-swap rejection, and rollback when replacement insertion fails. Three independent Codex P0–P2 review passes over complete source and dependency context found no actionable findings.

The data-model flag does not correspond to a schema or representation change. The diff changes only query construction in two provenance modules. It retains the existing serializers, legacy read projections, clocks, version filters, transaction boundaries and post-commit cache publication. All 52 focused tests passed, including schema-version handoff, runtime-cache and older-column read compatibility. Paired native runs and fresh-process readback matched stored rows, schema, errors and cache outcomes; only generated fixture paths were normalized for cross-run comparison. No migration or schema-version change is required.

Twelve commands through the built CLI also passed: create, planning, stale-consent refusal, add, status, update, reopen, removal and final empty-state checks. The checks preserved original installation time and unowned artifacts, verified the updated version and workspace contents, and ended with zero Claw provenance rows and integrity_check=ok. All live data was synthetic and removed afterwards. The full changed-file gate and exact-head CI are green.

@steipete
steipete merged commit 33b5289 into main Sep 5, 2026
179 checks passed
@steipete
steipete deleted the codex/sqlite-goal-claw-provenance branch September 5, 2026 07:31
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

1 participant