Skip to content

Rename AGENT_BACKEND to DEFAULT_BACKEND#719

Merged
dcellison merged 2 commits into
mainfrom
refactor/default-backend-rename
Jun 22, 2026
Merged

Rename AGENT_BACKEND to DEFAULT_BACKEND#719
dcellison merged 2 commits into
mainfrom
refactor/default-backend-rename

Conversation

@dcellison

Copy link
Copy Markdown
Owner

Summary

Renames the installation-wide and per-user "which backend by default" knob from AGENT_BACKEND to DEFAULT_BACKEND, paralleling DEFAULT_MODEL and dropping the redundant "agent_" prefix (backends are the agents in this codebase). The old name is still read for one release with a one-shot deprecation warning at every reader; all writers emit the new name only.

This is groundwork ahead of adding the Pi backend (#696), so that work only learns the new vocabulary.

What changed

  • Config.agent_backendConfig.default_backend and UserConfig.agent_backendUserConfig.default_backend. Every constructor call and attribute access swept.
  • Env var / config key: AGENT_BACKENDDEFAULT_BACKEND (env), agent_backend:default_backend: (users.yaml per-user key), AGENT_BACKENDDEFAULT_BACKEND (install.conf env dict).
  • Shared resolver _resolve_default_backend(get, new_key, old_key, *, context, default) in config.py: reads the new key, falls back to the old with a one-shot per-context deprecation log. Takes a required default so the two absence semantics stay distinct — global readers pass default="claude" (installation default); the per-user users.yaml reader passes default=None so a backend-less user still inherits the global backend via the existing user_backend or global_backend cascade (rather than being pinned to claude on a non-claude install).
  • Five readers routed through the resolver: load_config (env), _cmd_apply (install.conf dict), behavioral._run_cli (env), _load_user_configs (per-user yaml), plus the wizard prefill.
  • Installer (_cmd_apply) consumes the install.conf env dict directly (never through load_config), so it migrates a legacy AGENT_BACKEND key to DEFAULT_BACKEND once at the top of apply, before any backend gate reads it or /etc/kai/env is written. Without this, a legacy install.conf would validate a codex/goose default model against the wrong (claude/anthropic) surface and fail, or silently skip backend-specific setup.
  • Four installer-side users.yaml scanners (_users_yaml_goose_providers, _users_yaml_agent_backends, _collect_backends_from_yaml, _collect_goose_os_users_from_yaml) read each entry's backend through a new _entry_backend(entry) helper (prefer default_backend, fall back agent_backend).
  • Wizard: prompt label "Agent backend" → "Default backend"; prefill reads either key; writes DEFAULT_BACKEND only (so a re-run silently migrates install.conf).
  • Templates (templates/.env, templates/users.yaml, templates/config/goose-config.yaml) and docs (README; wiki pages pushed after merge).

Internal function parameters named agent_backend that hold the effective (post-cascade) backend at a call site (e.g. models_for_backend, review_pr, run_triage, _apply_goose_config) are intentionally left unchanged — they name a runtime value, not a default.

Test plan

  • make check (ruff + format) clean
  • make test clean (4576 passed, 1 skipped; +18 over main)
  • New back-compat tests: legacy AGENT_BACKEND env still resolves with a warning; new key wins when both set; legacy agent_backend: users.yaml key still resolves with a warning
  • New inheritance regression guard: a users.yaml user omitting the backend key inherits a non-claude global backend (resolver default=None), not claude
  • New apply-path tests: a legacy AGENT_BACKEND=codex install.conf validates against the codex surface and writes /etc/kai/env with DEFAULT_BACKEND and no AGENT_BACKEND; a new-name install.conf passes through cleanly
  • New scanner coverage: all four installer users.yaml scanners read both key names
  • New behavioral-eval coverage: resolves both DEFAULT_BACKEND and legacy AGENT_BACKEND
  • New wizard resave-migration test: re-running against a legacy install.conf writes DEFAULT_BACKEND, drops AGENT_BACKEND
  • Manual post-merge: make config shows the "Default backend" prompt; a legacy /etc/kai/env with AGENT_BACKEND logs the deprecation warning at startup and still resolves

Renames the global and per-user default-backend knob to parallel DEFAULT_MODEL and drop the redundant agent_ prefix. A shared _resolve_default_backend helper reads the new key with a one-release fallback to the old name (one-shot deprecation warning per source); a required default arg keeps the two absence semantics distinct (global readers default to claude, the per-user users.yaml reader defaults to None so a backend-less user still inherits the global backend). Five readers route through it: load_config, _cmd_apply, the behavioral eval, _load_user_configs, and the wizard prefill. _cmd_apply migrates a legacy AGENT_BACKEND key in the install.conf env dict before any gate reads it or /etc/kai/env is written. Four installer-side users.yaml scanners read both key names via _entry_backend. The wizard writes DEFAULT_BACKEND only. Effective-backend parameter names (post-cascade runtime values) are left unchanged. Adds nine back-compat/inheritance/migration tests.
Two installer-side scanners (_collect_backends_from_yaml, _collect_goose_os_users_from_yaml) stripped but did not lowercase the per-user backend value, unlike the runtime loader and the wizard-side scanners. A users.yaml entry with default_backend: Goose routes to goose at startup but the apply scanners saw 'Goose', so _apply_goose_config's 'goose' in <set> membership check skipped the per-user goose config deploy and _collect_goose_os_users_from_yaml dropped the os_user. Both now .strip().lower() to match the loader. _cmd_apply also writes the normalized global DEFAULT_BACKEND back into the env dict after validation so the downstream goose-config and sudoers gates and the written /etc/kai/env all see the canonical lowercase form. Pre-existing drift surfaced while routing all four scanners through _entry_backend; fixed here since the scanners are already in this change's blast radius. Adds three tests.
@dcellison
dcellison merged commit c72480b into main Jun 22, 2026
1 check passed
@dcellison
dcellison deleted the refactor/default-backend-rename branch June 22, 2026 19:59
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