Repository navigation
fix(database): prevent PostgreSQL failures in ancillary stores - #183296
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: blocked before merge. What this changesThis PR replaces SQLite-specific SQL in ancillary stores with shared dialect helpers while preserving existing store ownership and results. Example: Skill usage receives timestamps 200, 100, 300, 150, and 300 on PostgreSQL.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this useful maintainer-authored PR open; current main retains the PostgreSQL failures, and review found no definite introduced bug. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherAncillary store kernels receive usage events, OAuth prefixes, transcript queries, voice lookups, and legacy imports; they execute through existing database owners and return stored records or query results. flowchart TD
A[Feature operations] --> B[Existing store kernels]
B --> C[Shared SQL dialect helpers]
C --> D[Existing query executor]
D --> E[SQLite]
D --> F[PostgreSQL]
E --> G[Records and results]
F --> G
Technical reviewBest possible solution: Keep dialect spelling in the existing database-engine layer and retain each store's current predicates, write ownership, and persisted representation. Do we have a high-confidence way to reproduce the issue? Current-main source emits the identified SQLite-only constructs, and the PR reports intended PostgreSQL failures before repair; this read-only review executed no target code. Is this the best way to solve the issue? The patch follows the smallest complete repair: share dialect constructs, qualify conflicting references, reuse the JSON owner, and preserve existing operation boundaries. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e8b251188f50. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +142, Tests +526. Total +668 across 16 files. Added test files: 4. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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, 1:51 AM ET / 05:51 UTC. |
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. |
|
|
Merged via squash.
|
…law#183296) * fix(database): make ancillary store queries portable to PostgreSQL * refactor(database): use typed capture event counts * fix: include scalar dialect helper in wrapper inventory * chore: shrink assertion-safety baseline for typed debug-proxy query
Related: #183044, #183172
What Problem This Solves
Fixes PostgreSQL failures in skill usage, proxy capture, MCP OAuth prefix lookup, transcript search and deduplication, voice-session lookup, and legacy audit/debug-proxy migration when those paths emit SQLite-only SQL.
User Impact
These PostgreSQL paths preserve their existing SQLite results instead of failing during statement parsing or execution. This is PostgreSQL-readiness preparation: no SQLite runtime behavior, schema, configuration, dependency, admission, or transaction change.
Why This Change Was Made
One dialect owner now supplies numeric extrema, literal substring position, and NULL-safe equality. Voice lookup reuses the existing JSON dialect owner and retains the literal paths used by SQLite partial indexes. Existing inline node-settlement extrema and ACP accounting clamping also move to the shared owner.
All extrema operands here are non-NULL. The helper documents that SQLite scalar min/max propagate NULL while PostgreSQL least/greatest ignore NULL; nullable callers must coalesce explicitly. Skill upsert references are qualified to remove PostgreSQL's target/excluded ambiguity, and debug-proxy session aliases are quoted so reimport comparisons retain their field names.
This is phase 1 of the portability census. Protected session owners and the static guard are deliberately deferred to the final PR; cron repair is routed to its active owner. No allowlist of known defects is introduced.
Evidence
json_valid(text)); that setup failure is excluded from SQL proof.instrand scalarmin, non-NULLISsyntax,GLOB,json_valid, and ambiguous skill-upsert columns. Tests retain literal%/_matching, out-of-order timestamps, nullable utterance deduplication, malformed JSON filtering, and repeated migration idempotence.8faec4a3ab5ac2958c8acd1ab9a35a1179d65359through Testbox: 180 files / 1,230 tests passed, with 3 files / 39 tests intentionally skipped (the SQL-probe SQLite arm and existing Workboard native-only checks). Shards took 445.39 s, 617.17 s, and 376.76 s; total remote command 24m21.686s. This proof was obtained while the PR was draft, using the canonical conformance runner directly with production and runner sources verified against that head. Subsequent changes are limited to wrapper inventory and the assertion-safety allowance.pr-simplifycompleted. Production delta: +217/-75 lines; new owner regression tests and registration: +526 lines. Shared dialect spelling replaces leaf implementations; remaining growth is the four construct helpers and real two-engine regressions.Per-file test cost, each run as
pnpm test <file> --maxWorkers=1on the same Testbox (SQLite control; PG variants run separately above):src/infra/database-engine/scalar-portability.conformance.test.tstext-comparison.conformance.test.tsmigration-sql.conformance.test.tsvoice-lookup.conformance.test.tsFull PostgreSQL proof command, each shard run sequentially against a disposable PostgreSQL 17.11 container on the same Blacksmith Testbox:
The initial full-shard source check failed before SQL because a synthetic capsule omitted the original commit object. Fetching the exact pushed SHA and comparing source bytes corrected that setup assumption; the successful run used unchanged production code. The local Homebrew PostgreSQL server and remote PostgreSQL container are stopped.
Final process inventory found and stopped one leftover esbuild process; the follow-up remote inventory was empty.
The single task-owned Testbox lease was stopped through the repository wrapper and independently verified
completed,ready=false. Local worktree/runtime process checks and PostgreSQL port checks are empty. Coordinator review approved phase 1; the PR is ready for its exact-head CI and native landing gates. Phase 2 and the final static guard are not included.Follow-up check repairs
Added the shared scalar helper to the wrapper extraction inventory and reduced the debug-proxy assertion allowance from 5 to 4 after replacing its unsafe assertion with a typed query. Production and conformance-test bytes remain identical to the coordinator-reviewed head.
The two previously failing wrapper extraction cases pass locally (2/2; 93.02 s wall). All baseline ratchets, line cap, coercion helpers, duplicate detection, generated metadata, dependency patches, import cycles, and formatter checks pass on the isolated candidate. No further baseline change was required.
The three local macOS deadcode commands (
pnpm deadcode:dependencies,pnpm deadcode:unused-files,pnpm deadcode:exports) report unused declarations/files outside this PR. Running all three again on the exact original base with the same installed dependencies reproduces every path/symbol diagnostic; no changed SQL owner or new helper appears. These local results are recorded as inherited failures, not green checks. The preceding exact-head pull-request CI run completed with only the stale assertion allowance and aggregate gate failing; all three PostgreSQL conformance shards passed. Current-head CI and the additional attribution results are recorded below.Current-head CI attribution
Pull-request CI run 40174638340, attempt 1, completed on
db4d8cd0c2dd7d94a9dbd140c4778df637762e56. PostgreSQL shards 1 and 3 passed. The sole root failure was shard 2, job121112880812:postgres interactive setup > setup saves interactive setup and releases ownership for a Gatewaytimed out waiting for PTY exit after authenticated readiness. The aggregate gate also failed.An alternating three-base/three-candidate comparison used real Homebrew PostgreSQL 17.11 and the unchanged conformance runner, fixture, and deadlines. The base was CI's actual first parent
31d06089615d661c03ee35642626dfddfb234641; the candidate was its tested merge83fd01d6cf0a2af5782dc241e0312998853e5426. Base: one complete pass and two authenticated-readiness timeouts. Candidate: two complete passes and one authenticated-readiness timeout; that failed candidate fixture also reportedENOTEMPTYduring cleanup. None reproduced the CI shutdown timeout. Eight recent scheduled main PG2 runs were checked: seven passed and one failed a different idle-connection-reuse case.Coordinator review accepts this as diagnosed flakiness in the Gateway PTY test family, not caused by the candidate: base failed 2/3 attempts, candidate failed 1/3, and this diff changes no Gateway lifecycle, PTY, or shutdown code. Readiness and shutdown signatures remain distinct; passing replays are not claimed as a repair. One explicitly authorized failed-job rerun was submitted for run
40174638340. Attempt 2 completed successfully on the same head: all 101 effective jobs completed, with no failures. PostgreSQL shard 2 and the aggregate CI gate passed. No manual workflow was dispatched.Production and regression-test bytes remain identical to the reviewed head. The normal native merge command was invoked after green CI; it refused before submission because the task-owned clone has no PR review worktree. No admin merge or phase-2 work has been attempted. The five deferred guard files remain uncommitted. All local test processes and PostgreSQL services are stopped.
The initial native landing attempt was blocked on review initialization. From the ordinary checked-out task clone,
scripts/pr merge-run 183296 --auto-mergeexited 1 withMissing PR review worktree. Run: scripts/pr review-init 183296. The native helper confirmed its operation lock was released and all process-group/notification-pipe holders exited. The coordinator instruction forbids hand-runningreview-initand requires stopping on a new refusal, so no alternate initialization or merge route was attempted. Coordinator decision 7 subsequently authorized the documented review initialization sequence.Landed
Merged as
a6e32c0a0236472ca1f5b3644604170c4eebea55at 2026-10-25T10:37:56Z. The native review initialization, checkout, artifact validation, preparation and normal merge sequence all passed on the unchanged approved head. No admin route or manual workflow dispatch was used. GitHub MERGED and main ancestry were independently verified; native cleanup completed successfully. The session-owner fixes and static guard continue in a separate phase-2 PR.