Skip to content

improve: reduce repeated work in multi-agent catalog reads - #149170

Merged
steipete merged 3 commits into
mainfrom
codex/perf-runtime-owner-read-batch-7006
Sep 15, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/perf-runtime-owner-read-batch-7006

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #149057

What Problem This Solves

Reading prepared model catalogs for several configured agents repeatedly scans the same published runtime owners. A batch of N agent reads can visit N² owners even though the published state remains unchanged throughout the synchronous read.

User Impact

Session-list catalog reads do less repeated work as the configured agent count grows. Catalog results, exact-owner selection, ambiguity handling, and reload behavior remain unchanged.

Why This Change Was Made

The runtime owner builds a temporary agent index on the first fallback lookup in a synchronous batch. Subsequent reads reuse those candidate owners while retaining the existing selection predicate. The index is discarded when the batch returns or throws; nested batches restore their parent scope. Exact-key and ordinary scalar reads keep their existing behavior.

The Gateway uses this scope inside its existing lazy catalog boundary. No persistent cache, invalidation hooks, configuration, schema, or public SDK surface is added.

Evidence

  • The real configured-owner and Gateway bulk-reader fixture passed all 31 checks, preserving complete responses, object identities, ambiguity, and retirement on reload. Across its measured phases, bulk owner visits fell from 52,221 to 580; scalar visits were unchanged.
  • A fixed baseline/candidate/candidate/baseline comparison retained all 40 measurement blocks. For 128 agents, mean elapsed time fell 8.53% and execution-thread CPU fell 8.88%; both candidate runs beat both baselines. Single-agent differences remained within baseline variation.
  • These are bulk-reader measurements under the inherited dependency mocks, not full Gateway request benchmarks. Whole-process CPU and memory readings did not establish a gain; memory endpoints are not peak RSS or allocation measurements.
  • All 12 selected static checks passed, including formatting, lint, core and relevant agent/Gateway types, and graph/ratchet guards. All 68 Gateway sibling cases passed across four files. Five unchanged earlier passes were reused; the remaining checks completed after an earlier run stopped at host memory admission before launching its next check.
  • A fresh frozen installation, full build, and unused-export checks passed on an isolated Linux Testbox. All fourteen combined catalog/owner candidate files matched the frozen author, and every recorded process settled. This is the historical base plus the exact candidate, not a whole-current-main build.
  • Fresh maintained P2 review found no actionable issues in the four-file owner change. Exact-head hosted CI passed; native landing gates are enforced separately.

This focused four-file change is based on post-catalog main aff65c00b8b7. All four changed files match the reviewed candidate exactly; the earlier catalog change is already merged. Existing local and clean-install build evidence retains its recorded base qualification. Exact-head hosted CI passed on the current integration below.

Historical CI 34982341891 failed one QA native child-bundle case in job 104425947239: the first producer attempt lacks its evidence receipt. The shard passed 994 cases and failed 1; the other three native retry variants passed. The QA test, runner, lifecycle and public API are outside this four-file change and match the same owners involved in #148956. Cause remains unresolved. A subsequent isolated diagnostic on exact 04b911b509b9 plus instrumentation passed all 12 original-order cases with no skips. All nine commands settled, with source and installation fingerprints unchanged. The diagnostic brackets the broad API through a dynamic import, so this does not reproduce the original static-import CI failure or establish a fix. The original failed run remains recorded; deadlines and receipt assertions were unchanged. That failed run did not satisfy native landing gates.

Previous head 145defe364e0 normally integrates repaired main 22a07e0abe7f, including canonical #149243. That fixture uses the existing evidence-only API and records the command failure alongside its log without changing the child deadline or assertions. This does not establish the cause of the old intermittent failure. All four original/candidate file pairs and the complete owner patch are byte-identical to the prior reviewed integration. That previous integration awaited exact-head CI; historical proof retains its recorded base and the old failed run remains failed evidence.

Historical CI 34996069550 has failed the compact-large-15 and compact-small-28/31/34 tooling jobs. The common main also has native fixture failures after the repository metadata request introduced in #149230. Canonical repair owners investigated them; this run remains failed and no retry or deadline change was made. Exact-head gates remain required before landing.

Current head 7c416f20cf45 integrates main 273b6c5e11462, containing the merged native fixture repair #149294 and Codex model-attribution fixture repair #149301. Every complete original/candidate file pair and the complete binary PR patch are byte-identical to the preceding reviewed integration. Existing source review remains applicable; prior runtime evidence retains its recorded base. Exact-head CI35006734161 passed on 7c416f20cf45; native gates remain required before landing. Historical failures remain recorded; no CI retry or deadline/assertion change was made in this PR.

@steipete steipete self-assigned this Sep 15, 2026
@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 14:32
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S 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: needs maintainer review before merge. Reviewed September 15, 2026, 2:40 PM ET / 18:40 UTC (Revision 5).

ClawSweeper review

What this changes

Reuse a temporary agent index during bulk model-catalog reads to reduce repeated scans while preserving catalog selection and reload behavior.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused optimization absent from current main and the latest release. No actionable correctness or security findings remain, and the changed files match the previous reviewed head.

Priority: P2
Reviewed head: 7c416f20cf45ab77a867b575fb92eea146fc664f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with preserved selection semantics, relevant lifecycle coverage, and appropriately qualified performance evidence.
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. Reported configured-owner and Gateway bulk-reader comparisons exercise the changed path under dependency mocks; they remain supplemental evidence, not full Gateway runtime proof.
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. Reported configured-owner and Gateway bulk-reader comparisons exercise the changed path under dependency mocks; they remain supplemental evidence, not full Gateway runtime proof.
Evidence reviewed 7 items Bounded index preserves selection: The batch restores its parent scope in finally. Exact-key lookup remains first, agent-less reads retain the full candidate scan, and the existing ambiguity, directory, environment, workspace, and publication-state checks remain intact.
Production batch lifetime: The sole production caller enters the scope after its lazy import and configuration read, performs synchronous catalog projections, and isolates per-agent failures. Expired catalog renewal is queued as a microtask, after the scope has unwound.
Current main still needs the optimization: Fetched main still materializes all owner values for every fallback lookup. The merged roster-batching work in #149057 does not supply this runtime-owner index.
Findings None None.
Security None None.

How this fits together

The Gateway enriches session listings with model information from already-published agent runtimes. This change shares owner lookup work within one synchronous catalog batch before returning each agent’s catalog.

flowchart TD
  A[Session listing] --> B[Agent catalog batch]
  B --> C[Temporary agent index]
  D[Published runtime owners] --> C
  C --> E[Existing owner selection checks]
  E --> F[Per-agent catalog results]
  F --> G[Discard batch index]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +53, Tests +43. Total +96 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 69 16 +53
Tests 1 47 4 +43
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 116 20 +96

Review metrics

None.

Technical review

Best possible solution:

Keep owner indexing inside the existing synchronous read boundary, with unchanged selection predicates and no persistent cache or invalidation machinery.

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

Not applicable as a functional bug report; source confirms repeated fallback scans, and the supplied controlled comparison measures that work without claiming a full Gateway benchmark.

Is this the best way to solve the issue?

Yes. A temporary index in the existing owner removes repeated scans without duplicating selection policy or introducing persistent state.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded performance improvement for session listings with multiple configured agents.
  • 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. Reported configured-owner and Gateway bulk-reader comparisons exercise the changed path under dependency mocks; they remain supplemental evidence, not full Gateway runtime proof.

Evidence

What I checked:

  • Bounded index preserves selection: The batch restores its parent scope in finally. Exact-key lookup remains first, agent-less reads retain the full candidate scan, and the existing ambiguity, directory, environment, workspace, and publication-state checks remain intact. (src/agents/prepared-model-runtime.owner.ts:286, 7c416f20cf45)
  • Production batch lifetime: The sole production caller enters the scope after its lazy import and configuration read, performs synchronous catalog projections, and isolates per-agent failures. Expired catalog renewal is queued as a microtask, after the scope has unwound. (src/gateway/server-model-catalog.ts:227, 7c416f20cf45)
  • Current main still needs the optimization: Fetched main still materializes all owner values for every fallback lookup. The merged roster-batching work in improve: reduce repeated work when listing sessions across agents #149057 does not supply this runtime-owner index. (src/agents/prepared-model-runtime.owner.ts:300, e7dde047904e)
  • Latest release comparison: GitHub identifies v2026.9.4 as the latest release; its owner resolver also scans owners.values(). The release file was inspected through GitHub after local retrieval failed. (src/agents/prepared-model-runtime.owner.ts:308, 3a9d69db306c)
  • Re-review continuity: The comparison produced no differences across all four changed files. The supplied previous completed review contains no findings or published rank-up moves. (7c416f20cf45)
  • Behavioral coverage and performance evidence: The changed tests cover nested exception cleanup, ambiguous owners, exact workspace selection, and removed-agent visibility after reload. The captured PR body reports 31 fixture checks, owner visits falling from 52,221 to 580, and an 8.53% elapsed-time reduction at 128 agents under dependency mocks; it explicitly does not claim full Gateway latency or memory gains. No tests or target code were executed during this read-only review. (src/agents/prepared-model-runtime.owner-selection.test.ts:644, 7c416f20cf45)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (4 earlier review cycles)
  • reviewed 2026-09-15T14:51:40.457Z sha a7e655e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T15:04:34.362Z sha a7e655e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T16:46:40.021Z sha 145defe :: needs maintainer review before merge. :: none
  • reviewed 2026-09-15T17:02:08.101Z sha 145defe :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 7ff7434 into main Sep 15, 2026
200 checks passed
@steipete
steipete deleted the codex/perf-runtime-owner-read-batch-7006 branch September 15, 2026 19:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@kvnloo

kvnloo commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Why this matters

Multi-agent catalog reads that rebuild owner indexes per agent are a harness scaling tax — and a correctness hazard if a published owner can change while a sync “batch” still holds a temporary index. Operators feel this as wrong-model / wrong-plugin selection under hot reload, not as a micro-optimization miss.

Evidence

Tip 7c416f20cf45ab77a867b575fb92eea146fc664f — live CHECK on this head:

Check Result
Batch helper withPreparedModelRuntimeReadBatch WeakMap by-agent index; nested parent restore on throw
Gateway wrap readPreparedGatewayModelCatalogBatch ends both read scopes before yield
owner-selection.test.ts 28 passed (nested batch + post-reload Gateway batch)
server-model-catalog.test.ts 22 passed
Mid-batch Map mutation pin absent

Gap (agent-fixable):

  • Name and pin stale mid-batch owner selection: inside one withPreparedModelRuntimeReadBatch, mutate the same published owners Map (replace/retire agent A between two agent reads) and assert the later read sees the new owner — or assert the documented “never publish here” invariant fails loudly if mutation occurs. Nested restore + post-reload batch are covered; in-batch freshness is not.

Decision-changing ask: For this leaf — is mid-batch publish of owners while a read batch holds byAgent in-scope to pin now, or intentionally out of scope?

Review focus:

  1. Sync + no-yield claim vs any path that can publish mid-batch
  2. Nested restore / parent WeakMap discard on exit

Architecture (proposal)

Failure class: live shared Map + temporary index without a generation / epoch — cache without an invalidation contract in multi-agent prepared-runtime reads.
Never-again end-state (worth deciding as a contract, not on this PR): generation-scoped snapshot for the batch (COW / epoch), live Map + invalidate-on-publish of byAgent, or hard forbid-publish-while-batch (loud FAIL). WeakMap batching stays valuable either way once one of those is the named quality bar.

Ask (design, light) — prospective; no need to resolve on this leaf

  1. Class root: Why are multi-agent catalog owner candidates still reconstructed as N independent lookups against a live owners Map — what missing invariant lets a temporary byAgent index disagree with a mid-batch publish at all?
  2. Never-again: As agent count and hot-reload climb, what should OpenClaw’s permanent prepared-runtime / Gateway catalog contract be — generation-scoped snapshot, live Map + invalidate-on-publish, or forbid-publish-while-batch — so this class stops recurring?
  3. Repo quality: If this PR only lands the WeakMap leaf, what’s the cleanest place to own the generation/invalidation contract later (issue, follow-up PR, or catalog-coordinator design) so “stale mid-batch owner” cannot quietly return?

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: S 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