Skip to content

fix(gateway): reduce CPU work in session lists and searches - #148713

Merged
steipete merged 2 commits into
mainfrom
codex/perf-session-row-prepared-auth-metadata
Sep 15, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-session-row-prepared-auth-metadata

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large session lists and searches repeatedly resolve the same plugin metadata for individual rows, adding avoidable CPU work before results can be returned.

User Impact

Session listing and model search spend less CPU time projecting rows while preserving model aliases, runtime selection, plugin enablement, and incognito classification.

Why This Change Was Made

Carry the existing agent-scoped catalog owner's prepared metadata through runtime classification and model-reference normalization. The catalog projector privately associates captured facts with each returned view, preserving its public fields. Completed list-cache invalidation follows that metadata owner's identity, and current plugin enablement still gets checked. The incognito classifier also avoids splitting and rebuilding each candidate key.

The existing public resolver parameter contracts stay at their original owners; prepared internal callers use the same normalization implementation through explicit Core entrypoints. SDK exports and import topology remain unchanged.

Evidence

The original runtime-metadata path performed 260 current-metadata lookups for 128 rows in both listing and unmatched search. Regression coverage now checks bounded lookup work for rows with and without recorded model identities, successful search through prepared model aliases, metadata-owner replacement, and preservation of the public SDK input boundary.

Final validation: 318 focused list, cache, catalog, and SDK cases, the full build, and all selected changed checks passed. A compiled-helper probe verifies that the producer and consumers share the same private association module. Independent managed review found no actionable P0–P2 issues. Runtime proof uses synthetic session stores.

@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 03:03
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 14, 2026, 11:36 PM ET / September 15, 2026, 03:36 UTC (Revision 2).

ClawSweeper review

What this changes

The PR reuses prepared plugin metadata when listing and searching sessions, preserves public resolver inputs, and reduces allocation during incognito-key classification.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful optimization beyond current main. No blocking code defect was found, and the protected maintainer label excludes automatic closure.

Priority: P2
Reviewed head: cb4a2fd55c9f1c127bab93e96a591f050af15042

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with useful scaling, cache-replacement, and public-contract coverage; performance measurements remain the required follow-up.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer classification exempts this internal optimization from external-contributor proof. Synthetic stores exercise session projection and lookup scaling; reported build and helper checks are supplemental, and the scoped timing/RSS requirement remains outstanding.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer classification exempts this internal optimization from external-contributor proof. Synthetic stores exercise session projection and lookup scaling; reported build and helper checks are supplemental, and the scoped timing/RSS requirement remains outstanding.
Evidence reviewed 11 items Introduced patch reviewed: Inspected the complete merge-base-to-head changes across all introduced paths. The supplied test merge is stale, so endpoint drift and claims about removing current-main behavior were excluded.
Current main still lacks the metadata handoff: The fetched main catalog reader returns entries, route variants, and provider policy without associating the owner's metadata snapshot with the returned view.
Latest-release comparison: The v2026.9.4 CLI-provider classifier performs descriptor lookup without a prepared metadata argument. The local release-blob read failed; the same release source was successfully inspected through GitHub's contents API.
Findings None None.
Security None None.

How this fits together

The Gateway converts stored sessions and agent-scoped model catalogs into searchable summaries for clients. Plugin metadata supplies model aliases and runtime classification during that projection.

flowchart TD
  A[Session list or search request] --> B[Gateway session reader]
  C[Stored sessions] --> B
  D[Prepared agent catalog and metadata] --> E[Cache generation check]
  B --> E
  E --> F[Filter and project rows]
  D --> F
  F --> G[Session summaries for clients]
Loading

Before merge

  • Resolve merge risk (P1) - Lookup-count coverage establishes reduced repeated work, but the elapsed-time and memory effect remains unquantified.
  • Complete next step (P2) - Add or link before/after elapsed seconds and RSS measurements for session listing and search in the PR evidence, as required by src/agents/AGENTS.md.
Agent review details

Security

None.

PR surface

Source +128, Tests +220. Total +348 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 17 227 99 +128
Tests 5 256 36 +220
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 483 135 +348

Review metrics

Metric Value Why it matters
Metadata lookup scaling coverage 5 scenarios; 16 to 128 rows; at most 4 additional lookups The regression bounds repeated metadata work while checking ordinary lists, unmatched searches, and alias matches.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep session projections bound to the existing agent catalog owner's metadata generation, preserving current enablement checks, public inputs, and generation-based invalidation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep session projections bound to the existing agent catalog owner's metadata generation, preserving current enablement checks, public inputs, and generation-based invalidation.

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

