Skip to content

fix(sessions): reduce cold catalog listing delays - #139146

Merged
steipete merged 1 commit into
mainfrom
codex/session-catalog-performance-20260905
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/session-catalog-performance-20260905

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves a problem where operators opening or refreshing session catalogs wait unnecessarily for locally stored metadata when database handles are cold. Large inventories amplify that delay.

Why This Change Was Made

Reuse the metadata already parsed by canonical-key validation during the same listing read. The cache checks SQLite’s connection-local data version before consuming those complete facts and uses its existing fresh SELECT if an external commit intervened.

Retained-window keys, timestamp filtering, owner and participant projection, Doctor’s full entries, cache invalidation and fresh delivery privacy keep their existing contracts. No schema, migration, configuration, RPC, cache lifetime or retained-handle policy changes. Production LOC is +87/-28 (net +59); tests are +247/-2. The assertion baseline decreases one existing allowance from 3 to 2.

User Impact

Cold metadata listings, including sessions.catalog.list, perform less synchronous work. The large-inventory proof showed roughly 31–33% shorter cold handler times. Warm full-page reads showed a modest measured increase, recorded below; this is not a universal speedup claim.

Evidence

Linux Node 24.19.0 / SQLite 3.53.3 proof used the actual Gateway request router, synthetic authenticated connect metadata and real SQLite. All 864 final response digests and row, enumeration and progress counts matched between variants in each timing/SQL-diagnostic matrix. The matrix covers small/large inventories, sparse/full pages, temporary/held handles, native/adopted rows and progress/final delivery. A separate privacy control held provider planning fixed while a draft transition removed the progress row and restoration returned the final row. No WebSocket handshake or live provider call is claimed.

For two agents with 5,000 stored entries each and eight adopted hosts, handler elapsed medians were:

Read condition Before After
Temporary handles, 16 returned rows 431.6 ms 289.0 ms
Temporary handles, 5,000 returned rows 538.4 ms 369.9 ms
Warm retained handles, fresh catalog enumeration, 5,000 rows 90.1 ms 91.5 ms
Warm retained handles, cached catalog enumeration, 5,000 rows 29.8 ms 30.3 ms

Cold cells use three miss/hit pairs. Warm cells use 60 observations per variant across two processes in ABBA order. The final large warm full-page median with fresh enumeration increased 1.6%; an earlier run measured 3.4%. The immediately repeated cached-enumeration request increased from 29.77 to 30.30 ms (1.8%). Both are retained, with no causal explanation inferred. Separate SQL diagnostics showed 11 metadata scans returning 55,000 rows versus 22 scans returning 110,000 rows in the large sparse cold case.

All 159 focused owner/sibling tests, focused typed lint, cycle checks and the complete unchanged changed-file gate passed. The original implementation failed both decode-once regressions. The full gate took 956.1 seconds; all observed process groups closed, source inventories stayed unchanged and the test lease is completed. Earlier assertion bookkeeping, fixture typing and lint failures were corrected and retained with the refused finished-lease reuse attempt.

The source proof used base e55f25b plus this change. Rebasing onto current main preserved all six runtime/test postimages and merged only the strict assertion-count decrement into its updated baseline. Independent P2 review is clean. Fresh exact-head CI passed for dc3abd02ce8fc494557bd723a9b57d02a9d552db and the current dependency graph; CodeQL also passed.

Reuse completed canonical validation metadata for the first listing cache read. Recheck the connection data version before reuse and preserve full-entry reads, Doctor projections, and existing cache invalidation.
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete steipete self-assigned this Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 10:49 AM ET / 14:49 UTC.

ClawSweeper review

What this changes

Reuse session metadata already decoded during validation to reduce cold catalog listing delays while preserving existing listing and cache behavior.

Merge readiness

✅ Ready for maintainer review

This remains a useful optimization absent from current main. No introduced correctness or security defect was found, and the protected maintainer-owned PR is not eligible for automated cleanup.

Priority: P2
Reviewed head: dc3abd02ce8fc494557bd723a9b57d02a9d552db

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary optimization with useful production-path measurements, meaningful regression coverage, and no blocking finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured before/after results exercise the changed SQLite reader through the production Gateway router, showing faster cold listings with matching response digests and a separate privacy-transition control; synthetic connect metadata and absent live-provider coverage are explicitly disclosed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured before/after results exercise the changed SQLite reader through the production Gateway router, showing faster cold listings with matching response digests and a separate privacy-transition control; synthetic connect metadata and absent live-provider coverage are explicitly disclosed.
Evidence reviewed 9 items Verified introduced scope: The merge-base-to-head delta contains the seven supplied paths. Independently inspected raw test-merge parents match the pinned base followed by the exact PR head; its result changes those same paths, without the unrelated base-only changes.
Current main still discards validation metadata: Current main completes canonical validation without returning decoded entries. The affected runtime files also compare identically between the pinned merge base and fetched main, so this handoff remains unique work.
Latest release comparison: The v2026.9.1 cache implementation independently selects and decodes entries when loading a snapshot; it has no validated-metadata handoff.
Findings None None.
Security None None.

How this fits together

Session catalogs combine provider listings with metadata from OpenClaw’s per-agent SQLite databases. The shared session reader validates stored entries, builds listing snapshots, and supplies metadata for display and visibility filtering.

flowchart TD
  A[Catalog request] --> B[Session metadata reader]
  C[Per-agent SQLite database] --> B
  B --> D[Validate stored session keys]
  D --> E{Database version unchanged?}
  E -->|Yes| F[Reuse decoded metadata]
  E -->|No| G[Read fresh metadata]
  F --> H[Project and filter catalog results]
  G --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +59, Tests +245, Other 0. Total +304 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 87 28 +59
