Skip to content

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

Closed
franciscojavierarceo wants to merge 13 commits into
mainfrom
agentic-integration
Closed

franciscojavierarceo wants to merge 13 commits into
mainfrom
agentic-integration

Conversation

@franciscojavierarceo

@franciscojavierarceo franciscojavierarceo commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #188/#191 from reproducing #190 end-to-end (locally and on the kind cluster) with the agentic CLI. Each fix maps to a failure hit during that testing:

  • Validate --upstream at parse time as an http(s):// URL with a host. 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. The CLI now reads GET {upstream}/v1/models and uses the first entry instead of sending the agentic-api placeholder, which vLLM rejects.
  • Always pin Claude Code to a Qwen-compatible effort. --effort medium and CLAUDE_CODE_EFFORT_LEVEL=medium were only set under --yolo; a plain run inherited Claude Code's default high, which Qwen's chat template rejects. AGENTIC_CLAUDE_EFFORT overrides the pinned value. --yolo stays strictly opt-in.
  • Print the resolved gateway URL and model on launch.
  • Keep the Codex config.toml real-newline fix and complete model catalog from 3f51a22 (main still writes literal \n, which breaks TOML parsing for codex 0.144.6), and advertise supports_parallel_tool_calls: true now that fix: accept Codex parallel tool policy with built-ins #191 accepts it.
  • 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 (before/after table) → Kubernetes rollout and verification → troubleshooting. README and getting-started updated to match.

Deployment follow-up (second commit)

Following docs/deploying/kubernetes.md end-to-end on kind with both harnesses surfaced three more problems, fixed here:

  • Kustomize base crashed on current main (CrashLoopBackOff): fix: harden MCP and Agentic API config startup #189 writes a generated config.toml into /var/lib/agentic-api, but the base sets readOnlyRootFilesystem: true. The server now continues in memory when the home is unwritable (regression test), and the base mounts an emptyDir home.
  • /ready flapped 1–3×/min per pod with 503 readiness-probe failures while vLLM was healthy: the probe client reused pooled keep-alive connections that uvicorn had already closed (hyper::Error(IncompleteMessage)). The readiness client no longer pools connections; 0 flaps in 10+ minutes after the fix (was ~60 in 15 minutes).
  • Overlay location in the guide fails (cycle detected): overlays cannot live under deploy/kubernetes. Added deploy/overlays/kind as a working example and fixed the doc.

Verified on the kustomize deployment (2 replicas, PostgreSQL): persistence across a rolling restart via previous_response_id; 6 concurrent chained conversations across both replicas; Codex exec with a shell tool over WebSocket; Claude Code tool-call turn; an 86-case Responses/Messages edge battery (tool_choice variants, Codex-shaped store=false history replay with function_call items, include: reasoning.encrypted_content, reasoning efforts, json_schema, streaming event order, bad ids/bodies, 30k-char inputs, Claude Code beta headers, thinking, count_tokens, tool_result/is_error). Remaining gaps noted, not fixed: GET/DELETE /v1/responses/{id} are unrouted (404, empty body); conversation=<unknown id> is silently ignored; an empty messages array is passed to vLLM, which returns 500.

Test Plan

  • cargo fmt --all -- --check, cargo clippy --all-targets -- -D warnings, cargo test --workspace, pre-commit run --all-files — all pass.
  • New unit tests: malformed upstream rejection + trailing-slash normalization, effort pinned without --yolo, model discovery against a stub HTTP server, explicit --model precedence.
  • Live, 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.
    • Tool-call turn (Bash ls crates) completed through the gateway.
  • Kubernetes (kind): rebuilt agentic-api:kind, rolled deploy/agentic-api, then:

🤖 Generated with Claude Code

franciscojavierarceo and others added 8 commits August 20, 2026 12:36
Signed-off-by: Francisco Javier Arceo <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
- write config.toml with real newlines (was literal \n, broke TOML parse)
- complete Codex model catalog schema (shell_type, priority, base_instructions,
  truncation_policy, context windows) required by codex 0.144.6
- supports_parallel_tool_calls=false (vLLM rejects it with built-in tools)
- drop apply_patch_tool_type=freeform (gateway can't normalize; shell fallback)
- clamp Anthropic output_config.effort high/max -> xhigh for Qwen templates

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PPxUH9PtaytqJNmtRMJ5Kv
Signed-off-by: Francisco Javier Arceo <[email protected]>

# Conflicts:
#	README.md
#	crates/agentic-server/src/agentic_cli.rs
#	crates/agentic-server/src/agentic_harness.rs
#	crates/agentic-server/src/agentic_output.rs
#	crates/agentic-server/src/agentic_process.rs
#	crates/agentic-server/src/bin/agentic.rs
#	docs/developing/getting-started.md
- 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
- add docs/guides/harness-cli-testing.md with the local and Kubernetes
  verification checklist used for #190/#191, and refresh README and
  getting-started accordingly

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
franciscojavierarceo and others added 5 commits August 21, 2026 07:53
…/ready

Found by following docs/deploying/kubernetes.md end-to-end on kind with
Codex and Claude Code:

- config_file: an unwritable AGENTIC_API_HOME (read-only root filesystem,
  the documented base) no longer aborts startup; the generated config.toml
  is kept in memory with a warning. The base also mounts an emptyDir at
  /var/lib/agentic-api so the file is written when possible.
- readiness: the /ready upstream probe client no longer pools connections.
  Reusing a keep-alive socket the upstream (uvicorn, 5 s idle timeout) had
  already closed failed with hyper IncompleteMessage roughly 1-3 times a
  minute per pod and produced 503 readiness probe failures while vLLM was
  healthy.
- deploy/overlays/kind: working overlay for the kind guide (host vLLM,
  Linux hostAliases). Overlays must live outside deploy/kubernetes; the
  location the guide suggested fails with a Kustomize cycle error.
- docs: fix the overlay location, describe the emptyDir home, add a Codex
  on Kubernetes recipe and new troubleshooting rows to the harness guide.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
- restore the clippy allows for Rust 1.98 that the #191 revert removed
  (main is red on `cargo clippy -D warnings` without them)
- advertise supports_parallel_tool_calls=false in the Codex catalog again,
  since the gateway rejects it with built-in tools after the revert

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Francisco Javier Arceo <[email protected]>
Reference #197 (serialized parallel tool calls) instead of the reverted
#191 in the Codex catalog comment and the harness testing guide.

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

Copy link
Copy Markdown
Collaborator Author

Superseded by the split PRs: CLI hardening (fix/harness-cli-hardening) and Kubernetes base fixes (fix/k8s-base-readonly-readiness). Closing.

franciscojavierarceo added a commit that referenced this pull request Aug 21, 2026
## 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. 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.
- Clamp Anthropic `output_config.effort` `high`/`max` → `xhigh` on
`/v1/messages` for Qwen templates.
- 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 #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.

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 + trailing-slash
normalization, effort pinned without `--yolo`, model discovery against a
stub HTTP server, explicit `--model` precedence.
- 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](https://claude.com/claude-code)

---------

Signed-off-by: Francisco Javier Arceo <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
franciscojavierarceo added a commit that referenced this pull request Aug 22, 2026
…/ready (#199)

## Summary

Found by following `docs/deploying/kubernetes.md` end-to-end on kind
(kustomize base, 2 replicas, PostgreSQL) with Codex and Claude Code.

- **Kustomize base crashes on current main** (`CrashLoopBackOff`): #189
writes a generated `config.toml` into `/var/lib/agentic-api`, but the
base sets `readOnlyRootFilesystem: true` with no writable volume
(`failed to create temporary configuration file: Read-only file
system`). The server now continues with the generated configuration in
memory and logs a warning when the home is unwritable (regression test
included), and the base mounts a 64Mi `emptyDir` at
`/var/lib/agentic-api`.
- **`/ready` flapped 1–3×/min per pod** with 503 readiness-probe
failures while vLLM was healthy. The probe client reused pooled
keep-alive connections that the upstream (uvicorn, 5 s idle timeout ≈ 5
s probe period) had already closed, failing with
`hyper::Error(IncompleteMessage)`. The readiness client no longer pools
connections (`pool_max_idle_per_host(0)`).
- **The overlay location the guide suggested fails**: Kustomize rejects
a base that is an ancestor of the overlay (`cycle detected`). Added
`deploy/overlays/kind` as a working example for the kind guide (host
vLLM, Linux `hostAliases`) and fixed the doc.

Split out of #193; the CLI fixes are in a separate PR.

## Test Plan

- `cargo fmt --all -- --check`, `cargo clippy --all-targets -- -D
warnings`, `cargo test --workspace`, `kubectl kustomize
deploy/overlays/kind | kubectl apply --dry-run=server -f -`.
- New unit test: `create_or_load_continues_when_home_is_not_writable`.
- On kind with the kustomize base and PostgreSQL: before the fix both
replicas were in `CrashLoopBackOff`; after, both ready. Readiness
warnings went from ~60 in 15 minutes to 0 in 10+ minutes (also 0/24
probes locally at the 5 s cadence).
- Verified on the deployment: the guide's persistence check (`store:
true` → rolling restart → `previous_response_id` continuation), 6
concurrent chained conversations across both replicas, Codex `exec` with
a shell tool over WebSocket, Claude Code tool-call turn, and an 86-case
Responses/Messages edge battery.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Francisco Javier Arceo <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
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.

1 participant