Skip to content

Durable environment keeps the creating agent's frozen LLM env: rotated keys and model changes never reach it #652

Closed

Description

@kayahk

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:

  1. 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 direct POST https://ollama.com/v1/chat/completions (200) before the environment was touched.
  2. A model/provider change never reaches the environment either. The same Deployment still pointed OPENAI_HOST at the AI gateway while the agent had been switched to llm_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_url or llm_api_key and restarting its environment makes the next session/prompt use 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

  1. pullfrog commented on Oct 28, 2026

    @pullfrog
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions