Repository navigation
fix: let large PostgreSQL maintenance operations finish - #201869
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: needs maintainer review before merge. What this changesThis PR gives PostgreSQL migrations and search builds longer statement and bridge deadlines while preserving ordinary request limits. Example: A PostgreSQL migration contains a statement that takes 121 seconds.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a confirmed PostgreSQL timeout defect, and review found no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe database engine admits and migrates stores through a synchronous PostgreSQL connection backed by an I/O worker; transaction options now select maintenance budgets for SQL execution and bridge replies. flowchart LR
A[Store admission or search rebuild] --> B[Existing transaction owner]
B --> C[Transaction-local SQL budget]
B --> D[Synchronous bridge deadline]
D --> E[PostgreSQL I/O worker]
E --> F[PostgreSQL server]
F --> B
Technical reviewBest possible solution: Keep maintenance budgets in the existing transaction and bridge owners, preserving savepoint rollback, caller timeout restoration, and ordinary request limits. Do we have a high-confidence way to reproduce the issue? Current main applies runtime deadlines to maintenance, and the public reproduction records an injected 91-second migration failing with SQLSTATE 57014 while preserving its original schema and row; this review executed no target code. Is this the best way to solve the issue? The patch fixes the deadline owners directly, keeps the lock limit intact, and uses existing savepoints rather than introducing another connection or maintenance subsystem. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d874bf532f4c. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +46, Tests +101, Docs +9. Total +156 across 11 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 HistoryReviewed November 20, 2026, 2:08 PM ET / 19:08 UTC (Revision 3). |
…nce-budgets-p13 # Conflicts: # src/infra/database-engine/search-extension.ts
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…nce-budgets-p13 # Conflicts: # src/infra/postgres-sync/connection.ts
|
Merged via squash.
|
) * fix: let large PostgreSQL maintenance operations finish * test: keep maintenance statements past runtime client bounds --------- Co-authored-by: VACInc <[email protected]>
* fix: let large PostgreSQL maintenance operations finish * test: keep maintenance statements past runtime client bounds --------- Co-authored-by: VACInc <[email protected]> (cherry picked from commit c29f72b) Release adaptation: Preserve the baseline 120s runtime bridge deadline and existing search-extension semantics; apply only maintenance scopes. Do not import the separate client-cutoff protocol. Adjust live-test wording accordingly.: Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 624c457891f22803cb3dcd8c4437aeceb0197759) (cherry picked from commit 4d18a2a6dde2cfa4c42c4ab1e57c371d57fc8cc1)
Baseline adaptation: Apply the one-hour statement and bridge budget only to Workboard schema bootstrap and migration. Keep the existing lock and transaction owners, and omit the newer search-extension paths. (cherry picked from commit c29f72b) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 03b1215ca78c74cd072dd6d7397b18f9c4dfb0cc)
Summary
High Level TLDR
Large database upgrades and search rebuilds can fail at the same timeout on every retry. Give these maintenance transactions a one-hour SQL budget and matching bridge headroom, while keeping ordinary requests on their existing limits.
Root Cause
Runtime connections set a 90-second
statement_timeout, and each synchronous bridge request has a separate 120-second deadline. Schema migrations and whole-store derived builds used these runtime limits too. A migration statement canceled at 90 seconds rolls back, so retrying cannot advance it. Generation fingerprinting can also exceed the bridge deadline across multiple statements.On the base revision, a real
openEngineStoremigration with one retained row and an injectedSELECT pg_sleep(91)failed after 90,028 ms with57014: canceling statement due to statement timeout. The schema stayed at version 1 and the retained row was unchanged. This proves the deadline mechanism, not a production corpus-size threshold.Real behavior proof
On a disposable, Unix-socket-only PostgreSQL 17.12 server:
SHOW statement_timeoutreturned90safterward in both runs.OPENCLAW_E2E_OK_MAINTENANCEthroughagent --agent main --message 'Return marker OPENCLAW_E2E_OK_MAINTENANCE' --thinking off --json: exit 0, readiness true, marker true. No paid model calls.Release compatibility from the current stable release: the official npm
[email protected]package (schemas state 36 / agent 38) ran a real foreground Gateway on a disposable PostgreSQL 17 server with the repository's mock OpenAI config and completed a turn. The candidate, this PR combined with #201856 on the PR merge base, then randoctor --fix --yes --non-interactive --no-workspace-suggestions: it saved pre-migration backups and upgraded the schemas to 40/43. All 8 transcript events kept identical payload hashes, a stored setting and selected config values survived, a new runtime connection reportedstatement_timeout90s, and the candidate Gateway reopened the same session and returned the mock marker. Service repair was disabled; no paid model calls.The same harness fails on current
mainwithout this PR (built at themaincommit this branch merged): candidate Doctor exits 1 withThis agent database scope still requires its existing native owneraftermaintenance finish. The PR merge base passes it, so the failure was introduced onmainafter the merge base and is independent of this PR's code; this branch's current head inherits it through the conflict-resolving merge ofmain. An earlier run with[email protected]on this PR alone also passed.A third regression runs a real
runTransaction(..., { maintenance: true })withSELECT pg_sleep(12)on a connection whose runtime statement budget is 1 second. On the base it failed after 1112 ms (canceling statement due to statement timeout); with this PR it returns after 12015 ms andSHOW statement_timeoutis1safterward. 12 seconds also exceeds the 11-second client cutoff that #201856 derives from that 1-second budget, so this test guards the combination. On a scratch merge of this PR's earlier head with #201856's earlier head (fixed clientquery_timeout), the same test failed after 11078 ms (PostgreSQL connection lost; transaction rolled back). On a scratch merge with #201856's current head it passes in 12024 ms, together with #201856's silent commit and idle regressions (11134 ms and 10066 ms, peers kept).The two earlier committed regressions were red on the base: a delayed bridge reply was rejected at the runtime deadline, and maintenance retained the caller's runtime SQL limit. They now pass. The server regression also exercises migration admission and restoration after nested success and rollback, preserving committed rows.
Landing order
Land #201856 first, then merge
maininto this branch. The only code conflict is the request deadline line insrc/infra/postgres-sync/connection.ts(and its policy import); docs merge cleanly. Verified resolution:Either PR alone is safe: this PR alone has no client cutoff, and #201856 alone keeps the ordinary 100-second cutoff and 120-second deadline.
What was not tested
mainfailure described above. The combined PR code passed the same upgrade on the merge base.Verification
node scripts/test-database-conformance.mjs --engine postgres --connection "$TEST_POSTGRES_CONNECTION" -- src/infra/postgres-sync/connection.test.ts src/infra/database-engine/schema-admission.postgres.test.ts --maxWorkers=1: base 2 failed, 49 passed.node scripts/run-vitest.mjs src/infra/postgres-sync/connection.test.ts src/infra/database-engine/schema-admission.postgres.test.ts src/infra/database-engine/search-extension.postgres.test.ts src/infra/database-engine/postgres-search-admission.postgres.test.ts src/infra/database-engine/postgres-vector-search-schema.postgres.test.ts src/infra/database-engine/postgres-text-search-schema.postgres.test.ts src/infra/database-engine/adapters.test.ts src/infra/database-engine/open.test.ts --maxWorkers=1: 75 passed across eight files. Test shard durations: 1.02 s + 10.97 s; total wrapper wall time 52.74 s. Previous-head CI passed, including all four PostgreSQL conformance shards and the PostgreSQL 16 smoke lane.node scripts/run-vitest.mjs src/infra/database-engine/postgres-search.conformance.test.ts --maxWorkers=1with the same disposable-server preload: 10 passed, including retained source rows, source deletion, rollback, and nonempty derived rebuilds. File duration 3.21 s, wrapper wall time 52.18 s. Total focused proof: 85 passed.search-extension.ts: main's new owner-requested rebuild path now runs inside the maintenance transaction):node scripts/test-database-conformance.mjs --engine postgres --connection <disposable DSN> -- src/infra/postgres-sync src/infra/database-engine/schema-admission.postgres.test.ts src/infra/database-engine/search-extension.postgres.test.ts src/infra/database-engine/postgres-search.conformance.test.ts src/infra/database-engine/postgres-search-admission.postgres.test.ts extensions/memory-core/src/memory/manager-search-rebuild.postgres.test.tson a disposable PostgreSQL 17 server: 45 + 132 + 2 passed.tsconfig.core.jsonand test-infra typecheck, oxlint, oxfmt andgit diff --check: passed.e0836463f29: SUCCESS, including all four PostgreSQL conformance shards and the PostgreSQL 16 smoke.port-command.integration.test.ts: 45 + 160 + 2 passed, including the maintenance composition test (12024 ms), fix: keep database workers healthy after silent connection loss #201856's silent commit/idle regressions (11134 ms, 10066 ms), and the lost-commit-reply port case.node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo: passed.node scripts/run-oxlint.mjsandnode scripts/run-format.mts --checkon changed files: passed.git diff --check: passed.pnpm build: passed in 5m 1.2s, with nonblocking UI budget warnings.Evidence
Local autoreview on the current head (branch mode, P0 to P2, base
3587df70a233dc639b733b9169797d3abd138301) is scoped-clean with no actionable findings. On the earlier head, local autoreview was attempted against base3587df70a233dc639b733b9169797d3abd138301and the complete local change, at P0–P2 coverage. Its CLI isolation preflight failed before a reviewer ran. Hosted review covered heada109443fa41cf70572e7365fa2cd847f9ce25e02and reported no actionable code or security findings. It requested released-data compatibility proof; the real release-to-candidate Doctor upgrade above supplies that proof. Final maintainer review remains required.