Skip to content

refactor(proxy-capture): centralize typed diagnostic queries - #139015

Merged
steipete merged 1 commit into
mainfrom
codex/sqlite-goal-capture-reads
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sqlite-goal-capture-reads

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Capture session lists, diagnostic presets and legacy blob lookup maintained handwritten SQL and positional bindings in the write store while related reads already had a typed owner. The missing-ack query also repeated its optional session filter across outer and inner SQL.

Why This Change Was Made

Move these queries into the existing capture read owner using generated Kysely types. Six preset execution paths become one; a shared filtered event query keeps both sides of missing-ack scoped together. Explicit preset branches retain their grouping, counts, thresholds, aliases and order. The store delegates while retaining legacy file handling and both constructor contracts.

Native call-local get/all execution remains because the generic query executor would change corruption recovery and borrowed database lifetime. The public standalone reader and schema are unchanged. Session summaries retain native null fields despite the existing optional-only SDK type; correcting that public type is a separate compatibility decision.

Production grows by 47 lines to express the typed projection/owner boundary while removing repeated SQL fragments and bindings. A descriptor framework or new executor/cache would add concepts solely to reduce line count, so the domain branches remain explicit. Tests grow by 101 lines, consolidating the older duplicate-send checks into broader constructor-paired coverage; the removed assertion baseline shrinks from 23 to 16.

User Impact

Capture diagnostics keep their current results and output shapes. Empty sessions still count zero events; nullable labels and separate hash groups remain intact; scoped missing-ack results are not suppressed by another session. Legacy blob files still require an event reference. This changes query ownership without enabling another database or changing data, cleanup, retention or recovery policy.

Evidence

  • 50 focused tests passed: native store20, historical standalone reader11, CLI19. After final test-only cleanup, all 31 store/reader tests passed again. Full changed gate and explicit Kysely guard passed.
  • Native baseline/candidate comparison passed 84 preset/scope cases across both constructors, zero/negative/invalid limits, native get/all execution, authorization refusal/retry, payload custody and fresh reopen. Fifteen real corrupt-table cases retained identical errors and open-handle ownership.
  • Actual loopback QA HTTP served 55 requests covering all six presets, scoped/unscoped/trimmed/missing inputs, sessions/nulls, blobs, event/coverage siblings, refusal/retry and unchanged capture state.
  • Eighteen fresh real source-entry CLI processes preserved JSON wrappers and bare arrays, scope handling, unknown-preset behavior and blob bytes. Fresh database reopen matched. All synthetic state and processes were cleaned up; no external provider was involved.
  • The changed gate required SAFETY comments for native projections and then identified a test-local shadowed name. The comments, exact shrinking assertion baseline and local rename were applied; the final gate passed. Live runtime source equivalence across those comments is recorded, and native proof repeated on final source.

Independent Codex review completed nine passes with no P0–P2 findings. Direct installed Kysely and Node SQLite contracts were inspected.

@clawsweeper

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

@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 5, 2026, 7:11 AM ET / 11:11 UTC.

ClawSweeper review

What this changes

Moves capture session listings, diagnostic queries, and legacy blob-reference lookup into the existing typed reader while preserving diagnostic output and database ownership.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful maintainer-owned refactor absent from current main. No concrete introduced correctness or security defect was identified in the inspected paths.

Priority: P3
Reviewed head: e65c67e89bf8ef5923dbd424db198d33883c8d0a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused refactor with useful constructor-paired coverage and no supported blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor proof gate is exempt for this maintainer-authored internal refactor. The captured body reports native-store, QA HTTP, and CLI comparisons exercising the changed reads, without independently inspected runtime traces.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor proof gate is exempt for this maintainer-authored internal refactor. The captured body reports native-store, QA HTTP, and CLI comparisons exercising the changed reads, without independently inspected runtime traces.
Evidence reviewed 10 items Pinned introduction and merge scope: The complete merge-base-to-head patch changes only the capture reader, store, store tests, and assertion baseline. The recorded test merge has the pinned base followed by the exact PR head as parents; its file list matches that scope.
Current-main necessity: Fetched main still contains handwritten session, blob-reference, and six preset queries. The relevant production modules are unchanged between the pinned merge base and fetched main, so this consolidation is not already implemented there.
Query semantics: Inspected all six typed branches against the previous SQL: selected aliases, hash grouping, response threshold, ordering, and optional session filtering are retained. Both missing-ack subqueries derive from the same filtered event query.
Findings None None.
Security None None.

How this fits together

Proxy capture stores observed network exchanges for troubleshooting. The CLI and QA Lab request session summaries, traffic diagnostics, and payloads from this store.

