Skip to content

perf(gateway): reuse live session lists for one second - #149387

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-sessions-list-live-reuse-20260915
Sep 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-sessions-list-live-reuse-20260915

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

On team.openclaw.ai, active sessions prevent completed sessions.list cache hits, so repeated roster requests rebuild the same rows while the Gateway main thread is already saturated. The September 15 observation recorded 12,852 calls from 71 connections in one hour, p50/p90 latency of 2,172/4,354 ms, and 9,384 slow-list warnings. Logged slow calls included 4,845 projection owners, 279 in-flight followers, and zero completed hits; list/describe projection accounted for roughly 35% of the main-thread CPU profile.

User Impact

Matching requests can reuse a completed page containing live runs or child sessions for up to one second. Access, identity, profile, database membership, and configuration changes still invalidate immediately. Earlier agent-status deadlines take precedence. This reduces repeated projection work without changing the UI refresh cadence.

The first commit also fixes a prerequisite caller-isolation gap: internal operator callers now use the same sharing identity as row visibility, so one operator cannot receive another operator's cached draft rows.

Why This Change Was Made

The cache previously discarded every result containing live work, and transcript/activity version changes rotated its entire state. The cache owner now gives live pages a fixed one-second deadline matching the UI's maximum refresh wait, carries bounded completed entries across soft changes without extending their deadlines, and preserves the existing in-flight and model-catalog fences. Idle pages without an expiry retain immediate mutation invalidation.

The hard fence includes the existing Gateway access revision, whose owner also incorporates profile aliases. This was necessary because visibility/ownership changes need not change session identity. Its owner and producers are unchanged.

Caller audit: the key includes the sharing policy's identity, authenticated profile identity separately for owner-first/involving-me/membership decoration, admin/session-cap classification, system-actor state, GitHub-sync presence, and every sorted request parameter (filters, agent selection, ordering, paging). Those cover all caller-dependent visibility and projected sharing fields. The only relevant internal field is the operator role actor; its identity, system distinction, and effective cap are represented. Model-selection scope checks only the already-keyed admin scope plus fenced configuration and process-wide state. Connection IDs, other internal fields, and other scope bits do not select rows or change this projection.

Tradeoff: conservative keyed sessions.changed mutations, including run-boundary and patch notifications, advance the hard access revision and immediately invalidate live pages. Mutation frequency can therefore shorten the one-second reuse window. The existing explicit accessChanged: false certification skips that access bump; transcript updates—the dominant signal—do not bump it either. The coordinator will measure the rebuild rate after deployment; the planned projection redesign replaces this cache. This PR does not change per-rebuild sessions.describe or subagent-index work and includes no production deployment or post-deployment CPU measurement.

Evidence

  • Caller-isolation regression: failed before commit 1 by returning another internal operator's draft, then passed after the key repair.
  • Five live-window regressions: all failed before the cache lifecycle change and passed after it. They cover reuse, transcript-version changes, immediate user-profile invalidation, expiry at exactly 1,000 ms, and shorter status deadlines on both live and other rows. Reuse reports cacheRole=completed-hit through the existing diagnostics channel.
  • Access-revocation regression: failed under the original hard-fence set by returning a newly hidden row 100 ms after the change; passed after adding the existing access revision.
  • The existing store-RPC test passes with its original assertions and timing, unchanged from the branch base.
  • All 857 tests across the 61 requested files passed. The full changed-file lint/typecheck/guard checks and git diff --check passed. Fresh Codex autoreview is clean at P2 with a retained, verified JSON result.

Commands:

node scripts/run-vitest.mjs src/gateway/server-methods/sessions-list-cache*.test.ts src/gateway/server-methods/sessions-read-cache.test.ts src/gateway/server-methods/sessions-read-diagnostics.test.ts src/gateway/server.sessions*.test.ts
node scripts/check-changed.mjs
git diff --check

The protocol bootstrap documentation now describes the bounded reuse and immediate hard invalidation. Diagnostics hooks and subscription contracts are unchanged. Search, active-only, activity-window, and parent-filtered requests still share only in-flight work.

Final validation and landing

Reviewed head: 829592348ff5a18ec759ec53916a12091c9bf8ff. The conflict-free rebase included #149477 (476fa7a270e), fixing the earlier unrelated alias-fixture failures. Both reviewed patches remained unchanged.

All 92 wrapper tests, all 62 cache/diagnostics/store-RPC tests across eight files, full node scripts/check-changed.mjs, and git diff --check passed. The earlier full requested selection passed 857 tests across 61 files. Retained P2 autoreview is scoped-clean with zero findings.

Exact-head CI run 35046743154 completed successfully on attempt 1. The canonical watcher returned GREEN, zero pending checks, and six superseded ancillary checks. No failed jobs were rerun or cancelled.

Native review artifacts validated as READY FOR /prepare-pr, and hosted preparation passed at the same head. Earlier merge attempts stopped at a shared GraphQL quota limit and a concurrent-main observation guard. The task-owned locks were recovered under coordinator authorization after process verification; no rebase or check bypass was used for those retries. Native merging then succeeded at 0d4a0154dd791445acc089c4dc370e02965078b5, with a complete receipt and cleanup. GitHub reports MERGED, and the merge commit is reachable from origin/main.

The wrapper warned about relevant mainline drift and explicitly proceeded under its default policy. It also emitted ordinary cleanup warnings for native branches retained by the receipt rather than the invoking checkout's HEAD. No completion step remains pending. Native completion comment.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 15, 2026 19:58
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 11:09 PM ET / September 16, 2026, 03:09 UTC (Revision 9).

ClawSweeper review

What this changes

The PR lets Gateway session lists reuse live results for one second, strengthens caller isolation, and updates cache tests and protocol documentation.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 4 items remain

The optimization remains useful, but the previously reported idle-page invalidation defect is still present at the reviewed head. Current main does not contain this optimization, and the linked merged PRs address separate test failures.

Priority: P2
Reviewed head: 829592348ff5a18ec759ec53916a12091c9bf8ff

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused optimization has substantial reported validation, but the unresolved cache-freshness defect prevents a merge-ready rating.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from ordinary contributor proof; supplied cache regressions support the changed owner, but no deployed performance improvement is claimed.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from ordinary contributor proof; supplied cache regressions support the changed owner, but no deployed performance improvement is claimed.
Evidence reviewed 7 items Introduced cache-retention defect: The new carry-forward condition retains every unexpired entry. The expiration resolver also assigns deadlines from agentStatus alone, so an idle page qualifies without any one-second live-reuse deadline.
Concrete status-duration and invalidation contracts: Session status notes default to 30 minutes. Existing cache tests separately cover immediate transcript invalidation and idle status expiration, but do not combine a status-bearing idle page with a soft mutation.
Prior finding remains applicable: The supplied completed review at the same head reports this exact defect and requests separate live-reuse eligibility. Inspection confirms it remains unresolved; this is a repeated finding, not a newly discovered concern.
Findings 1 actionable finding [P2] Preserve soft invalidation for idle pages with status deadlines
Security None None.

How this fits together

The Gateway builds session rosters from stored session metadata and live activity for connected clients. Its list cache avoids repeated projection work while keeping results separated by caller and invalidating them when relevant state changes.

flowchart TD
  A[Client roster request] --> B[Caller identity and filters]
  B --> C[Session list cache]
  D[Access and state changes] --> C
  C --> E{Reusable result?}
  E -->|Yes| G[Session roster response]
  E -->|No| F[Stored sessions and live activity]
  F --> G
Loading

Before merge

  • Preserve soft invalidation for idle pages with status deadlines (P2) - This previously reported blocker remains. expiresAt can come solely from agentStatus.expiresAt on a page with no live runs or children. Cache such a page with the default 30-minute status note, then emit a transcript update: this condition carries the old page into the new generation, so repeated requests can return stale previews and other projections until status expiry or a hard invalidation. Track live-reuse eligibility separately and cover the combined idle-page/status/soft-mutation case.
  • Resolve merge risk (P1) - Merging unchanged can leave idle session projections stale until a status note expires or a hard invalidation occurs; the frequency of this combination in production is unmeasured.
  • Resolve merge risk (P1) - The actual CPU reduction remains unmeasured because conservative access notifications can shorten the reuse window.
  • Complete next step (P2) - Separate live-page reuse eligibility from status expiry and add a regression for an idle status-bearing page invalidated by a transcript update.

Findings

  • [P2] Preserve soft invalidation for idle pages with status deadlines — src/gateway/server-methods/sessions-list-cache.ts:193-195
Agent review details

Security

None.

PR surface

Source +30, Tests +142, Docs +12. Total +184 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 1 52 22 +30
Tests 3 184 42 +142
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 248 64 +184

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Separate reuse eligibility from expiry (recommended)
    Retain only live-eligible pages across soft mutations and add a regression proving immediate refresh for an idle page with an unexpired status note.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Separate live-page reuse eligibility from agent-status expiry in the session-list cache; preserve immediate soft invalidation for idle pages and add a failing-before/passing-after regression through sessions.list.

Technical review

Best possible solution:

Keep the existing cache owner, but track live-page reuse eligibility separately from status expiration so idle pages retain immediate soft invalidation.

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

Yes, source establishes a precise PR-head reproduction: cache an idle page with an unexpired status note, emit a transcript update, then repeat the same list request. The old page survives; no runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

The existing cache is the right owner, but the patch needs a narrower retention condition: status expiry alone must not authorize reuse across soft mutations.

Full review comments:

  • [P2] Preserve soft invalidation for idle pages with status deadlines — src/gateway/server-methods/sessions-list-cache.ts:193-195
    This previously reported blocker remains. expiresAt can come solely from agentStatus.expiresAt on a page with no live runs or children. Cache such a page with the default 30-minute status note, then emit a transcript update: this condition carries the old page into the new generation, so repeated requests can return stale previews and other projections until status expiry or a hard invalidation. Track live-reuse eligibility separately and cover the combined idle-page/status/soft-mutation case.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c1c870a41755.

Labels

Label justifications:

  • P2: This is a bounded Gateway performance improvement with a concrete cache-freshness defect.
  • merge-risk: 🚨 session-state: The introduced carry-forward condition can serve stale session projections for a status note's lifetime rather than one second.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The maintainer-authored PR is exempt from ordinary contributor proof; supplied cache regressions support the changed owner, but no deployed performance improvement is claimed.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/server-methods/sessions-list-cache.live-reuse.test.ts src/gateway/server-methods/sessions-list-cache.visibility.test.ts src/gateway/server-methods/sessions-read-cache.test.ts.
  • [P1] node scripts/check-changed.mjs.
  • [P1] git diff --check.

What I checked:

  • Introduced cache-retention defect: The new carry-forward condition retains every unexpired entry. The expiration resolver also assigns deadlines from agentStatus alone, so an idle page qualifies without any one-second live-reuse deadline. (src/gateway/server-methods/sessions-list-cache.ts:194, 829592348ff5)
  • Concrete status-duration and invalidation contracts: Session status notes default to 30 minutes. Existing cache tests separately cover immediate transcript invalidation and idle status expiration, but do not combine a status-bearing idle page with a soft mutation. (src/sessions/session-agent-status.ts:10, 829592348ff5)
  • Prior finding remains applicable: The supplied completed review at the same head reports this exact defect and requests separate live-reuse eligibility. Inspection confirms it remains unresolved; this is a repeated finding, not a newly discovered concern. (src/gateway/server-methods/sessions-list-cache.ts:194, 829592348ff5)
  • Current-main necessity: Fetched main retains immediate mutation invalidation and rejects completed caching for live pages. The main comparison agrees with the separately pinned introduced delta; it is used only to establish current behavior. (src/gateway/server-methods/sessions-list-cache.ts, c1c870a41755)
  • Caller and revocation safeguards: The cache key now uses the sharing policy identity alongside attribution and role distinctions. Completed hits check the access revision synchronously before responding; its existing owner includes profile-alias changes, and session-change notifications conservatively advance it unless certified otherwise. Added tests exercise foreign-operator draft exclusion and visibility revocation. (src/gateway/gateway-access-revision.ts:9, 829592348ff5)
  • Merged area history: Current-main history shows repeated session-cache work by Peter Steinberger, including the recent model-catalog fence change. GitHub commit metadata identifies steipete and supplies the matching patch. Deeper local blame and release-blob inspection encountered unavailable promisor objects; no introduction or shipped-release claim relies on those failed reads. (src/gateway/server-methods/sessions-list-cache.ts:100, 238c33347fe0)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

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

  • Separate live-reuse eligibility from status expiration and prove immediate soft invalidation of an idle page with a long-lived status note.

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 (8 earlier review cycles)
  • reviewed 2026-09-15T20:11:09.779Z sha 4f245d0a2797289b0726c225aa50362483c53b0c :: blocked before merge. :: [P2] Preserve soft invalidation for idle pages with status deadlines
  • reviewed 2026-09-15T21:21:37.404Z sha 62d5187 :: blocked before merge. :: [P2] Preserve soft invalidation for idle pages with status deadlines
  • reviewed 2026-09-15T22:59:12.022Z sha 44be1af80be53e573c64f1b070487730f751bbd1 :: blocked before merge. :: [P2] Preserve soft invalidation for idle pages with status deadlines
  • reviewed 2026-09-16T00:23:34.993Z sha 44be1af80be53e573c64f1b070487730f751bbd1 :: blocked before merge. :: [P2] Preserve soft invalidation for idle pages with status deadlines
  • reviewed 2026-09-16T00:31:02.107Z sha 44be1af80be53e573c64f1b070487730f751bbd1 :: blocked before merge. :: [P2] Preserve soft invalidation for idle pages with status deadlines
  • reviewed 2026-09-16T01:08:37.876Z sha 44be1af80be53e573c64f1b070487730f751bbd1 :: blocked before merge. :: [P2] Preserve soft invalidation for idle pages with status deadlines
  • reviewed 2026-09-16T02:15:34.814Z sha 8295923 :: blocked before merge. :: [P2] Preserve soft invalidation for idle pages with status deadlines
  • reviewed 2026-09-16T02:49:12.352Z sha 8295923 :: blocked before merge. :: [P2] Preserve soft invalidation for idle pages with status deadlines

@steipete
steipete force-pushed the steipete/perf-sessions-list-live-reuse-20260915 branch from 4f245d0 to 62d5187 Compare September 15, 2026 20:57
@steipete
steipete force-pushed the steipete/perf-sessions-list-live-reuse-20260915 branch from 62d5187 to 44be1af Compare September 15, 2026 22:14
Use the sharing policy identity for internal operator callers so cached lists cannot return another operator’s draft rows. Preserve attribution, role caps, system actors, and GitHub sync state in the key.
Retain completed live pages across transcript and activity changes until their original deadline, capped by earlier agent-status expiry. Preserve immediate access, identity, profile, database, and configuration invalidation, along with in-flight generation semantics.
@steipete
steipete force-pushed the steipete/perf-sessions-list-live-reuse-20260915 branch from 44be1af to 8295923 Compare September 16, 2026 02:07
@steipete
steipete merged commit 0d4a015 into main Sep 16, 2026
210 of 212 checks passed
@steipete
steipete deleted the steipete/perf-sessions-list-live-reuse-20260915 branch September 16, 2026 03:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
* fix(gateway): isolate cached session lists by sharing identity

Use the sharing policy identity for internal operator callers so cached lists cannot return another operator’s draft rows. Preserve attribution, role caps, system actors, and GitHub sync state in the key.

* perf(gateway): reuse live session lists for one second

Retain completed live pages across transcript and activity changes until their original deadline, capped by earlier agent-status expiry. Preserve immediate access, identity, profile, database, and configuration invalidation, along with in-flight generation semantics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant