Repository navigation
perf(gateway): reduce sessions.list read amplification under streaming load - #118207
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 6:46 PM ET / 22:46 UTC. ClawSweeper reviewWhat this changesThis PR reduces Gateway Merge readiness⛔ Blocked until real behavior proof is added - 6 items remain Keep this PR open for maintainer review. The performance target is real in current Gateway code, and the earlier cache-fence findings appear addressed in the supplied PR history, but the exact current PR head could not be hydrated from the partial clone and no inspectable after-fix concurrency artifact is present. The existing Priority: P2 Review scores
Verification
How this fits togetherGateway clients use flowchart LR
A[Gateway clients] --> B[sessions.list request]
B --> C[Session store and transcript metadata]
C --> D[Visibility and active-run projection]
D --> E[Shared list result]
E --> F[Dashboard response]
G[Session mutation] --> H[sessions.changed event]
H --> B
Decision needed
Why: The patch changes session-list freshness and notification timing, and the protected maintainer label requires explicit owner judgment rather than automated merge or closure. Before merge
Agent review detailsSecurityNone. Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Retain the focused Gateway optimization only if an exact-head review confirms the cache fences cover every session and active-run mutation path, then attach a redacted before/after concurrency benchmark or runtime transcript showing lower Do we have a high-confidence way to reproduce the issue? Yes, at source level: current Is this the best way to solve the issue? Unclear. The supplied design targets real current hot paths and its prior active-run fence findings were addressed, but the exact-head diff could not be inspected; a maintainer should compare the full cache/notification change against all session mutation owners before calling it the best fix. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against adedc323b689. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
ClawSweeper rank-up moves handled for exact head c24e111:
|
|
Merged via squash.
|
…g load (openclaw#118207) * perf(gateway): reduce sessions list read amplification * test(gateway): stabilize title batch perf proof * fix(gateway): satisfy sessions list CI contracts * perf(gateway): reuse warm batch title fields * fix(gateway): satisfy strict title cache types * test(gateway): use transcript write scope in cache test * fix(gateway): fence session list cache on active runs * refactor(infra): extract agent run registry * fix(infra): keep run-registry context types module-local
What Problem This Solves
Issue #118027: under 8 concurrent streaming turns,
sessions.listrose from ~2.1 s to 9.1 s. Code reading found the latency is read amplification on the gateway main loop, not just queuing: per-row synchronous title probes (~4 sync SQLite queries × 100 rows per call, always missing cache for actively-streaming sessions), an in-flight dedupe that could only share within a singlesetImmediatetick, whole-listing recomputation on any visibility drift, full snapshot-cache invalidation on every message persist, an O(cache) sharing-snapshot invalidation scan per mutation, and undebouncedsessions.changedevents that convert write load into client re-list load.Why This Change Was Made
sessions-list-cache.ts): a sessions-mutation counter advances synchronously inemitSessionsChangedbefore any coalescing; a request joins an in-flight build or reuses the last completed result only when the counter still matches the build's start version. Preserves the existing no-stale-projection contract exactly while letting N concurrent dashboard clients cost one build when nothing mutated.session-accessor.sqlite-title-probes.ts): one chunked Kysely query per store (chunk 400) oversession_windows/session_transcript_active_eventsreplaces up to ~400 per-call synchronous probes; per-miss widening fallback retained. Perf-shape test asserts O(batch queries), not O(rows). Read-only; no schema changes.session_nodessnapshot in place post-commit while retaining the old validity token, so unknown concurrent writes are still discovered by the incremental diff and data_version changes still force full reload. Structural/unknown writes keep hard invalidation.sessions.changedcoalescing: leading emit after quiet, 100 ms trailing coalesce per (agentId, sessionKey), shutdown flush. Events are coalesced, never dropped; the trailing emission reflects newest state. This is the one intentional behavior change: bursts emit fewer, newer events.User Impact
sessions.listunder concurrent streaming load stops paying per-row synchronous SQLite work and stops rebuilding identical projections per client; dashboards see fewer, freshersessions.changedevents. No visibility or consistency contract changes.Evidence
scripts/bench-gateway-concurrency.ts, which reproduces the Gateway single event-loop ceiling under concurrent streaming turns #118027 degradation locally on origin/main (sessions.list p99 1.34 s under N=8 mock streaming load) and provides the before/after measuring stick.Part of #118027. Siblings: perf/stream-hot-path-118027, feat/event-loop-observability-118027.