Repository navigation
perf: reduce CPU spent resolving model references - #149799
Conversation
Exercise repeated candidate resolution, missing artifacts, generation replacement, environment selection, and retirement through model canonicalization.
Avoid repeating artifact candidate resolution for every model reference in session and model lists. Retain resolved surfaces in the plugin metadata owner while respecting registry publication, bundled-directory selection, and instance admission.
Document generation invalidation and runtime selection for bundled provider policy resolution.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 3:23 AM ET / 07:23 UTC (Revision 3). ClawSweeper reviewWhat this changesCaches resolved provider policy hooks within the existing plugin metadata lifecycle so repeated model-reference lookups avoid resolving the same artifact paths. Merge readiness✅ Ready for maintainer review This remains a useful performance improvement absent from current main and the latest release. No blocking defect was found; the related merged optimization addresses a different lookup layer. Priority: P2 Review scores
Verification
How this fits togetherModel selection and catalog listing ask provider plugins to normalize model references. The plugin loader supplies those policy hooks, while its metadata cache controls their reuse across registry generations. flowchart TD
A[Model references] --> B[Provider policy lookup]
B --> C{Matching cached generation?}
C -->|Yes| D[Check instance admission]
C -->|No| E[Resolve and load policy artifact]
E --> F[Retain policy in metadata cache]
F --> D
D --> G[Canonical model reference]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +56, Tests +184, Docs +8. Total +248 across 7 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Reuse resolved policy surfaces through the existing metadata owner while preserving registry selection, invalidation, and instance admission. Do we have a high-confidence way to reproduce the issue? Yes, source establishes repeated candidate resolution on current main, and the supplied benchmark exercises canonicalization through real bundled policy. This review did not execute the benchmark or tests. Is this the best way to solve the issue? Yes. The change extends the existing cache owner, preserves public policy contracts, and avoids another cache lifecycle or configuration option. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e1472df83942. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Share provider policy types through a leaf contract so metadata does not import the runtime resolver. Preserve the resolver companion exports and unchanged runtime behavior while satisfying the type-aware architecture guard.
|
Merged via squash.
|
* test: cover provider policy cache generations Exercise repeated candidate resolution, missing artifacts, generation replacement, environment selection, and retirement through model canonicalization. * perf: reuse bundled provider policies during model selection Avoid repeating artifact candidate resolution for every model reference in session and model lists. Retain resolved surfaces in the plugin metadata owner while respecting registry publication, bundled-directory selection, and instance admission. * docs: explain provider policy cache lifetime Document generation invalidation and runtime selection for bundled provider policy resolution. * fix: keep provider policy cache contracts acyclic Share provider policy types through a leaf contract so metadata does not import the runtime resolver. Preserve the resolver companion exports and unchanged runtime behavior while satisfying the type-aware architecture guard.
What Problem This Solves
Model selection and large session/model lists repeatedly resolve the same bundled provider policy artifacts, spending CPU on candidate paths and filesystem-cache lookups for every model reference.
User Impact
Repeated model-reference canonicalization uses less CPU while preserving provider policy and catalog behavior. No configuration changes or migration are required.
Why This Change Was Made
The module loader already caches exports, but runtime facade resolution happens before that cache. Keep resolved policy surfaces, including missing surfaces, in the existing plugin metadata cache. Entries follow the selected registry and its publication version plus the existing bundled-directory selection. Mutable registration/unpublished registries bypass the memo, and managed surfaces retain instance admission checks. Shared policy types live in a leaf contract so the metadata cache does not depend on the runtime resolver.
The memo is discarded by the existing metadata invalidation/reload lifecycle. The generic facade loader retains its cold-resolution and boundary checks; no Plugin SDK exports, time-based expiry, or filesystem freshness polling are added.
Evidence
Regression first: repeated present and missing policy lookups both failed on the original code with “expected 1 call, received 2” at candidate resolution.
Real-module coverage exercises replacement and retained generations, different registries sharing a cache, metadata invalidation, registry republication, retirement, unpublished registration, and bundled environment changes.
Warm local microbenchmark: seven batches of 10,000 bundled-provider model-reference canonicalizations after 1,000 warmups, using the real bundled policy and a published fixture registry on Node 26.8.2.
This is 4.86× faster (79.4% less time) for the canonicalization path; it does not measure end-to-end Gateway throughput.
The Plugin SDK surface-budget check passed; no public exports were added.
The full repository build passed. Focused proof passed 724 tests across 38 files: plugin/cache/facade owners, model selection, model-list results and lifecycle, and session-list catalog behavior.
CI initially caught a type-import cycle that the runtime-only cycle check did not detect. Extracting the existing policy contracts removed the dependency back into the resolver: Madge reports zero cycles, emitted runtime JavaScript is unchanged, and all 120 affected owner tests passed again. No guard, baseline, or budget was changed.
Regression excerpt:
The native-catalog test initially hit its existing 120-second timeout before a full build, on both the candidate (120.86 s) and original owner source (120.49 s). After the full build, all three cases passed serially; the formerly failing case took 31.54 s with a load average around 124. The subsequent freshness file also passed all three cases in a clean process. No timeout, assertion, or retry changes were made.
node scripts/check-changed.mjscompleted successfully,git diff --checkpassed, and fresh independent autoreview was clean at P2. No production deployment or live Gateway profile was performed.Exact-head CI: run 35065846225 completed successfully for
0f1b57d57e1452bfcd924afd8e91fc7dee1eb1d0. The canonical watcher returned GREEN with zero pending checks and six superseded records excluded.