Repository navigation
Description
Symptom
A conversation attached to a durable environment died at its first model call:
executor: acp session/prompt: Authentication required
The gateway recorded the request as 401 KeyNotFoundError, and the environment's agent-server was running with a base URL and API key that no agent had been configured with for days.
Cause
A static environment's Pod carries the creating agent's LLM env (GOOSE_PROVIDER, GOOSE_MODEL, the provider's key var, OPENAI_HOST) and it is never reconciled afterwards. Manager.ensureEnvironmentEnv (services/agent-runner/internal/sandbox/k8s/environment.go) backfills missing keys only:
if existing["GOOSE_PROVIDER"] {
return nil
}So once the Deployment has been created, StartEnvironment — and therefore every cold start, restart and attach — leaves the agent's current model, provider and credential unapplied. Two failures follow:
- A rotated or replaced key never reaches the environment. Observed live: the environment still carried an
sk-…LiteLLM virtual key that had since been revoked (KeyNotFoundError), while the agent row held a valid ollama.com key — verified working with a directPOST https://ollama.com/v1/chat/completions(200) before the environment was touched. - A model/provider change never reaches the environment either. The same Deployment still pointed
OPENAI_HOSTat the AI gateway while the agent had been switched tollm_provider=ollama,llm_base_url=https://ollama.com.
Because an environment pod serves exactly one provider configuration, every agent attached to it inherits the first agent's frozen config — a second agent with a different provider (sgc-ai) also gets the first one's base URL and key, which cannot work.
Recovery required patching the Deployment's env by hand to the agent's current values; nothing in the API or UI can re-apply them, and StartEnvironment's "backfill" cannot fix an env that already exists.
Proposed fix
Reconcile the keys the executor owns instead of only backfilling absent ones: compute the managed set (GOOSE_PROVIDER, GOOSE_MODEL, the provider's key env var, OPENAI_HOST, and the per-conversation PACA_* keys) and overwrite exactly those on every StartEnvironment, leaving any other env var (agent agent_environment_variables such as GITHUB_TOKEN, infra keys from ensureEnvironmentInfraEnv) untouched. A key that was intentionally removed from the agent should be deleted, not left behind — today there is no way to drop one.
Acceptance
- Changing an agent's
llm_model,llm_provider,llm_base_urlorllm_api_keyand restarting its environment makes the nextsession/promptuse the new values, with no manual Deployment edit. - An env var not owned by the executor (e.g.
GITHUB_TOKEN) survives the reconcile. - Agent env vars removed between two starts are gone from the Pod after the second start.
Activity
pullfrog commentedon Oct 28, 2026