Skip to content

docs(backends): architecture guide + Codex cache invalidation - #178

Merged
claudiusthebot merged 1 commit into
mainfrom
feat/codex-polish-3
May 16, 2026
Merged

docs(backends): architecture guide + Codex cache invalidation#178
claudiusthebot merged 1 commit into
mainfrom
feat/codex-polish-3

Conversation

@claudiusthebot

Copy link
Copy Markdown
Collaborator

Adds docs/backends.md with full backend-architecture documentation (backend selection matrix, shared helpers inventory, remote-server family, QueryBackend interface annotated, per-backend notes, adding-a-new-backend walkthrough). Also fixes a subtle bug where re-initialising the Codex backend would keep returning a stale cached Codex instance β€” initCodexAgent now clears state.codex = null so the next ensureCodex(chatId) rebuilds with the new config.

Test plan

  • tsc clean, lint 0 errors, 2305 passing, 0 failing

πŸ€– Generated with Claude Code

@claudiusthebot
claudiusthebot enabled auto-merge (squash) May 16, 2026 00:13
Two improvements:

1. **`docs/backends.md`** β€” comprehensive guide to Talon's backend
   architecture:
   - Backend selection matrix (claude/kilo/opencode/codex).
   - `backend/shared/` helper inventory + what each does.
   - `backend/remote-server/` for HTTP-server backends (Kilo +
     OpenCode shared infrastructure).
   - Full `QueryBackend` interface annotated.
   - Per-backend implementation notes (transport, auth, MCP wiring).
   - "Adding a new backend" walkthrough β€” minimum surface + wiring
     + factory registration + config schema + tests.
   - Backend conformance tests rationale.

2. **Codex cache invalidation on re-init.** `initCodexAgent` now
   clears `state.codex = null` so a follow-up call (e.g. plugin
   reload, hot-reload, test isolation) doesn't return a stale Codex
   instance built with the previous MCP / API-key / frontend config.
   The next `ensureCodex(chatId)` rebuilds from scratch.

Tests: 2305 passing, 12 skipped, 0 failing.
@claudiusthebot
claudiusthebot merged commit 0938212 into main May 16, 2026
31 checks passed
claudiusthebot added a commit that referenced this pull request May 16, 2026
9 new tests in `codex-init.test.ts` covering the Codex backend's
state-lifecycle invariants that aren't exercisable through the
factory test alone:

- `ensureCodex` throws if called before `initCodexAgent`
- Same chat id β†’ cached instance returned
- Different chat id β†’ fresh instance built
- Same chat id after chat-switch β†’ cached again
- `initCodexAgent` re-invocation invalidates the cached instance
  (this is the new behaviour from `docs/backends.md` PR #178)
- Re-init with the same config still invalidates (defensive default)
- Gateway port + frontend label captured on init
- OPENAI_API_KEY env wins over config.openaiApiKey
- Falls back to config.openaiApiKey when env is absent
- Uses env-only when no config key provided

Total: 2314 passing (was 2305), 12 skipped (live), 0 failing.
tsc clean, lint 0 errors / 15 pre-existing warnings.
claudiusthebot added a commit that referenced this pull request May 16, 2026
9 new tests in `codex-init.test.ts` covering the Codex backend's
state-lifecycle invariants that aren't exercisable through the
factory test alone:

- `ensureCodex` throws if called before `initCodexAgent`
- Same chat id β†’ cached instance returned
- Different chat id β†’ fresh instance built
- Same chat id after chat-switch β†’ cached again
- `initCodexAgent` re-invocation invalidates the cached instance
  (this is the new behaviour from `docs/backends.md` PR #178)
- Re-init with the same config still invalidates (defensive default)
- Gateway port + frontend label captured on init
- OPENAI_API_KEY env wins over config.openaiApiKey
- Falls back to config.openaiApiKey when env is absent
- Uses env-only when no config key provided

Total: 2314 passing (was 2305), 12 skipped (live), 0 failing.
tsc clean, lint 0 errors / 15 pre-existing warnings.
claudiusthebot added a commit that referenced this pull request May 16, 2026
…#179)

* test(codex): init lifecycle + cache invalidation + API-key resolution

9 new tests in `codex-init.test.ts` covering the Codex backend's
state-lifecycle invariants that aren't exercisable through the
factory test alone:

- `ensureCodex` throws if called before `initCodexAgent`
- Same chat id β†’ cached instance returned
- Different chat id β†’ fresh instance built
- Same chat id after chat-switch β†’ cached again
- `initCodexAgent` re-invocation invalidates the cached instance
  (this is the new behaviour from `docs/backends.md` PR #178)
- Re-init with the same config still invalidates (defensive default)
- Gateway port + frontend label captured on init
- OPENAI_API_KEY env wins over config.openaiApiKey
- Falls back to config.openaiApiKey when env is absent
- Uses env-only when no config key provided

Total: 2314 passing (was 2305), 12 skipped (live), 0 failing.
tsc clean, lint 0 errors / 15 pre-existing warnings.

* feat(cli): make \`talon doctor\` backend-aware

Previously `talon doctor` always checked for the Claude Code CLI on
PATH, even when the active backend was `kilo` / `opencode` / `codex`.
Result: a Codex user running `doctor` would get a false-positive
"Claude Code not found" issue count.

Now the doctor reads `backend` from the config and checks the right
thing:

- `claude`: looks for `claude` on PATH (or honours `claudeBinary`
  config). Same as before.
- `codex`: looks for `codex` on PATH (`npm i -g @openai/codex` hint
  if missing). Plus checks for OpenAI auth β€” accepts any of:
  `OPENAI_API_KEY` env, `openaiApiKey` in talon.json, or
  `~/.codex/auth.json` (left behind by `codex login`).
- `kilo` / `opencode`: notes that the SDK is bundled (no external
  binary to check).

`Config` type in cli.ts gained `backend?: ... | "codex"` and
`openaiApiKey?: string` to match the runtime schema in
`util/config.ts`.

Tests: 2314 passing (unchanged), 12 skipped, 0 failing.
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