Skip to content

perf(sessions): incremental snapshot revalidation and shallow list projections - #115359

Merged
steipete merged 1 commit into
mainfrom
perf/entry-cache-incremental
Jul 28, 2026
Merged

steipete merged 1 commit into
mainfrom
perf/entry-cache-incremental

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

sessions.list on team.openclaw.ai runs 271ms avg × 98/2h under active use (118ms idle-warm), and pure in-memory RPCs (question.list 178ms, plugin.surface.refresh 134ms) show the same synchronous occupancy floor. Root cause: the session-entry snapshot cache validates with PRAGMA data_version + total_changes(). total_changes() is connection-scoped and all-tables — and the read path deliberately reuses the process writer handle — so every transcript-event append, unconditional session_windows touch, lease heartbeat, or trajectory row from any running agent invalidates the cache. With 3 concurrent agents the hit rate is ~zero, and every miss synchronously re-reads all ~800 entry_json blobs, JSON.parses each, rest-spread copies each, and structuredClones each — only to delete the two heaviest fields (skillsSnapshot, systemPromptReport) from the clone.

Why This Change Was Made

session_nodes already carries updated_at with a covering index (idx_agent_session_nodes_updated_at), so changed keys can be found with an index-only probe that never touches entry_json. Parse cost then scales with what changed, not store size.

User Impact

Active-use sessions.list returns toward (and below) the idle-warm floor, and the event-loop occupancy tax on every other RPC drops with it.

Evidence

  • Incremental revalidation: on a token mismatch with data_version unchanged (same-connection writes — the frequent trigger), an index-covered SELECT session_key, updated_at diff re-parses only changed/new keys, drops removed ones, and reuses parsed entries + memoized projections for the rest. Verified via SQLite query plan that the probe is index-only.
  • Safety gate (documented in code): other-connection commits (data_version moved) always take the full reload because updated_at is entry-controlled and a cross-process same-ms rewrite could be missed; tracked in-process entry writes still hard-delete the cache; external commits racing the incremental reads are detected; oversized changed-key batches fall back to full reload.
  • Shallow list projection replaces structuredClone (+delete) with {...entry} (+delete); a downstream consumer audit across gateway listing, TUI, embedded gateway, catalog, sharing, and row projections found no nested mutation — the immutability contract is stated at the site.
  • 240 tests across cache + gateway consumer suites, including: same-connection non-entry write reuses the snapshot (parse-count spy), tracked write invalidates, cross-connection commit full-reloads, add/remove keys, same-ms rewrite gate proof. Both deadcode lanes, full lint, core prod+test tsgo, format, git diff --check clean; autoreview clean. Testbox run: https://github.com/openclaw/openclaw/actions/runs/30385296092

@steipete
steipete marked this pull request as ready for review July 28, 2026 18:14
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 28, 2026
@steipete
steipete merged commit 3c9714d into main Jul 28, 2026
173 of 181 checks passed
@steipete
steipete deleted the perf/entry-cache-incremental branch July 28, 2026 18:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to christian-lallo/openclaw that referenced this pull request Jul 28, 2026
* origin/main: (61 commits)
  perf(ui): debounce event-driven session list refreshes and right-size child paging (openclaw#115374)
  feat(talk): support GPT-Live realtime voice over ChatGPT OAuth (openclaw#115226)
  feat(system-agent): guide gateway configuration in Ask OpenClaw (openclaw#115363)
  fix(agents): make overflow recovery append-only via branch-and-reappend (openclaw#115271) (openclaw#115310)
  fix(macos): bound websocket ping so a dropped pong cannot orphan its continuation (openclaw#115362)
  fix(codex): isolate native hook relay startup (openclaw#115078)
  fix(ci): stop reviving superseded pull request workflows (openclaw#115378)
  feat(openshell): add workspace selection (openclaw#114952)
  fix(skills): persist workshop apply reason; correct Skill Workshop docs (openclaw#114471)
  fix: agent stops replying when a session transcript has no header row (openclaw#115080)
  perf(usage): stale-while-revalidate caches for usage.status and sessions.usage (openclaw#115369)
  fix(discord): reject invalid UTF-8 probe responses (openclaw#111734)
  feat(gateway): add memory.search operator method (openclaw#115346)
  fix(android): keep welcome action reachable with large text (openclaw#111747)
  fix(gateway): validate doctor memory agent ids (openclaw#115365)
  refactor: harden shell completion and shard Control UI E2E (openclaw#115332)
  fix(ui): anchor the thread branches menu to its trigger button (openclaw#115352)
  perf(sessions): incremental snapshot revalidation and shallow list projections (openclaw#115359)
  refactor(sessions): consolidate entry state (openclaw#115299)
  feat(ui): swap three plain Lobsterdex palettes for balloon, ascii, and portal (openclaw#115308)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant