Skip to content

perf(gateway): fold session touched-files incrementally via transcript delta - #114401

Merged
steipete merged 4 commits into
mainfrom
perf/session-files-incremental-scan
Jul 27, 2026
Merged

steipete merged 4 commits into
mainfrom
perf/session-files-incremental-scan

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

sessions.files.list on production (team.openclaw.ai) averaged 4.7s with tails to 78s. Every request ran a full transcript scan — reading and JSON.parseing every message event from SQLite, synchronously — to rebuild the touched-files list. On long-running agent sessions (tens of thousands of messages) each Files-panel open burned seconds of CPU and blocked the gateway event loop, inflating latency of unrelated methods; journal analysis shows sessions.list/sessions.catalog.list spikes clustering exactly around Files-panel usage windows.

Why This Change Was Made

Request latency must not scale with transcript size. The transcript store already exposes an append-stable paged read (readSessionTranscriptVisibleMessageDelta) with an opaque continuation cursor and a rewrite-generation reset signal — exactly the seam an incremental fold needs. This PR folds touched files incrementally: a bounded (16-entry LRU, keyed agent + session + store) process-local cache stores the fold and its cursor; each request consumes only messages appended since the last fold. A delta reset (rewrite/branch switch) discards and refolds; missing clears. Entry-scoped reads always resolve to the canonical SQLite marker, so the old full-visitor call at this call site is deleted rather than kept as a fallback (legacy transcript files are doctor-owned migration debt, not a runtime read path).

User Impact

Files panel opens in milliseconds after first fold instead of multi-second (worst-case 78s) stalls, and unrelated Control UI requests stop spiking while it loads. No response-shape or behavior change.

Evidence

  • Production journal (24.6h): sessions.files.list n=46, avg 4722ms, max 78s pre-fix; slow-neighbor correlation documented in fix(gateway): stop fabricating assistant agent id "main" before roster resolution #114257 (comment)
  • node scripts/run-vitest.mjs src/gateway/server-methods/sessions-files.test.ts — 39/39 passing, with new regressions: incremental fold after cached cursor, reset rebuild, cross-store cache isolation, aggregation parity
  • tsgo core test lane clean; autoreview (Codex gpt-5.6-sol, xhigh) clean, "patch is correct (0.87)"

Sibling note: artifacts.list and MCP app reconstruction still use full transcript visitation but are cold in production (n=13, avg 79ms); left for a follow-up if they heat up.

@steipete
steipete marked this pull request as ready for review July 27, 2026 07:14
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Jul 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 3:39 AM ET / 07:39 UTC.

ClawSweeper review

What this changes

This PR changes the gateway’s session-files API to retain a bounded per-session touched-file fold and advance it from SQLite transcript deltas instead of rescanning the complete transcript on every Files-panel request.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

Keep this PR open. Its stated target is a real gateway-performance regression, and the branch has a plausible bounded-cache design with focused contract tests, but it still lacks reviewed after-fix evidence from a representative long-running SQLite session; the existing maintainer label also requires explicit maintainer handling rather than cleanup closure.

Priority: P1
Reviewed head: 86114d21a761d234d28026e2f420d6fb53edbbcd
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has focused tests and no confirmed code defect in this review, but missing after-fix runtime proof remains a merge gate.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Focused tests and pre-fix production measurements are useful, but the PR supplies no redacted after-fix live timing, runtime log, recording, or artifact from a representative long-running session. Add that evidence before merge and redact endpoints, IP addresses, keys, and other private data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Focused tests and pre-fix production measurements are useful, but the PR supplies no redacted after-fix live timing, runtime log, recording, or artifact from a representative long-running session. Add that evidence before merge and redact endpoints, IP addresses, keys, and other private data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items PR scope and intended contract: The PR body states that the cache is keyed by agent, session, and store; that transcript rewrites reset the fold; and that missing sessions clear it. The patch adds the delta reader import and cache entry types to implement that path.
Focused regression coverage: The branch adds a dedicated touched-files test suite and splits shared fixtures from the existing session-files tests; the PR body reports coverage for cached-cursor advancement, reset rebuilds, cross-store isolation, and aggregation parity.
Current-main baseline: Current main still imports the full transcript visitor in the session-files handler, so the proposed incremental behavior is not already implemented on main.
Findings None None.
Security None None.

How this fits together

The Control UI Files panel calls the gateway for files referenced by an agent session. The gateway resolves the canonical session transcript, folds tool-call paths into a response, and returns that derived file list to the UI.

flowchart LR
  A[Control UI Files panel] --> B[Gateway session-files API]
  B --> C[Canonical session transcript]
  C --> D[SQLite transcript delta reader]
  D --> E[Incremental touched-file fold]
  E --> F[Bounded process cache]
  F --> G[Files list response]
Loading

Decision needed

Question Recommendation
After receiving representative after-fix runtime proof, should OpenClaw accept the 16-entry process-local touched-file cache as the gateway performance tradeoff for session Files-panel reads? Accept with runtime proof: Merge after redacted live evidence confirms complete file results and materially improved repeated Files-panel timings on a long SQLite-backed session.

Why: The source path intentionally trades process-local retained state for lower gateway latency; tests describe its invariants, but the cache size and operational result need the owner’s judgment after live evidence.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Focused tests and pre-fix production measurements are useful, but the PR supplies no redacted after-fix live timing, runtime log, recording, or artifact from a representative long-running session. Add that evidence before merge and redact endpoints, IP addresses, keys, and other private data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The bounded cache changes a session-derived response path: before merge, runtime evidence should confirm that a long transcript’s first fold is complete and later appends, rewrites, missing entries, and store changes do not produce stale or incomplete Files-panel results.
  • Resolve merge risk (P1) - The submitted evidence demonstrates pre-fix production latency and mocked regression tests, but not an observed after-fix latency/result from a representative long-running SQLite-backed session.
Agent review details

Security

None.

PR surface

Source +226, Tests +146. Total +372 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 242 16 +226
Tests 2 412 266 +146
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 654 282 +372

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server-methods/sessions-files.test-support.ts, serialized state: src/gateway/server-methods/sessions-files.test.ts, serialized state: src/gateway/server-methods/sessions-files.touched-files.test.ts, serialized state: src/gateway/server-methods/sessions-files.ts, serialized state: src/gateway/session-transcript-readers.ts, unknown-data-model-change: src/gateway/server-methods/sessions-files.test-support.ts, and 3 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Prove cache correctness before merge (recommended)
    Add redacted after-fix output from a long SQLite-backed session covering initial fold, append, rewrite/reset, and missing-session behavior before merging.
  2. Accept the operational tradeoff
    A gateway owner may merge based on the focused tests and production rationale if they explicitly accept the remaining lack of live after-fix evidence.

Technical review

Best possible solution:

Keep the canonical SQLite-delta implementation, add redacted after-fix runtime evidence from a representative long-running session that shows both the returned files and materially improved repeated-request timing, then let the owning gateway reviewer decide whether the bounded cache limits are appropriate.

Do we have a high-confidence way to reproduce the issue?

No high-confidence current-main live reproduction was established in this read-only review. The current-main full-visitor path and the PR’s pre-fix production measurements make the scaling problem source-reproducible, but the supplied record does not include a repeatable representative session fixture or after-fix run.

Is this the best way to solve the issue?

Unclear: incrementally folding the canonical SQLite transcript delta is the narrowest apparent fix because it removes the repeated full scan, but live proof is still needed to confirm that the delta contract preserves complete Files-panel results under realistic history size and resets.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d4ed57bc8847.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The new process-local cache derives session file state from cursored transcript data, so an incorrect reset, cursor, or store-isolation path could show stale or incomplete session files.

Label justifications:

  • P1: The reported 4.7-second average and 78-second tail can block Files-panel use and delay unrelated gateway methods in active long-running sessions.
  • merge-risk: 🚨 session-state: The new process-local cache derives session file state from cursored transcript data, so an incorrect reset, cursor, or store-isolation path could show stale or incomplete session files.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Focused tests and pre-fix production measurements are useful, but the PR supplies no redacted after-fix live timing, runtime log, recording, or artifact from a representative long-running session. Add that evidence before merge and redact endpoints, IP addresses, keys, and other private data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • PR scope and intended contract: The PR body states that the cache is keyed by agent, session, and store; that transcript rewrites reset the fold; and that missing sessions clear it. The patch adds the delta reader import and cache entry types to implement that path. (src/gateway/server-methods/sessions-files.ts:22, 86114d21a761)
  • Focused regression coverage: The branch adds a dedicated touched-files test suite and splits shared fixtures from the existing session-files tests; the PR body reports coverage for cached-cursor advancement, reset rebuilds, cross-store isolation, and aggregation parity. (src/gateway/server-methods/sessions-files.touched-files.test.ts:1, 86114d21a761)
  • Current-main baseline: Current main still imports the full transcript visitor in the session-files handler, so the proposed incremental behavior is not already implemented on main. (src/gateway/server-methods/sessions-files.ts:31, d4ed57bc8847)
  • Prior review continuity: The previous completed ClawSweeper cycle found no patch defect but required real after-fix behavior proof. The new head contains only test cleanup after that reviewed head; no redacted live timing, runtime log, recording, or artifact was added to the supplied PR body or discussion. (86114d21a761)
  • Repository-policy constraint: The PR carries the protected maintainer label, so conservative cleanup must keep it open for maintainer handling even while proof remains outstanding. (AGENTS.md:1, d4ed57bc8847)

Likely related people:

  • steipete: Authored the current gateway performance branch and the related merged gateway/Control UI repair, giving a concrete recent history signal in this subsystem; exact current-main ownership of this cache seam was not independently recoverable in the read-only environment. (role: recent gateway contributor; confidence: medium; commits: bb55d44840df, 86114d21a761; files: src/gateway/server-methods/sessions-files.ts, src/gateway/assistant-identity.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Post redacted after-fix gateway timing or terminal/log output from a representative long-running SQLite session.
  • Show the returned touched-file list remains complete across initial fold, append, reset, and missing-session cases.
  • Update the PR body after adding proof; if a fresh review does not start automatically, ask a maintainer to comment @clawsweeper re-review.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-07-27T07:19:54.503Z sha 25f3879 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Jul 27, 2026
@steipete
steipete merged commit 4aa2ab2 into main Jul 27, 2026
126 checks passed
@steipete
steipete deleted the perf/session-files-incremental-scan branch July 27, 2026 08:33
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 28, 2026
…t delta (openclaw#114401)

* perf(gateway): fold session touched-files incrementally via transcript delta

* refactor(gateway): keep session touched-files fold on the canonical sqlite path

* test(gateway): split session files transcript-fold coverage

* test(gateway): drop unused session-files test-support exports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant