Repository navigation
perf(gateway): fix event-loop convoys from per-session hot paths under concurrent sessions - #129135
Conversation
…folds Raise the touched-files fold cache from 16 to 256 entries so >16 viewed sessions no longer thrash it into repeated full-transcript refolds, use in-process insideGitCheckout instead of spawning git rev-parse per call, and reuse one prepared fs-safe workspace root per request instead of re-opening it per touched file.
…ligned caches controlUi.sessionPullRequests.subscribe now registers the replace-set, pushes cached snapshots, hydrates cold keys in the background (bounded concurrency 4) and responds immediately instead of awaiting serial git and GitHub batteries per session key. Local-git caches grow 10s->75s and the GitHub success cache 60s->90s so the 60s poll hits warm caches instead of re-running the full battery for every watched session every minute; failure and rate-limit semantics are unchanged.
…ot seam loadSkillEntries now serves repeat loads from a bounded 64-entry cache keyed on the chokidar snapshot version plus config fingerprint, instead of synchronously rescanning every skill root 4-6x per inbound message. The session snapshot cache serves fresh sessions read-through, and the skill precedence collision warning fires once per snapshot version instead of ~9k times/day.
… reads sessions.preview reads a bounded recent tail (64-256 events/1MiB, one 8MiB escalation when filtered messages starve the 12-item preview) and yields between batch keys instead of synchronously materializing every transcript in a 64-key loop. chat.message.get resolves visibility via the message-ID-anchored reader instead of loading the full projected transcript per request.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 4:06 AM ET / 08:06 UTC. ClawSweeper reviewWhat this changesThis PR bounds session transcript reads, caches skill discovery and workspace facts, and moves Control UI pull-request hydration into limited-concurrency background work to avoid Gateway event-loop convoys. Merge readinessKeep open for maintainer review. The source-level design follows the owning Gateway and skills boundaries, but the cache TTLs deliberately reduce normal PR-status freshness and the review environment could not retrieve current main or the latest review comment. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherGateway RPC handlers serve Control UI session data and chat messages from SQLite transcript state, workspace files, Git, GitHub, and skill discovery. The changed paths turn those inputs into session previews, file lists, PR indicators, and model skill snapshots. flowchart LR
UI[Control UI and chat clients] --> RPC[Gateway RPC handlers]
RPC --> Sessions[Session transcript reads]
RPC --> Workspace[Workspace and Git facts]
RPC --> PRs[GitHub pull-request snapshots]
RPC --> Skills[Workspace skill discovery]
Sessions --> Output[Session and chat responses]
Workspace --> Output
PRs --> Output
Skills --> Output
Decision needed
Why: The patch changes observable status-refresh cadence while describing the result as latency/logging-only; the appropriate freshness budget is a maintainer product and operator-experience choice. Before merge
Agent review detailsSecurityNone. PR surfaceSource +92, Tests +308, Other -1. Total +399 across 23 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the bounded owner-path changes, explicitly accept or adjust the normal PR-status freshness budget, then validate the resolved merge head against current main. Do we have a high-confidence way to reproduce the issue? Do we have a high-confidence way to reproduce the issue? No independent live reproduction was possible here; source and the PR’s reported production measurements identify the hot paths, but the checkout could not run them or read current main. Is this the best way to solve the issue? Is this the best way to solve the issue? Unclear: the bounded reads and owner-local caches are coherent, but maintainers must first confirm that the resulting normal PR-status freshness delay is acceptable. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 876f2de46f1a. LabelsLabel changes:
Label 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
|
|
Maintainer decision on the ClawSweeper items, landing under explicit maintainer authority: Freshness budget: accepted. The 75s local-git / 90s GitHub success TTLs intentionally trade up to ~2 minutes of background PR-indicator staleness for eliminating the per-minute full git+GitHub battery per watched session (previously ~15 git spawns + 2–9 API calls per session per minute, serialized on a busy gateway). Structural refreshes ( Current-main comparison: the review runner's checkout lacked git objects (promisor fetch unavailable) — locally this branch is rebased on Live verification timeout: the runner's |
|
Merged via squash.
|
…r concurrent sessions (openclaw#129135) * perf(gateway): stop sessions.files.list convoying on cold transcript folds Raise the touched-files fold cache from 16 to 256 entries so >16 viewed sessions no longer thrash it into repeated full-transcript refolds, use in-process insideGitCheckout instead of spawning git rev-parse per call, and reuse one prepared fs-safe workspace root per request instead of re-opening it per touched file. * perf(gateway): make session PR subscriptions non-blocking with poll-aligned caches controlUi.sessionPullRequests.subscribe now registers the replace-set, pushes cached snapshots, hydrates cold keys in the background (bounded concurrency 4) and responds immediately instead of awaiting serial git and GitHub batteries per session key. Local-git caches grow 10s->75s and the GitHub success cache 60s->90s so the 60s poll hits warm caches instead of re-running the full battery for every watched session every minute; failure and rate-limit semantics are unchanged. * perf(skills): memoize workspace skill discovery on the watcher snapshot seam loadSkillEntries now serves repeat loads from a bounded 64-entry cache keyed on the chokidar snapshot version plus config fingerprint, instead of synchronously rescanning every skill root 4-6x per inbound message. The session snapshot cache serves fresh sessions read-through, and the skill precedence collision warning fires once per snapshot version instead of ~9k times/day. * perf(gateway): bound sessions.preview and chat.message.get transcript reads sessions.preview reads a bounded recent tail (64-256 events/1MiB, one 8MiB escalation when filtered messages starve the 12-item preview) and yields between batch keys instead of synchronously materializing every transcript in a 64-key loop. chat.message.get resolves visibility via the message-ID-anchored reader instead of loading the full projected transcript per request.
What Problem This Solves
On busy gateways (observed live on the team host, 20+ concurrent Control UI sessions and several active codex runs), the whole gateway degrades: WS methods that normally answer in milliseconds take 8–20s in bursts, and there are ~11s windows where every in-flight method completes at the same instant — a whole-event-loop stall. Live log analysis (43MB gateway log, one day) plus code tracing found four independent per-session hot paths that either block the event loop with synchronous full-transcript work or serially spawn subprocess/network batteries per watched session:
sessions.files.list(536 calls/day, 32% >2s): cold touched-files folds re-parse entire 30–80MB transcripts synchronously; the process-wide LRU held only 16 entries, so >16 viewed sessions thrash it and concurrent cold folds convoy (each request observes the sum of all concurrent folds' CPU). Every call also spawnedgit rev-parse --show-topleveljust to compute a boolean, and re-opened/realpathed the fs-safe workspace root per touched file.controlUi.sessionPullRequests.subscribe(2,527 calls/day, p50 1.9s, max 45s): the RPC awaited serial cold loads (~10–18 git spawns + 1–3 serial GitHub fetches with 8s timeouts, per session key, up to 200 keys). Worse, the cache TTLs were inverted: local-git caches lasted 10s against a 60s poll, and the GitHub success cache expired at exactly the poll interval (stamped at load start) — so every poll re-ran the full battery for every watched session, every minute.sessions.preview/chat.message.get: preview batches (≤64 keys) synchronously loaded every message event per session to keep the last 12 items, with no yields between keys; message-get loaded the full projected transcript to check one messageId. Together with the folds above this drove repeatedmemory pressure: level=critical reason=rss_growthevents (heap oscillating 0.75→3.1+ GiB).Why This Change Was Made
The shared invariant violation: request paths answered small questions by synchronously materializing entire transcripts or re-running full discovery batteries, instead of bounded reads and caches sized/invalidated correctly. Fixes stay at the owning boundaries:
insideGitCheckoutreplaces the per-call git spawn; one prepared fs-safe workspace root per request instead of per-file realpath round trips.loadSkillEntriesis memoized (bounded 64-entry cache) keyed on the existing chokidar snapshot-version seam plus config fingerprint/roots; the session snapshot cache now serves fresh sessions read-through; collision warnings fire once per snapshot version.User Impact
Control UI stays responsive with many sessions active: sidebar/file-panel/PR-indicator refreshes no longer convoy behind full transcript re-parses or per-session git/GitHub batteries, subscribe RPCs return immediately, and the gateway's background load drops from ~N×15 git spawns + N×2–9 GitHub calls per minute to near-zero for unchanged repos. Heap churn from preview/message-get paths shrinks accordingly. No config surface, schema, or protocol changes; no behavior changes beyond latency/logging (collision warning now deduped per snapshot version).
Evidence
Live diagnosis on team.openclaw.ai (gateway 2026.8.1): per-method latency distribution extracted from the gateway JSONL log —
sessions.files.list536 calls/172 >2s;controlUi.sessionPullRequests.subscribe2,527 calls, p50 1,873ms; a synchronized ~11.18s completion cluster across 8 unrelated methods at 00:39:12 (event-loop stall); 26 critical rss_growth memory-pressure events; 8,964 skill-collision warnings. Subprocess sampling over 30s showed the PR poller'sgit diff --shortstatbattery cycling across all watched worktrees.Local verification: targeted Vitest for all touched surfaces green — gateway shard (7 files, 117 tests), skills + workshop suites (57 files, 815 tests incl. new regressions), preview/chat shard. New regression coverage: cursor retention across 24 viewed sessions; subscribe responds without awaiting cold loads; no re-scan within a snapshot version and rescan after version bump; collision warning once per version; 1,024-message transcript preview reads only 64 events; hidden announce messages remain inaccessible via message-get.
pnpm check:changedgreen (assertion-safety baseline shrink included). Production LOC delta: +184/−93 (bounded-parallelism helper, memoization, and bounded-read logic); tests +323/−15.