Repository navigation
fix(gateway): keep transcript reads out of session-row materialization - #150989
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 17, 2026, 4:31 PM ET / 20:31 UTC (Revision 9). ClawSweeper reviewWhat this changesThe Gateway prepares requested conversation rows independently of bulk refreshes and fills optional transcript-derived titles, previews, and model metadata through bounded background work. Regression provenancePossible 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 Review scores
Verification
How this fits togetherThe 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
Before merge
Agent review detailsSecurityNone. PR surfaceSource +541, Tests +1140, Docs +8. Total +1689 across 64 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
ce11d19 to
cf328b0
Compare
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.
cf328b0 to
d1f461c
Compare
|
Merged via squash.
|
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.
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, andchat.startupprepare 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 build9a4468148bc):sessions.listp50 / p95sessions.describep95sessions.describep50sessions.resolvemaximumchat.startupThe 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.describehandler during startup and during a subsequent dirty drain. Both sides run with--pool=forks, soprocess.threadCpuUsage()measures the child process main thread. Original production modules were restored from base4b38266964828d528ecb7823a1dde833b8b25d75for the baseline and the candidate bytes were restored and verified afterward.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.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 completenode scripts/check-changed.mjsrun 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
runningstatus 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 ford1f461cb49529e9da8c0b9f3d47034c54afdf854. 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.