Skip to content

fix(ai): drop the localhost fallbacks of the AI dry-run plans #5395

Done

Description

@dan-petty

Problem Description

The dry-run plans of the devops ai commands in src/devops_cli/ai/ai_plans.py give service URLs that no setting gives. The rule of #1165 allows no such URL: the code reads the setting, or it names the setting.

  • Nine sites fall back to ["http://localhost:11434"] when ai.ollama_urls is empty: lines 33, 57, 110, 231, 248, 269, 308 and 327 on origin/main at release 0.127.0, and line 337 in _get_llm_embedding_target.
  • _resolve_gateway_base falls back to DEFAULT_AI_GATEWAY_URL (http://localhost:4000/v1) when ai.gateway_url is not set.
  • _get_qdrant_target falls back to DEFAULT_QDRANT_URL (http://localhost:6333) when qdrant.url is not set.
  • _get_llm_chat_target has no gateway branch, so a gateway provider gets the OpenAI default URL.

The guard of #1165, the ast-grep rule net-localhost-fallback, reads these files but does not find the sites: it matches or "http://localhost..." and not or ["http://localhost..."] or a fallback to a constant.

#5345 fixed the same problem in src/devops_cli/review/review_plans.py: the plan builders call resolve_ai_endpoint and show an unset setting as a placeholder, such as <ai.ollama_urls>.

Reproduction Steps

  1. Use a config file that holds only ai.provider: ollama.
  2. Run uv run devops ai test --dry-run and uv run devops ai chat --dry-run.
  3. Read the target of the planned model request.

Expected vs Actual Behavior

  • Expected: the plan target names ai.ollama_urls as a placeholder, as the review plans do after fix(review): drop the fixed gateway URL of the review dry run #5345.
  • Actual: the plan target is http://localhost:11434/api/chat.

Environment Diagnostics

origin/main at release 0.127.0. git grep -n 'or \["https\?://localhost' src finds 9 sites in src/devops_cli/ai/ai_plans.py after #5345.

Logs, Traces, or Terminal Output

None.

Proposed Fix

Get each AI target in ai_plans.py from resolve_ai_endpoint, as review_plans.py does, and show an unset setting as a placeholder. Give the gateway and Qdrant plans the same rule. Extend .ast-grep/rules/net-localhost-fallback.yml (and its rule test) to match a fallback list, such as or ["http://localhost:11434"], so the guard fails if the problem returns.

Refs #5345, #1165.

Alternatives check of 2026-11-28: none.
Tool: none found.
Reason: Searches surfaced no library that resolves AI plan endpoints from settings or renders an unset setting as a placeholder; the fix stays in the project's own resolver code, and ast-grep only needs a new rule branch.

Lacks:

  • No tool resolves ai_plans targets from ai.ollama_urls, ai.gateway_url or qdrant.url
  • No tool renders an unset setting as a <key> placeholder in a dry-run plan
  • No tool adds the gateway branch to _get_llm_chat_target
  • No tool drops the DEFAULT_AI_GATEWAY_URL and DEFAULT_QDRANT_URL imports

Proposed design

Problem statement

The AI dry-run plans show service URLs that no setting gives: http://localhost:11434 for Ollama, http://localhost:4000/v1 for the gateway and http://localhost:6333 for Qdrant. The guard net-localhost-fallback misses a list fallback such as or ["http://localhost:11434"]. The change resolves each AI target from the settings through resolve_ai_endpoint and shows an unset setting as a placeholder, as review_plans.py does after #5345.

Acceptance criteria

Requirement: Chat plan names the unset Ollama setting

The chat plan SHALL resolve the Ollama endpoint from the settings and SHALL show an unset ai.ollama_urls as <ai.ollama_urls>.

Scenario: Chat plan with no Ollama URLs

  • WHEN plan_ai_chat runs with ai.provider set to ollama and no ai.ollama_urls
  • THEN the target of the planned request is <ai.ollama_urls>/api/chat

Requirement: Every Ollama plan names the unset setting

The agents, models, test, preload, prewarm and benchmark plans MUST use the same resolved Ollama endpoint or its placeholder.

Scenario: Ollama plan builders with no URLs

  • WHEN plan_ai_agents, plan_ai_models, plan_ai_test, plan_ai_preload, plan_ai_prewarm and plan_ai_benchmark run with no ai.ollama_urls
  • THEN each planned target starts with <ai.ollama_urls>

Requirement: Embedding plan names the unset setting

The embedding plan target SHALL resolve the configured endpoint and SHALL show an unset setting as a placeholder.

Scenario: Analyze plan with no Ollama URLs

  • WHEN plan_ai_analyze_path runs with ai.provider set to ollama and no ai.ollama_urls
  • THEN the target of the planned request is <ai.ollama_urls>/api/embeddings

Requirement: Gateway chat plan uses the gateway setting

_get_llm_chat_target MUST return the base of ai.gateway_url plus /chat/completions for a gateway provider.

Scenario: Chat target with a gateway provider

  • WHEN _get_llm_chat_target runs with ai.provider set to gateway and ai.gateway_url set to http://gw:4000/v1
  • THEN the target is http://gw:4000/v1/chat/completions

Requirement: Gateway plans name the unset setting

The gateway route, status, tune and ask plans MUST use ai.gateway_url, and an unset setting MUST show as <ai.gateway_url>.

Scenario: Gateway status plan with no gateway URL

  • WHEN plan_ai_gateway_status runs with no ai.gateway_url
  • THEN the target of the planned request is <ai.gateway_url>/health

Requirement: Qdrant plans name the unset setting

Each Qdrant plan target MUST use qdrant.url, and an unset setting MUST show as <qdrant.url>.

Scenario: RAG status plan with no Qdrant URL

  • WHEN plan_ai_rag_status runs with no qdrant.url
  • THEN the target of the planned request is <qdrant.url>/collections

Requirement: The localhost guard catches a list fallback

The net-localhost-fallback rule SHALL report a fallback list that holds a localhost URL.

Scenario: Rule test for a list fallback

  • WHEN uv run ast-grep test runs the rule test that holds x = urls or ["http://localhost:11434"]
  • THEN the command exits 0 and its output shows the net-localhost-fallback rule test passing

Requirement: The AI plans import no default URL constant

src/devops_cli/ai/ai_plans.py MUST NOT import DEFAULT_AI_GATEWAY_URL or DEFAULT_QDRANT_URL.

Scenario: Source test over the AI plans module

  • WHEN a test inspects the imports of src/devops_cli/ai/ai_plans.py
  • THEN the module imports neither DEFAULT_AI_GATEWAY_URL nor DEFAULT_QDRANT_URL

Existing Tool Considered

The alternatives check of 2026-11-17 records the verdict none (see the alternatives block in the issue body). No external tool covers the need. The plan reuses the project's own resolve_ai_endpoint helper in src/devops_cli/ai/endpoints.py, as review_plans.py does after #5345. It extends the project's own ast-grep rule net-localhost-fallback to match a fallback list. The only new code is the rule branch and its test: about 10k tokens and under one hour to write, keep and fix.

Key questions

  • How does a dry-run plan show a setting that is not set?: Catch ConfigurationError from resolve_ai_endpoint and use <key> from exc.key, as review_plans.py does after fix(review): drop the fixed gateway URL of the review dry run #5345. (best practice) [sources: src/devops_cli/review/review_plans.py, src/devops_cli/ai/endpoints.py]
  • Where does the shared plan resolver live?: Add resolve_ai_plan_base to src/devops_cli/ai/endpoints.py. Both plan modules call it. (best practice) [sources: src/devops_cli/ai/endpoints.py, src/devops_cli/review/review_plans.py, src/devops_cli/ai/ai_plans.py]
    • Chosen: Shared helper in ai/endpoints.py. One copy stays next to resolve_ai_endpoint and serves both plan modules.
    • Rejected: Copy _resolved_base into ai_plans.py. Two copies of the placeholder rule drift.
    • Rejected: Import the private _resolved_base. A module must not import a private helper of another module.
  • How do the preload, prewarm and benchmark plans list the Ollama servers?: Read settings.ai.get_ollama_urls. When it is empty, use ['<ai.ollama_urls>']. These plans target every server, and resolve_ai_endpoint returns one primary URL. (best practice) [sources: src/devops_cli/ai/ai_plans.py]
    • Chosen: List the setting with a placeholder. It keeps every server in the plan and names the setting when it is empty.
    • Rejected: Use one primary from resolve_ai_endpoint. It drops the other servers from the plan.
  • How does _get_qdrant_target show an unset qdrant.url?: Read settings.qdrant.url. When it is empty, return <qdrant.url> plus the path. (best practice) [sources: src/devops_cli/ai/ai_plans.py, src/devops_cli/ai/rag/indexer.py]
    • Chosen: Placeholder <qdrant.url>. It matches the review plan rule and makes no request.
    • Rejected: Use resolve_qdrant_client. It builds a client, and the plan needs only the URL.
    • Rejected: Keep DEFAULT_QDRANT_URL. It shows a URL that no setting gives.
  • What path does a gateway chat target use?: Return the gateway base plus /chat/completions. The gateway serves the OpenAI chat path. (best practice) [sources: src/devops_cli/ai/ai_plans.py, src/devops_cli/review/review_plans.py, src/devops_cli/config/defaults.py]
    • Chosen: Gateway base plus /chat/completions. The gateway serves the OpenAI chat path at that base.
    • Rejected: Keep the OpenAI default URL. It ignores ai.gateway_url.
    • Rejected: Use the gateway root plus /v1/chat/completions. primary_url already holds the version suffix.
  • Which ast-grep pattern catches a fallback list?: Allow an optional [ before the localhost string in the boolean-operator regex. (best practice) [sources: .ast-grep/rules/net-localhost-fallback.yml]
    • Chosen: Optional [ in the existing regex. One branch catches both the string and the list form.
    • Rejected: New list kind branch. It reports a localhost list even when it is not a fallback.
    • Rejected: Match or DEFAULT_*_URL. The rule cannot tell a localhost constant from another URL constant, so it gives false positives.
  • Does an open tool or library cover the need?: No. The alternatives check of 2026-11-17 records none. The plan reuses the internal resolver and extends the project's ast-grep rule. [sources: src/devops_cli/ai/endpoints.py, .ast-grep/rules/net-localhost-fallback.yml]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/ai
    status/new
    value/medium
    effort/medium
    on Nov 13, 2026
  2. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 13, 2026
  4. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches found only general linters (Semgrep) and unrelated documentation; no open tool or library resolves a configured AI endpoint or replaces an unset setting with a placeholder. The need is a change inside this project's own code: src/devops_cli/ai/ai_plans.py should use the existing internal resolve_ai_endpoint helper, as review_plans.py does after #5345, and the project's own ast-grep rule net-localhost-fallback should be extended, so nothing external covers it.

    Tool: none found

    Lacks:

    • Resolving the Ollama, gateway and Qdrant targets of the AI dry-run plans from settings through the internal resolve_ai_endpoint helper
    • Showing an unset setting as a placeholder such as <ai.ollama_urls> instead of a default service URL
    • Adding a gateway branch to _get_llm_chat_target
    • Extending the project's own ast-grep rule and rule test to match a fallback list such as or ["http://localhost:11434"]

    Searches run:

    • ast-grep rule match array literal fallback default value, results: 5
    • static analysis tool detect hardcoded default URL configuration fallback, results: 5
    • python library show unset configuration setting as placeholder instead of default value, results: 5

    Sources:

    Checked on 2026-11-17. A person decides what this means for the item. The check changes no label and closes no issue.

  5. added
    status/ready
    and removed
    status/new
    on Nov 17, 2026
  6. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 2620fae (see proposed design in issue body).

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  9. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 16:17 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/aisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions