Skip to content

fix: harden harness CLI upstream handling and Claude effort - #198

Merged
franciscojavierarceo merged 2 commits into
mainfrom
fix/harness-cli-hardening
Aug 21, 2026
Merged

franciscojavierarceo merged 2 commits into
mainfrom
fix/harness-cli-hardening

Conversation

@franciscojavierarceo

@franciscojavierarceo franciscojavierarceo commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On current main, both harness paths of the agentic CLI fail out of the box against vLLM serving Qwen:

  • agentic run codex --upstream … --model … → Codex exits with Error loading config.toml: … unexpected key or value, expected newline. The generated file contains literal \n sequences instead of newlines.
  • agentic run claude --upstream … --model … (without --yolo) → API Error: 500 Unexpected reasoning effort high. Supported types are xhigh (default), medium, and low. The compatible effort was only pinned under --yolo.

This PR fixes those and the other CLI failure modes hit while reproducing #190 end-to-end. It does not change gateway behavior for parallel_tool_calls; that is #197. The Codex catalog keeps supports_parallel_tool_calls: false to match #197's serialized execution.

  • Codex config: write config.toml with real newlines and complete the model catalog schema codex 0.144.6 requires (shell_type, priority, base_instructions, truncation_policy, context windows).
  • Claude effort: always pass --effort medium and set CLAUDE_CODE_EFFORT_LEVEL=medium (the env var wins inside Claude Code), overridable with AGENTIC_CLAUDE_EFFORT. --yolo stays strictly opt-in and only adds the harness's native bypass flag.
  • Validate --upstream at parse time as an http(s):// URL with a host and without a query string or fragment (endpoint paths are appended to the base). A typo such as http//127.0.0.1:8000 previously started the gateway and surfaced only as 502s on every request.
  • Discover the model when --model is omitted with --upstream from GET {upstream}/v1/models, instead of sending the agentic-api placeholder that vLLM rejects. The base is normalized first, so an upstream ending in /v1 does not request /v1/v1/models.
  • Clamp Anthropic output_config.effort high/max → xhigh on /v1/messages for Qwen templates, through new typed OutputConfig / ReasoningEffort / ReasoningEffortLevel types on MessagesRequest in agentic-server-core (unknown effort strings are preserved verbatim; all other fields round-trip via extra).
  • Print the resolved gateway URL and model on launch.
  • Add docs/guides/harness-cli-testing.md: a shareable checklist covering validate → smoke test → tool-call round trip → interactive session → direct Testing with codex: Handle parallel_tool_calls flag #190 curl repro → Kubernetes verification (Claude Code and Codex over WebSocket) → troubleshooting. README and getting-started updated to match.

Split out of #193; the Kubernetes base fixes are in #199, and the testing guide's Kubernetes troubleshooting rows state that dependency.

Review round (e03b115): /v1-suffixed upstream normalization, query/fragment rejection, typed output_config model, and the #199 dependency note in the guide.

Known follow-up (not in this PR): the CLI places the Codex session home under the system temp dir, so Codex warns Refusing to create helper binaries under temporary dir "/tmp" and skips its PATH aliases. Sessions still work.

Test Plan

  • cargo fmt --all -- --check, cargo clippy --all-targets -- -D warnings, cargo test --workspace (743 passed), pre-commit run --all-files.
  • New unit tests: malformed upstream rejection (including query/fragment) + trailing-slash normalization, effort pinned without --yolo, model discovery against a stub HTTP server (including a /v1-suffixed upstream), explicit --model precedence, typed effort clamp with extras preserved.
  • Live, with a binary built from this branch against vLLM serving Qwen/Qwen3.8-27B-FP8:
    • agentic run claude --upstream http//… → rejected at parse with invalid upstream URL.
    • agentic run claude --upstream http://127.0.0.1:8000 (no --model, inherited CLAUDE_CODE_EFFORT_LEVEL=high) → discovered model, effort pinned to medium, -p turn answered.
    • agentic run codex --upstream http://127.0.0.1:8000 --yolo -- exec … (no --model) → Codex loaded the generated config, ran a shell tool call over WebSocket, listed the crates.
  • Baseline on main (same commands, binary built from origin/main): Codex fails to load config.toml; Claude Code returns the effort 500 above.
  • Kubernetes (kind, kustomize base with PostgreSQL): Claude Code tool-call turn and Codex exec + shell tool through the cluster gateway.

🤖 Generated with Claude Code

- validate --upstream as an http(s):// URL at parse time so typos such as
  `http//127.0.0.1:8000` fail fast instead of surfacing as 502s
- discover the harness model from the upstream's /v1/models when --model is
  omitted alongside --upstream, replacing the `agentic-api` placeholder
- always pin Claude Code to a Qwen-compatible effort (`medium`, overridable
  with AGENTIC_CLAUDE_EFFORT) instead of only under --yolo
- print the harness summary (gateway URL + resolved model) on launch
- write the Codex config.toml with real newlines (the literal `\n` broke
  TOML parsing) and complete the model catalog schema codex 0.144.6 needs
- clamp Anthropic output_config.effort high/max to xhigh for Qwen templates
- add docs/guides/harness-cli-testing.md with the local and Kubernetes
  verification checklist, and refresh README and getting-started

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Hardens CLI harness startup against invalid upstreams, missing models, incompatible Claude effort, and malformed Codex configuration.

Changes:

  • Adds upstream validation, model discovery, and Claude effort pinning.
  • Updates Codex model catalog/config generation.
  • Normalizes Messages effort and adds harness testing documentation.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
README.md Documents model discovery and Claude effort.
mkdocs.yaml Adds the harness testing guide.
docs/guides/harness-cli-testing.md Provides end-to-end testing procedures.
docs/developing/getting-started.md Updates CLI setup guidance.
crates/agentic-server/src/handler/http/messages.rs Normalizes reasoning effort.
crates/agentic-server/src/agentic_process.rs Adds model discovery and launch behavior.
crates/agentic-server/src/agentic_harness.rs Fixes generated Codex configuration.
crates/agentic-server/src/agentic_cli.rs Validates upstream URLs.
Suppressed comments (1)

crates/agentic-server/src/handler/http/messages.rs:124

  • This maps high/max for every /v1/messages request, regardless of the requested model or configured upstream. A non-Qwen backend that accepts high but not xhigh will now reject requests that previously passed through unchanged—the note above already identifies this failure mode. Make the translation conditional on an explicit backend/model capability instead of applying it globally.
    let mapped = match effort.as_str()? {
        "high" | "max" => "xhigh",

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/guides/harness-cli-testing.md Resolved
- normalize an upstream ending in /v1 before model discovery so
  --upstream http://host/v1 does not request /v1/v1/models
- reject query strings and fragments in --upstream, since endpoint paths
  are appended to the base URL
- model output_config.effort as typed OutputConfig/ReasoningEffort in
  agentic-server-core types and clamp through MessagesRequest instead of
  an untyped JSON value at the handler boundary
- note in the testing guide that the Kubernetes remedies require #199

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
@franciscojavierarceo

Copy link
Copy Markdown
Collaborator Author

Addressed the Copilot review in e03b115:

  • /v1 upstream: discovery now runs the base through normalize_base_url before appending /v1/models (test: resolve_model_does_not_double_the_v1_suffix).
  • Query/fragment in --upstream are rejected at parse time (test extended).
  • output_config.effort is now a typed OutputConfig/ReasoningEffort on MessagesRequest in agentic-server-core; the handler clamps through the typed request (unknown effort strings round-trip unchanged; test covers extras preservation). Live-checked high/max/medium against vLLM.
  • Guide troubleshooting rows now state the Kubernetes remedies require fix: keep the Kubernetes base healthy on a read-only root and stable /ready #199.

@franciscojavierarceo
franciscojavierarceo merged commit 575b0da into main Aug 21, 2026
6 checks passed
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.

2 participants