Skip to content

improve: reduce chat metadata refresh work - #147137

Merged
steipete merged 1 commit into
mainfrom
codex/perf-chat-metadata-roster-7006
Sep 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-chat-metadata-roster-7006

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #145679

What Problem This Solves

Chat metadata refreshes repeat agent-roster resolution while reading the already-published model owners for each configured agent.

Why This Change Was Made

Run the synchronous generation-fact capture inside the existing roster-facts batch. The batch ends with that capture; the next capture reads fresh configuration. Published-owner lookup, admission, auth/skills generations, and asynchronous generation checks retain their existing owners.

User Impact

Reduces work during prepared chat metadata refreshes for larger keyed agent rosters. In the fixed synthetic 64-agent keyed-roster comparison, mean elapsed time fell 27.25% and CPU time fell 21.83%. The list-roster result was mixed, including one slower candidate pair; this is not a claim of consistent improvement for every roster shape or of Gateway-wide throughput, cold startup, or sustained idle performance.

Evidence

  • The regression uses real configured directory registration, persisted synthetic plugin catalogs, and published model owners. All 520 complete output objects across the four timing processes matched the corrected diagnostic output, with the expected model present in both catalogs. Replacement, publication, removal, build counts, and unchanged-refresh behavior matched.
  • The instrumented original fails both 64-agent work-bound cases (4,352 reads exceeds 512); the candidate passes all four cases and records 192 reads for each 64-agent shape. The 56 unaffected metadata lifecycle/auth/shutdown tests passed in the original selected proof and are reused.
  • One fixed O1/C1/C2/O2 timing cohort used plain rosters, 16 awaited unchanged refreshes per cell, after real publication and initial refresh. Assertions and lifecycle mutations were outside the clock. No resampling, warmup discard, or forced GC was used.
  • Source was restored after each process. Unchanged dependencies/build outputs and recorded process cleanup were independently verified at terminal.
  • The previous hosted head failed the shared Control UI gzip gate and its dependent aggregate. Main separately repaired that gate in #147116; this patch-identical base refresh changes no UI budget or UI source. Refreshed exact-head CI passed with 114 successful jobs and 17 skipped, including the required aggregate and Control UI gate.
  • Fresh review's sole optional-result test typing finding is resolved. The corrected four tests, production core and owning agents-root test typechecks, exact-file formatting/lint, and diff check passed. The fresh hosted source review found no actionable findings at the refreshed head.
Raw fixed timing and qualifications

Each cell contains 16 refresh calls. Elapsed/CPU are milliseconds for the whole cell; CPU includes process user and system time. Columns retain execution order.

Roster O1 elapsed/CPU C1 elapsed/CPU C2 elapsed/CPU O2 elapsed/CPU
1 keyed agent 2.059 / 2.554 2.053 / 2.531 1.951 / 2.390 2.184 / 3.230
1 list agent 3.377 / 3.413 2.562 / 2.582 1.191 / 1.202 0.943 / 0.952
64 keyed agents 76.325 / 93.578 50.020 / 64.888 51.122 / 67.567 62.695 / 75.863
64 list agents 76.105 / 131.755 57.255 / 110.119 58.237 / 102.984 50.150 / 92.089

For 64 keyed agents, both elapsed/CPU pairs improved (mean elapsed 69.510 to 50.571 ms; mean CPU 84.721 to 66.227 ms). For 64 list agents, the mean improved 8.52% elapsed and 4.80% CPU, but O2/C2 regressed from 50.150 to 58.237 ms and from 92.089 to 102.984 ms. The second singleton-list pair was also adverse. Two observations per variant do not establish statistical significance.

Native process peak RSS in O1/C1/C2/O2 order was 2790.30 / 2765.13 / 2786.06 / 2751.53 MiB. Those GNU-time peaks cover the full test invocation and setup; they are not summed concurrent process-tree RSS. The worker RSS before/after each cell and worker lifetime peaks are retained separately. Neither is a window-only allocation measurement or evidence of a memory improvement.

The timed boundary excludes imports, initial publication, and initial generation. Real published-owner fallback scans remain in the measured path. Instrumented work counts are separate from timing. Stateful roster getters can observe fewer reads within the synchronous batch; fresh facts are not retained across captures.

Source/behavior/timing proof uses frozen c1191cf5c9b29f617b765216b16ffa992a8bef09 plus this candidate. All 34 reviewed source contexts and the three publication-policy files are unchanged at refreshed main 8baed117f6d9aa4172e6bd71fb7d18d88c81b1b5; the new test is absent on both bases. Exact-head hosted integration passed. Later main commit 05177019 separates runtime default designation from legacy data ownership; source inspection confirmed that the existing exact-config synchronous batch lifetime and published-owner lookup remain intact. The historical measurements do not quantify that newer main policy. No local full build is claimed for this existing synchronous import and unchanged API contract.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 15:21
@clawsweeper

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

@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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 12:49 PM ET / 16:49 UTC (Revision 3).

ClawSweeper review

What this changes

The PR reuses agent-roster lookups during synchronous chat metadata capture and adds regression coverage for refresh cost, owner replacement, and roster changes.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused performance improvement absent from current main. No actionable correctness or security findings remain; the protected maintainer PR should proceed through ordinary review.

Priority: P2
Reviewed head: 1b4540418a9a6dffdc69f9ec111d4facaa311dc3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with meaningful lifecycle coverage, qualified measurements, and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its supplied synthetic benchmark exercises metadata refresh with real published owners and substituted projection leaves; it supports the bounded optimization, not whole-Gateway throughput or memory claims.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its supplied synthetic benchmark exercises metadata refresh with real published owners and substituted projection leaves; it supports the bounded optimization, not whole-Gateway throughput or memory claims.
Evidence reviewed 9 items Introduced production change: The pinned merge-base-to-head diff only adds the existing roster batch around synchronous fact capture. Admission filtering, published-owner selection, authentication revisions, catalog status, and skills versions remain intact.
Batch lifetime and ownership: The existing helper keys facts to the exact config object and restores the previous batch in finally. Fact capture contains no await; asynchronous generation construction and subsequent freshness capture remain outside that lifetime.
Current main still needs the optimization: Fetched main still traverses agents without the batch in captureGenerationFacts. Comparing the reviewed base with main shows a separate default-agent policy update in agent-scope-config, preserving the synchronous batch helper; no replacement implementation was found in the relevant production paths.
Findings None None.
Security None None.

How this fits together

The Gateway prepares chat metadata from configured agents and their published model catalogs. Its refresh lifecycle supplies coherent model and command information to chat readers while tracking configuration, authentication, and skill changes.

flowchart TD
  A[Configured agents] --> B[Synchronous roster batch]
  C[Published model catalogs] --> B
  B --> D[Capture metadata facts]
  D --> E{Generation changed?}
  E -->|No| F[Reuse prepared metadata]
  E -->|Yes| G[Build and verify replacement]
  G --> H[Chat metadata readers]
  F --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3, Tests +197. Total +200 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 40 37 +3
Tests 1 197 0 +197
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 237 37 +200

Review metrics

Metric Value Why it matters
Reported roster work 64 agents: 4,352 reads before, 192 after The instrumented comparison supports reduced repeated work independently of noisy elapsed-time measurements.
Production versus test growth Production net +3 lines; tests +197 lines The small production increase reuses an existing owner, while the test growth validates real publication and roster lifecycle behavior.

Root-cause cluster

Relationship: partial_overlap
Canonical: #145679
Summary: This PR implements one bounded part of the broader runtime performance campaign.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep roster reuse confined to each synchronous capture while preserving published-owner selection and fresh generation checks after asynchronous preparation.

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

Yes: current source repeats roster resolution through published-owner input preparation, and the added 64-agent cases target that cost directly. This review inspected the path without executing it.

Is this the best way to solve the issue?

Yes: using the existing exact-config synchronous batch is a narrow solution that avoids a new cache or invalidation policy.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Gateway performance improvement with measured benefit for larger agent rosters.
  • 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 maintainer-authored PR is exempt from the external-contributor proof gate. Its supplied synthetic benchmark exercises metadata refresh with real published owners and substituted projection leaves; it supports the bounded optimization, not whole-Gateway throughput or memory claims.

Evidence

What I checked:

  • Introduced production change: The pinned merge-base-to-head diff only adds the existing roster batch around synchronous fact capture. Admission filtering, published-owner selection, authentication revisions, catalog status, and skills versions remain intact. (src/gateway/server-methods/chat-metadata-runtime.ts:127, 1b4540418a9a)
  • Batch lifetime and ownership: The existing helper keys facts to the exact config object and restores the previous batch in finally. Fact capture contains no await; asynchronous generation construction and subsequent freshness capture remain outside that lifetime. (src/agents/agent-scope-config.ts:121, 1b4540418a9a)
  • Current main still needs the optimization: Fetched main still traverses agents without the batch in captureGenerationFacts. Comparing the reviewed base with main shows a separate default-agent policy update in agent-scope-config, preserving the synchronous batch helper; no replacement implementation was found in the relevant production paths. (src/gateway/server-methods/chat-metadata-runtime.ts:126, 4b2b59362dec)
  • Latest release check: The v2026.9.4 release endpoint confirms publication, and its pinned source also captures agents without roster batching. This review does not identify a shipped implementation of the proposed optimization. (src/gateway/server-methods/chat-metadata-runtime.ts, 3a9d69db306c)
  • Regression coverage and supplied measurements: All four added cases retain real directory registration, persisted synthetic catalogs, and published-owner lookup while substituting projection leaves. They check unchanged refreshes, startup catalog outputs, replacement, missing publication, removal, and bounded roster reads. The captured PR body reports 4,352 original versus 192 candidate reads for 64 agents, full output parity, and qualified timing/RSS results. Tests were inspected but not executed during this read-only review. (src/agents/prepared-model-catalog-worker.chat-metadata.integration.test.ts:29, 1b4540418a9a)
  • Dependency boundary: The new test calls createCatalogFixture without codexNativeOwner; the fixture enables only its synthetic plugin in that mode. The changed path reuses OpenClaw roster facts and published owners and supplies no affirmative dependency on the Codex runtime contract. (src/agents/prepared-model-catalog-worker.test-support.ts:331, 1b4540418a9a)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: 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-13T15:27:50.654Z sha 6bc4ab68a7f47f3c698f242d95d68364b2052110 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-13T16:31:16.838Z sha 1b45404 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/perf-chat-metadata-roster-7006 branch from 6bc4ab6 to 1b45404 Compare September 13, 2026 16:23
@steipete
steipete merged commit 5a2c1c4 into main Sep 13, 2026
190 of 192 checks passed
@steipete
steipete deleted the codex/perf-chat-metadata-roster-7006 branch September 13, 2026 16:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

1 participant