Skip to content

improve: reduce model capability preparation work - #152128

Merged
steipete merged 2 commits into
mainfrom
codex/perf-catalog-lookup-dc66
Sep 18, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-catalog-lookup-dc66

Conversation

@steipete

@steipete steipete commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Related: #143686

What Problem This Solves

Preparing model capabilities scans and allocates the complete provider catalog even when the selected model appears near the beginning.

User Impact

Less CPU work preparing agent runs, with the same selected model and capabilities. This measures capability preparation, not total response latency. Whole-process memory peaks were variable; Node 26's mean peak increased by 21 MiB in the benchmark cohort.

Why This Change Was Made

Combine provider filtering and literal matching in one pass that stops on the first literal match. If no literal matches, reuse the collected provider rows for the existing canonical-alias and unique case-insensitive fallbacks. Preserve sparse-array behavior and literal precedence over aliases; no cache or invalidation policy is added.

Evidence

  • Actual prepareModelRunCapabilities caller, Node 24.19.0 and 26.8.2, 24 fresh processes: six alternating baseline/candidate pairs per runtime, three measured blocks per scenario. All outputs and reference-identity contracts match. All adverse pairs retained; independent saved-data audit recomputed every pair and receipt hash.
  • 39/40 paired scenario medians improve; 213/240 elapsed-time pairs improve. At 1,000–5,000 rows, literal matches improve 89–91% at the beginning, 49–54% in the middle, and 13–22% at the end. Miss/alias medians improve 1.45–10.10%, with mixed individual pairs.
  • Node 26's 10-row case fallback is effectively flat (+0.096%, 3/6 wins); Node 24's 5,000-row case fallback also has no established gain (-0.477%, 3/6 wins). The worst 5,000-row late-hit pair on Node 24 was +39.56% despite an improved median. Shared-host load and synthetic catalogs limit generalization.
  • Mean whole-process peak RSS: Node 24, 371.83 → 364.38 MiB; Node 26, 323.03 → 344.04 MiB. Peaks include imports, correctness checks, warmup and all scenarios; they do not establish per-call allocation or retained-memory changes. Both runtimes have higher peaks in 3/6 pairs.
  • The corrected sparse-array fixture passes all 16 lookup tests, formatting, and 230-rule syntax lint. The unchanged production candidate previously passed 25 lookup/embedded model-resolution tests and 17 changed-file gates. Fresh independent canonical review of the corrected diff is clean at P0–P2.
  • The initial PR run caught unicorn/no-new-array in the new test; the fixture now creates the same holes without that constructor. The separate mainline duplicate-declaration failures are repaired by merged fix: preserve model failure causes and worker fallback runtime #152028 and included in the refreshed base; fix: restore SQLite test collection #152137 was closed as superseded with identical repaired test blobs. Required hosted CI passed on final head ba00f051b69f7c8e5005e3a9086aca1ea62df14f, including build, type checking, lint and the required test shards.
  • Local validation limits are retained: type-aware lint and an earlier test setup exceeded 2 GiB; the 16 tests subsequently passed under 4 GiB. An earlier core typecheck exceeded 4 GiB, and bounded concurrency resolved an earlier compiler thread-limit failure. None of those failed runs is counted as passing evidence.
Benchmark scope and representative timings

Base: 1def359971d0d45129db27c73b5c5a970daf623b. Candidate owner SHA-256: 2548569e857beabf86a1af79d57d10a8be77ef21c7669ba13bf48d81315f0873.

Synthetic mutable dense catalogs contain 10, 1,000 or 5,000 rows; three quarters of ordinary rows belong to the target provider. Configured catalogs contain one tenth as many rows (minimum two), with the target at the end. Controls include wrong-provider ID collisions, missing IDs, unique case fallback, provider equivalence and empty configured catalogs. Iterations were calibrated once from a fresh baseline and then fixed; the inspector was disconnected during warmup and timing. The cohort measured 31,080,960 calls. No production hit-frequency or full-turn speedup is assumed.

Times below are separately summarized microseconds per complete capability preparation. Percentage changes above are medians of paired percentage changes, so they need not equal ratios of these time medians.

Runtime Catalog / match Baseline Candidate
Node 24 1,000 / first 20.235 1.912
Node 24 1,000 / middle 22.479 11.016
Node 24 5,000 / last 111.328 99.112
Node 24 5,000 / miss 410.338 387.999
Node 26 1,000 / first 19.743 2.071
Node 26 1,000 / middle 22.826 11.252
Node 26 5,000 / last 122.834 94.552
Node 26 5,000 / miss 435.067 401.557

An earlier separate literal-prepass candidate was rejected for repeated fallback regressions. This PR uses the fused pass and its own fresh measurement cohort.

@clawsweeper

clawsweeper Bot commented Sep 18, 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 18, 2026 19:59
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Sep 18, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 18, 2026, 5:23 PM ET / 21:23 UTC (Revision 3).

ClawSweeper review

What this changes

The PR stops model catalog scanning at the first literal match, preserves existing alias fallbacks, and adds coverage for sparse arrays.

Merge readiness

⛔ Blocked before merge - 1 item remains

The optimization remains useful: current main and the latest release still scan the full catalog before checking literal matches. No actionable correctness or security finding remains, and the recorded benchmark supports the bounded performance claim.

Priority: P2
Reviewed head: ba00f051b69f7c8e5005e3a9086aca1ea62df14f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with preserved lookup contracts, relevant benchmark evidence, and successful hosted validation on the reviewed head.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured before/after results exercise the actual capability-preparation owner on Node 24 and 26 with synthetic catalogs, report preserved outputs and reference identities, and match the inspected candidate file hash; they support the narrow preparation-time claim.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured before/after results exercise the actual capability-preparation owner on Node 24 and 26 with synthetic catalogs, report preserved outputs and reference identities, and match the inspected candidate file hash; they support the narrow preparation-time claim.
Evidence reviewed 8 items Introduced optimization preserves selection semantics: The pinned delta replaces full filtering followed by literal lookup with one short-circuiting pass. A literal miss collects every provider-matching row in original order, leaving canonical and unique case-insensitive fallback behavior intact.
Production caller and implementation boundary: prepareModelRunCapabilities looks up prepared and configured catalog rows; run-embedded-attempt passes the resulting capabilities into runAgentAttempt. The changed operation uses OpenClaw-owned provider normalization and local catalog rows, without changing a Codex protocol or harness contract.
Selection and sparse-array coverage: Existing tests cover literal precedence over provider equivalence, both row orders, duplicate IDs, provider isolation, and ambiguous case matches. The new sparse fixture protects hole-skipping for literal hits, fallback hits, and misses without introducing a production test seam.
Findings None None.
Security None None.

How this fits together

OpenClaw looks up the selected model in prepared catalogs before assembling an agent run. The selected row supplies image-input and thinking capabilities.

flowchart TD
  A[Selected provider and model] --> C[Catalog lookup]
  B[Prepared and configured catalogs] --> C
  C --> D{Literal match found}
  D -->|Yes| E[Selected model row]
  D -->|No| F[Alias and unique case fallback]
  F --> E
  E --> G[Agent run capabilities]
Loading

Before merge

  • Resolve merge risk (P1) - Synthetic catalogs and shared-host measurements do not establish whole-turn speedups or lower memory use; Node 26 mean whole-process peak RSS increased by about 21 MiB.
Agent review details

Security

None.

PR surface

Source +10, Tests +10. Total +20 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 15 5 +10
Tests 1 10 0 +10
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 25 5 +20

Review metrics

Metric Value Why it matters
Capability-preparation benchmark 39/40 paired scenario medians improved across 24 processes The reported production-caller measurements support a bounded CPU-work improvement while retaining adverse results.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the fused lookup with literal precedence and unchanged fallback semantics, keeping performance claims scoped to measured capability preparation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the fused lookup with literal precedence and unchanged fallback semantics, keeping performance claims scoped to measured capability preparation.

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

Not applicable as a functional bug reproduction: source confirms the full-scan cost, and the PR supplies before/after production-caller measurements; this review did not execute them.

Is this the best way to solve the issue?

Yes. Combining provider filtering with literal matching avoids redundant work without adding caching, changing the public API, or replacing the existing fallback owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a focused agent-preparation performance improvement with no demonstrated urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured before/after results exercise the actual capability-preparation owner on Node 24 and 26 with synthetic catalogs, report preserved outputs and reference identities, and match the inspected candidate file hash; they support the narrow preparation-time claim.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after results exercise the actual capability-preparation owner on Node 24 and 26 with synthetic catalogs, report preserved outputs and reference identities, and match the inspected candidate file hash; they support the narrow preparation-time claim.

Evidence

What I checked:

  • Introduced optimization preserves selection semantics: The pinned delta replaces full filtering followed by literal lookup with one short-circuiting pass. A literal miss collects every provider-matching row in original order, leaving canonical and unique case-insensitive fallback behavior intact. (src/agents/model-catalog-lookup.ts:157, ba00f051b69f)
  • Production caller and implementation boundary: prepareModelRunCapabilities looks up prepared and configured catalog rows; run-embedded-attempt passes the resulting capabilities into runAgentAttempt. The changed operation uses OpenClaw-owned provider normalization and local catalog rows, without changing a Codex protocol or harness contract. (src/agents/command/run-embedded-attempt.ts:462, ba00f051b69f)
  • Selection and sparse-array coverage: Existing tests cover literal precedence over provider equivalence, both row orders, duplicate IDs, provider isolation, and ambiguous case matches. The new sparse fixture protects hole-skipping for literal hits, fallback hits, and misses without introducing a production test seam. (src/agents/model-catalog-lookup.test.ts:66, ba00f051b69f)
  • Current main still performs full filtering: Fetched main retains catalog.filter before its literal lookup, so the central optimization has not already landed. (src/agents/model-catalog-lookup.ts:158, dc5b321b5f89)
  • Latest-release comparison: The v2026.9.4 source also filters the complete catalog before checking literals. The local historical blob read failed; the GitHub contents API supplied the release source successfully. (src/agents/model-catalog-lookup.ts:155, 3a9d69db306c)
  • Benchmark evidence matches the production file: The captured PR body reports execution of prepareModelRunCapabilities across 24 fresh Node 24/26 processes, with identical outputs and reference identities and improvements in 39/40 paired scenario medians. The inspected production file SHA-256 equals the reported candidate hash, 2548569e857beabf86a1af79d57d10a8be77ef21c7669ba13bf48d81315f0873. This review did not rerun the benchmark. Prepared screenshots were inspected and belong to the unrelated worker-error PR, so they are not counted as lookup proof. (src/agents/model-catalog-lookup.ts:127, ba00f051b69f)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • 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 (2 earlier review cycles)
  • reviewed 2026-09-18T20:05:16.206Z sha adacae2 :: blocked before merge. :: none
  • reviewed 2026-09-18T20:55:20.265Z sha ba00f05 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/perf-catalog-lookup-dc66 branch from adacae2 to ba00f05 Compare September 18, 2026 20:47
@steipete
steipete merged commit fc81680 into main Sep 18, 2026
218 checks passed
@steipete
steipete deleted the codex/perf-catalog-lookup-dc66 branch September 18, 2026 21:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 18, 2026
…n-20260918-v4

* origin/main: (81 commits)
  fix: retire failed setup plugins without replaying facade initialization (#152026)
  fix(test): select Node for built runtime recovery fixtures (#152162)
  refactor(auth): reuse privately assembled choice groups (#152166)
  fix: preserve chat media delivery and session boundaries (#152079)
  fix: keep stale Stop messages from canceling replacement sessions (#152116)
  improve(plugins): reduce mutable argument handling overhead (#152154)
  fix(scripts): prevent host tooling drift from blocking PR workflows (#152078)
  improve: reduce model capability preparation work (#152128)
  fix: stop marking delivered scheduled reports as failed (#152165)
  fix: start background context maintenance after durable turns (#151936)
  fix(models): avoid ambient state reads during prepared selection (#152119)
  feat: recover abandoned Crabbox source staging (#152006)
  chore(ui): refresh control ui locales (#152098)
  fix(ui): keep cloud startup prompts and progress in chat (#152024)
  fix: report completed subprocess cleanup after cancellation (#152107)
  perf(reply): reuse normalized inbound text (#152110)
  fix(cron): paused future one-shots disappear after Run now (#152126)
  perf(sessions): reuse rows and skip discarded terminal labels (#152109)
  fix(ui): keep keyboard-focused automation controls clear of sticky actions (#152135)
  fix(ui): load remote images in compact activity previews (#152045)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
* improve: reduce model capability preparation work

* test: preserve sparse catalog lookup coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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