Repository navigation
feat(harness): support operator base_url for local LLM endpoints (fixes #764) - #799
Amankumar-10012004 wants to merge 1 commit into
Conversation
mlieberman85
left a comment
There was a problem hiding this comment.
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. Withbase_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 abase_urlwith user info when the configuration is applied (the key belongs in the environment), and record only host and port (hostname[:port], notnetloc). - 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_callsrecords the endpoint, butllm_callsis still{"total": 15, "provider": "openai:stub-model"}. Either add it there or adjust the sentence. - Optional:
localcovers RFC 1918 addresses, so a model server elsewhere on a company network or in a cloud VPC is reported aslocal.loopback/private/publicwould 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.
265f76b to
eacbde6
Compare
|
Thanks @mlieberman85! All requested changes have been implemented:
|
|
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:
So the environment no longer picks the endpoint, for either provider. Nit: the alpha.33 history row is dated 2026-11-28. Looks good to meleaving the merge to Mike. |
|
Thanks @Marc-cn for verifying and re-testing on RHEL, Really appreciate the detailed confirmation. Standing by for @mlieberman85's review. |
mlieberman85
left a comment
There was a problem hiding this comment.
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-5change API. On main,model = "gpt-4.1"goes to/v1/responses(pydantic-ai's default foropenai:). Here it goes to/v1/chat/completions, because only names starting withgpt-5getOpenAIResponsesModel. 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 configuredbase_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>
eacbde6 to
f839553
Compare
|
Hi @mlieberman85, Thanks for the review and approval, I have rebased onto Maintainer notes addressed:
Additional hardening (and why):
Verified locally: |
mlieberman85
left a comment
There was a problem hiding this comment.
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_URLandANTHROPIC_BASE_URLare ignored (0 requests to the stub; main sends all 45 there). Statuses match main on all 64 controls. - Credentials in
base_urlare 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_urlgoes to/v1/messages. - Ollama serving
qwen3:4b: all 15 answered (7 FAIL, 8 WARN, no candidate), each with127.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.
|
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. |
Summary
Operator configuration now supports
[llm] base_urlto direct harness model evaluations to local or custom OpenAI-compatible endpoints (such as Ollama, vLLM, LM Studio or llama.cpp).base_urlto the operatorLlmSettingsschema.base_urlis configured,PydanticAILLMStepusesOpenAIChatModelwithOpenAIProvider(base_url=..., api_key=api_key or "not-needed")matching local server support for OpenAI Chat Completions.base_urlis set.llm_endpoint(host) andllm_endpoint_kind(localvshosted) in its evidence.framework-design.md(spec 1.0.0-alpha.31),SECURITY_GUIDE.mdandCHANGELOG.md.Type of Change
Framework Changes Checklist
If this PR modifies the darnit framework (
packages/darnit/):docs/architecture/framework-design.md) if behavior changeduv run python scripts/validate_sync.py --verboseand it passesControl/TOML Changes Checklist
If this PR modifies controls or TOML configuration:
Testing
uv run pytest tests/ -v)uv run ruff check .)AI assistance
Additional Notes
Closes #764.