Skip to content

feat(harness): support operator base_url for local LLM endpoints (fixes #764) - #799

Open
Amankumar-10012004 wants to merge 1 commit into
darnitdevorg:mainfrom
Amankumar-10012004:feat/harness-operator-base-url-764
Open

Amankumar-10012004 wants to merge 1 commit into
darnitdevorg:mainfrom
Amankumar-10012004:feat/harness-operator-base-url-764

Conversation

@Amankumar-10012004

Copy link
Copy Markdown
Contributor

Summary

Operator configuration now supports [llm] base_url to direct harness model evaluations to local or custom OpenAI-compatible endpoints (such as Ollama, vLLM, LM Studio or llama.cpp).

  • Added base_url to the operator LlmSettings schema.
  • When base_url is configured, PydanticAILLMStep uses OpenAIChatModel with OpenAIProvider(base_url=..., api_key=api_key or "not-needed") matching local server support for OpenAI Chat Completions.
  • Provider API keys in the environment are optional when base_url is set.
  • Harness preflight verifies endpoint reachability fast (<2s) rather than checking credentials.
  • Every model judgment records llm_endpoint (host) and llm_endpoint_kind (local vs hosted) in its evidence.
  • Updated framework-design.md (spec 1.0.0-alpha.31), SECURITY_GUIDE.md and CHANGELOG.md.

Type of Change

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

Framework Changes Checklist

If this PR modifies the darnit framework (packages/darnit/):

  • Updated framework spec (docs/architecture/framework-design.md) if behavior changed
  • Ran uv run python scripts/validate_sync.py --verbose and it passes

Control/TOML Changes Checklist

If this PR modifies controls or TOML configuration:

  • Control metadata defined in TOML (not Python code)
  • SARIF fields (description, severity, help_url) included where appropriate
  • Ran validation to confirm TOML schema compliance

Testing

  • Tests pass locally (uv run pytest tests/ -v)
  • Added tests for new functionality (if applicable)
  • Linting passes (uv run ruff check .)

AI assistance

  • No AI assistance was used
  • AI assistance was used

Additional Notes

Closes #764.

@mlieberman85 mlieberman85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Amankumar-10012004. The configured path works. One problem with the evidence needs fixing before I approve.

Tested at 265f76b merged into current main (03f81fb; the spec conflict resolved to main for the local merge). I ran darnit harness on wtf-frontend at 939e838 (a copy with no remote, darnit in a throwaway HOME, no real keys, outbound HTTP(S) sent to a closed port). Every model endpoint was on localhost: a stub that logs each request, or Ollama.

case result
base_url to a closed port setup error in under a second: "configured LLM base_url 'http://127.0.0.1:59999/v1' is unreachable", exit 2
base_url to a stub answering 200 with a non-JSON body, no keys all 15 judgments ERROR, none a PASS candidate; evidence llm_endpoint = 127.0.0.1:18799, local
the same, the stub answering with free text and no tool call (what small local models often do) all 15 ERROR, none a candidate
provider = "anthropic" with base_url requests go to the stub's /v1/messages, all 15 ERROR, endpoint recorded
base_url = "http://127.0.0.1:11434/v1", Ollama serving qwen3:4b, no keys preflight passes, all 15 judgments answered by the model (7 FAIL, 8 WARN, no candidate), each with llm_endpoint = 127.0.0.1:11434, local

The evidence can name an endpoint that never got the request. Without base_url, the evidence says api.openai.com (or api.anthropic.com), but the SDK still reads OPENAI_BASE_URL / ANTHROPIC_BASE_URL from the environment. With provider = "openai", no base_url, and OPENAI_BASE_URL pointing at the stub, all 45 requests (21 of them carrying text from the repository) went to 127.0.0.1, and all 15 judgments record llm_endpoint = api.openai.com, llm_endpoint_kind = hosted. The person confirming a candidate reads that field to learn where the files went. The new spec text also says base_url "comes strictly from operator configuration, never from the repository or ambient environment", but the environment still redirects the calls.

Suggestion: build the provider explicitly every time, with the configured base_url or else the provider's hosted default, so the environment never picks the endpoint (as the second comment on #764 asked). Then record the URL you passed. If you'd rather keep honoring the environment variables, record the base URL the client actually used, not a fixed hostname.

Smaller:

  • Credentials in base_url. With base_url = "http://user:s3cret@127.0.0.1:18799/v1" and the stub running, preflight reports the endpoint as unreachable, and the setup error prints the password. Please reject a base_url with user info when the configuration is applied (the key belongs in the environment), and record only host and port (hostname[:port], not netloc).
  • Spec version. #761 merged with 1.0.0-alpha.31, so this needs the next free number (#778 and #697 are waiting for one too), and the spec conflicts with main.
  • Report. The new 14.1 sentence reads as if the report's llm_calls records the endpoint, but llm_calls is still {"total": 15, "provider": "openai:stub-model"}. Either add it there or adjust the sentence.
  • Optional: local covers RFC 1918 addresses, so a model server elsewhere on a company network or in a cloud VPC is reported as local. loopback/private/public would say what was actually checked.

With the stub behind OPENAI_BASE_URL and no base_url, main and this PR give the same status on all 65 controls. Full suite on the merged tree: 6247 passed, 11 skipped. ruff, the mypy gate, validate_sync.py and comply replay (default and on a case-sensitive volume) all pass.


Drafted with AI assistance (Claude), reviewed and filed by me. Measurements quoted were executed and verified.

@Amankumar-10012004

Copy link
Copy Markdown
Contributor Author

Thanks @mlieberman85! All requested changes have been implemented:

  • Explicit Provider Instantiation: Providers are now explicitly constructed with either the operator-configured base_url or the provider's hosted default (https://api.openai.com/v1, https://api.anthropic.com), ensuring ambient OPENAI_BASE_URL / ANTHROPIC_BASE_URL cannot silently redirect traffic away from what evidence records.
  • Credential Validation & Sanitization: Any base_url containing user info (user:pass@) is rejected at configuration time before preflight pings it. Evidence records strictly hostname[:port] in llm_endpoint.
  • Spec Bump & Conflict: Rebased onto latest main, resolved the conflict in docs/architecture/framework-design.md and bumped the spec to 1.0.0-alpha.33.
  • Section 14.1 Clarification: Updated the spec text to cleanly distinguish report-level llm_calls.provider (<provider>:<model>) from judgment evidence (llm_endpoint, llm_endpoint_kind).
  • All unit/integration tests and validate_sync.py pass cleanly.

@Marc-cn

Marc-cn commented Nov 27, 2026

Copy link
Copy Markdown
Member

Re-tested eacbde6 merged into current main on RHEL, with a stub on 127.0.0.1:18799 logging every request, OPENAI_BASE_URL and ANTHROPIC_BASE_URL both pointing at it, dummy keys:

provider configured base_url where requests went stub hits
openai none api.openai.com (401) 0
openai stub stub 3
anthropic none api.anthropic.com (401) 0
anthropic stub stub 3

So the environment no longer picks the endpoint, for either provider. base_url with user info is rejected at config load and the operator-config error prints location and message only, not the URL. Spec is alpha.33 on top of main's alpha.32. ruff, validate_sync and 1555 core/harness/config/sieve tests pass.

Nit: the alpha.33 history row is dated 2026-11-28.

Looks good to meleaving the merge to Mike.

@Amankumar-10012004

Copy link
Copy Markdown
Contributor Author

Thanks @Marc-cn for verifying and re-testing on RHEL, Really appreciate the detailed confirmation. Standing by for @mlieberman85's review.

mlieberman85
mlieberman85 previously approved these changes Dec 1, 2026

@mlieberman85 mlieberman85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Amankumar-10012004, all of it is addressed. Approving. CHANGELOG.md now conflicts with main, so this needs a rebase before it can merge, and the rebase will dismiss this approval; I'll re-approve once I've checked that the rebase only resolves the conflict.

Tested at eacbde6 merged into current main (778878b; the CHANGELOG conflict resolved to main for the local merge), with the same setup as before: darnit harness on wtf-frontend at 939e838, a copy with no remote, darnit in a throwaway HOME, no real keys, outbound HTTP(S) sent to a closed port, every model endpoint on localhost (a stub that logs each request, or Ollama).

case result
provider = "openai", no base_url, OPENAI_BASE_URL pointing at the stub no request reaches the stub; all 15 judgments ERROR with llm_endpoint = api.openai.com, hosted. On main, all 45 requests went to the stub.
provider = "anthropic", no base_url, ANTHROPIC_BASE_URL pointing at the stub the same: no request reaches the stub, all 15 record api.anthropic.com, hosted. On main, all 45 went to the stub.
base_url = "http://user:s3cret@127.0.0.1:18799/v1" setup error at configuration load ("must not contain credentials"), exit 2, no request sent, and the password appears nowhere in the output
base_url to a closed port setup error in about a second, exit 2
base_url to the stub answering with a non-JSON body, or with free text and no tool call all 15 judgments ERROR, none a PASS candidate, each with llm_endpoint = 127.0.0.1:18799, local
provider = "anthropic" with base_url requests go to the stub's /v1/messages, endpoint recorded
base_url = "http://127.0.0.1:11434/v1", Ollama serving qwen3:4b, no keys all 15 answered by the model (6 FAIL, 9 WARN, no candidate), each with llm_endpoint = 127.0.0.1:11434, local

With the environment variable cases, main and this PR give the same status on all 64 controls. No run changed a file in its copy. Full suite on the merged tree: 6233 passed, 11 skipped. ruff, the mypy gate, validate_sync.py and comply replay (default and on a case-sensitive volume) all pass.

Not blocking:

  • Hosted OpenAI models other than gpt-5 change API. On main, model = "gpt-4.1" goes to /v1/responses (pydantic-ai's default for openai:). Here it goes to /v1/chat/completions, because only names starting with gpt-5 get OpenAIResponsesModel. Both APIs serve those models, so I don't expect a different result, but it's a change in what's sent to a hosted provider. Either keep the Responses API for hosted OpenAI whatever the model name (and Chat Completions only with a configured base_url), or say it in the CHANGELOG entry.
  • #794 also claims 1.0.0-alpha.33, so whichever of the two merges second needs the next number.

Drafted with AI assistance (Claude), reviewed and filed by me. Measurements quoted were executed and verified.

darnitdevorg#764)

Support operator configuration [llm] base_url to direct harness model evaluations to local and custom OpenAI-compatible endpoints (Ollama, vLLM, LM Studio, llama.cpp).

- Add base_url to LlmSettings operator schema; reject credentials in base_url.
- In PydanticAILLMStep:
  - Build providers explicitly with base_url or hosted defaults (blocking ambient OPENAI_BASE_URL/ANTHROPIC_BASE_URL redirection).
  - Preserve OpenAIResponsesModel for hosted OpenAI regardless of model name, and use OpenAIChatModel whenever base_url is configured.
  - Skip requiring provider API keys in the environment when base_url is set.
  - Add format_endpoint_host() and harden endpoint_kind() so IPv6 bracketed hosts and malformed strings are handled safely.
- In HarnessRun:
  - Validate scheme, credentials, non-empty hostname, and numeric port when applying llm.base_url.
  - In _check_endpoint_reachable(), handle http.client.InvalidURL/ValueError cleanly and strip/redact URL query secrets from error messages.
  - In _check_credentials(), when base_url is set, skip API key checks and perform an active endpoint reachability check in <2s (SC-002).
  - Propagate effective endpoint to consultation responses.
- In SieveOrchestrator, record llm_endpoint (hostname[:port], preserving IPv6 brackets) and llm_endpoint_kind ('local' vs 'hosted') on every model judgment's evidence, including failures.
- Update cli.py harness help/docstring, framework-design.md (14.1, 1.0.0-alpha.33 dated 2026-12-01), SECURITY_GUIDE.md, and resolve CHANGELOG.md against upstream/main.
- Add unit and fake-endpoint integration tests covering hosted Responses API, local Chat Completions without API keys, IPv6 endpoints, malformed ports/missing hosts, and query token redaction.

Fixes darnitdevorg#764

Signed-off-by: Amankumar-10012004 <devirinki402@gmail.com>
@Amankumar-10012004

Copy link
Copy Markdown
Contributor Author

Hi @mlieberman85,

Thanks for the review and approval, I have rebased onto upstream/main, resolved the CHANGELOG.md conflict, and also addressed the non-blocking notes along with a few edge-case fixes:

Maintainer notes addressed:

Additional hardening (and why):

  • IPv6 endpoints (llm_step.py, orchestrator.py): Added format_endpoint_host() so IPv6 hosts preserve brackets ([::1]:11434)—without this, stripping brackets produced ::1:11434 and raised ValueError in endpoint_kind().
  • Malformed URLs & query redaction (driver.py): Validated non-empty hostnames and ports during config load, caught http.client.InvalidURL / ValueError in _check_endpoint_reachable() so bad ports fail cleanly as setup errors instead of unhandled tracebacks, and stripped/redacted URL query strings from reachability errors.
  • CLI docs (cli.py): Updated cmd_harness docstring and parser description to mention optional [llm] base_url.

Verified locally: ruff check, validate_sync.py, and 314 targeted tests across core, sieve, harness, config/operator, cli, and trust all pass. Ready for re-review.

@mlieberman85 mlieberman85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Amankumar-10012004. The rebase also changed code: it addresses my non-blocking note on the Responses API and adds IPv6, port, hostname and redaction handling. So I retested rather than only checking the conflict resolution. Approving.

Tested at f839553, which sits directly on current main (778878b). Same setup as before: darnit harness on wtf-frontend at 939e838, a copy with no remote, darnit in a throwaway HOME, no real keys, outbound HTTP(S) sent to a closed port, every model endpoint on localhost.

New since my last review:

case result
hosted gpt-4.1, no base_url (hosted default pointed at a logging stub in a test-only sitecustomize) all 45 requests to /v1/responses, as on main
hosted gpt-5, the same all 45 to /v1/responses
base_url with gpt-4.1 or gpt-5 /v1/chat/completions
base_url = "http://[::1]:18799/v1", stub on ::1 requests reach the stub; all 15 judgments record llm_endpoint = [::1]:18799, local
base_url = "http://127.0.0.1:abc/v1" setup error at load ("llm.base_url is invalid: Port could not be cast to integer value as 'abc'"), exit 2
base_url = "http://" setup error ("must include a hostname"), exit 2
base_url to a closed port with ?token=TOPSECRET setup error naming http://127.0.0.1:59999/v1 without the query; TOPSECRET appears nowhere in stdout, stderr or the report

Everything from the last round gives the same result again:

  • Environment OPENAI_BASE_URL and ANTHROPIC_BASE_URL are ignored (0 requests to the stub; main sends all 45 there). Statuses match main on all 64 controls.
  • Credentials in base_url are a setup error, and the password appears nowhere.
  • A closed port is a setup error within a second.
  • Non-JSON and free-text replies make all 15 judgments ERROR, with no PASS candidate.
  • Anthropic with base_url goes to /v1/messages.
  • Ollama serving qwen3:4b: all 15 answered (7 FAIL, 8 WARN, no candidate), each with 127.0.0.1:11434, local.

No run changed a file in its copy. Full suite on the tree: 6240 passed, 11 skipped. ruff, the mypy gate, validate_sync.py and comply replay (default and on a case-sensitive volume) all pass.

The 1.0.0-alpha.33 row also appears in #802-#808 and #810, so whichever merges after this needs the next number.


Drafted with AI assistance (Claude), reviewed and filed by me. Measurements quoted were executed and verified.

@Amankumar-10012004

Copy link
Copy Markdown
Contributor Author

Thanks @mlieberman85 for the thorough re-test and approval, Leaving #799 as-is for merge, and I'll bump the spec version on #794 once this lands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harness: support OpenAI as an LLM provider ([llm] provider = "openai")

3 participants