Skip to content

fix(api): apply api_key_env/base_url in PATCH /api/agents/{id}/config instead of dropping them#6303

Merged
houko merged 1 commit into
mainfrom
fix/agent-config-api-key-env-base-url
Jun 24, 2026
Merged

fix(api): apply api_key_env/base_url in PATCH /api/agents/{id}/config instead of dropping them#6303
houko merged 1 commit into
mainfrom
fix/agent-config-api-key-env-base-url

Conversation

@houko

@houko houko commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

PatchAgentConfigRequest is shared by two endpoints and declares api_key_env: Option<String> and base_url: Option<String>. The OpenAPI schema for PATCH /api/agents/{id}/config advertises both as settable, but patch_agent_config never read them — the only consumer of those two fields was the sibling patch_hand_agent_runtime_config (hand agents only).

So a non-dashboard API/SDK client that set a custom provider plus its credential env var or base URL in one PATCH /config call got 200 {"status":"ok"} while api_key_env and base_url were silently discarded. The agent stayed pointed at stale credentials / URL — exactly the failure the in-code comment at the model-update block documents (#2380: provider rejects the request with "Missing Authentication header").

Fix

/config now applies both fields via the existing AgentRegistry::update_model_provider_config, run after set_agent_model (which clears stale api_key_env / base_url on a provider change, so the override must be re-applied after it).

Tri-state per field, merged against the current value:

  • Some(non-empty) → set it
  • Some(empty / whitespace) → clear it
  • None (field absent) → leave unchanged (so sending only one field does not wipe the other)

No OpenAPI change — the schema already advertised these fields; this makes the behavior match the published contract, so no openapi.json regeneration is required.

Tests

Adds two #[tokio::test] cases to agents_routes_integration.rs (read-back is via the registry, since no GET endpoint exposes api_key_env):

  • test_patch_config_applies_api_key_env_and_base_url — both fields land on the manifest.
  • test_patch_config_empty_string_clears_api_key_env_but_preserves_base_url — empty string clears, absent field is preserved.

Verification

This host has no native Rust toolchain and no working container runtime, so local cargo verification was not possible — CI is the gate. Reviewers / CI: cargo test -p librefang-api.

Scope

One of several independent findings from a repo audit; filed as its own PR per the one-PR-one-domain policy.

@github-actions github-actions Bot added area/docs Documentation and guides size/M 50-249 lines changed labels Jun 24, 2026
@houko
houko force-pushed the fix/agent-config-api-key-env-base-url branch 2 times, most recently from ed793be to 7abbe89 Compare June 24, 2026 01:09
@houko
houko enabled auto-merge (squash) June 24, 2026 01:22
@github-actions github-actions Bot added the has-conflicts PR has merge conflicts that need resolution label Jun 24, 2026
@houko
houko force-pushed the fix/agent-config-api-key-env-base-url branch from 7abbe89 to 51385c1 Compare June 24, 2026 01:27
@github-actions github-actions Bot added ready-for-review PR is ready for maintainer review has-conflicts PR has merge conflicts that need resolution and removed has-conflicts PR has merge conflicts that need resolution ready-for-review PR is ready for maintainer review labels Jun 24, 2026
… instead of dropping them

PatchAgentConfigRequest declares api_key_env and base_url and the OpenAPI schema for /config advertises both, but patch_agent_config never read them — only the sibling patch_hand_agent_runtime_config did.
A client that switched a non-hand agent to a custom provider plus its credential env var / base URL in one PATCH /config call got 200 while the two fields were silently discarded, leaving the agent on stale credentials/URL (the #2380 class of failure).

/config now applies them via update_model_provider_config after set_agent_model (which clears stale overrides on a provider change). Tri-state per field: a non-empty value sets it, an empty/whitespace value clears it, an absent field is left unchanged (merged against the current value so sending one field does not wipe the other).

No OpenAPI change — the schema already advertised these fields; this makes behavior match the contract. Adds integration tests for the apply path and the empty-string-clears / absent-preserves semantics.
@houko
houko force-pushed the fix/agent-config-api-key-env-base-url branch from 51385c1 to 02d7876 Compare June 24, 2026 03:17
@github-actions github-actions Bot added ready-for-review PR is ready for maintainer review and removed has-conflicts PR has merge conflicts that need resolution labels Jun 24, 2026
@houko
houko merged commit dc7c83b into main Jun 24, 2026
31 checks passed
@houko
houko deleted the fix/agent-config-api-key-env-base-url branch June 24, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation and guides ready-for-review PR is ready for maintainer review size/M 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant