Skip to content

improve(gateway): reduce publication receipt fetches - #148144

Merged
steipete merged 2 commits into
mainfrom
codex/sqlite-publication-0914
Sep 14, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/sqlite-publication-0914

Conversation

@steipete

@steipete steipete commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Related: #146197

What Problem This Solves

Shared GitHub publication status reads can fetch the latest receipt twice and materialize older history unnecessarily; deferring requests also returns large receipt fields that notifications do not use.

User Impact

No user-visible behavior changes. Publication reads and deferred notifications transfer less data from SQLite, with unchanged validation, history selection, errors, transactions, and event order. No schema or migration changes.

Why This Change Was Made

Reuse the latest receipt after the existing workspace validation when it matches the current lifecycle and workspace. Keep the existing paginated fallback and receipt-integrity checks. Deferred updates return only the three fields consumed by the existing notification owner.

The shared test counter now observes StatementSync.all() as well as get, iterate, and run; Node 26.6 and newer use this path for Kysely reads. The initial incomplete-counter attempt is excluded from the measurements below.

Evidence

Measurements use real SQLite owners with synthetic fixtures on Node 26.8.2. Text bytes are the summed UTF-8 bytes of returned string values, not heap usage or transport serialization size.

Operation Statements, before → after Returned rows Returned text bytes
Latest current receipt with 70 older receipts 2 → 1 65 → 1 24,068 → 352
Defer two rich receipts, including a duplicate ID and a missing ID 4 → 4 3 → 3 42,512 → 165
  • Both resource regressions fail on the original owner with the corrected counter. All 46 candidate owner/shared-read/event tests pass, including unchanged receipt fields, late-failure rollback, missing IDs, duplicate IDs, and exact post-commit event order.
  • Fresh independent P0–P2 review is clean.
  • All 31 existing counter-consumer files were exercised: 29 passed, with 670 passing tests and 15 pre-existing failures across two race-fixture files. Representative failures from both files reproduce with the original owner and original counter; their private hooks omit all() and the failing cases do not use the shared counter. That test-fixture repair is fix(tests): restore session race coverage on Node 26 #148182, with 41 passing tests on both Node 24 and Node 26 and all 20 selected checks passing.
  • All 34 selected static commands passed across pinned recovery phases: 19 initial passes, four passes after restoring the declared dependency, and eleven final passes. The two-line publication-test lint repair also passed its canonical boundary and consuming type graph checks. Dependency deltas were assessed, source overlays were restored exactly, and all observed child processes settled. Both earlier failures remain preserved; this is composed proof, not one uninterrupted run.
  • No latency or heap improvement is claimed. The stale-history fallback retains its existing work.

The follow-up test lint repair at 7abc6a640784078ebdb8783f780f1debea3d690e changes only the prefix assertion and nonmutating expected-row construction. All 46 owner tests pass again with the same measurements, and a fresh independent P0–P2 review is clean.

At 7abc6a640784078ebdb8783f780f1debea3d690e, the Docker CI job failed the stale plugin-fixture assertion; the equivalent fix merged as #148129 at abbdd5287afc59899721285bca79fdfd8e6d289d (#148118 remains an open duplicate, correcting the earlier note). The memory CI job separately failed with ENOTEMPTY during watcher-fixture teardown. One complete original-order watcher-file run on Node 24.19.0, with the shared counter restored to its original version, passed all 78 tests. No direct counter instrumentation path reaches that fixture, but the late writer was not identified and the full hosted shard remains unverified. The Docker failure justifies refreshing onto its merged fix; fresh exact-head CI and native landing gates remain required. No failing result is waived.

Refreshed head: dd48fd8f42add57140251a9860ebddf730d955f4 on f4ffd8c21fcd9ff9df417fba01c3c1afb1ad3c7a. The complete two-commit patch, reviewed context, and dependency inputs are unchanged. New exact-head CI passed.

Current CI completion: Exact-head CI run 34837821263, attempt 1, completed successfully for dd48fd8, including required openclaw/ci-gate job 103976009033. Run evidence.

@clawsweeper

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

@steipete
steipete marked this pull request as ready for review September 14, 2026 09:40
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 7:45 AM ET / 11:45 UTC (Revision 3).

ClawSweeper review

What this changes

The PR reduces SQLite data fetched for GitHub publication status and deferred notifications, and extends test instrumentation to count native all() reads.

Merge readiness

✅ Ready for maintainer review

Keep open as a useful, bounded optimization that current main does not contain. No actionable correctness or security findings remain; the protected maintainer label also precludes cleanup closure.

Priority: P2
Reviewed head: dd48fd8f42add57140251a9860ebddf730d955f4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with relevant owner-boundary measurements, retained compatibility coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied Node 26.8.2 measurements exercise the publication reader and defer owner against real SQLite with synthetic receipts, showing reduced fetched rows/bytes and preserved rollback and event order. The three changed files match the previously measured revision; evidence establishes owner-level behavior, not deployed Gateway latency.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Node 26.8.2 measurements exercise the publication reader and defer owner against real SQLite with synthetic receipts, showing reduced fetched rows/bytes and preserved rollback and event order. The three changed files match the previously measured revision; evidence establishes owner-level behavior, not deployed Gateway latency.
Evidence reviewed 10 items Introduced optimization preserves receipt validation: The latest candidate is returned only after existing workspace qualification, matching session/lifecycle/worktree/repository/branch checks, and checkSharedWorktreeReceipt. Nonmatching or unbound candidates retain the existing paginated fallback and errors.
Compact notification results preserve the consumer contract: The deferred UPDATE changes only its returned columns. The notification owner consumes session_key, agent_id, and identity_source for these worktree receipts; transaction ownership, updates, filtering, duplicate handling, and notification order remain unchanged.
Owner-boundary regression coverage: The added tests exercise the publication coordinator and real SQLite store, verify a one-row fetch budget, compare complete retained rows, inject a late UPDATE failure, and check rollback plus duplicate/missing-ID notification order. Existing shared-read coverage checks corruption, stale lifecycles, legacy unbound terminal receipts, wrong sessions, and pagination.
Findings None None.
Security None None.

How this fits together

The Gateway records GitHub publication outcomes in SQLite and reads them to report publication status for a session’s workspace. Deferred publication updates notify session observers after their transaction commits.

flowchart TD
  A[Session status request] --> B[Publication receipt reader]
  C[SQLite receipts and workspace records] --> B
  B --> D{Latest receipt matches current workspace?}
  D -->|Yes| E[Validate and return receipt]
  D -->|No| F[Search receipt history]
  F --> E
  C --> G[Deferred request updates]
  G --> H[Post-commit session notifications]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +7, Tests +148. Total +155 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 17 10 +7
Tests 2 149 1 +148
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 166 11 +155

Review metrics

Metric Value Why it matters
Latest receipt materialization Reported 65 → 1 returned rows; 2 → 1 statements The measured current-receipt scenario demonstrates the intended reduction without claiming latency improvement.
Deferred notification payload Reported 42,512 → 165 returned text bytes The same three affected rows retain their notification order while unused receipt bodies stay in SQLite.

Root-cause cluster

Relationship: partial_overlap
Canonical: #146197
Summary: This PR implements one bounded part of the broader SQLite optimization campaign; the race-fixture repair is adjacent dependent work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep receipt selection and notification semantics at their existing owners while avoiding redundant row materialization.

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

Not applicable as a functional bug report; the source shows redundant materialization, and the supplied owner-boundary measurements quantify it. This read-only review did not rerun tests.

Is this the best way to solve the issue?

Yes. Reusing the already-qualified latest receipt and narrowing UPDATE return columns removes unnecessary work without introducing another owner, cache, schema, or configuration option.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Gateway efficiency improvement with measured savings and no intended user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Node 26.8.2 measurements exercise the publication reader and defer owner against real SQLite with synthetic receipts, showing reduced fetched rows/bytes and preserved rollback and event order. The three changed files match the previously measured revision; evidence establishes owner-level behavior, not deployed Gateway latency.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Node 26.8.2 measurements exercise the publication reader and defer owner against real SQLite with synthetic receipts, showing reduced fetched rows/bytes and preserved rollback and event order. The three changed files match the previously measured revision; evidence establishes owner-level behavior, not deployed Gateway latency.

Evidence

What I checked:

  • Introduced optimization preserves receipt validation: The latest candidate is returned only after existing workspace qualification, matching session/lifecycle/worktree/repository/branch checks, and checkSharedWorktreeReceipt. Nonmatching or unbound candidates retain the existing paginated fallback and errors. (src/gateway/github-publication-store.ts:137, dd48fd8f42ad)
  • Compact notification results preserve the consumer contract: The deferred UPDATE changes only its returned columns. The notification owner consumes session_key, agent_id, and identity_source for these worktree receipts; transaction ownership, updates, filtering, duplicate handling, and notification order remain unchanged. (src/gateway/github-publication-store.ts:534, dd48fd8f42ad)
  • Owner-boundary regression coverage: The added tests exercise the publication coordinator and real SQLite store, verify a one-row fetch budget, compare complete retained rows, inject a late UPDATE failure, and check rollback plus duplicate/missing-ID notification order. Existing shared-read coverage checks corruption, stale lifecycles, legacy unbound terminal receipts, wrong sessions, and pagination. (src/gateway/github-publication-sqlite.test.ts:22, dd48fd8f42ad)
  • Native counter matches the existing execution adapter: The production SQLite adapter uses get() for first-row SELECTs and all() on supported Node versions for general result reads. The helper now observes that existing all() path without changing the production adapter. (src/infra/kysely-sync.ts:101, dd48fd8f42ad)
  • Still necessary on fetched main: Fetched main still performs the initial candidate query followed by the history-page query and still returns complete deferred rows. The current-main comparison establishes missing optimization, not PR introduction ownership. The release file identity was also checked at v2026.9.4; no merged fixing PR for this optimization was established. (src/gateway/github-publication-store.ts:137, 9a5af1b95370)
  • Prior-review continuity verified through blob identities: GitHub contents reads at the previous reviewed revision, 7abc6a640784078ebdb8783f780f1debea3d690e, returned the same three file blobs as HEAD: 7f48b4a00df11e82b3bdc42480b4d29cd4c920e6, d75dd42cca2138af874668388d07d94d09fbd37f, and 5f5f04908628006cb517198468e1cf6d1965410b. This independently confirms unchanged reviewed files after local historical comparison could not load the older revision. The supplied prior review contains no findings or published rank-up moves. (dd48fd8f42ad)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • roboclaw-bot: 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-14T09:52:25.430Z sha 37f01d3670dfae7e428991d595959b9ae3ea05df :: needs maintainer review before merge. :: none
  • reviewed 2026-09-14T10:58:48.158Z sha 7abc6a640784078ebdb8783f780f1debea3d690e :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/sqlite-publication-0914 branch from 7abc6a6 to dd48fd8 Compare September 14, 2026 11:21
@steipete
steipete merged commit 00dd4f1 into main Sep 14, 2026
195 of 197 checks passed
@steipete
steipete deleted the codex/sqlite-publication-0914 branch September 14, 2026 12:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
* improve(gateway): reduce publication receipt fetches

* test(gateway): satisfy publication regression lint rules

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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