Repository navigation
perf(sessions): stop per-row full-store scans in ACP meta reads - #114237
Conversation
Every per-session ACP meta read listed and JSON-parsed the entire session store just to find one row, making gateway sessions.list O(rows^2). A CPU profile on team.openclaw.ai showed 12.7s of a 78.5s window inside parseSqliteSessionEntryJson via buildGatewaySessionRow -> readAcpSessionMeta. Resolve the store key with exact read-only single-row probes (exact key, then lowercased key) and keep the full scan only as the fallback for legacy case-variant keys. Adds the missing read-only exact-probe accessor next to loadExactSessionEntry.
max-lines pushed session-meta.ts past 700; the store-binding helpers (resolveStoreEntryForSessionKey, resolveSessionStorePathForAcp, readSessionEntryFromStore) are one cohesive unit and move to session-meta-store.ts. Re-export keeps the public entrypoint stable.
Review caught that a per-row miss still parsed the full store. The fallback only needs persisted keys to find a legacy case-variant, so list keys without touching entry_json and probe the single winner.
|
Codex review: needs real behavior proof before merge. Reviewed July 26, 2026, 10:14 PM ET / July 27, 2026, 02:14 UTC. ClawSweeper reviewWhat this changesThis PR changes ACP session metadata reads so gateway session listing probes the needed persisted session row instead of repeatedly parsing every row in the session store. Merge readiness⛔ Blocked until stronger real behavior proof is added - 4 items remain Keep this PR open for normal maintainer review. The targeted-read design preserves the existing exact/lowercase/case-variant lookup order and the submitted CI is largely green, but the PR body supplies a before-fix production profile rather than after-fix real-behavior evidence; the branch is also behind current Priority: P2 Review scores
Verification
How this fits togetherGateway flowchart LR
A[Gateway sessions list] --> B[Build one session row]
B --> C[ACP metadata lookup]
C --> D[Exact and lowercase key probes]
D --> E[Legacy case-variant key fallback]
D --> F[Single persisted session entry]
E --> F
F --> G[Gateway session response]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +83. Total +83 across 6 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase onto current Do we have a high-confidence way to reproduce the issue? No high-confidence current-main live reproduction was independently established here. The submitted production profile and the per-row call chain make the repeated full-store decode path source-reproducible, but the reported timing was not rerun against current Is this the best way to solve the issue? Yes, provisionally. Exact and lowercase targeted probes preserve the documented old lookup precedence, while the keys-only legacy fallback avoids returning to full JSON decoding; a post-rebase merge review and live before/after measurement should confirm that conclusion. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7846a327576d. 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
|
|
Addressing the review's rank-up moves. After-fix proof (rank-up move 1). Micro-benchmark of the changed surface: a seeded store of 180 sessions (the row count on team.openclaw.ai), 60 with ACP rows, timing 180 sequential
The 1.5 KB row is the honest null result: at toy entry sizes, per-call DB open/query overhead dominates and the fix changes nothing. At realistic entry weights the eliminated cost is exactly the full-store Rebase (rank-up move 2): intentionally skipped. Repo policy is explicit that merge drift is advisory and PRs are not rebased merely because Deployment to team.openclaw.ai follows the merge, where the plan is to re-enable the session observer (disabled since the 2026-07-26 incident) and confirm this removes the cost that made it unaffordable — that live measurement will be the final after-fix evidence. |
|
Merged via squash.
|
…claw#114237) * perf(sessions): stop per-row full-store scans in ACP meta reads Every per-session ACP meta read listed and JSON-parsed the entire session store just to find one row, making gateway sessions.list O(rows^2). A CPU profile on team.openclaw.ai showed 12.7s of a 78.5s window inside parseSqliteSessionEntryJson via buildGatewaySessionRow -> readAcpSessionMeta. Resolve the store key with exact read-only single-row probes (exact key, then lowercased key) and keep the full scan only as the fallback for legacy case-variant keys. Adds the missing read-only exact-probe accessor next to loadExactSessionEntry. * refactor(acp): split session store binding out of session-meta max-lines pushed session-meta.ts past 700; the store-binding helpers (resolveStoreEntryForSessionKey, resolveSessionStorePathForAcp, readSessionEntryFromStore) are one cohesive unit and move to session-meta-store.ts. Re-export keeps the public entrypoint stable. * perf(sessions): case-variant fallback scans keys, not parsed entries Review caught that a per-row miss still parsed the full store. The fallback only needs persisted keys to find a legacy case-variant, so list keys without touching entry_json and probe the single winner.
What Problem This Solves
Gateway
sessions.listis O(rows²) in JSON parsing. Every per-session ACP meta read (buildGatewaySessionRow→resolveGatewaySessionThinkingProjectionInternal→readAcpSessionMeta→readSessionEntryFromStore) listed and JSON-parsed the entire session store just to find one row. With 180 sessions on team.openclaw.ai, a CPU profile (--cpu-prof, 10ms sampling, 78.5s window under normal agent load) attributes:parseSqliteSessionEntryJson+executeCompiledSqliteQuerySyncunder exactly this chainlistAcpSessionEntrieshad the same shape per ACP row.Why This Change Was Made
readSessionEntryFromStoreonly needs one row and its persisted key. Resolve it with targeted read-only single-row probes — exact key, then lowercased key — matching the first two steps of the oldresolveStoreSessionKeyexactly. Only when both probes miss can a legacy case-variant key match, and that fallback now lists persisted keys only (noentry_jsonparsing) and probes the single winner. The common path parses 1 row instead of N; the miss path parses ≤1 row instead of N.Two narrow accessors were added next to their existing siblings:
loadExactSessionEntryReadOnly(the read-only twin ofloadExactSessionEntry, keeping hot reads off the writable lifecycle handle) andlistSessionEntryKeysReadOnly. The store-binding helpers moved tosession-meta-store.tsbecause the change pushedsession-meta.tsover the 700-line cap; the public entrypoint is re-exported unchanged.User Impact
Faster session list and lower steady-state CPU on gateways with many sessions; the effect scales quadratically with session count. This is also the dominant cost that made the session observer unaffordable to re-enable on team.openclaw.ai.
Evidence
--cpu-profvia systemd drop-in).src/acp/runtime/session-meta12 passed — includingkeeps SQLite ACP metadata visible when legacy store keys are canonicalized, which exercises the case-variant fallback, and lifecycle-revision binding tests that provestoreSessionKey/entrysemantics are unchanged.src/config/sessions/session-accessor175 passed;src/gateway/session-utilssuites passed;src/acp/runtime43 passed.git diff --checkclean.gpt-5.6-sol, xhigh): first pass flagged that the fallback still parsed the full store per miss — fixed with the keys-only listing; second pass clean, "patch is correct (0.88)".tsgoshows one pre-existing unrelated error (@openclaw/session-url-contractunresolved — stale worktreenode_modulesfor a package newly added onmain); present on cleanorigin/maincheckout too, CI is authoritative.