Yes, source inspection traces repeated metadata resolution through session-row runtime classification and unmatched searches; the scaling regression targets that path. Runtime reproduction was not performed during this review.

Is this the best way to solve the issue?

Yes, passing existing prepared facts through the projection avoids another discovery cache and retains the public SDK contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded performance improvement for large session lists and searches without evidence of an urgent outage.
  • 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 maintainer classification exempts this internal optimization from external-contributor proof. Synthetic stores exercise session projection and lookup scaling; reported build and helper checks are supplemental, and the scoped timing/RSS requirement remains outstanding.

Evidence

What I checked:

  • Introduced patch reviewed: Inspected the complete merge-base-to-head changes across all introduced paths. The supplied test merge is stale, so endpoint drift and claims about removing current-main behavior were excluded. (cb4a2fd55c9f)
  • Current main still lacks the metadata handoff: The fetched main catalog reader returns entries, route variants, and provider policy without associating the owner's metadata snapshot with the returned view. (src/gateway/server-model-catalog.ts:205, 1528bc1614de)
  • Latest-release comparison: The v2026.9.4 CLI-provider classifier performs descriptor lookup without a prepared metadata argument. The local release-blob read failed; the same release source was successfully inspected through GitHub's contents API. (src/agents/model-selection-cli.ts:26, 3a9d69db306c)
  • Private metadata association and invalidation: A WeakMap associates metadata with each catalog view without adding public fields. The completed-list fence includes that metadata identity, and the handler-level regression checks replacement while retaining identical catalog entries. (src/gateway/server-methods/sessions-list-cache.ts:94, cb4a2fd55c9f)
  • Enablement remains current: Prepared snapshots replace inventory lookup, while descriptor resolution still calls isInstalledPluginEnabled with current configuration. Tests cover narrowed snapshots and enabled-disabled-enabled transitions. (src/plugins/setup-registry.runtime.ts:48, cb4a2fd55c9f)
  • Public resolver contracts preserved: Published session-model and stored-override resolvers explicitly forward their existing inputs to shared internal implementations. SDK coverage checks the public types and that extra caller-supplied normalization metadata does not affect those public resolvers. (src/plugin-sdk/command-auth.test.ts:54, cb4a2fd55c9f)

Likely related people:

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

Rank-up moves

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

  • Record before/after elapsed seconds and RSS for the affected session-list and search workload.

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-09-15T03:11:04.956Z sha 8f830a3 :: blocked before merge. :: none

@steipete
steipete merged commit 238c333 into main Sep 15, 2026
193 of 195 checks passed
@steipete
steipete deleted the codex/perf-session-row-prepared-auth-metadata branch September 15, 2026 03:57
@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 15, 2026
…#148713)

* perf(gateway): reuse prepared metadata in session lists

* fix(gateway): keep prepared catalog metadata private
vincentkoc added a commit that referenced this pull request Sep 15, 2026
* commit 'd8e50a38fd1c4df6dd69bcbc155697c464e1be45': (23 commits)
  fix(cron): release queued reservations when activation fails (#141008)
  fix(gateway): reduce CPU work in session lists and searches (#148713)
  feat(gateway): add admin CPU profile diagnostics (#148004)
  fix(gateway): cap device-required probe cache to prevent unbounded growth (#147708)
  fix(ci): align Gateway E2E expectations (#148653)
  refactor(ai): remove unused overflow wrapper (#148719)
  feat: stage selected chat text as editable comments (#148649)
  fix(ci): admit reachable release refs with large histories (#148161)
  fix(agents): allow authorized email CLI actions (#148521)
  improve(agents): trim large tool results with less CPU (#148718)
  refactor(docker): share image version parsing (#148243)
  fix(ci): retain passing hosted checks after skipped duplicates (#148722)
  fix(update): report configuration failures during repair (#144819)
  refactor(imessage): share handle classification (#148229)
  fix(ui): keep the selected agent across Settings pages (#148667)
  test(telegram): reuse deferred fixture helper (#148501)
  fix(media): resize images before understanding (#122431)
  fix: preserve unfinished work during completed PR cleanup (#148704)
  refactor(migrate-hermes): reuse canonical config record coercion (#148645)
  perf(channels): reduce history worker metadata footprint (#148711)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

1 participant