Skip to content

fix(gateway): keep transcript reads out of session-row materialization - #150989

Merged
steipete merged 4 commits into
mainfrom
steipete/fix-projection-transcript-probe-20260917
Sep 17, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/fix-projection-transcript-probe-20260917

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes multi-second waits when opening or resolving a conversation while a large Gateway refreshes its resident session roster. Related: #150196.

User Impact

sessions.describe, sessions.resolve, and chat.startup prepare their requested row without waiting for the bulk refresh. Stored titles and usage are immediately available; legacy titles, previews, and terminal fallback-model metadata can arrive later through bounded background enrichment.

Why This Change Was Made

Resident materialization consumes stored metadata and prepared model facts. It no longer probes transcript titles, usage, or terminal model messages. Startup prepares one bounded batch, then continues filling rows in the background. Discovery selectors use stored entries, and keyed reads retain current sharing and session-generation checks.

Legacy titles use the existing display-name persistence contract without model calls or activity changes. Optional enrichment runs one session per session-list work turn, after metadata readiness, with hard message/byte bounds. Foreground request lifetimes take priority over transcript reads and title commits. Background writes participate in Gateway work admission, and event dispatch retains its publisher until queued transcript reads settle. The normal usage writer remains authoritative; unknown legacy usage is not inferred from a transcript tail.

Evidence

Operator-provided production measurements from the first 15 minutes after deploying #150196 (build 162d0fcfcc91, previous build 9a4468148bc):

Metric Previous build Regressed build
sessions.list p50 / p95 96 / 724 ms 690 / 34,219 ms
sessions.describe p95 506 ms 36,886 ms
sessions.describe p50 — 16,884 ms
sessions.resolve maximum — 40,683 ms
chat.startup — 39,937 ms

The sample contained 78 list and 107 describe requests. Event-loop delay p99 was 55 ms with ELU 0.2–0.76: requests waited behind cooperative work. Slow-list warnings increased from 0–1 to 43 per ten minutes; RSS reached 4.7 GB and was rising, with three memory-pressure events per ten minutes. Two CPU profiles attributed 14.5–16.7% self time to transcript-row JSON parsing, predominantly beneath resident refresh/title and usage readers. The deployment had approximately 4,000 session nodes and a 17 GB agent database. SQLite iteration added about 5% self time plus 7–11% native time; roughly 75% of the parser samples followed the resident refresh/title chain.

A real SQLite fixture creates 2,048 sessions, each missing stored title/usage fields, with linked user/assistant transcript events (~14 KiB assistant text per session). It calls the actual sessions.describe handler during startup and during a subsequent dirty drain. Both sides run with --pool=forks, so process.threadCpuUsage() measures the child process main thread. Original production modules were restored from base 4b38266964828d528ecb7823a1dde833b8b25d75 for the baseline and the candidate bytes were restored and verified afterward.

2,048-session reproduction Original source Current candidate
Constructor / first batch 3,032 ms 434 ms
Initial fill wall time 3,035 ms 966 ms
Initial fill main-thread CPU 2,857 ms 953 ms
Describe during startup fill 1,617 ms 4.8 ms
Describe during dirty drain 1,429 ms 11.7 ms
Unrelated dirty rows remaining when describe returns 0 2,046
Title / usage / terminal-message reads during materialization, across both drains 4,096 / 4,096 / 2 0 / 0 / 0

These are individual local measurements, not production latency percentiles. The current candidate is rebased over #150964, #151062, and #151080; the original baseline is the task-start source at the commit above. These shared-host runs are not controlled wall-time benchmarks. This run used less main-thread CPU and finished the initial fill sooner; foreground requests returned before unrelated rows finished. The original source fails the new regression (expected 4096 to be +0); the candidate passes, including the under-100-ms describe bounds and response-before-drain assertion. The separate legacy-title regression fails before the fix because no stored title appears, and passes with the bounded backfill.

node scripts/run-vitest.mjs src/gateway/session-row-projection.transcript-regression.test.ts --pool=forks

Targeted Gateway proof also covers eventual titles/previews, byte bounds, lifecycle/name/running races, foreground naming priority, shared physical stores, incognito reads, parent changes, catalog races, stored and terminal fallback models, describe authorization, history/startup, and the unchanged row-output golden fixtures. A 3,474-row real tool → Gateway inventory fixture returned 37 sparse matches in 7.8–9.6 ms warm, with no transcript reads in the request path. No test deadlines, assertions, baselines, or retry policies were weakened.

Earlier validation passed the full build, both import-cycle guards (zero cycles), and the built-CLI SQLite lifecycle proof. The branch is rebased onto c9ab1cff77ecd3986b46078243a5c7c8498e9f42, which includes the #151062 fixture fix and #151080 Slack boundary fix. All four P24 patches replayed unchanged. The complete node scripts/check-changed.mjs run passed on the current base on its first attempt, including core-test typechecking. The formerly failing plugin-test boundary guard also passes locally across 4,083 extension files. No retry was needed. The latest requested run passes 125 tests across 10 files, including the 2,048-row reproduction, transcript backfill, foreground priority, all resolver suites, acquisition budgets, and parent links. The earlier broader integration run passed 180 tests, including diagnostics, current visibility, physical ownership, and immediate describe responses. The full ordered chat/subscription run passes 136 tests; title/transport/discussion proof passes 95 tests and combined-store proof passes 21 tests.

The unchanged configured/inherited fallback cases also protect a stale stored running status after the live run ends: they failed before the final owner repair (106 passed / 2 failed), then passed in the 127-test repair run and the 180-test integration run. Resident materialization prepares stored fallback facts independently of live activity; presentation selects the current live model. Raw/legacy transcript events select metadata without requiring enrichment, and queued publications retain their publisher until their reads settle. Tests preserve the original golden output, authorization, error, and accounting assertions while measuring warm reads after metadata readiness and waiting for optional fields only when asserting their eventual arrival.

The branch was rebased only after #150964 created a concrete conflict in the same refresh loop. It retains that change’s one-row-at-a-time metadata acquisition and the catalog-readiness guard; all four acquisition/materialization budget cases and parent-link tests pass. Fresh independent P2 review of the rebased candidate reports no findings. An earlier physical-agent substitution suggestion was rejected with source evidence and eight shared-store/alias cases: metadata writes require the logical key owner, and the accessor resolves the physical database separately. The earlier base-side Slack test boundary violation was fixed by #151080. This candidate cleanly replays all four P24 patches onto c9ab1cff77ecd3986b46078243a5c7c8498e9f42; it preserves #150964’s acquisition-in-budget loop and P24’s guards. Fresh P2 review is scoped-clean with zero findings. Exact-head CI run 35268119786 passed for d1f461cb49529e9da8c0b9f3d47034c54afdf854. The single bounded watch exited successfully with the check rollup green and zero pending checks. No CI jobs were rerun. The PR is ready and mergeable; no merge or deployment was performed.

Risks and Gaps

No configuration, schema, storage-format, retention, or dependency changes. Early responses can omit optional transcript-derived fields. Backfill preserves manual names, activity ordering, foreground naming, and session identity; it skips cold archives and oversized messages. Incognito rows remain outside the resident roster and retain their transient exact-read title/preview contract. Live Gateway deployment and post-deployment measurements are outside this PR's proof.

@clawsweeper

clawsweeper Bot commented Sep 17, 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 docs Improvements or additions to documentation gateway Gateway runtime labels Sep 17, 2026
@steipete
steipete marked this pull request as ready for review September 17, 2026 16:17
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Sep 17, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 17, 2026, 4:31 PM ET / 20:31 UTC (Revision 9).

ClawSweeper review

What this changes

The Gateway prepares requested conversation rows independently of bulk refreshes and fills optional transcript-derived titles, previews, and model metadata through bounded background work.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 1 item remains

The latency problem remains on current main, and the earlier describe-test blocker is resolved. No actionable introduced defect was found; this PR remains a useful landing candidate.

Priority: P1
Reviewed head: d1f461cb49529e9da8c0b9f3d47034c54afdf854

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent repair with substantial relevant regression coverage and no remaining actionable finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository context identifies a maintainer author, so the external-contributor proof gate does not apply. The inspected real-SQLite fixture exercises the changed describe handler and supports the reported improvement; post-deployment latency and memory measurements remain outside that evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository context identifies a maintainer author, so the external-contributor proof gate does not apply. The inspected real-SQLite fixture exercises the changed describe handler and supports the reported improvement; post-deployment latency and memory measurements remain outside that evidence.
Evidence reviewed 8 items Current main still waits for bulk readiness: The fetched main implementation still awaits ensureMaterialized in sessions.describe before selecting the requested row. The PR removes that dependency and refreshes dirty requested rows synchronously through the projection owner.
Introduced behavior and ownership: The pinned merge-base-to-head diff separates metadata preparation from transcript enrichment without changing plugin SDK exports, configuration, dependencies, or schema declarations. The verified test-merge context identifies the same introduced paths.
Prior blocker resolved: The persisted-worker regression keeps catalog loading paused, applies a replacement or privacy change, and asserts that describe responds immediately with current metadata or a null session. This replaces the obsolete expectation that describe joins bulk readiness.
Findings None None.
Security None None.

How this fits together

The Gateway’s session projection combines stored conversation metadata with runtime activity to serve lists, descriptions, history startup, and session events. This change separates requested-row preparation from optional transcript enrichment.

flowchart TD
  A[Stored session metadata] --> B[Resident session projection]
  C[Conversation request] --> D[Prepare requested row]
  B --> D
  D --> E[Current visibility checks]
  E --> F[Conversation response]
  G[Transcript history] --> H[Bounded background enrichment]
  H --> B
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +541, Tests +1140, Docs +8. Total +1689 across 64 files.

View PR surface stats
Area Files Added Removed Net
Source 22 865 324 +541
Tests 40 1379 239 +1140
Docs 2 16 8 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 64 2260 571 +1689

Review metrics

Metric Value Why it matters
Production versus regression coverage Net production +541 lines; tests and test support +1,140 lines Production growth implements bounded background enrichment and requested-row preparation, with regression coverage for latency, lifecycle, visibility, and naming.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/gateway/dashboard-session-title-backfill.ts, migration/backfill/repair: src/gateway/session-row-projection-backfill.ts, migration/backfill/repair: src/gateway/session-row-projection.ts, migration/backfill/repair: src/gateway/session-row-transcript-backfill.ts, unknown-data-model-change: src/gateway/dashboard-session-title-backfill.ts, unknown-data-model-change: src/gateway/session-row-projection-backfill.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep one resident projection owner, serve keyed requests from current stored facts, and let bounded background enrichment preserve existing names, activity ordering, and session identity.

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

Yes, source inspection establishes the bulk-readiness dependency, and the PR supplies a focused 2,048-session handler regression with before/after measurements; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes, the patch repairs the existing projection owner and separates optional enrichment without adding a competing cache, public API, or configuration mode.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The reported production measurements show conversation description, resolution, and startup delayed by tens of seconds during resident refresh.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository context identifies a maintainer author, so the external-contributor proof gate does not apply. The inspected real-SQLite fixture exercises the changed describe handler and supports the reported improvement; post-deployment latency and memory measurements remain outside that evidence.

Evidence

What I checked:

Likely related people:

  • steipete: 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 (8 earlier review cycles)
  • reviewed 2026-09-17T16:26:44.141Z sha d3ac840 :: blocked before merge. :: [P2] Migrate the remaining describe regression off bulk readiness
  • reviewed 2026-09-17T16:36:15.974Z sha e5c11a4 :: blocked before merge. :: [P2] Migrate the remaining describe regression off bulk readiness
  • reviewed 2026-09-17T17:54:40.943Z sha 0a99b1a :: needs changes before merge. :: [P2] Migrate the remaining describe regression off bulk readiness
  • reviewed 2026-09-17T18:22:45.412Z sha 4a9b167467abe8adc00d616cea154907246dcf35 :: blocked before merge. :: none
  • reviewed 2026-09-17T18:40:59.044Z sha ce11d19 :: blocked before merge. :: none
  • reviewed 2026-09-17T19:19:01.792Z sha ce11d19 :: blocked before merge. :: none
  • reviewed 2026-09-17T19:40:08.053Z sha cf328b0 :: blocked before merge. :: none
  • reviewed 2026-09-17T20:08:57.597Z sha d1f461c :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 17, 2026
@steipete
steipete force-pushed the steipete/fix-projection-transcript-probe-20260917 branch 2 times, most recently from ce11d19 to cf328b0 Compare September 17, 2026 19:25
Serve keyed session reads independently of bulk resident refresh. Materialize stored metadata incrementally and backfill optional transcript fields under the existing work budget.
Break the resident projection import cycle while retaining shared pending naming and explicit-title decisions.
Keep optional transcript backfill behind foreground requests and retain
queued session publications until their reads settle. Resolve missing ACP
metadata through its owner and seed usage fixtures through normal accounting.

Preserve sharing checks, physical store ownership, and bounded legacy title
recovery while migrating consumers and fixtures off eager enrichment.
Prepare stored fallback facts independently of live run activity so a stale
running status cannot hide the completed model. Presentation still selects
the current live model.

Align session-read fixtures and diagnostics with incremental metadata
readiness while preserving ownership, visibility, and error assertions.
@steipete
steipete force-pushed the steipete/fix-projection-transcript-probe-20260917 branch from cf328b0 to d1f461c Compare September 17, 2026 19:59
@steipete
steipete merged commit 85b8a9b into main Sep 17, 2026
218 checks passed
@steipete
steipete deleted the steipete/fix-projection-transcript-probe-20260917 branch September 17, 2026 20:34
@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 18, 2026
openclaw#150989)

* fix(gateway): keep transcript reads out of session-row materialization

Serve keyed session reads independently of bulk resident refresh. Materialize stored metadata incrementally and backfill optional transcript fields under the existing work budget.

* fix(gateway): separate title state from model execution

Break the resident projection import cycle while retaining shared pending naming and explicit-title decisions.

* fix(gateway): preserve session projection request lifetimes

Keep optional transcript backfill behind foreground requests and retain
queued session publications until their reads settle. Resolve missing ACP
metadata through its owner and seed usage fixtures through normal accounting.

Preserve sharing checks, physical store ownership, and bounded legacy title
recovery while migrating consumers and fixtures off eager enrichment.

* fix(gateway): preserve stored fallback models in resident rows

Prepare stored fallback facts independently of live run activity so a stale
running status cannot hide the completed model. Presentation still selects
the current live model.

Align session-read fixtures and diagnostics with incremental metadata
readiness while preserving ownership, visibility, and error assertions.
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 gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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