flowchart LR
  A[Captured network exchanges] --> B[Capture database]
  C[CLI or QA Lab request] --> D[Capture store]
  D --> E[Typed diagnostic reader]
  E --> F[Preset and session filter]
  F --> B
  B --> G[Native SQLite results]
  G --> H[Diagnostic output]
Loading

Before merge

  • Resolve merge risk (P1) - Independent dependency-contract verification remains incomplete because Kysely source was unavailable locally and network DNS failed; the reported native comparisons were not rerun by this reviewer.
Agent review details

Security

None.

PR surface

Source +47, Tests +101, Other 0. Total +148 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 148 101 +47
Tests 1 123 22 +101
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 4 272 124 +148

Review metrics

Metric Value Why it matters
Production versus test growth Production net +47 lines; tests net +101 lines; assertion baseline net 0 The production growth expresses typed projections in the existing read owner; paired-constructor coverage replaces the narrower duplicate-send test.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep diagnostic query construction in the existing reader while preserving native execution, public result shapes, and both store constructors.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep diagnostic query construction in the existing reader while preserving native execution, public result shapes, and both store constructors.

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

Not applicable: this PR reorganizes existing queries rather than claiming a broken user behavior; the inspected tests check behavioral equivalence.

Is this the best way to solve the issue?

The owner boundary is appropriate: it reuses the existing typed reader and avoids the generic executor's different failure handling. Full dependency-level confirmation remains unavailable in this review environment.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 49ecde890905.

Labels

Label changes:

  • add P3: This is an internal diagnostic-query refactor with preserved behavior and no demonstrated urgent user-facing failure.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P3: This is an internal diagnostic-query refactor with preserved behavior and no demonstrated urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

  • Pinned introduction and merge scope: The complete merge-base-to-head patch changes only the capture reader, store, store tests, and assertion baseline. The recorded test merge has the pinned base followed by the exact PR head as parents; its file list matches that scope. (d2e2b3273299)
  • Current-main necessity: Fetched main still contains handwritten session, blob-reference, and six preset queries. The relevant production modules are unchanged between the pinned merge base and fetched main, so this consolidation is not already implemented there. (src/proxy-capture/store.sqlite.ts:461, 49ecde890905)
  • Query semantics: Inspected all six typed branches against the previous SQL: selected aliases, hash grouping, response threshold, ordering, and optional session filtering are retained. Both missing-ack subqueries derive from the same filtered event query. (src/proxy-capture/store-readonly.ts:69, e65c67e89bf8)
  • Native failure ownership: The new queries compile through the existing binding helper but execute native get/all calls. The generic executor reports errors to a registered handler that can evict a corrupted shared database, supporting the decision to preserve call-local execution. (src/state/openclaw-state-db-cache.ts:120, e65c67e89bf8)
  • Callers and public boundary: CLI session/query commands retain their existing JSON wrappers and bare-array output. QA Lab calls the same store methods. The public SDK barrel and standalone reader interface do not expose the new internal helpers. (src/cli/proxy-cli.runtime.ts:286, e65c67e89bf8)
  • Behavioral coverage: The constructor-paired test exercises every preset, cross-session acknowledgments, separate payload hashes, nullable fields, empty sessions, limits, and denial followed by successful retry on the same open handle. Existing standalone-reader and CLI tests cover neighboring contracts; tests were inspected, not executed. (src/proxy-capture/store.sqlite.test.ts:534, e65c67e89bf8)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Tak Hoffman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the dependency-verification item from the latest ClawSweeper review. I directly inspected installed Kysely 0.29.5 builders/parsers, aggregate handling, the default and SQLite compilers, and our synchronous binding helper. These queries compile through Kysely and still execute through the existing native get/all calls, preserving the capture owner's error boundary.

The retained actual-store baseline/candidate proof covers 84 preset comparisons, 14 limit cases, and 15 corruption/error cases across both constructors. It preserves COUNT(e.id), grouping, nulls, truthy session scoping in both missing-ack branches, ordering, limits, and successful reuse after a denied read. The real QA HTTP and CLI flows passed (55 requests and 18 CLI commands), together with focused tests and the full changed-file gate. Independent review found no P0–P2 findings.

The first hosted run timed out in the unchanged provider-destroy fixture. Its focused tests and original 3,815-test group passed locally; one unchanged failed-job retry is now green. The original hosted timeout's initiating await was not established, so this is not a claim that its root cause was repaired. No test assertion or timeout was weakened. Exact-head CI is green on e65c67e89bf8ef5923dbd424db198d33883c8d0a.

@steipete
steipete merged commit 994ae0c into main Sep 5, 2026
298 of 300 checks passed
@steipete
steipete deleted the codex/sqlite-goal-capture-reads branch September 5, 2026 12:39
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant