Repository navigation
refactor(storage): make shared-state identities portable (v22) - #170280
Conversation
|
Codex review: blocked before merge. What this changesThis PR introduces schema v22 with indexed ACP resume columns and explicit receipt and Workshop cursor identities. Example: An approval has rowid 30 and an issued cursor a:100:30.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep this PR open: it implements the accepted storage-portability design and remains distinct from main, with one previously reported documentation defect. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherExisting shared-state writers persist ACP metadata and receipts; resume lookups and audit pages consume their derived identities, while the PostgreSQL generator translates the canonical schema. flowchart LR
A[ACP metadata writers] --> C[Shared state owner]
B[Receipt and Workshop writers] --> C
C --> D[Schema v22 migration]
D --> E[SQLite shared state]
E --> F[Resume and receipt readers]
G[Canonical schema] --> H[PostgreSQL DDL generator]
Technical reviewBest possible solution: Preserve canonical JSON, resume matches, issued cursors, and backup-based rollback through the existing storage owners. Do we have a high-confidence way to reproduce the issue? This is a portability refactor rather than a runtime bug report; source confirms the SQLite-specific constructs it replaces, and no target code was executed. Is this the best way to solve the issue? The implementation follows the approved design by maintaining derived identities in existing writers and replacing the expression-index and runtime rowid paths together. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1fe1e63fe00d. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +191, Tests +544, Docs +24, Config 0, Other -10. Total +749 across 54 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (10 earlier review cycles; latest 8 shown)
Reviewed October 12, 2026, 11:46 PM ET / October 13, 2026, 03:46 UTC (Revision 11). |
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
6541630 to
ff3bf5b
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 649d54ac75
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // same row. New writes subsequently allocate max(cursor_id) + 1. | ||
| // sqlite-allow-raw -- One-time v22 rowid preservation, inside schema maintenance. | ||
| db.exec(`CREATE TABLE ${temporary} (cursor_id INTEGER NOT NULL, ${create.slice(create.indexOf("(") + 1)}; | ||
| INSERT INTO ${temporary} (rowid, ${columns}, cursor_id) SELECT rowid, ${columns}, rowid FROM ${name} ORDER BY rowid; |
There was a problem hiding this comment.
Exclude generated columns from the migration copy
When a v21 database has a generated column on any affected cursor table, normal runtime/Doctor admission makes readTableColumns() use parsed admitted schema facts, which include generated columns. This INSERT consequently names those columns as write targets and SQLite rejects the upgrade with cannot INSERT into generated column, rolling back the schema migration. The preservation test does not expose this because its raw DatabaseSync is not admitted, so the helper falls back to PRAGMA table_info, which omits generated columns; derive the copy list from writable columns (for example, table_xinfo entries with hidden = 0).
AGENTS.md reference: AGENTS.md:L81-L81
Useful? React with 👍 / 👎.
Use typed string bindings for ACP identity writes and native SQLite string extraction during the v22 backfill. Read resume columns directly and remove the scalar conversion parser.
Restore the schema-owner reuse and Doctor migration description from the reviewed merge commits flattened during the rebase. The migration sources match the previously approved PR head.
Build the legacy kind-repair fixture from the frozen pre-v22 schema. Keep the older-reader proof on row decoding and decision writes through the current database owner instead of asserting the pre-v22 physical schema.
Adapt the retained cron history fixture to the shared-state v22 cursor contract. Preserve main's finalization and retention assertions.
649d54a to
94aba42
Compare
…law#170280) Promote shared-state receipt cursors and ACP resume selectors to explicit portable columns while preserving historical identities, opaque cursors, and v21 upgrade behavior. Keep promoted resume values in the existing ACP metadata writer. Adapt the retained cron-history fixture to the v22 cursor contract. Validation: exact-head PostgreSQL conformance, canonical/Workboard generation, focused cron finalization proof, formatting, lint, and Codex review. CI is admitted under the documented unrelated-failure exception for mocked UI timeouts, provider credential fixture admission, and memory-index assertions.
Related: #169254, v22 addendum, combined-v22 sequencing, #170059, #170055, #170084.
Prepared-selection authority regression
The failing CI run tested the PR merged with newer main, including #170470. The original PR head passed all 16 selection-authority cases locally; both reported role/alias cases also passed under Node 24. Pre-fix main
2bd6ca195418c5ff269439f02dd4b0b9b7c664b0independently failed exactly those two cases (14 passed), reproducing CI's missing-revocation assertion.Schema admission renewed an integrity epoch, replacing the profile authority store while native role/alias publishers retained the old store. Workshop change identity and ordering were unrelated. This branch now incorporates main's c445da4029e17 repair, which separates physical-owner lifetime from renewable schema integrity proof. No additional production code or Workshop change was needed. The existing role/alias cases are the regression tests.
Approved pre-rebase head:
649d54ac75429, merging main through877301a3af040.Final merged-head verification: all 46 cases passed across seven suites with
--maxWorkers=1: selection authority (16), Workshop (2), v22 parity/upgrade (4), profile authority (7), and ACP writer/cache/resume (17). The existing role/alias cases fail on pre-fix main and pass with the upstream repair. Vitest times: unit 134.54s, infra 936.01s, ACP 94.68s. Compiler verification completed. Exact-head PostgreSQL conformance passed in run 38343100840, on649d54ac754290a9c5b80d61fc8dfbf31d267984. The broader CI run is not green; failures are recorded below.All 15 PostgreSQL generator tests and canonical/workboard DDL freshness checks passed;
pendingPromotionis empty. Wrapper inventory, formatting,git diff --check, and madge (zero cycles) passed. Core and generator lint passed. Extension lint could not start because plugin-SDK declaration preparation hit its unchanged 300-second timeout twice. Hosted extension lint subsequently passed on the same exact head in job 115118791075, closing the local lint verification gap. No timeout or guard was changed.The final PR delta remains +169 production/config lines, +544 test lines, +26 documentation lines, and +10 generated lines. This repair adds no PR-specific production code; main's owner repair is +25/-5 production lines. No manual merge resolutions were needed.
Landing candidate and CI
Current head:
94aba42c907dc. The rebase onto current main completed without conflicts. The four PR commits preserve their reviewed implementation; the first commit has generator-context differences, and the other three are patch-identical. The rebased main baseline uses shared-state schema v21.The one landing fix adapts main's new retained cron-history fixture to v22 by assigning explicit
cursor_idvalues. Its finalization, retention, and duplicate-result assertions remain intact.pnpm test src/cron/store/run-finalization.worker.test.ts --maxWorkers=1passed: 1 case, 8.126s test time, 906.04s Vitest, 1,021.02s command wall time. Compilation accounts for most of that wall time. A direct check against the canonical v22 DDL reproduces the old fixture's NOT NULL failure and verifies 65 unique cursor identities with the corrected insert. Formatting, lint, whitespace, and a focused Codex review through P2 passed.pnpm db:postgres:genproduced no output changes.pnpm db:postgres:checkpassed all 16 generator cases (115.13s Vitest); canonical and Workboard artifacts are current, andpendingPromotion: [].Exact-head CI run 38359012138 completed: 153 jobs passed, six unrelated jobs failed, and the aggregate CI gate failed. PostgreSQL conformance, security-fast, build artifacts, lint, and the final core shard passed. No job was cancelled by fail-fast, and no wrapper-inventory or eager-import-closure failure was reported. Earlier owner, parity, and upgrade results above remain prior-head proof.
Landing uses the operator-authorized CI exception and head-pinned REST fallback after the native workflow stalled. The workflow's scheduled-main table marked these jobs unknown because it had no matching main shard; the causal-path evidence below supplies the requested attribution. None is described as passing CI.
checks-ui-e2e (1/7)chat-position-rail.e2e.test.ts. Unrelated: mocked Gateway UI tests execute no changed database owners, and this PR has no UI changes.checks-ui-e2e (2/7)chat-reply-preview-recovery.e2e.test.ts. Unrelated: mocked Gateway UI test and owners are outside the PR.checks-ui-e2e (5/7)chat-collapsed-reply-reveal.e2e.test.ts. Unrelated: browser capture in unchanged mocked Gateway UI proof.checks-node-changed-extensions-bundle-29Auth profile credential writes require an admitted worker. Unrelated: the unchanged auth-profile worker-custody guard rejects fixture setup before the v22 migration path.checks-node-changed-extensions-bundle-20checks-node-changed-extensions-bundle-22manager-search-reindex-backoff.test.tsandmanager-session-delta.test.ts. Unrelated: failing memory-index tests, tables, and owners are outside this PR's changes.The generic admission helper's only PR change is exporting catalog capture and defaulting its revision argument; existing call behavior is retained. The failing test files and their owners are outside the 55-file PR delta. All six failed job logs were inspected once and retained as landing evidence.
The previous approved-head run 38344756340 completed with these failures:
run-finalization.worker.test.ts:cron_run_receipts.cursor_idNOT NULLdoctor-maintenance.requester-authority.test.ts: missing expected revocation errorloader.trust-diagnostics.test.ts: runtime config not preparedbundled-provider-auth-literal-parity.2.test.ts: llama-cpp local authThe current required CI failures are admitted under the operator-authorized unrelated-failure exception above. Failed checks remain failed.
The earlier run 38343100840 also reported session-reconnect, exec-approval, and node-worker-launch E2E timeouts. Main-side comparison attempts on pinned main
5ac63514950809ba05512c161264ec0bc0945639were inconclusive: setup and outer harness watchdog failures returned no usable case-level result. The latest attempt retained the cases' own timeouts and assertions, with a longer outer startup budget. These cases are not claimed inherited or passing; the comparison remains an explicit verification gap.What Problem This Solves
ACP resume indexes and shared-state receipt cursors depended on SQLite JSON expressions and implicit rowid identities, preventing equivalent PostgreSQL storage.
Behavior and Ownership
The typed ACP metadata owner uses one identity binding for runtime writes and Doctor identity rewrites. It trims only string resume IDs and writes both promoted columns in the same upsert as
identity_json. Missing and non-string IDs become NULL. The v22 migration uses SQLite's guardedjson_typeandjson_extract, preserving native first-duplicate-key behavior for historical rows. Resume lookup compares the indexed columns directly, without parsing identity JSON or applying a post-filter. The scalar/number parser has been deleted. JSON stays canonical; receipts and the accepted cohort-cache lifetime are unchanged.Approvals, cron receipts, execution decision facts, and Skill Workshop changes receive unique
cursor_idcolumns. Migration preserves original rowids, including gaps, and existing opaque cursor formats. Writers allocatemax(cursor_id) + 1inside their existing transactions. Legacy approval repair recognizes a pinned pre-v22 schema and supplies the cursor column during its rebuild. One migration kind declares all five affected tables. PostgreSQL generation has an emptypendingPromotionlist.Existing resume results, cursors, and insertion ordering survive the v21-to-v22 upgrade. Older builds refuse v22; rollback restores the verified pre-upgrade backup with its matching build. No configuration, retention, or authorization change is introduced.
Accepted Edges
cursor_id = max(cursor_id) + 1re-issues the cursor of a deleted top row, as implicit rowid did. A reader paging> Ncan miss a new row N. This is rare because retention prunes the oldest rows.PostgreSQL text still cannot hold NUL; data-port preflight owns that limitation. This change proves schema conformance, not full PostgreSQL runtime support.
Pre-rebase evidence
Current verification with
--maxWorkers=1: all four v22 parity/upgrade tests, all three wrapper-inventory tests, both resume tests, and the selected Doctor ownership/identity rewrite regression passed. The six-suite ACP infra run passed 39 of 40 cases; the independent clear-writer child hit its unchanged 60-second process timeout after reporting imports ready and write start. It never reported write settlement. That clear branch and its test/process harness are unchanged by this reduction; its isolated replay passed with the same timeout and assertions (102.33s case, 339.35s Vitest). That passing replay does not establish a timing fix; the original timeout remains documented.The other receipt/cohort, metadata read, memory, write, control, and reset cases passed. The full multi-project command took 1,988.29s; the resume command took 206.75s, and the selected Doctor command took 593.82s. The final parity body took 426ms, including exhaustive whitespace verification. All 14 PostgreSQL generator tests and both generated-DDL freshness checks passed. Type-aware lint, formatting, whitespace, and madge (zero cycles) passed. The dialect guard remains shrink-only (design 34→32, engine-maintenance 25→25);
pendingPromotionremains empty.The string parity test exercises the actual metadata writer against migration SQL for trimmed/untrimmed text, the complete whitespace set, Unicode, empty-after-trim strings, and missing/non-string fields. It checks every Unicode code point against the exact 25-character SQL whitespace set. Native migration cases cover invalid JSON and duplicate keys. The Doctor regression verifies that normalizing duplicate-key JSON refreshes the promoted resume column through the same binding. Runtime and Doctor v21 upgrade tests preserve cursor gaps, opaque cursor decoding, ordering, and resume results.
Retained proof for unchanged cursor owners: 51 tests across six suites, six legacy approval migration tests, three historical upgrade regressions, and version/refusal plus publication/restart migration enumerations passed. The prior local Doctor orphan-repair test timed out at its unchanged 120-second limit; a following repair case also failed. These earlier failures remain unresolved and are not counted as passing proof.
Pre-rebase final-head Codex autoreview was clean. The landing rebase retains that reviewed implementation.
Net production/config lines: +169; tests +549; docs +26; generated output +10. No reserved owner file changed.
Rowid inventory and schema-bump coverage
operator-approval-store.receipts.ts/ approval writeroperator_approvals.cursor_id; existing wirerowIdretained.execution-owner-lifecycle-receipts.ts/ cron writercron_run_receipts.cursor_id; same timestamp/cursor ordering.execution-decision-facts.tsexecution_decision_facts.cursor_id; existing receipt-key ordering and wire selectors retained.skills/workshop/changes.kernel.tsskill_workshop_changes.cursor_id; preserves insertion-order ties and pruning.openclaw-state-db-schema-v22-columns.ts,openclaw-state-db-operator-approval-migration.tsopenclaw-state-db-schema-additive.tsdoctor-session-incognito-key-repair-state.tsopenclaw-state-db-task-delivery-recovery.tsupdate-database-restore-source.tsopenclaw-migration-witness.ts,snapshot/git-backup-codec.tssqlite-integrity,sqlite-strict,sqlite-schema-contract-assembly,kysely-sync)rowId/ audit sequenceNo still-reserved owner files were changed. Schema-bump coverage includes the typed migration-to-tables map, runtime/Doctor migration registration, native version limit, version-constant assertions, publication/restart migration enumerations, raw-SQL migration markers, eager wrapper import inventory, generated types, and regenerated PostgreSQL fragments.
Earlier landing candidate:
754ff2fd53f6709a0808862962272c15a42baf9a. Rebased onto main after #170266 and regenerated PostgreSQL artifacts into its single runtime DDL form. All four v22 preservation/parity/upgrade cases passed on the rebased implementation (pnpm test src/state/openclaw-state-db-schema-v22-columns.test.ts --maxWorkers=1: 422.33s command wall time, 370.91s Vitest).pnpm db:postgres:genandpnpm db:postgres:checkpassed, including all 15 generator cases, canonical/workboard freshness, andpendingPromotion: []. The previously reviewed schema-owner reuse and Doctor migration descriptions are preserved.The pre-rebase head passed PostgreSQL conformance, while CI run 38327468439 reported Knip/runtime-config failures and unresolved node-worker lifecycle/launch assertions. These are prior-head evidence, not passing CI for the landing head; final-head attribution remains pending.
Landing CI classification and fixture repair
The rebased CI run 38331192286 completed with four failed test jobs. The two schema-fixture failures are repaired in this head; production code is unchanged by the repair. Focused validation passed for both cases: the legacy Doctor fixture (274.89s command wall time) and the older-reader decision/reopen fixture (329.16s through the repository Node test wrapper). Targeted lint, formatting, and Codex autoreview are clean.
openclaw-state-db.test.ts: migrate operator approvals to system-agent recordsoperator-approval-store.execution-identity.test.ts: older reader write/reopenloader.trust-diagnostics.test.ts: runtime config not preparedtelegram-ingress-coalescing.e2e.test.ts: test/hook and no-output timeoutsIf the two unrelated failures recur, landing uses the authorized native admin exception with exact-head evidence; neither is reported as passing CI.