Skip to content

improve(gateway): reduce CPU spent listing agent-owned sessions - #137745

Merged
vincentkoc merged 4 commits into
mainfrom
codex/team-opt-session-list-20260904
Sep 13, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
codex/team-opt-session-list-20260904

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated agent-roster scans while the Gateway prepares session lists, adding unnecessary work as configured agents and sessions grow.

User Impact

Session listing does less repeated preparation work while preserving filtering, ordering, visibility checks and cooperative yielding. Configuration changes remain visible between requests and after a yield. No configuration, protocol or storage migration is required.

Why This Change Was Made

Use the existing roster-facts batch at synchronous selection and each generator preparation step. Every batch ends before the next await, so one request cannot retain another request's configuration facts. This keeps memoization at its existing owner.

The remaining production change is +3 lines; tests add 208 net lines. Original contributor head 20fcb497c43b5e88e783a1ffc68b6ac95b8670ae remains an ancestor of signed head a1cbfddfff3dc654ef2eb79fde6366034b53237e. The refresh merges main through f513c0f345f7f2514c49ccfbc00adc3f78b9a755; it does not duplicate earlier work already on main.

Evidence

  • Original production at 55f3e3428a89ee82ccd4992b77895d61405d774d fails all three new work-bound assertions after output and freshness checks pass. The synchronous 30-agent fixture reads roster data 2,430 times against its 90-read bound.
  • Twenty unchanged focused cases passed on Linux. After correcting the asynchronous test counter to exclude its own pause-time identity probe, that case passed separately at d3912d33b5af438dd68eb6067f458ea2cf64ef25; the other 20 cases were filtered in that follow-up.
  • The asynchronous case uses a real event-loop yield, changes an identity during the pause, verifies fresh identity data, and retains the original per-chunk work bound. The correction changes only accounting for the test's own probe.
  • Tested production SHA-256 5993caceddba4969521714af3d2e9b9953d4bfb602dd2e12782b3539980aee1c and test SHA-256 afe6f0a4464d5932369bc8b862db57a77acadc8713583bbe181071ddf288e2c2 are unchanged in the refreshed head. The final runtime receipt confirmed both hashes and a clean checkout.
  • Listing, batching and test owners are unchanged between the tested base and the refreshed main base. Targeted formatting, diff checks and independent P0–P2 review passed. Fresh hosted CI and native preparation remain pending.

These results establish reduced preparation work and preserved freshness, not measured end-to-end Team latency.

@clawsweeper

clawsweeper Bot commented Sep 4, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 01:21
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 7:20 AM ET / 11:20 UTC (Revision 3).

ClawSweeper review

What this changes

The Gateway reuses agent-roster lookup facts during synchronous session selection and each preparation chunk, with tests covering bounded work and configuration freshness.

Merge readiness

✅ Ready for maintainer review

The PR remains useful: current main still repeats roster lookups during session preparation. No introduced correctness or security defect was found; the previous review identified only routine CI follow-up.

Priority: P3
Reviewed head: a1cbfddfff3dc654ef2eb79fde6366034b53237e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful regression coverage and no blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply; focused tests exercise the production listing owner, but do not measure real Gateway latency.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply; focused tests exercise the production listing owner, but do not measure real Gateway latency.
Evidence reviewed 8 items Introduced production change: The pinned delta wraps synchronous selection and each preparation.next() invocation with the existing roster batch. Every wrapper returns before the next await; no new persistent cache or API is introduced.
Existing cache lifecycle owner: withAgentRosterFactsBatch keys facts by the exact configuration object, reuses a matching enclosing batch, and restores the parent in finally. resolveAgentEntry preserves first-match and clone-on-read behavior.
Current-main necessity: Current main still consumes synchronous selection and preparation generator steps without roster batching, leaving the optimization absent.
Findings None None.
Security None None.

How this fits together

The Gateway turns stored sessions and configured agent identities into filtered, ordered session lists. Roster batching reduces repeated identity lookups while allowing configuration changes to become visible between synchronous chunks.

flowchart TD
  A[Session list request] --> B[Stored sessions and agent configuration]
  B --> C[Filter and prepare sessions]
  C --> D[Reuse roster facts within chunk]
  D --> E{More preparation work?}
  E -->|Yes| F[Release batch and yield when needed]
  F --> C
  E -->|No| G[Project ordered session rows]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3, Tests +208. Total +211 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 8 +3
Tests 1 209 1 +208
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 220 9 +211

Review metrics

Metric Value Why it matters
Production versus regression coverage production +3 net lines; tests +208 net lines Production growth reuses the existing cache owner; test growth covers work bounds, freshness, and nested cleanup.

Technical review

Best possible solution:

Keep roster memoization in its existing owner and scope reuse to synchronous selection or one preparation chunk.

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

Yes, source establishes repeated roster traversal through session-owner identity projection on current main; the supplied regression evidence quantifies it, but this review did not execute tests.

Is this the best way to solve the issue?

Yes, reusing the existing batch owner at synchronous boundaries is a narrow solution that preserves yielding and avoids a second cache lifecycle.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is a bounded internal performance improvement without demonstrated urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply; focused tests exercise the production listing owner, but do not measure real Gateway latency.

Evidence

What I checked:

  • Introduced production change: The pinned delta wraps synchronous selection and each preparation.next() invocation with the existing roster batch. Every wrapper returns before the next await; no new persistent cache or API is introduced. (src/gateway/session-utils-list.ts:591, a1cbfddfff3d)
  • Existing cache lifecycle owner: withAgentRosterFactsBatch keys facts by the exact configuration object, reuses a matching enclosing batch, and restores the parent in finally. resolveAgentEntry preserves first-match and clone-on-read behavior. (src/agents/agent-scope-config.ts:121, a1cbfddfff3d)
  • Current-main necessity: Current main still consumes synchronous selection and preparation generator steps without roster batching, leaving the optimization absent. (src/gateway/session-utils-list.ts:591, 32bf352734f0)
  • Latest-release comparison: The supplied latest release, v2026.9.4, also performs synchronous selection without the roster batch. Its source was inspected through GitHub after the local release blob could not be read. (src/gateway/session-utils-list.ts:545, 3a9d69db306c)
  • Regression coverage and captured validation: New coverage exercises both roster representations, removal between requests, identity replacement across an actual event-loop yield, and enclosing-batch restoration after failure. The captured PR body reports baseline work-bound failures and focused Linux passes. Both file SHA-256 values match that body; tests were not executed during this read-only review. This establishes test evidence, not measured end-to-end latency. (src/gateway/session-utils.perf.test.ts:53, a1cbfddfff3d)
  • Visibility and authority boundary: The RPC caller supplies its prepared visibility filter and rechecks page sharing after projection yields. The changed batch holds configuration-derived lookup facts, not access grants; session ownership is documented as responsibility rather than access control. (src/gateway/server-methods/sessions-read.ts:289, a1cbfddfff3d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-04T01:32:43.005Z sha 088e7d5 :: blocked before merge. :: none
  • reviewed 2026-09-04T06:46:24.893Z sha 20fcb49 :: blocked before merge. :: none

Batch synchronous session-owner projections through the existing agent roster index, so selection does not rescan the roster per retained session. Reuse normalized values for main-session aliases and remove the duplicate key builder. Preserve request-scoped freshness, legacy aliases, global scope, and row semantics.
@steipete
steipete force-pushed the codex/team-opt-session-list-20260904 branch from 088e7d5 to 20fcb49 Compare September 4, 2026 06:37
…ssion-list-roster-batch-20260913

* commit 'f513c0f345f7f2514c49ccfbc00adc3f78b9a755': (46 commits)
  chore(i18n): refresh native locales (#146924)
  perf(secrets): limit expiry metadata to transient credentials (#146882)
  fix(ui): preserve queued refreshes during session discovery (#146535)
  test(ui): wait for quiet scrolling and close named file tabs (#146836)
  fix(ui): prevent Usage hour filters from freezing during DST (#146919)
  test(ui): share browser page cleanup across layout fixtures (#146805)
  ci: balance complete PR runtime test groups (#146916)
  improve(infra): reduce scheduling work for session notice bursts (#146818)
  improve: prepare Gateway skill commands asynchronously (#146812)
  improve(agents): skip unused assistant delivery parsing (#146858)
  improve(ui): reuse date formatters across timestamp lists (#146789)
  fix(tests): isolate installer and Docker shell snippets (#146897)
  test(heartbeat): share explicit channel configuration fixtures (#146853)
  fix: retain conversation reply claims through write admission (#146866)
  perf(sessions): bound history reads and stabilize cursor paging (#146770)
  fix(ui): let slow dashboard downloads finish before recovery (#146881)
  fix: share Doctor lifecycle coordination with SQLite workers (#146714)
  fix: retain native session model provenance (#146801)
  fix: settle embedded transcript repairs before session cleanup (#146842)
  feat(macos): improve agent navigation and chat layout (#146531)
  ...
@vincentkoc vincentkoc self-assigned this Sep 13, 2026
@vincentkoc
vincentkoc merged commit 4883e46 into main Sep 13, 2026
191 checks passed
@vincentkoc
vincentkoc deleted the codex/team-opt-session-list-20260904 branch September 13, 2026 11:34
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

vincentkoc added a commit to zachisfine/openclaw that referenced this pull request Sep 13, 2026
* temp/pr-146799: (70 commits)
  test: reuse explicit fallback config fixtures (openclaw#146948)
  fix(computer): return fresh window observations after actions (openclaw#146822)
  refactor(feishu): remove unreachable requester topic selection (openclaw#146904)
  improve(gateway): reduce CPU spent listing agent-owned sessions (openclaw#137745)
  fix(ui): avoid recapturing chat drafts during UI updates (openclaw#146884)
  fix(ui): show system uptime in the debug overlay (openclaw#146960)
  fix(retry): honor waits beyond the native timer limit (openclaw#145718)
  fix(ui): keep chat history idle when run status changes (openclaw#146802)
  fix(ui): reuse persisted text during chat streaming (openclaw#146831)
  refactor(qa): share harness drift result construction (openclaw#146903)
  test(agents): coordinate settings lock contention (openclaw#146949)
  fix(worker): avoid repeatedly serializing screenshot history (openclaw#146907)
  fix(secrets): stop buffered upload writes after cancellation (openclaw#146840)
  perf(doctor): avoid unnecessary state runtime imports (openclaw#146926)
  improve: reduce compaction request estimation work (openclaw#146961)
  fix(ci): wait for forwarded avatar imports before assertions (openclaw#146729)
  perf(workers): skip configured Git author lookups (openclaw#146833)
  fix: admit borrowed memory writes through the agent database owner (openclaw#146760)
  fix(discord): prevent voice playback gaps and stale turn controls (openclaw#146798)
  improve: reduce worktree filesystem stalls and archive syncs (openclaw#146906)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
…claw#137745)

* perf(gateway): reuse normalized session and owner facts

Batch synchronous session-owner projections through the existing agent roster index, so selection does not rescan the roster per retained session. Reuse normalized values for main-session aliases and remove the duplicate key builder. Preserve request-scoped freshness, legacy aliases, global scope, and row semantics.

* test(gateway): isolate roster freshness probe accounting

---------

Co-authored-by: Vincent Koc <[email protected]>
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants