Skip to content

refactor(agents): split embedded model resolution - #113785

Merged
steipete merged 2 commits into
mainfrom
codex/h7-eamodel
Jul 25, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/h7-eamodel

Conversation

@steipete

@steipete steipete commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

src/agents/embedded-agent-runner/model.ts had grown to 2,091 lines and mixed provider-hook normalization, configured metadata overlays, fallback synthesis, registry/dynamic selection, and public discovery orchestration. That made the model-resolution owner difficult to audit and kept the file on the max-lines grandfather list.

Why This Change Was Made

This maintainer-commissioned, AI-assisted refactor keeps model.ts as the public facade and moves the existing mechanics into four concern-owned modules, all below the repository's max-lines budget. Provider/model normalization remains with the canonical owners established by #112772, and the intentionally divergent auth-preparation and runner behavior documented in #113240 is unchanged.

User Impact

No user-visible behavior changes. Embedded model selection keeps the same configured, registry, dynamic-runtime, static-catalog, suppression, auth-profile, transport, and unknown-model behavior through smaller auditable modules.

Beyond the split

  • Removed a duplicate inline-model lookup and its unreachable API-bearing branch. It repeated the exact lookup after the API-bearing case had already returned; API-less inline rows still stop synthetic fallback selection.
  • Removed an impossible requestTimeoutMs spread from a branch that is entered only when requestTimeoutMs === undefined.
  • Named the common sync/async resolution options once while retaining the original public return declaration shapes.
  • Narrowed four split-only helpers to module-private scope; the compatibility helper's only external caller had been the removed unreachable branch.

Audit findings

Bugs found

  • Pre-existing, not fixed here: model.configured-fallback.ts:153 can combine a configured lower contextWindow with a larger static-catalog maxTokens, unlike the discovered-model overlay path which clamps the output cap. A dedicated behavior PR should centralize that normalization and add a configured-fallback regression test.

Placement findings

  • None. Dynamic runtime/auth behavior stays in the embedded-runner owner; no core/plugin or cross-runner ownership move is attempted.

Baseline

  • Removed src/agents/embedded-agent-runner/model.ts from config/max-lines-baseline.txt; the resulting files are 217–602 lines.

Evidence

  • LOC: production +1588/-1592 (net -4); tests +0/-0; max-lines baseline +0/-1; total +1588/-1593 (net -5).
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/model.test.ts src/agents/embedded-agent-runner/model.forward-compat.test.ts src/agents/embedded-agent-runner/model.forward-compat.errors-and-overrides.test.ts src/agents/embedded-agent-runner/model.startup-retry.test.ts src/agents/embedded-agent-runner/model.skip-agent-discovery-hooks.test.ts — 5 files / 185 tests passed.
  • node scripts/check-changed.mjs -- config/max-lines-baseline.txt src/agents/embedded-agent-runner/model.ts src/agents/embedded-agent-runner/model.configured-fallback.ts src/agents/embedded-agent-runner/model.configured-overrides.ts src/agents/embedded-agent-runner/model.provider-hooks.ts src/agents/embedded-agent-runner/model.registry-resolution.ts — passed formatting, max-lines ratchet, production/test typechecks, core lint, boundary guards, and runtime import-cycle checks on Blacksmith Testbox tbx_01kyd4jw73arb8yp9h6tvzebtq (run).
  • node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --timing-json -- env CI=1 OPENCLAW_TESTBOX=1 OPENCLAW_TESTBOX_REMOTE_RUN=1 corepack pnpm build — passed on Blacksmith Testbox tbx_01kyd5t4wjqwv956s6y3rh36kv, with no ineffective dynamic-import warning (run).
  • node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --timing-json --shell -- "pnpm deadcode:dependencies && pnpm deadcode:unused-files && pnpm deadcode:exports" — all Knip production/full-tree dependency, unused-file, and unused-export scans passed on Testbox tbx_01kyd6bnsxa7rgsw9n1tvmc98y (run).
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-output — clean; no accepted/actionable findings, overall correctness 0.97.
  • git diff --check — passed.

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Jul 25, 2026
@steipete steipete self-assigned this Jul 25, 2026
@steipete
steipete marked this pull request as ready for review July 25, 2026 17:43
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Jul 25, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification complete for head 202097a594700efdc9e74c6a509f365994b21a74.

  • Required rebase onto current origin/main was clean; the patch id remained 60fd567986ad79a300445d6deb9592d660149c78.
  • Focused resolver proof: 5 files / 185 tests passed with node scripts/run-vitest.mjs.
  • Changed gate: formatting, max-lines ratchet, production/test typechecks, core lint, boundary guards, and import cycles passed on Testbox tbx_01kyd4jw73arb8yp9h6tvzebtq (Actions 30167374756).
  • Build: passed on Testbox tbx_01kyd5t4wjqwv956s6y3rh36kv with no ineffective dynamic-import warning (Actions 30168095596).
  • The first hosted head exposed module exports that should have stayed private. After narrowing them, all Knip dependency, unused-file, and unused-export scans passed on Testbox tbx_01kyd6bnsxa7rgsw9n1tvmc98y (Actions 30168412366).
  • Exact-head hosted CI is green, including openclaw/ci-gate (Actions 30168894125).
  • Fresh autoreview after the repair reported no accepted/actionable findings (correctness 0.96); the earlier full-patch review was also clean (0.97).
  • Repo-native review artifacts validate as READY FOR /prepare-pr with issueValidation.status=valid.
  • ClawSweeper's latest exact-head comment is a review-started placeholder and contains no Rank-up moves: entries to apply or skip.

Known proof gap: no live provider call was run because this is a deterministic, behavior-neutral module split; focused resolver tests, full build, dead-code checks, changed gates, and hosted CI cover the changed contract.

@steipete
steipete merged commit 0bc11c4 into main Jul 25, 2026
117 checks passed
@steipete
steipete deleted the codex/h7-eamodel branch July 25, 2026 18:13
@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 maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant