Skip to content

perf(db): remove redundant consume and deletion probes - #183069

Merged
steipete merged 4 commits into
mainfrom
dbasync/sqlprobe-2
Oct 25, 2026
Merged

steipete merged 4 commits into
mainfrom
dbasync/sqlprobe-2

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Three owners asked the database for a fact their next write already reports. Pairing redemption now consumes and returns the join-code row in one dialect-generated DELETE RETURNING. Selected capture deletion reports the two DELETE changes counts inside the existing transaction. Progress overflow pruning embeds the ordered cutoff query in the DELETE.

All pairing authority and validation checks remain: success, missing and expired response bytes, rate-limit error precedence, expired/malformed code consumption, and concurrent single use. Capture still deletes event metadata before session metadata, preserves shared blobs, and removes legacy files only after commit. Progress keeps its 200,000-row cap, 1,024-row prune batch, sequence ordering and affected-row cache update. No schema, public API, cache, worker-routing or cross-store commit change.

Preregistered acceptance (before first run)

Base: 285029f. Committed rule: scripts/perf/sql-probe.md.

Synthetic initialized-owner counts must change: join-code consume 3→2 table statements for present/missing/expired outcomes; selected capture deletion removes exactly two COUNTs per nonempty ID request; overflow progress append 5→4 table statements. Worker requests and main-thread work must not increase. Deterministic count regressions must fail on base, pass on candidate; outcome tests pass on both. Keep rollback, single-use, malformed row and exact HTTP response/error precedence tests.

Use isolated Gateway with real transport, frozen observer and three alternating baseline/candidate warm control pairs when admission load is below 64 (otherwise one pair under the loaded-host rule), with five warm target actions per arm; separate cold/warm. Report median/p95/range for repeated actions, statement/request/MAIN totals and operation attribution. Profile per thread with Node. No elapsed-time claim unless timing lock/load<24 and ≥5 interleaved samples per arm. Investigate each ≥20% increase; no 'within spread' exception. PostgreSQL conformance and exact-head review are required before landing.

Evidence

The deterministic regressions failed on unchanged production only on the intended counts; the outcome and retained-state assertions passed. Candidate native capture, progress, real HTTP pairing, worker and async-consumer tests pass (53 tests; one PostgreSQL-only case skipped). SQLite and PostgreSQL join outcomes, PostgreSQL shared-blob deletion and progress retention pass (10 passed, the PostgreSQL-only capture case skipped for the SQLite half). Both independent Codex reviews found no actionable P0–P2 defects; the second covered the complete production patch.

Initialized owner operation Baseline Candidate target
Join-code redemption, table statements 3 2
Capture selected-delete COUNT statements per request 2 0
PG capture shared / final / missing table statements 6 / 7 / 5 4 / 5 / 3
Progress append crossing retention cap, table statements 5 4

The final head is 4de61b17d3ea1e73c6a7f8a1ce19e1e511f3b1ab, approved by PostgreSQL review. The final shared index contained 2,665 open PRs targeting main. All 80 overlapping heads passed base-only versus base-plus-candidate merge-tree comparisons: no added conflict paths, blocks, messages or changed conflict contents. Current-main merge-tree is clean. All comparisons have zero new conflicts: #183114, #183044, #182971, #182951, #182329, #182216, #182104, #180832, #180026, #178768, #178124, #178033, #177356, #177351, #175345, #175029, #174317, #174235, #173557, #173026, #170160, #169723, #169504, #169438, #169241, #169081, #168522, #168434, #167221, #167090, #166166, #165710, #165583, #164935, #164843, #164721, #164551, #163835, #163655, #163239, #162989, #162583, #162565, #162530, #161997, #161410, #160908, #160851, #159478, #159326, #159255, #158502, #158244, #157693, #157557, #157427, #156634, #155630, #154904, #153907, #153856, #151648, #150078, #149882, #149241, #148533, #146847, #146326, #145839, #141239, #141004, #140609, #139620, #136474, #129388, #126224, #124337, #121204, #107366, #93952.

Exact-head CI 40151411023 completed successfully (53 passed, 26 skipped), including all three PostgreSQL shards, types, lint, source contracts/export collisions, architecture/Madge and T1/worker/dialect ratchets. Canonical Knip is unchanged across all three scans: production 75, full-tree 98, scripts 1,136. Focused local lint/format/diff checks passed. A duplicate local check:changed run was stopped during worker inventory after CI supplied the same gates; it is recorded as incomplete, not passed. The original PR-context heading failure was corrected in the body; replacement run 40151662474 passed.

Synthetic Gateway count evidence

One completed baseline/candidate pair exercised all 36 target actions per arm: one cold and five warm samples for six actions, with per-thread Node profiles. Pairing uses real Gateway WebSocket minting and HTTP redemption/replay. Capture uses its production async worker API. No live user state was used.

Cells below show SQL median / p95 [min–max]. Each warm row has five samples per arm; every action has MAIN=0.

Warm action Baseline SQL Candidate SQL Worker request median
Pairing redeem 5 / 7 [5–7] 4 / 6 [4–6] 1 → 1
Pairing replay 5 / 6 [5–6] 4 / 5 [4–5] 1 → 1
Capture shared delete 8 / 8 [8–8] 6 / 6 [6–6] 1 → 1
Capture final delete 9 / 9 [9–9] 7 / 7 [7–7] 1 → 1
Capture missing 7 / 8 [7–8] 5 / 6 [5–6] 1 → 1
Pairing mint, unchanged 12 / 23 [12–23] 12 / 23 [12–23] 2 → 2

Cold redeem/replay each fall 5→4 SQL, shared/final/missing capture fall 8/9/7→6/7/5; requests remain 1 and MAIN=0. Cold mint is 24→23 SQL and 6→5 requests. These are one cold sample per arm, not timing estimates.

Owner attribution across cold and warm actions: join redemption 60→48 SQL over 12 requests; capture deletion 144→108 SQL over 18 requests. Both owners retain exactly the same request count and MAIN=0. The entire target process is 1,395→1,350 SQL, 186→187 requests, MAIN 731→731 (startup included). The difference from the 48 removed owner statements is exactly +1 SQL from unchanged prepared-pool presence and +2 SQL/+1 request from unchanged state-lease acquisition. All other operation totals match.

The frozen control completed successfully at 2,996→3,002 SQL, 802→803 requests, MAIN 96→95. Ten warm control windows have SQL median 50→50, p95 55→68, range [50–55]→[50–68]; requests median 12→12, p95 14→22, range [12–14]→[12–22]; MAIN remains zero. These increases are explicitly retained: warm-window additions are unchanged lease probes/acquisition, plugin catalog/metadata refresh and watched-session reads; first-turn/compaction increases are unchanged worker admission/schema/WAL work moving between phases. Whole-run differences also include periodic proactive-job reads, deletion snapshots and checkpoints, offset by fewer maintenance/list/lifecycle calls. None of the three touched tables is accessed in either control arm. Per-phase and per-operation attribution covers all flagged cells; no warm-performance improvement or timing claim is made.

One candidate target cron SELECT has an empty phase label because the observer read during a phase-file write. It remains counted in the total and explicit unassigned bucket; its phase was not guessed. Native and worker CPU profiles were inspected for owner attribution only, with no CPU-speed claim.

Maintainer-approved acceptance amendment: the remaining two census pairs were waived based on the red-on-base/green-on-head native and PostgreSQL count regressions and exact-head green CI. The already-started second baseline was stopped during its build, before measured actions; it contributes no samples. The completed first pair and all its adverse cells are disclosed above. No schema, authority or durability gate was waived.

Production delta: 28 fewer lines. Tests/registry grow by 309 lines and workload/docs by 296 lines for deterministic counts, both-engine behavior proof and a rerunnable transport workload.

@clawsweeper

clawsweeper Bot commented Oct 25, 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.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: XS labels Oct 25, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds an acceptance plan for removing redundant queries from pairing redemption, capture deletion, and progress retention.

Example: Redeem an initialized pairing join code once.

  • Before: Current main executes expiry cleanup, a SELECT, and a DELETE.
  • After: This documentation-only head preserves that behavior and specifies a future two-statement target.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The acceptance document is coherent and introduces no identified defect, while the central optimization remains unimplemented.
Proof confidence 🦐 gold shrimp (3/6) This head only documents a future experiment and explicitly claims no completed validation; runtime proof is not required for the documentation addition.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Partial
User problem: Pairing redemption, selected capture deletion, and progress overflow perform queries whose results could potentially come from the corresponding mutations.
Reason: The maintainer-directed experiment follows the repository's count-first performance policy and preserves existing owners, but this head only preregisters acceptance.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored draft open: it registers a focused performance experiment but does not yet implement the SQL reductions. No actionable defect was found in the documentation patch.

Priority: P3
Reviewed head: 3c02058aebc10bd830e535dde313a8e5dc7ab6cf

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway operations reach existing database owners that consume pairing codes, delete capture records and payloads, and retain bounded outbound progress history.

flowchart TD
  A[Gateway operations] --> B[Pairing worker]
  A --> C[Capture kernel]
  A --> D[Progress store]
  B --> E[State database]
  C --> E
  D --> E
  F[Acceptance plan] --> B
  F --> C
Loading

Technical review

Best possible solution:

Complete the measured reductions inside the existing database owners while preserving consumption, deletion ordering, and retention contracts.

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

Current-main source confirms the separate queries targeted by the experiment; no runtime measurement was supplied or executed during this read-only review.

Is this the best way to solve the issue?

The plan appropriately targets existing owners and preserves their contracts, but implementation and measured results are needed to assess the proposed optimization.

AGENTS.md: found and applied where relevant.

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

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

  • Pinned introduced patch: The complete introduced diff adds only a workload document; it changes no production code, tests, schemas, or authority checks. (scripts/perf/sql-probe.md:1, 3c02058aebc1)
  • Current-main work remains: Pairing redemption still selects before deleting; capture deletion still reads two counts before deleting metadata; progress overflow still selects its ordered cutoff separately. (src/infra/device-pairing-join-code.worker.ts:53, 734822d0d863)
  • Draft scope and discussion: The full live body explicitly calls this a preregistration draft with validation pending; both discussion comments are bot status messages, and no submitted review supplies implementation evidence. (3c02058aebc1)
  • Failing check attribution: The inspected PR context check fails because it requests authored problem and evidence sections in the body; its annotations establish no runtime regression. (3c02058aebc1)
  • Feature-history ownership: Main history repeatedly records Peter Steinberger across pairing worker migration, capture kernel separation, engine-neutral handles, and progress persistence work; the pairing migration explicitly preserved one-use burns and expiry. Older-blob inspection and blame encountered a missing promisor object, so exact line introduction remains unverified. (src/infra/device-pairing-join-code.worker.ts, f28801628446)
  • Related work is distinct: refactor: remove redundant collection precondition probes #182890 removes native collection membership probes and explicitly makes no SQL changes; it does not implement these database reductions.

PR surface

Docs +18. Total +18 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 1 18 0 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 18 0 +18

Labels

Label changes:

  • add P3: The reviewed head is a performance acceptance document with no runtime change or demonstrated urgent user failure.
  • 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: The reviewed head is a performance acceptance document with no runtime change or demonstrated urgent user failure.
  • 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.

  • Implement the owner-local SQL reductions and publish the preregistered before-and-after results.

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 October 24, 2026, 9:19 PM ET / October 25, 2026, 01:19 UTC.

@steipete
steipete marked this pull request as ready for review October 25, 2026 01:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-10-25T01:37:01.871036Z 18be9f1 Draft marked ready
ℹ️ 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.

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 4de61b17d3ea1e73c6a7f8a1ce19e1e511f3b1ab
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/infra/device-pairing-join-code.worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L and removed size: XS labels Oct 25, 2026
@steipete
steipete merged commit b916ac7 into main Oct 25, 2026
151 of 152 checks passed
@steipete
steipete deleted the dbasync/sqlprobe-2 branch October 25, 2026 02:37
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
perf(db): remove redundant consume and deletion probes (openclaw#183069)

Consume pairing join codes with dialect-generated DELETE RETURNING, report capture deletion totals from affected-row counts, and embed the progress retention cutoff in its DELETE. Preserve pairing authority, error precedence, expired-code consumption and single use, capture transaction/file ordering, and progress retention.

Native and PostgreSQL outcome/count regressions pass; exact-head CI and PostgreSQL review passed. Removes one join consume statement, two capture count statements per request, and one overflow prune statement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed size: L 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