Skip to content

fix: avoid repeated provider preparation during model fallback - #201632

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-plugin-auto-enable-config-rederivation-20260919
Nov 19, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-plugin-auto-enable-config-rederivation-20260919

Conversation

@steipete

@steipete steipete commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Choosing a fallback model repeatedly prepares provider plugins just to read each candidate's shared rate-limit state. Long fallback chains repeat config normalization, auto-enable preparation, and registration-key calculation before every run, even when the config and registry have not changed.

User Impact

Fallback selection uses substantially less CPU and memory. Candidate ordering, account selection, rate-limit gates, and reload behavior stay the same. No configuration changes or migration are required.

Why This Change Was Made

Normal reply fallback runs before candidate-level model-runtime acquisition, so the existing prepared-snapshot route map does not cover this outer health read. The selected plugin registry's existing load context now retains normalized candidate routes per captured config, only when the caller uses the metadata owned by that registry. Scoped inspections selecting another inventory retain the existing resolution path. This preserves plugin-derived model IDs, endpoints, and headers; account eligibility and current rate limits are still read on every run. Config publication, registry replacement, and existing context rebinding select fresh facts. Mutable setup inputs retain the existing uncached behavior.

The production delta is +35 lines for this lifecycle-owned projection; there is no new global or request-keyed cache. Existing prepared-snapshot consumers continue to carry their routes directly.

Evidence

The executable synthetic plugin regression fails on the base with 18 auto-enable calls across three warm six-candidate runs; the fix makes zero auto-enable, config-normalization, registration-key, or model-normalization calls. Differential tests preserve candidate ordering, skipped-attempt records, and final-attempt eligibility as all six routes become saturated, including plugin transport rewrites. Config republication and registry replacement select fresh routes. Interleaved inspection inventories with different transport endpoints cannot borrow each other's routes.

Five alternating before/after pairs, each with 500 measured runs after 100 warmups, using 48 plugin entries, three executable providers, one configured channel, and six fallback candidates:

Per warm fallback run Before After
Main-thread CPU 5.345 ms 0.149 ms
Process CPU 6.171 ms 0.243 ms
Owner wall time 5.281 ms 0.122 ms
Sampled allocation 10.727 MB 0.276 MB
Allocation beneath activation preparation 8.096 MB 0

Cold first-run wall time was 85.4 ms versus 81.0 ms. The final A/A control showed a 2.3% CPU shift and 0.21% allocation shift; the improvement is well beyond that variation. Timing, allocation, and work-count passes ran separately. This synthetic metadata/health path does not access session databases or enumerate workspaces.

Reproduce with node --expose-gc --import ./scripts/tsx.mjs scripts/perf/model-fallback-activation-inputs.ts --flow registry-runner --config published --iterations 500 --warmup 100, adding --allocation or --counts in separate processes.

35 focused tests passed, covering fallback activation, prepared and registry-owned routes, shared rate-limit and sticky behavior, plugin load context, and prompt-prefix stability. Codex autoreview is clean through P2. The changed modules have no Control UI imports.

pnpm check:changed --base 67aacbb676e55db620f56fbdb5132726d69ff512 passed on the final patch, including all guards, typechecks, and lint. Final staged Codex autoreview is clean through P2. There are no unresolved local failures.

CI qualification

Final-head CI run 44467659599 completed with one inherited failure: checks-ui-e2e (1/2), the Plugins first-visit asset bound (57 assets versus a limit of 56). Every other selected job passed, including all Node shards and security-fast; the aggregate gate is red because of that UI case.

The same case fails on the exact CI main parent 43ed271df4a1bc109d8fe07c502985f40c116d6a. Attribution is 37e7af19884b4, #201620: its security-audit Tooltip import adds an asset. The immediate parent 3b0b7e23f65fd passes the same focused case; the introducing commit fails identically. This is a main regression requiring a separate owner repair, not a passing CI result. The entire UI tree and relevant test/build inputs are unchanged between the tested main parent and this PR merge.

Reproduction at each unmodified checkout: node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/route-asset-requests.e2e.test.ts -t 'bounds plugins ready-window asset requests' --maxWorkers=1.

The scoped maintainer instruction permits pinned-head admin landing for exact-parent reproduced, commit-attributed inherited failures with green local proof. The native workflow retains that evidence. ClawSweeper reviewed final head aab9b17faa964 with zero findings and zero open items.

@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts agents Agent runtime and tooling size: M labels Nov 19, 2026
@steipete
steipete marked this pull request as ready for review November 19, 2026 05:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T05:51:44.112411Z aab9b17 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please check registry/config snapshot ownership and invalidation of the retained fallback health routes, including transport-derived model IDs, endpoints, and headers. Account eligibility and shared rate-limit state remain live reads. Final head: 32a1f37c1f67207aa5760145472981986d52201f.

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses normalized fallback health routes within the selected plugin registry and captured configuration.

Example: Three warm fallback runs with six configured candidates and three synthetic provider plugins.

  • Before: The reported baseline performs 18 auto-enable calls.
  • After: The reported final patch performs zero auto-enable calls while preserving candidate selection.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and source-consistent, with useful production-owner measurements and regression coverage, but required runtime proof remains incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Configured fallback chains repeatedly spend CPU and allocate memory preparing unchanged provider routes before a reply attempt.
Reason: The maintainer-authored direction targets measured repeated work without adding configuration, changing fallback policy, or introducing a separate lifecycle owner.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-directed optimization addresses repeated preparation still present on main, and the final diff has no actionable correctness findings.

Priority: P2
Reviewed head: aab9b17faa964fec49b196d02040d11b51d1282c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide final-head logs or terminal output from an isolated Gateway with a real agent/model exercising repeated configured-fallback turns and a config reload, showing preserved selection and reduced preparation work; redact credentials, IPs, and non-public endpoints.
Agent review details

How this fits together

Fallback selection resolves candidate transports before consulting live account eligibility and shared rate limits; the resulting health facts determine candidate ordering.

flowchart TD
  A[Fallback candidates] --> B[Route resolver]
  C[Registry and captured config] --> B
  B --> D[Live account and rate limits]
  D --> E[Ordered candidate attempts]
Loading

Technical review

Best possible solution:

Keep transport projections with the existing registry lifecycle, keyed by captured config and restricted to registry-owned metadata, while reading auth and health live.

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

Main's outer fallback health path normalizes each candidate without registry-owned reuse, matching the supplied baseline work counts; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change uses the existing lifecycle owner, preserves standalone and mismatched-inventory resolution, and adds distinct regressions for warm reuse, saturation parity, config publication, registry replacement, and inventory isolation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 64b382c adds src/plugins/runtime/load-context.ts:71 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 64b382cf3d73; files: src/plugins/runtime/load-context.ts)

PR surface

Source +35, Tests +229, Docs +7, Other +33. Total +304 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 37 2 +35
Tests 2 246 17 +229
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 1 47 14 +33
Total 7 337 33 +304

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: Repeated preparation adds avoidable CPU and allocation to configured fallback runs, with no demonstrated outage or delivery failure.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Repeated preparation adds avoidable CPU and allocation to configured fallback runs, with no demonstrated outage or delivery failure.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-19T05:30:51.314Z sha 32a1f37 :: needs maintainer review before merge. :: none

Reviewed November 19, 2026, 12:51 AM ET / 05:51 UTC (Revision 2).

@steipete
steipete marked this pull request as draft November 19, 2026 05:35
@steipete
steipete marked this pull request as ready for review November 19, 2026 05:48
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Please review final head aab9b17. The preceding review had zero open findings. A subsequent differential test exposed a scoped-inventory collision in the initial patch, now corrected: the ownership check reuses routes only for the selected registry's metadata. The interleaved-inventory regression failed on the first patch and passes now, while ordinary warm fallback runs retain zero activation calls.

All 35 focused tests and the full check:changed gate pass; final Codex autoreview is clean through P2. The body contains refreshed final-head paired CPU/allocation measurements and A/A controls. Proof uses the real fallback runner and executable synthetic provider plugins; no live Gateway/model service was exercised.

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete enabled auto-merge (squash) November 19, 2026 05:56
@steipete
steipete disabled auto-merge November 19, 2026 06:07
@steipete
steipete merged commit 11b6559 into main Nov 19, 2026
210 of 217 checks passed
@steipete
steipete deleted the steipete/perf-micro-plugin-auto-enable-config-rederivation-20260919 branch November 19, 2026 06:13
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 20, 2026
…law#201632)

* perf: reuse registry-owned fallback health routes

* fix(agents): bind fallback routes to registry metadata ownership
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
* perf(agents): prepare fallback rate-limit routes with model snapshots

Reuse configured fallback models within the admitted config snapshot and share provider handles across configured normalization hooks. Preserve cold resolution for standalone or mismatched snapshots and reload route facts with their owning snapshot.

* fix(agents): preserve static model selection during fallback preparation

Skip projection for agents without configured fallbacks. Match the production plugin-runtime scope in fallback benchmarks and regressions so both variants use the same retained registry.

(cherry picked from commit 2b58c8e)

Companion audit: #201632 is selected to preserve registry and metadata ownership for the fallback hot path. #200605, #203901, #203095 and #202618 make independent TUI, custody, module separation and model listing changes; none is required by this port.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
* perf: reuse registry-owned fallback health routes

* fix(agents): bind fallback routes to registry metadata ownership

(cherry picked from commit 11b6559)

Release adaptation: Keep the stable NormalizePluginId load-context hook alongside the registry-scoped fallback map. No later follow-up required.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. docs Improvements or additions to documentation scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant