Skip to content

perf(gateway): reuse committed session projection facts - #168719

Merged
steipete merged 60 commits into
mainfrom
dbasync/pcrows
Oct 11, 2026
Merged

steipete merged 60 commits into
mainfrom
dbasync/pcrows

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session metadata and transcript publications discard independent Gateway row facts and repeat database reads; Memory also resolves the same queued session corpus twice.

This is Phase C pcrows, integrated with #168602 and targeting main.

User Impact

Session lists and channel readers retain current Board, ACP, workspace, and summary freshness facts with fewer database round trips. Streaming presentation keeps its existing coalescing window. Memory indexing observes appends and forgetting tombstones committed while notifications are queued.

There is no schema, SDK, retention, configuration, update, Doctor, plugin-loading, or service-lifecycle change. Target selection, session-entry readers, and B2–B4 write commands are outside this change.

Why This Change Was Made

The existing Gateway projection consumes canonical transcript receipts and keeps independent row facets across same-lifecycle metadata publications. A receipt installs its committed watermark before observers run; an unmatched notification or explicit invalidation follows the existing bounded read path. Shared facts stay reusable only while their bindings match. This uses the existing projection and writer receipt owners without another cache, generation protocol, or cross-thread handshake.

The actor hot snapshot does not contain Board presence, so this reuses the existing projection facets and transcript postimages without expanding the shared actor contract. Remaining initial/fallback row acquisition and activity-summary source reads stay visible in the measurements.

Memory queues session identities directly and resolves corpus membership and tombstones once in the indexing owner. The earlier notification-time resolution is removed. No SQLite-specific SQL is added.

The diff is +80 net production lines, +185 test/support lines, and +11 documentation lines. The extra production code connects existing receipt postimages to the existing row projection and preserves its invalidation/coalescing lifecycle.

Evidence

Three alternating pairs (M,C,M,C,M,C) ran the shared harness on base 6e8a0034934c and candidate fa9baeee005e. Each warmed observation is the mean of ten turns; values below are median [min–max] across the three observations. Every sample completed 13 successful turns, RPCs, cron, compaction and shutdown.

Warmed metric Base Candidate
All-thread SQL statements 677 [659.1–677.2] 663.4 [644.2–663.5]
MAIN SQL statements 11.2 [8.6–11.2] 11.2 [8.6–11.2]
All logical requests 169.4 [165.1–169.5] 163.5 [159.1–164]
DB requests 146.2 [142.2–146.3] 140.7 [136.5–141.2]
This lane: SQL / requests 61.1 / 16.4 46.5 / 11.6

Logical requests include CPU and release operations, matching the census. DB requests exclude releases and the two source-identified CPU-only tasks; zero-SQL database commands still count. session-entry is excluded from this lane because pcentry owns it.

Warmed operation Base SQL / requests Candidate SQL / requests Delta SQL / requests
session-row-facts 32 / 6.4 22 / 4.4 -10 / -2
sessionRows.sharedFacts 4.3 / 6.4 2.4 / 4.4 -1.9 / -2
session-corpus-inventory 2.6 / 0.8 1.6 / 0.4 -1 / -0.4
session-tombstones 3.2 / 0.8 1.6 / 0.4 -1.6 / -0.4
session-row-backfill 5 / 1 5 / 1 0 / 0
session-activity-summary-source 14 / 1 14 / 1 0 / 0

First-turn SQL decreased 1727 [1701–1892] → 1693 [1505–1889]. Entire-workload SQL decreased 15544 [15533–15630] → 15383 [15322–15469], and logical requests decreased 2950 [2950–2969] → 2887 [2885–2903]. Warmed duration ratio was 1.014, with no phase-skew failure. The lane target remains an aim: the remaining row acquisition, preview backfill and summary-source reads are not eliminated by this change.

Phase attribution: boot+connect was +24 SQL (+0.76%); its increases are in unchanged delivery, cron scheduling, plugin-state, image and device owners, with zero lane work in that phase. Startup including the first turn decreased by 14 SQL. Cron performed three additional session-row-backfill requests (+15 SQL), and the same +3/+15 remains in the whole-workload backfill total. This is a known cost in the changed projection owner, not attributed to unrelated noise. Warmed backfill remains 1 request / 5 SQL. Receipt-triggered materialization can precede the normal transcript notification; further optional-preview coalescing is a follow-up, preserving immediate summary freshness. No new scheduling or invalidation protocol was added to hide this cost. Whole-workload statements and requests still decrease.

Remote focused proof on the candidate used pnpm test <file> --maxWorkers=1:

Test file Passed Command wall seconds
src/gateway/session-row-projection.publication.test.ts 7 41.873
src/gateway/session-row-projection.accepted-facts.test.ts 24 61.191
src/gateway/session-row-projection.backfill.test.ts 13 43.333
src/gateway/session-row-projection.transcript-regression.test.ts 1 43.484
src/gateway/session-row-projection.worker-read.test.ts 17 49.091
extensions/memory-core/src/memory/manager-sync-ops.startup-catchup.test.ts 35 79.901

These 97 tests cover projection publication, archived/current summary freshness, worker-read fallbacks, preview backfill, streaming coalescing, and queued Memory appends/tombstones. The new transcript regression warms the first append before measuring the real row-facts and shared-facts boundaries; it does not count a CPU-only worker wrapper as a SQL read. Focused command wall time totals 318.873 seconds; CI runtime itself has not been measured.

Madge passed (18.914s), T1 passed without growth, and the dialect ratchet passed without added SQLite-specific SQL. Two isolated Codex autoreview rounds were scoped-clean at P2. No SDK surface changed, and the published-driver × candidate update cell does not apply.

check:changed --base 6e8a0034934c --head fa9baeee005e completed remotely in 2094.031s. Formatting, all 27 core-test typecheck shards, core/extension/extension-test typechecks, plugin boundaries and the other reported guards passed. Its only failure is the inherited dead-export scan: the update inspection constant, two session fixture exports, and the Solid lint default export. The standalone production/all-exports Knip findings are exactly identical on the pinned base and candidate; none concern changed files. Production Knip also reports the same 16 unused worker/UI files, unused @solidjs/signals dependency, and unlisted @solidjs/compiler dependency on both sides.

The three targeted negative controls fail at the intended assertions on the original production implementation: native metadata performs the redundant read, transcript summary freshness stays incorrectly current, and Memory still performs the earlier notification-time resolution. They passed as negative controls in 36.115s, 39.310s and 41.689s respectively. The temporary test overlay was restored byte-for-byte; the base and candidate were verified clean, and measurement evidence was unchanged. Initial negative-control setup hit missing workspace links and a temporary-volume quota; using the installed base checkout with caches on the larger disk resolved those tooling failures. The separate base dead-export scan reproduces every export failure above.

Landing validation

Integrated main at c2d584acd704 with a conflict-resolution merge, preserving the row-projection changes and current main ownership boundaries. The follow-up repair preserves the transcript publisher receiver, explicitly invalidates the concurrency fixtures that need a pending read, and asserts zero redundant reads after committed metadata updates. The repair-only P0/P1 review found no actionable findings.

On final source 32cda4cc0237587424d500fceefcc67a90bdabf6, all 250 tests in 11 focused files passed (pnpm test <files> --maxWorkers=1, 1378.79 seconds including local preparation): 72 Gateway tests, 18 worker-read/runtime-ownership tests, 125 TUI mock-consumer tests, and 35 Memory startup-catchup tests. Formatting and the export-name-collision guard passed. Core type-aware oxlint passed on all changed Gateway files. Memory type-aware oxlint passed on byte-identical source copies using the repository's source type graph and unchanged lint rules; the ordinary generated-boundary preparation timed out before lint, so that compiler timeout is not claimed as a pass.

Knip's only production findings are SQLITE_DATABASE_GENERATION_LENGTH in src/infra/sqlite-database-admission-record.ts and the four existing exports in ui/src/components/lobster-pet-look.ts; the full-tree scan reports the same three UI helper exports. These exact rules and files also fail on main in run 38112256403, and those source files are unchanged here.

That main run independently reproduces the same notification corruption failure (job 114390202032), public-session corruption failure (job 114390202044), and worker-launcher invalid-transcript failure (job 114390202043) seen by the prior PR attempt. Their test files are byte-identical to the tested main baseline. The prior attempt also reported a worker-runtime capacity admission failure; it is recorded as an environment failure, not a passing test.

The native worktree allocator stalled for more than 15 minutes before creating review artifacts. Its lock was recovered after confirming no native children remained. Landing uses the explicitly authorized head-pinned REST squash fallback and inherited-CI exception. The update cell does not apply; no update, Doctor, schema/migration, plugin-loading, or service-lifecycle surface changes.

The final-head production typecheck reports TS2353 at src/cli/gateway-cli/run-loop-startup.test-support.ts:380 (the new runtime argument). The identical error independently fails on main at d4e9d09e9422 in job 114398621086. That test and the called production owner are unchanged by this PR; the test blob is also identical on current main 8267c24051ff. All security reviews and security-fast passed for the final PR head. The approved inherited-failure override leaves CI recorded as failed/pending, not green.

…odules

Merge current main while preserving shared physical admission, cancellation, reader validation birthtime, and live deletion authority. Split worker usage, pool construction, failure settlement, and schema owner types to keep the existing line caps.
Checkpoint the single-owner cutover, cache invalidation regressions, and request-owned read transactions. Keep explicit migration verification. Paired measurement and final validation are still in progress.
Route retained existing-state writer coverage through the host-owned worker project, preserve first-admission incompatibility refusal, and match the final deletion-authority contract. Keep the gateway test under its inherited line count by moving existing pure fixture helpers. Regenerate assertion allowances without adding production assertions.
Include the thirteen transitive admission modules required by the native wrapper import-closure proof. Carry the existing birthtime through the worker validation fixture to preserve its physical-file identity.
Merge current main and preserve its optional settlement-only receipt delivery through the extracted owner. Keep the worker refusal error with the leaf contract to stay within the existing admission line cap. End the marker-free read-only fixture transaction normally; dedicated rollback and explicit revocation coverage remains unchanged.
Preserve snapshot-local reuse without freshness queries, publish dedicated archive writes, and remove Workboard polling. Retain native authority and settlement boundaries. Checkpoint reviewed corrections and focused regression repairs; final integrated proof remains in progress.
Define inactive typed durable phases, versioned hot snapshots, complete commit receipts, pure bookkeeping reducers, and unknown-outcome fencing. Share lifetime and settlement vocabulary with the existing incognito actor without changing routing or persistence.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR reuses committed Gateway session facts and resolves queued Memory session identities once during indexing.

Example: Rename agent:main:acp:row-receipts to Published label after its Board and ACP facts are loaded.

  • Before: The metadata publication discards reusable facts and triggers additional database reads.
  • After: The projection displays Published label while retaining current Board and ACP facts.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful performance work has meaningful owner-boundary evidence, but a confirmed fixture defect leaves validation incomplete.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; reported paired Gateway workloads and inspected owner-boundary regressions support the optimization, without establishing an independently inspected shipped-entry-point run.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Session updates repeat database work despite already-published committed facts, and Memory resolves queued identities twice.
Reason: Maintainer-directed work has measured request savings and preserves the existing presentation and indexing owners.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the maintainer-directed optimization remains useful and absent from main, but its changed read behavior still breaks projection fixtures. Three earlier stack-related findings are resolved.

Priority: P2
Reviewed head: ca26b56af873fe33412c7f455303b571bf8c634f

Before merge

  • Update the remaining fixtures for retained metadata facts (P2) - A warmed same-lifecycle metadata replacement now retains complete facts and skips readRowFacts. The foreground fixture therefore throws “List bypassed pending row facts” before testing the newer summary and membership revocation; the catalog fixture awaits captured.promise indefinitely, and the subagent fixture never performs its injected registry mutation. Exact-head CI confirms the foreground and subagent failures. Emit an explicit factsInvalidated change where a pending acquisition is essential, following the worker-read fixtures already changed here. Update the inheritance test’s obsolete read inventories to expect reuse while preserving its model and relationship assertions.

Findings

  • [P2] Update the remaining fixtures for retained metadata facts — src/gateway/session-row-projection-publication.ts:140-146

Tests

  • Missing end-to-end proof: Repair pending-read fixtures so their final freshness and membership-revocation assertions execute under the new reuse behavior.
Agent review details

How this fits together

Session writers publish committed receipts into the Gateway’s resident row projection, which supplies session presentation; Memory queues transcript identities for its indexing owner.

flowchart LR
A[Session writers] --> B[Committed receipts]
B --> C[Resident row projection]
C --> D[Session lists and readers]
A --> E[Memory identity queue]
E --> F[Memory indexing owner]
Loading

Technical review

Best possible solution:

Retain the receipt-based optimization and repair the affected projection fixtures without restoring redundant reads.

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

Source explains the bypassed reads, and exact-head CI confirms foreground and subagent failures; no local tests were run during this read-only review.

Is this the best way to solve the issue?

Reusing the existing receipt, projection, and indexing owners removes duplicate work without introducing another cache or invalidation protocol.

Full review comments:

  • [P2] Update the remaining fixtures for retained metadata facts — src/gateway/session-row-projection-publication.ts:140-146
    A warmed same-lifecycle metadata replacement now retains complete facts and skips readRowFacts. The foreground fixture therefore throws “List bypassed pending row facts” before testing the newer summary and membership revocation; the catalog fixture awaits captured.promise indefinitely, and the subagent fixture never performs its injected registry mutation. Exact-head CI confirms the foreground and subagent failures. Emit an explicit factsInvalidated change where a pending acquisition is essential, following the worker-read fixtures already changed here. Update the inheritance test’s obsolete read inventories to expect reuse while preserving its model and relationship assertions.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Transcript watermark retention keeps the original intent (9afa39c: Summary-bearing rows reacquired watermarks because ordinary notifications did not certify transcript facts; this PR uses canonical postimages and retains fallback acquisition for unmatched notifications.)
  • Committed row publication keeps the original intent (892911b: Complete commit receipts install before observers, while unknown outcomes invalidate uncovered facts; the optimization extends reuse within that existing lifecycle.)
  • Queued Memory synchronization keeps the original intent (fix(memory): retain transcript updates during active sync #124024: Updates arriving during active synchronization must enter the targeted queue rather than disappear when an older sync clears dirty state; identities still enter that queue directly.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/session-row-projection.foreground.test.ts --maxWorkers=1
  • pnpm test src/gateway/session-row-projection.subagent-index.test.ts --maxWorkers=1
  • pnpm test src/gateway/server-methods/sessions-list-config.test.ts --maxWorkers=1
  • pnpm test src/gateway/session-row-projection.invalidation.test.ts --maxWorkers=1
  • pnpm test src/gateway/session-row-projection.accepted-facts.test.ts --maxWorkers=1

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 2a3b917 adds src/gateway/session-row-projection-transcript.ts:5 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2a3b91735d2b; files: src/gateway/session-row-projection-transcript.ts)
  • Vincent Koc: Raw commit 4412a22 adds extensions/memory-core/src/memory/manager-session-sync-ops.ts:206 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4412a22653b2; files: extensions/memory-core/src/memory/manager-session-sync-ops.ts)

PR surface

Source +83, Tests +185, Docs +11. Total +279 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 110 27 +83
Tests 6 214 29 +185
Docs 1 16 5 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 340 61 +279

Review metrics

Metric Value Why it matters
Net production versus test growth Production +83 lines; tests/support +185 lines Production growth connects existing receipts to the resident owner; regression coverage checks freshness and indexing outcomes.

Labels

Label changes:

  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This is a bounded internal performance improvement with concrete projection-fixture failures, without evidence of an urgent production outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-10T23:12:37.937Z sha fa9baee :: needs maintainer review before merge. :: none
  • reviewed 2026-10-11T04:15:42.644Z sha fa9baee :: needs changes before merge. :: [P2] Explicitly invalidate facts in the remaining fallback-race fixtures | [P2] Include the new runtime dependencies in the wrapper inventory | [P2] Keep native incognito acquisition with its existing owner | [P2] Use an inferred builder result for the session-window write

Reviewed October 11, 2026, 12:52 AM ET / 04:52 UTC (Revision 3).

Base automatically changed from dbasync/actorb1 to main October 11, 2026 04:06
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XL and removed size: M labels Oct 11, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Oct 11, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed agents Agent runtime and tooling size: XL labels Oct 11, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Oct 11, 2026
@steipete
steipete merged commit b77568d into main Oct 11, 2026
134 of 138 checks passed
@steipete
steipete deleted the dbasync/pcrows branch October 11, 2026 05:44
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
)

Reuse committed session projection facts and settle queued Memory work once, reducing redundant row reads while preserving invalidation and transcript publication ownership.

Keep concurrency fixtures aligned with committed facts and preserve the transcript publisher receiver. All 250 tests in 11 focused files passed; changed-file type-aware lint, formatting and export-collision checks passed. Knip findings and prior unrelated CI failures reproduce on main.

Landed through the explicitly authorized head-pinned REST fallback after native worktree allocation stalled. Inherited CI failures and validation details are recorded in the PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant