Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review Please review the prepared fallback-rate-limit model projection and shared provider-normalization handle context at this head. Pay particular attention to config reload/retained snapshot behavior, custom runtime hooks, transport and auth/header parity, and the cold path for unprepared or mismatched candidates. Local regressions and Codex review pass; the predeclared A/A/B performance campaign is running while this remains a draft. |
|
🦞👀 Re-review progress:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR prepares fallback route facts with model snapshots and shares provider selection across synchronous normalization hooks. Example: A reused snapshot runs 100 turns with synthetic-first/primary and four configured fallback candidates.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes repeated fallback setup still present on main, addresses both earlier findings, and introduces no actionable correctness or security defect found in this review. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe model runtime prepares route facts from config and plugin registrations; fallback admission combines those facts with current auth and health to order eligible candidates. flowchart TD
A[Config and plugin generation] --> B[Prepared model snapshot]
B --> C[Fallback route facts]
D[Requested candidate chain] --> E[Rate limit preparation]
C --> E
F[Live auth and health] --> E
E --> G[Ordered model attempts]
Technical reviewBest possible solution: Keep final route facts on their existing snapshot owner, reuse synchronous provider handles, and retain live auth, health, and cold resolution. Do we have a high-confidence way to reproduce the issue? Current-main source repeats normalization for every candidate before attempting the primary, and the supplied corrected benchmark quantifies that work; no target code was executed during this read-only review. Is this the best way to solve the issue? The change follows existing snapshot and normalization owners, preserves custom/static hook policy, and shares the original cold algorithm between preparation and unmatched reads. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 801073ff843a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +119, Tests +265, Other +43. Total +427 across 10 files. Added test files: 2. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed November 18, 2026, 9:07 AM ET / 14:07 UTC (Revision 2). |
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.
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.
d734179 to
9f22a34
Compare
|
Addressed all three items from the review of
The separate inherited Stop-test regression was reproduced on the exact CI main parent and traced to #201157. Main's #201222 repair is incorporated; all six selected Stop cases now pass. The lane commits are patch-identical after that rebase. Changed checks and fresh Codex autoreview are clean; exact-head hosted CI is running. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…1216) * 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.
* 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]>
What Problem This Solves
A five-candidate fallback chain normalizes five configured models and selects provider handles twenty times before each turn, even when the primary succeeds. Current admitted turns already reuse their plugin generation, so activation/config preparation is largely absent; the remaining repeated model and hook work is unnecessary.
User Impact
Fallback health checks reuse model facts from the admitted snapshot. Model selection, transport, credential selection, and rate-limit decisions keep their existing behavior. There are no configuration changes or migration steps.
Why This Change Was Made
Rate-limit identity needs the resolved provider, model, endpoint, and credential/organization headers; harness/auth selection also needs the resolved API. The existing model snapshot now prepares its configured primary/fallback routes in the retained plugin generation. Reads require the same config identity. Replacement snapshots prepare replacement routes; retained snapshots keep their own facts. Live auth and health remain live. Unknown, standalone, and projected-config candidates retain the cold resolver.
Configured model normalization shares one provider handle across its model and transport hooks using the catalog normalizer's existing synchronous context. Custom/static hooks retain their policy. Agents without configured fallbacks skip projection, and initial primary selection uses static normalization before the candidate resolver applies its policy. No global activation/config cache was added; earlier activation-policy work remains the owner.
Runtime source grows by 119 lines. The growth supplies the missing snapshot-owned route projection and shared normalization context; raw catalog rows do not contain the final transport/header facts. Proof/workload/fixtures add 308 lines.
Evidence
Final measured head:
9f22a34e22107ddce37323927093ae8c0b3a7561. Baseline:80607c31486ed53baa082340949784572785f9d7.The committed workload uses 48 synthetic plugins, three providers and five fallback candidates. Both variants enter the prepared-model scope and plugin-runtime generation scope used by reply execution. Pin Node 24.22.1; five serial A/A/B blocks alternate A/A/B and B/A/A order. Each process runs 100 warmup and 1,000 measured turns separated by
setImmediate. Timing, sampled allocation, precise counts, and CPU profiles are separate passes. No session DB or workspace traversal is exercised, so unrelated disk fixtures are omitted. No production data or live model call is used.Predeclared acceptance: identical selection and rate-limit behavior, zero model normalization on prepared reads, CPU/allocation gains beyond control variation, and no unexplained 20% candidate regression. Snapshot preparation is reported separately as the intended once-per-snapshot work transfer.
Main-thread CPU falls about 68%, process CPU 66%, and sampled allocation 64%. The extra publication work amortizes after approximately 39 warm turns using total process CPU; this is an amortization estimate, not a measured cold-first-turn latency claim. This optimization is for reused snapshots. No whole-Gateway speedup is claimed.
A/A CPU difference has median 2.62%; allocation difference has median 0.38% and maximum 1.41%. One timing A2 outlier is retained: 1,001.7 µs CPU, making the maximum A/A CPU difference 121.3%. All candidate CPU samples (141.9–277.7 µs) remain below every baseline sample (416.9–1,001.7 µs); allocation ranges also do not overlap. One-minute host load ranged 8.0–30.9. No samples were dropped.
Precise coverage over 100 turns: configured-model normalization 500 → 0, provider-runtime lookup 2,000 → 0, auto-enable 0 → 0. Plugin-entry normalization occurs once on the base and zero times on the candidate, not once per turn. Regression spies also verify zero
normalizePluginsConfigcalls on prepared reads. Separate CPU profiles show 66.0 ms inclusive in configured-model normalization and 19.6 ms in provider lookup on the base, versus zero samples in either on the candidate; these are profiled-pass numbers, not warm timing results.Two regressions fail before the fix on the intended counts: 15 model normalizations over three five-candidate turns versus zero, and four provider selections per configured normalization versus one. Tests also cover resolved-model parity, saturated-route selection, endpoint/config replacement, retained old snapshots, and a mismatched config/snapshot control. Forty-five focused tests plus catalog and sticky-rate-limit coverage passed. After the review repairs, the 24-test command suite and corrected snapshot regression passed; all six affected Stop cases pass after incorporating the main repair below.
OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 pnpm check:changedexits 0, reusing the earlier successful unused-export scans. Fresh independent Codex review reports no actionable P0–P2 findings.Review/CI corrections are retained explicitly: the first benchmark omitted the plugin-runtime scope, so all its timing/allocation/activation figures were withdrawn and replaced by the complete campaign above. CI also exposed a PR-caused static custom-provider selection regression; it was reproduced and fixed without weakening the existing test. A separate main test regression was attributed to #201157 by exact-main-parent reproduction and adjacent-commit testing; #201222 repaired it. This branch incorporates #201222, with patch-identical lane commits verified by
git range-diff. No inherited-failure exception is requested.Reproduce:
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/model-fallback-activation-inputs.ts --flow prepared-runner --iterations 1000 --warmup 100, with separate--allocation,--counts --iterations 100 --warmup 0, and--profile <file> --iterations 100 --warmup 0passes.