Skip to content

perf(update): skip empty reconciliation snapshots - #193359

Merged
steipete merged 1 commit into
mainfrom
dbasync/regress53-reconciliation
Nov 5, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/regress53-reconciliation

Conversation

@steipete

@steipete steipete commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Update reconciliation starts a read transaction even when no running update matches the request. Startup and restart pay BEGIN/COMMIT for an empty result.

Why This Change Was Made

Related: #190918, #191332.

The reconciliation reader first uses its existing row selection without opening a transaction. An empty result needs no accompanying recovery or restart-sentinel facts. A nonempty result is discarded and selected again inside the existing snapshot before inspecting those facts. Already-pinned callers keep their snapshot. Other admission commands retain their transaction.

No schema, cache, generation, recovery decision, write admission, or SQL projection changes. This accepts one extra SELECT on the uncommon nonempty unpinned path to remove empty-path transaction work. An empty read performs no mutation; its discovery cutoff remains the SELECT. An idle empty watcher has no periodic timer: later discovery comes from admission or a scheduled wake, an explicit status read, or restart.

Evidence

Acceptance before candidate measurement: frozen v3.1.5 synthetic Gateway/WebSocket workload on the exact parent and candidate, including boot, 14 turns, history/control RPCs, nested turn, cron, connected idle, and restart. Count SQL statements, worker requests, and Gateway MAIN by operation; cold/restart and warm remain separate. Expected: eight fewer BEGIN/COMMIT statements in updateRuns.reconciliationCandidates, no request increase or MAIN increase. All shared session-read families and causal first/warm turns must hold. Any new adverse cell of 20% stops acceptance; the explicitly accepted nonempty-path SELECT is recorded separately. This is count evidence, with no latency or CPU improvement claim.

Initial current-main reproduction on 97b24c9: reconciliation 12 SQL / 4 requests / 0 MAIN. The synthetic workload has no update_runs table, so this reproduces missing-table empty envelope overhead, not an existing-table empty SELECT. An existing real-ledger regression separately verifies the empty-result contract after excluding the only running update.

Regression: the existing-ledger empty selection returns the correct result on the parent but issues BEGIN/COMMIT (two exec calls); with the change it returns the same result with zero transaction commands. All 52 focused reader, worker-reconciliation, and recovery-admission tests pass (89.26 seconds for the three-file run). Two isolated Codex P0–P2 reviews are scoped-clean. PostgreSQL semantic review approved this exact head. All three PostgreSQL shards, required normal PR CI, and both published-driver update steps passed on the exact head.

Exact-parent refresh: bc11de935b017b79c2c5cd407c750d8cc1cdebc4, after config-health landed. The frozen baseline passed before the production cut: 2967 SQL / 796 requests / 105 MAIN overall; reconciliation remains 12 / 4 / 0. Ten warm turns have median 49 / 14 / 0, p95 52 / 15 / 0, ranges 49–52 / 14–15 / 0. The earlier reproduction is context, not the new exact-parent comparison.

Simplification: transaction ownership moves into the existing reconciliation reader; the shared dispatcher no longer unconditionally pins this command. Production is +14 lines; tests are net zero by reusing the existing equivalent state-database fixture teardown. No new exported API.

Open-PR overlap: all ten indexed peer heads were unchanged at refresh. Paired git merge-tree comparisons add no conflict paths or blocks: #163964 (581→581 paths), #162160 (580→580), #162144 (579→579), #162132 (579→579), #162126 (579→579), #161344 (583→583), #152205 (610→610), #151441 (584→584), #150246 (582→582), #148581 (582→582).

Final frozen pair on the exact parent above and 81182484b0d91dbb4119918c64b4b84d8b3ef1b4:

Metric (SQL / requests / MAIN) Parent Candidate
Reconciliation, whole workload 12 / 4 / 0 4 / 4 / 0
Reconciliation, cold boot 8 / 2 / 0 4 / 2 / 0
Reconciliation, restart 4 / 2 / 0 0 / 2 / 0
Causal warm median 49 / 14 / 0 49 / 14 / 0
Causal warm p95 52 / 15 / 0 52 / 15 / 0
Whole workload 2967 / 796 / 105 2990 / 794 / 105

Ten warm turns per arm in one same-platform pair; warm ranges are 49–52 SQL, 14–15 requests and zero MAIN in both. All count-conservation checks pass, unknown attribution stays 9 SQL / 25 requests, and exact-entry, actor hydration, row facts, entry receipts, snapshot reads and rewrite watermarks are unchanged. Both workloads complete boot, real WebSocket turns, five-minute connected idle, restart and clean shutdown. No timing or CPU saving claim.

Whole-workload SQL rises by 23 despite the targeted eight-statement saving. Operation attribution shows +30 SQL / +1 request from unchanged transcript-index installStatusTracking on the restart turn, +1 SQL each from unchanged deletion snapshot, model catalog and unattributed-to-request worker bookkeeping, and -2 SQL from memory-source reads. The restart turn's 141→174 SQL (>20%) is disclosed as unchanged-owner initialization, not accepted as a reconciliation regression or a whole-workload improvement. Runtime MAIN stays zero; total MAIN stays 105. Phase-placement changes in unrelated background requests are not causal warm-turn changes.

Local check:changed passes format, typed lint, all selected type lanes, source contracts, T1/dialect guards and Madge (zero cycles). Its script Knip scan is clean; production/full Knip fail only on the pre-existing handleUpgradeRequest export in src/secrets/egress-proxy/proxy-forward.ts. That file is byte-identical on parent and candidate; current main already fixes the export in 73145ebb3d2af927adab8aff1ed6040d30b2b5d8. This is not reported as a clean local aggregate. CI static results and merge-tree inclusion of that fix are verified separately before landing.

Supplemental run 42001310015 dependency job 127157750439 reports only that same export. Scheduled main run 41994726590 at ba75cf710e1589b58af0b547de2df9e17468e2fb, job 127135524057, independently reports it at the identical source blob. Current main's repair is already included in the clean prospective merge tree. No static exception for a PR-caused failure is used. The hosted review completed on the exact head with no findings.

Supplemental-only UI observation: run 42001310015, job 127157747987, passes 32 cases and fails ui/src/e2e/slack-inline-identity.e2e.test.ts:144 because the transcript remains a loading skeleton instead of containing the expected text. That UI source is untouched. This is recorded as an unverified out-of-scope observation, not a matching-main reproduction or a passing check. The required normal PR run is tracked separately.

Exact-head normal CI 42001291157 completed successfully, including PostgreSQL jobs 127157761487, 127157761457 and 127157761367 and required gate 127169429907. No source push or CI retry was needed.

Published-driver update: run 42001310015, job 127165041922 passed both “Update published driver to candidate” and “Update published baseline under native systemd” using the candidate package from this exact-head run. The supplemental run is not claimed green: its inherited dependency-export failure and separate unverified UI observation are recorded above. The required normal PR run is green. No source changes or test retries followed review.

@clawsweeper

clawsweeper Bot commented Nov 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T09:21:07.942394Z 8118248 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR skips reconciliation read transactions when no running update matches, while preserving snapshots for nonempty results.

Example: Reconciliation excludes the ledger’s only running update.

  • Before: Returns an empty candidate list after BEGIN and COMMIT.
  • After: Returns the same empty list without transaction commands.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is small and source-consistent; reported runtime counts support its narrow benefit, but upgrade execution and broader validation remain unfinished.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body supplies exact-parent Gateway/WebSocket count results, while the inspected screenshots belong to a separate reconnect PR and provide no evidence for reconciliation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Startup and restart perform unnecessary transaction work when no running update needs reconciliation.
Reason: Maintainer direction is established, the saving is narrowly measured, and the implementation preserves existing recovery and completion ownership.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it is a focused, maintainer-backed optimization absent from current main, with no introduced correctness or security defect found.

Priority: P3
Reviewed head: 81182484b0d91dbb4119918c64b4b84d8b3ef1b4

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The body explicitly leaves the published-driver upgrade run pending; its completed result is not yet available.
Agent review details

How this fits together

Gateway and updater reconciliation send selection criteria to the shared-state reader, which returns update records and recovery facts for the existing writer to revalidate before mutation.

flowchart TD
A[Gateway or updater] --> B[Shared state reader]
B --> C[Reconciliation selection]
C --> D[Empty result]
C --> E[Nonempty snapshot read]
E --> F[Writer revalidation]
Loading

Technical review

Best possible solution:

Retain this small reader-owned optimization and complete the existing validation gates before landing.

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

The parent dispatcher unconditionally opens a snapshot before discovering an empty reconciliation result; source inspection establishes the overhead, and the body reports matching parent/head measurements without this review executing target code.

Is this the best way to solve the issue?

The patch uses the existing reader and transaction helper, preserves writer revalidation, and adds no cache, state, public API, or competing owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d0eb40dc0153.

Provenance checked

  • Admission snapshot ownership changes intended behavior with a stated reason (1a74a80: Read recovery metadata coherently through the isolated live-reader boundary while preserving writer-side checks.)
  • Read-only reconciliation module keeps the original intent (f2715ed: Separate reconciliation reads from the update write graph to avoid bundling the Gateway into standalone state readers.)
  • Foreground update completion keeps the original intent (6f60774: Preserve replacement-Gateway completion ownership instead of falsely marking successful foreground updates abandoned.)
  • Reader fixture cleanup keeps the original intent (bafb952: Preserve worker cleanup, artifact protection, and history semantics when moving asynchronous ledger reads off the caller thread.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduction and current main: The introduced diff changes only the admission reader, reconciliation reader, and existing reader tests; fetched main retains unconditional reconciliation snapshot admission. (src/infra/update-run-admission.read.ts:16, 81182484b0d9)
  • Snapshot consistency preserved: The preliminary nonempty selection is discarded; records and their recovery/sentinel facts are read again inside the existing snapshot helper, which also reuses an already-open transaction. (src/infra/update-run-reconciliation.read.ts:73, 81182484b0d9)
  • Mutation owner unchanged: The writer rereads selected records and recovery eligibility under its write transaction, retaining current-authority checks before committing. (src/infra/update-run-reconciliation.worker.ts:76, 81182484b0d9)
  • Measured scope and accepted tradeoff: The body reports exact-parent Gateway/WebSocket reconciliation counts of 12→4 SQL statements with four requests and zero MAIN SQL unchanged, explicitly accepts an extra selection for nonempty unpinned reads, and discloses whole-workload SQL rising 2967→2990 without claiming overall latency or CPU improvement. (81182484b0d9)
  • Earlier recovery contract: fix(update): avoid snapshot failures in live recovery checks #191332 established coherent metadata snapshots and writer-side recovery rechecks; this PR retains both protections whenever candidates exist. (src/infra/update-run-admission.read.ts:22, 1a74a80617cf)
  • Validation remains unfinished: The pull-request CI run remains in progress at its aggregate gate; a separate exact-head workflow dispatch has dependency/deadcode and Slack UI assertion failures, with published-driver update execution still pending and no demonstrated attribution of those failures to this diff. (81182484b0d9)

Likely related people:

  • Peter Steinberger: Raw commit 6f60774 adds src/infra/update-run-reconciliation.read.ts:22 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6f60774dcb9d; files: src/infra/update-run-reconciliation.read.ts)
  • Vincent Koc: Raw commit 1a74a80 adds src/infra/update-run-admission.read.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1a74a80617cf; files: src/infra/update-run-admission.read.ts)

PR surface

Source +14, Tests 0. Total +14 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 24 10 +14
Tests 1 11 11 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 35 21 +14

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +14 net lines; tests net zero The added selection helper permits conditional snapshot ownership; the regression reuses an existing fixture and equivalent shared teardown.

Labels

Label changes:

  • add P3: Removes bounded startup/restart transaction overhead without repairing a demonstrated user-facing failure or claiming latency improvement.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: Removes bounded startup/restart transaction overhead without repairing a demonstrated user-facing failure or claiming latency improvement.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete the existing published-driver update run and resolve or establish the cause of the separate dispatch failures.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 5, 2026, 4:46 AM ET / 09:46 UTC.

@steipete
steipete merged commit 8723b3f into main Nov 5, 2026
227 of 231 checks passed
@steipete
steipete deleted the dbasync/regress53-reconciliation branch November 5, 2026 09:58
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
Let the reconciliation owner skip read transactions for empty selections while retaining the existing composite snapshot for nonempty runs and already-pinned callers. The synthetic boot/restart workload removes eight statements with unchanged warm turns. Related: openclaw#190918, openclaw#191332.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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