Repository navigation
fix: avoid sorts on non-null PostgreSQL partial indexes - #183443
Conversation
|
🦞👀 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. |
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. |
|
Codex review: blocked before merge. What this changesThis PR aligns PostgreSQL partial-index ordering with non-null predicates and migrates existing state, agent, and Logbook indexes. Example: Read the first archived-session page from 50,000 PostgreSQL rows.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 5 items remain Keep open: this maintainer-directed PR addresses a measured PostgreSQL performance gap, but three verified introduced regressions block merge. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherCanonical SQLite schemas feed the PostgreSQL generator; existing migration owners install its index definitions, which session, approval, and pruning queries consume. flowchart LR
A[Canonical SQLite schemas] --> B[PostgreSQL schema generator]
B --> C[Generated PostgreSQL indexes]
C --> D[Doctor migration owners]
C --> E[Logbook migration owner]
D --> F[PostgreSQL stores]
E --> F
F --> G[Session and pruning queries]
Technical reviewBest possible solution: Retain the shared generator repair and existing migration owners while completing schema-version consumers, wrapper packaging, and upgrade validation. Do we have a high-confidence way to reproduce the issue? Current-main DDL and query ordering expose the mismatch, supported by the supplied PostgreSQL 17 before/after plans; this read-only review executed no target code. Is this the best way to solve the issue? Predicate-derived nullability belongs in the existing generator, with historical definitions reconstructed by the existing migration helper and no query-specific overrides. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 192947deb5f3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +136, Tests +757, Docs +4, Config 0, Generated 0, Other +20. Total +917 across 35 files. Added test files: 2. 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 Reviewed October 25, 2026, 4:42 AM ET / 08:42 UTC. |
653543d to
4fb00a8
Compare
4fb00a8 to
22ba230
Compare
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
Absorbs openclaw/openclaw main at 2e963ca (2026-10-25T14:37:03-07:00), 545 commits past jump 5's upstream base 9629838, into P' 17d81d6. 27 conflicted files, resolved upstream-first, hunk by hunk: - generated files regenerated with their generators (config baseline, worker-access inventory, gateway validators, PostgreSQL schema catalogs); - tests upstream rewrote or trimmed take upstream's shape, and keep the fork's continuation cases and imports; - source hunks keep the continuation lines alongside upstream's change (announce owner-failure formatting, the attempt continuation import, the embedded candidate's continuation options, the liveness-type import). Agent schema: upstream took 35 for a PostgreSQL-only partial-index ordering step (openclaw#183443). The continuation recipient-authority step moves 35 -> 36, on top of it. On SQLite a jump-5 database at 35 is upstream's 35 plus the authority table, so the idempotent step 36 admits it and keeps its rows. This is the default pending the seat owners' ruling (TROUBLE posted with fixtures before this commit). Hand port in a cleanly merged file: session-transcript-worker-readers.ts follows upstream's reader(prepare, project) signature for the fork's readEntryAvailability reader. Refs karmaterminal/openclaw-bootstrap#1727 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The jump-6 merge moved the continuation recipient-authority step from 35 to 36, above upstream's PostgreSQL-only 35 (openclaw#183443). The fork's schema tests pinned 35, so they now pin 36 at the same strength. That includes the two rollback cases' publication guards: they deny the user_version write of the target, and at 35 they would never fire. New cases prove the renumber at its owner: - an upstream-history SQLite database at 35 (metadata-only step, no authority table) gains the table on the way to 36, beside 32-34; - a database jump 5 wrote at its schema 35 (upstream's 35 plus the table, the shape live on four seats) reaches 36 and keeps its authority rows across reopen, beside the pre-jump-5 schema-32 case. RED at the merge 86ed749: 7/8/5 failures on the version literals. GREEN here: 10/10, 11/11, 9/9. Patch-only negative control (authority left at 35): the upstream schema-35 case fails with "missing table session_recipient_authority", the database the rejected numbering strands. Also names the authority constant in openclaw-agent-schema-history.ts, where a comment still said v32. Refs karmaterminal/openclaw-bootstrap#1727 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Fixes extra PostgreSQL sorts when a partial index excludes null keys but its index ordering still preserves SQLite null placement, including archived session listing and terminal-record pruning.
Related: #183015, #183114.
User Impact
PostgreSQL-readiness preparation with no observable SQLite result change, canonical SQLite DDL change, new runtime dependency, driver, or configuration option. Existing PostgreSQL stores advance state 32→33, agent 34→35, and Logbook 2→3 through their existing migration owners. The migration rebuilds only the affected indexes; primary-key indexes remain in place.
Why This Change Was Made
The schema generator now treats a direct key as non-null for ordering when the index predicate proves it with
IS NOT NULL. AND combines proofs, OR retains their intersection, and NOT discards them. One rule covers all 28 qualifying indexes, including equality-only indexes; there are no per-index overrides or ORDER BY compiler changes. The affected production queries already emit matching PostgreSQL-default ordering.Historical admissions and backup/port descriptors retain their original ordering policy. Doctor owns state and agent upgrades; Logbook retains its service-open migration owner. Existing advisory-lock and transaction boundaries are unchanged.
Evidence
Homebrew PostgreSQL 17, 50,000-row synthetic cohorts,
EXPLAIN (ANALYZE, BUFFERS), before/after median milliseconds:These are query-plan measurements, not a blanket Gateway latency claim. Four initially suspect unchanged-plan cells were rerun with fresh VACUUM ANALYZE, ABAB interleaving, and 15 samples per side:
All four retain the same plan/index structure and paired buffer counts (prefix pruning saves one buffer hit). The remaining conversation-update +0.781 ms median difference is within the observed variability; no systematic regression was reproduced.
Validation so far: focused generator regression RED/GREEN; historical-policy unit tests; byte-exact predecessor DDL reconstruction; 17/17 focused runtime tests, including all five production owners on both engines, historical state/agent migration, and selective Logbook migration; formatting and diff checks. The new two-engine test file took 119.51 s within the focused runner on the loaded host; the complete three-file run took 524.24 s including worker compilation and artifact verification.
pr-simplifyand final isolated autoreview are clean (no actionable P0–P2 findings). Normal formatting, Markdown, and line-cap commit hooks passed; feature-head source-performance build passed in 6m 16.9s before the mechanical CI repairs and main integration.All affected generated DDL files remain byte-identical to that successful runtime proof. Real CLI migration proof on feature head
653543dd3558used genuine predecessor-owned state32/agent34/Logbook2 stores with 50,000-row cohorts and valid original schema seals.pnpm openclaw doctor --fix --non-interactive --no-workspace-suggestionsexited0, upgraded state/agent, and preserved all seeded row hashes/counts and primary-key OIDs. Gateway startup reached ready/coreReady with no failing readiness components and migrated Logbook to3. Restart pluspnpm openclaw gateway health --json --timeout 30000passed without any further index rebuild.The full Doctor duration includes physical validation, backup export and other maintenance; server batch durations are not caller/bridge timings. Host CPU pressure was reported degraded. These measurements establish migration completion and cost, not a Gateway speed improvement. The first Gateway legitimately installed three unchanged lazy fragments (11 new indexes); independent catalog reconciliation verified this after the scratch runner's overly strict no-new-index assertion failed. A subsequent restart/health proof passed with no catalog change. All owned Gateway/PG processes were stopped and the cluster removed.
CI repairs register the new version and extracted wrapper module, use the supported source-worker loader, and update only current Logbook version expectations. Corrected focused validation passes: 10 two-engine owner tests, 2 historical-policy tests, 4 SQLite diagnostics cases, 5 PostgreSQL diagnostics cases, and the existing Logbook future-version guard. All 200 historical DDL/migration output comparisons remain byte-identical after lint-only edits. The latest owner-test file duration was 206.84s on this loaded host. The branch is integrated with current main; Logbook migrations follow its private schema owner. All five Logbook PG tests pass after that move, including selective v2→v3 rebuild (573ms). Final full-branch isolated review is clean at P0–P2. The approved pre-rebase head passed all three PostgreSQL conformance shards. No Gateway latency or throughput claim is made.
Approved pre-rebase PostgreSQL CI: run 40181892424, head
4fb00a8067f1de42dc4476629f7a9b57f8cd867f.All 1,245 passing tests ran on that approved pre-rebase head, including all 10 new two-engine owner cases, both state/agent historical migrations, and all five PostgreSQL Doctor diagnostics. The 39 skips are reported separately. CI does not provide an isolated wall time for the new file; the earlier isolated 119.51s file measurement above is the test-cost evidence.
The pre-rebase CI run failed five other test jobs, plus the aggregate gate: hooks newline encoding, sandbox configured-agent precedence and Telegram retry input equality, recovered-finalizer tool exposure, pinned external CLI version, and Codex history-clone count. Their attribution remains separate from the PostgreSQL proof; no inherited-failure conclusion is claimed from source equality.
The branch was rebased without conflicts onto main
43cd7f54d1a5, producing22ba23054d6e. The hand-written production patch ID is unchanged. All PostgreSQL generators reproduced the committed outputs byte-for-byte, and the generator, catalog, and ordering tests passed (184 tests; 36.831s).Current-head CI: run 40189744412, tested merge
0c6b64ada928against main5abc0c66e293.All three shards passed: 1,319 executed passes and 40 skips across 12 logged invocations. All ten new SQLite/PostgreSQL ordering cases and the selective predecessor migration cases explicitly passed. The full run completed 187 jobs: 164 passed, 18 skipped, four test jobs failed, and the aggregate failed. Remaining assertions concern sandbox validation precedence, Telegram retry input, hooks stderr newlines, recovered-artifact tools, and the external CLI version. The earlier history-clone failure did not recur.
The requested local
check:changedfinished in 3005.405s with three failures. SDK surface-budget counts and all unused-export findings reproduce exactly on the rebase baseline. Broad lint timed out during Plugin SDK declaration preparation; current-head CI lint jobs passed. Local typechecks, changed-file format, line-cap, Doctor contract checks, import cycles, and root-test lint passed. Failed local checks remain recorded as failed.The coordinator classified CLI JSON stdout and Telegram retry as inherited. All six CLI JSON samples reproduced the sandbox assertion. Three Telegram baselines and candidate B1 reproduced the original input-equality assertion. Candidate B2 missed an earlier fallback reply under x64 emulation; that raw observation is retained and explicitly accepted as timing variance in the already-broken SQLite flow. This PR changes SQLite only through schema-version metadata, with no SQLite DDL or fallback-send behavior change.
The remaining files were replayed sequentially on the exact CI baseline
5abc0c66e293on native Linux x64 (AMD EPYC, Node 24.22.1, pinned Bun 1.4.4), using CI's prepared runtime, an 8192 MiB Node heap, and internal pnpm/Bun caches:All five target assertions reproduced on baseline in all three repetitions. There were no setup timeouts or additional failures. The nine invocations contain 69 passes and 15 expected baseline failures; these are attribution results, not passing test runs or performance comparisons. Under the coordinator's rule, no candidate repetitions were required. The baseline command used
node --import tsx scripts/ci-run-node-test-shard.mtswith one file per invocation.This attributes all four failed jobs in the completed head run 40189744412, attempt 1. CI remains failed; landing uses the explicitly authorized inherited-failure route. The Testbox payload completed without interruption, its final process list was empty, and its evidence was collected before lease cleanup. No source change or manual CI dispatch was made during attribution.