Tests 2 247 2 +245
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 7 335 31 +304

Review metrics

Metric Value Why it matters
Production versus test growth Production net +59 lines; tests net +245 lines Production growth carries completed validation facts into the cache with freshness and projection safeguards, rather than adding another persistent cache.
Reported performance tradeoff Cold reads 31–33% faster; warm full-page reads 1.6% slower The evidence supports a cold-listing improvement rather than a universal speedup; an earlier warm run measured 3.4% slower.

Technical review

Best possible solution:

Keep reuse confined to the synchronous listing read; the added handoff and freshness check preserve validation and Doctor contracts without extending cache lifetime.

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

Yes: current source shows a cold validation scan followed by a separate listing decode, and the supplied benchmark measures that path; this read-only review did not rerun it.

Is this the best way to solve the issue?

Yes: passing completed metadata across the existing owner boundary removes duplicate work without skipping validation or changing database-handle retention.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded session-catalog performance improvement with measured benefit for large cold inventories.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after results exercise the changed SQLite reader through the production Gateway router, showing faster cold listings with matching response digests and a separate privacy-transition control; synthetic connect metadata and absent live-provider coverage are explicitly disclosed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded session-catalog performance improvement with measured benefit for large cold inventories.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after results exercise the changed SQLite reader through the production Gateway router, showing faster cold listings with matching response digests and a separate privacy-transition control; synthetic connect metadata and absent live-provider coverage are explicitly disclosed.

Evidence

What I checked:

  • Verified introduced scope: The merge-base-to-head delta contains the seven supplied paths. Independently inspected raw test-merge parents match the pinned base followed by the exact PR head; its result changes those same paths, without the unrelated base-only changes. (1537b14a2fbf)
  • Current main still discards validation metadata: Current main completes canonical validation without returning decoded entries. The affected runtime files also compare identically between the pinned merge base and fetched main, so this handoff remains unique work. (src/config/sessions/session-canonical-key.ts:230, bcecb3d1d19a)
  • Latest release comparison: The v2026.9.1 cache implementation independently selects and decodes entries when loading a snapshot; it has no validated-metadata handoff. (src/config/sessions/session-accessor.sqlite-entry-cache.ts, ad6fe23aecb9)
  • Freshness and lifecycle preservation: Prepared entries are reused only after a same-connection data-version comparison. Full reads, latest reads, transaction bypass, generation tracking, and post-commit publication retain their existing paths. This is local SQLite metadata handling, with no affirmative dependency on Codex runtime or protocol behavior. (src/config/sessions/session-accessor.sqlite-entry-cache.ts:124, dc3abd02ce8f)
  • Projection and admission regressions: Read the complete added tests covering absent owner columns, duplicate/deep JSON, timestamp mismatch, an external commit during validation, malformed later rows, retired aliases, retained-window keys, owner/participant projection, and decode-once behavior. Existing cache tests additionally cover connection isolation, raw writes, tracked writes, and rollback. Tests were inspected, not executed. (src/config/sessions/session-canonical-key.test.ts:43, dc3abd02ce8f)
  • Caller and final-delivery boundary: Catalog snapshots call the shared list reader with the list projection. The catalog handler constructs a fresh metadata snapshot and reevaluates visibility for each progress/final delivery; the patch does not transfer authorization or extend provider-result authority. (src/gateway/server-methods/session-catalog.ts:376, dc3abd02ce8f)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit d1df83e into main Sep 5, 2026
182 checks passed
@steipete
steipete deleted the codex/session-catalog-performance-20260905 branch September 5, 2026 15:42
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to aniruddhaadak80/openclaw that referenced this pull request Sep 5, 2026
* origin/main: (46 commits)
  fix(gateway): keep chat metadata responsive across auth refresh (openclaw#139192)
  fix(doctor): keep Workshop relocation lint read-only (openclaw#139193)
  perf(ui): retain unchanged forwarded avatar publications (openclaw#139181)
  fix(config): guide exec policy migration repairs (openclaw#139143)
  test(i18n): refresh representative Watch key (openclaw#139197)
  fix(agents): preserve recovered scheduled-run outcomes (openclaw#139037)
  refactor(acp): simplify pending operation accounting (openclaw#139189)
  fix(plugin-sdk): harden account scope for pairing requests and challenges (openclaw#139142)
  perf(gateway): avoid redundant PR landing ancestry checks (openclaw#139186)
  perf(ui): release captured audio cache leases directly (openclaw#139174)
  fix(skills): validate names in library forms (openclaw#139184)
  fix(sessions): reduce cold catalog listing delays (openclaw#139146)
  perf(cron): scan preserved action output once (openclaw#139163)
  fix(agents): keep fresh tool results readable under context pressure (openclaw#139165)
  fix(compaction): heartbeat sessions ignore the active transcript byte cap (openclaw#136533)
  perf(agents): reuse snapshotted web search result rows (openclaw#139162)
  fix(onboarding): keep Tauri setup recoverable and verify model results (openclaw#139140)
  fix(memory): rank indexed sessions by source activity (openclaw#139112)
  perf(terminal): avoid rebuilding sanitized link fallbacks (openclaw#139159)
  perf(agents): bound retained tool result projection data (openclaw#139157)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
Reuse completed canonical validation metadata for the first listing cache read. Recheck the connection data version before reuse and preserve full-entry reads, Doctor projections, and existing cache invalidation.
necromman pushed a commit to necromman/openclaw that referenced this pull request Sep 20, 2026
Reuse completed canonical validation metadata for the first listing cache read. Recheck the connection data version before reuse and preserve full-entry reads, Doctor projections, and existing cache invalidation.

(cherry picked from commit d1df83e)
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