Skip to content

fix(agents): skip implicit provider discovery when models.mode is replace [AI-assisted]#73557

Closed
luyao618 wants to merge 1 commit into
openclaw:mainfrom
luyao618:fix/models-replace-mode-skip-implicit-discovery
Closed

fix(agents): skip implicit provider discovery when models.mode is replace [AI-assisted]#73557
luyao618 wants to merge 1 commit into
openclaw:mainfrom
luyao618:fix/models-replace-mode-skip-implicit-discovery

Conversation

@luyao618

Copy link
Copy Markdown
Contributor

🤖 AI-assisted (built with Claude Code via Hermes orchestration). Test level: fully tested. Prompt summary available on request.

Summary

  • Problem: models.mode="replace" is documented to use only explicitly configured providers, but resolveProvidersForModelsJsonWithDeps unconditionally calls resolveImplicitProviders(), causing unnecessary provider discovery and 72+ second startup delays.
  • Why it matters: Users who explicitly set models.mode="replace" to avoid implicit provider discovery still get the full discovery cost, defeating the purpose of the config.
  • What changed: Guarded the resolveImplicitProviders call with a mode !== "replace" check so replace mode skips implicit discovery entirely and uses only explicit providers.
  • What did NOT change (scope boundary): No changes to merge mode behavior, no changes to provider discovery logic itself, no changes to how explicit providers are handled.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Core agent runtime

Linked Issue/PR

Root Cause

  • Root cause: resolveProvidersForModelsJsonWithDeps called resolveImplicitProviders unconditionally at line 58, before any mode-specific handling. The mode check only happened later in resolveProvidersForMode() which only affects merge behavior, not whether implicit discovery runs.
  • Missing detection / guardrail: No test for the replace mode skipping implicit provider discovery.
  • Contributing context: The mode handling in resolveProvidersForMode was only designed for merge-vs-replace provider merging, not for gating discovery itself.

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
  • Target test or file: src/agents/models-config.replace-mode-skip-implicit-discovery.test.ts
  • Scenario the test should lock in: When models.mode="replace", resolveImplicitProviders is never called and only explicit providers are returned.
  • Why this is the smallest reliable guardrail: The test injects a mock resolveImplicitProviders and verifies it is/isn't called based on the mode setting.

User-visible / Behavior Changes

  • Users with models.mode="replace" will see significantly faster startup (no implicit provider discovery delay).

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? No
  • This fix only changes when implicit provider discovery runs. No security surface changes.

@greptile-apps

greptile-apps Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where resolveImplicitProviders() was called unconditionally even when models.mode="replace", causing unnecessary 72+ second startup delays. The fix adds a mode !== "replace" guard before implicit provider discovery and includes a dedicated test file verifying both the skip behavior and the preservation of "merge" mode behavior.

Confidence Score: 5/5

This PR is safe to merge — the fix is minimal, targeted, and fully covered by new tests.

Single-line guard added at the right callsite, default 'merge' behavior is unchanged, mergeProviders correctly handles an empty implicit map, and five tests cover replace/merge/default mode scenarios end-to-end.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(agents): skip implicit provider disc..." | Re-trigger Greptile

@luyao618
luyao618 force-pushed the fix/models-replace-mode-skip-implicit-discovery branch from b9393f8 to b1fb0cd Compare April 28, 2026 15:52
@clawsweeper

clawsweeper Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR skips implicit provider discovery when models.mode is replace in model-config planning and adds Vitest coverage for replace, merge, default, and planning behavior.

Reproducibility: yes. A high-confidence source-level path exists on current main: call resolveProvidersForModelsJsonWithDeps or planOpenClawModelsJsonWithDeps with models.mode: "replace" and an injected implicit resolver; the resolver is reached before mode handling despite the documented replace-mode contract.

Real behavior proof
Needs real behavior proof before merge: The PR body reports testing and unit coverage, but includes no after-fix real OpenClaw startup output, terminal output, redacted logs, screenshot, or linked artifact.

Next step before merge
Contributor-supplied real behavior proof is still required before merge; automation can add a changelog entry, but it cannot prove the contributor's real setup for them.

Security
Cleared: The diff only changes agent model-provider planning and unit tests; it does not touch dependencies, workflows, permissions, secrets handling, package resolution, or downloaded code execution.

Review findings

  • [P3] Add the required changelog entry — CHANGELOG.md:70
Review details

Best possible solution:

Land the narrow replace-mode discovery guard after adding the required changelog entry and contributor-supplied real startup/log proof; keep the separate pricing-fetch delay tracked in #74020.

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

Yes. A high-confidence source-level path exists on current main: call resolveProvidersForModelsJsonWithDeps or planOpenClawModelsJsonWithDeps with models.mode: "replace" and an injected implicit resolver; the resolver is reached before mode handling despite the documented replace-mode contract.

Is this the best way to solve the issue?

Yes in direction, but not ready to merge as submitted. The current PR head uses the narrow maintainable callsite guard and preserves merge/default behavior, but still needs a changelog entry and real behavior proof.

Full review comments:

  • [P3] Add the required changelog entry — CHANGELOG.md:70
    This is a user-visible startup/config fix for models.mode="replace", so repo policy requires a single-line entry under Unreleased / Fixes. The PR changes runtime behavior but does not touch CHANGELOG.md.
    Confidence: 0.91

Overall correctness: patch is correct
Overall confidence: 0.89

Acceptance criteria:

  • Contributor-supplied real OpenClaw startup/log proof showing models.mode="replace" skips implicit provider discovery
  • pnpm test src/agents/models-config.replace-mode-skip-implicit-discovery.test.ts
  • pnpm check:changed in Testbox

What I checked:

Likely related people:

  • steipete: Recent commits touched the same provider-planning and implicit discovery paths, including scoped startup provider discovery and external CLI auth discovery. (role: recent maintainer and feature-history owner; confidence: high; commits: 1787d3be0793, 13757465ba1b; files: src/agents/models-config.plan.ts, src/agents/models-config.providers.implicit.ts, src/config/schema.help.ts)
  • shakkernerd: Recent provider metadata and discovery scoping work modified the planner and implicit discovery path that this PR changes. (role: recent adjacent maintainer; confidence: medium; commits: 4e7de4b5c9ed, 5531502cb009; files: src/agents/models-config.plan.ts, src/agents/models-config.providers.implicit.ts)
  • brokemac79: A recent merged fix touched both central models-config files while keeping provider discovery metadata-only. (role: recent adjacent contributor; confidence: medium; commits: 20c7a98fb8b3; files: src/agents/models-config.plan.ts, src/agents/models-config.providers.implicit.ts)

Remaining risk / open question:

  • The PR body and comments still do not show after-fix real OpenClaw startup/log output from the contributor's setup.
  • The PR changes user-visible startup/config behavior but has no CHANGELOG.md entry under Unreleased/Fixes.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 70d92b5e59df.

@luyao618
luyao618 force-pushed the fix/models-replace-mode-skip-implicit-discovery branch from b1fb0cd to 41bc76c Compare April 30, 2026 01:42
@luyao618
luyao618 force-pushed the fix/models-replace-mode-skip-implicit-discovery branch from 41bc76c to 794faa9 Compare May 5, 2026 10:22
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 5, 2026
…lace

resolveProvidersForModelsJsonWithDeps unconditionally called
resolveImplicitProviders regardless of mode. Per docs, replace mode
should use only explicit providers. Guard the call with a mode check
so replace mode skips the expensive implicit provider discovery.

Closes openclaw#66957

AI-assisted (built with Claude Code via Hermes orchestration).
@luyao618
luyao618 force-pushed the fix/models-replace-mode-skip-implicit-discovery branch from 794faa9 to da95a42 Compare May 5, 2026 10:52
@luyao618

Copy link
Copy Markdown
Contributor Author

Closing: stale (2+ weeks), no maintainer review. Will re-submit if the fix is still needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: models.mode="replace" still triggers implicit provider discovery and causes large startup delays

1 participant