Skip to content

fix(codex): keep threads working after switching the connection - #345

Merged
nixuuu merged 1 commit into
devfrom
fix/codex-provider-switch
Nov 7, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/codex-provider-switch

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Existing Codex threads can fail at turn/start after their instance switches between Device login and Proxy. The thread selects canopy_native, while the app-server process still defaults to openai, producing a provider mismatch that the UI labels as a Canopy internal error.

Fixes: #85

Cause and fix

  • Threads pin provider_profile_id, the instance ID. Changing another instance does not move them. Explicitly changing their instance's connection applies on the next turn, after running work drains.
  • Device login uses openai; a proxy uses canopy_<instance id>. In particular, canopy_native is the proxy on the instance named native, not device login. Configure the single-instance app-server's model_provider as well as the existing modelProvider on thread start/resume. Credentials remain in env.
  • Codex 0.164.0 supports a provider override on cold resume. Keep the same conversation, full history and turn references. A fork or seeded continuation is unnecessary, so there is no migration timeline note. The adapter regression exercises the real CLI against two local fake APIs and confirms earlier prompts and replies reach the new connection.
  • Recognize the reported refusal as connection_changed, with instructions to restore the previous connection and an Open provider settings action. Preserve the native error behind Show details. This shared presentation covers web and mobile.
  • Claude and Grok keep their existing session stores when switching connections; the gateway↔worker regression covers both. Explicit home/own-login changes can point at another store and do not migrate history; document that boundary and remove the obsolete statement that in-use instances cannot change connection.

Pinned source reviewed: app-server resume/fork, core resume, provider requirements. Managed Codex requirements remain enforced. Canopy uses the installed CLI; the strict scripted server also reproduces versions that compare the thread route with the current process provider.

Validation

  • Passed bun install, bun run gen:check, bun run typecheck, bun run lint, bun run format:check, and bun run --cwd apps/web build. No proto or migration changes.
  • Focused gateway↔worker tests: 7 passed, including strict provider admission, native→proxy→native, restart, error presentation and retry; Claude/Grok switches and drain are covered too.
  • Real Codex adapter with local fake inference: device login → proxy → another proxy → another profile → device login keeps one conversation and earlier history. No paid live inference; no real CLI homes or credentials.
  • Passed full bun run check:tmp: 1751 passed, 161 skipped, 0 failed across 312 files; nothing left in the test temp directory. Tests use worktree-local temp data, isolated provider homes and a Git discovery ceiling. CANOPY_LIVE is unset; paid live tests require 1. The test container was removed.
  • Manual T3 browser check against an isolated gateway, worker and Postgres: light/dark at 1280×800 and 390×844. Verified completed Cześć after switching, specific fallback text, details wrapping, and navigation to the correct instance/worker settings. Stopped the dev server and fixture; closed the preview tab.

Copy audit — docs/copy.md §8

Before: “Canopy had an internal error. Retry…” → After: “Codex could not use this thread with the current connection. Restore its previous connection in provider settings, then retry.” This identifies the connection problem and gives a recovery step.

Checks Result
1–2: wording and glossary 2 short, active sentences; sentence case and punctuation; uses thread, connection and provider settings; no protocol names on the surface.
3–4: actions and errors Existing Open provider settings and Retry actions; source, code and original refusal stay in Show details with copy support.
5–8: states, repetition, dependencies and soul No new empty states or confirmations; no duplicate title/body fact; names the connection dependency and recovery; no humour.
9: text lengths and widths Short Cześć, typical prompt and a long thread title checked at desktop/phone widths in both themes; error and expanded details wrap without horizontal overflow. The error has no interpolated names.
10: accessibility Meaning and actions are visible text; no dependence on colour, icon shape or position.

Align each instance app-server model_provider with thread start and resume. Keep the existing conversation and full history across connection changes, and present provider refusals with settings recovery.

Fixes: #85
@nixuuu
nixuuu marked this pull request as ready for review November 7, 2026 16:50
@nixuuu
nixuuu merged commit b8f4bea into dev Nov 7, 2026
12 checks passed
@nixuuu
nixuuu deleted the fix/codex-provider-switch branch November 7, 2026 16:52
nixuuu added a commit that referenced this pull request Nov 7, 2026
…351)

Imported Codex threads can fail on their first Canopy turn because their
rollout names a custom CLI provider that does not exist in Canopy's
private `CODEX_HOME`.

Fixes: #312
Related: #345

## Cause and fix

- Keep the explicit `modelProvider` override from #345. Codex 0.164
accepts it, but 0.166 validates the saved provider before applying it.
The real 0.166 binary reproduces the reported “which is no longer
configured” refusal against a local fake API.
- Before cold resume, normalize only the manifest-owned private
rollout's session provider and its own settings snapshots to the
thread's Canopy connection (`openai` or `canopy_<instance id>`). Use the
existing staged, identity-checked copy writer and update the manifest,
preserving Undo. Session ID, history, messages and turn references stay
intact.
- Paginated Codex sessions also read their saved provider from SQLite,
including on path-based resume. Update only `threads.model_provider` in
the private index, matching both session ID and verified rollout path.
Do not create a database or change its schema; leave unknown schemas
alone. Reject symbolic/hard links and special files in the index and
SQLite companions. Source CLI files, configuration and databases remain
untouched. Codex still enforces managed requirements on the selected
connection.
- Classify the missing-provider refusal as `connection_changed`, reusing
the specific explanation and **Open provider settings** action from
#345. Retain the native harness error under **Show details**.
- Claude already receives the instance endpoint and selected model on
resume; Grok loads the copied history and explicitly selects the thread
model. Extend their real-CLI regressions with a conflicting source
endpoint/model and a retired source model respectively.

## Already-imported threads

The next cold resume repairs the existing private copy and its matching
index entry, including copies that already failed with 0.166. No
re-import, new conversation, history summary or gateway migration is
needed. Copies without valid ownership evidence are not rewritten;
harness refusals retain their specific classification.

## Validation

- Passed: `bun install`, `bun run gen:check`, `bun run typecheck`, `bun
run lint`, `bun run format:check`, and `bun run --cwd apps/web build`.
- Real Codex 0.166 against a local fake API plus copy/index security
regressions: **9 passed**, including native and proxy connections,
failed old-copy recovery, a second cold resume, complete history,
unchanged source and Undo. The standard installed Codex 0.164, Claude
and Grok adapters also pass against local fake APIs.
- Gateway↔worker import integration covers native continuation with the
same session ID/history and an impossible override classified as
`connection_changed`, retaining the native error and provider-settings
recovery.
- Full `bun run check:tmp`: **1772 passed, 161 skipped, 0 failed** (1933
tests across 317 files); no test temp-directory leaks. Its PostgreSQL
container and volume were removed. `CANOPY_LIVE` stayed unset; no paid
API calls or UI/E2E tests.
- Final self-review and `git diff --check` passed. CI and external
review are pending.

## Copy audit — docs/copy.md §8

Effective message before → after: “Canopy had an internal error. Retry.
If it happens again, copy the details and report them.” → “Codex could
not use this thread with the current connection. Restore its previous
connection in provider settings, then retry.” The missing-provider
variant now uses the existing actionable connection explanation; no new
UI string or layout is introduced.

| Checks | Result |
|---|---|
| 1–2: wording and glossary | Reuses #345's two short sentences,
sentence case, punctuation, thread and provider-settings terminology. No
native provider ID appears on the surface. |
| 3–4: actions and errors | Existing **Open provider settings** and
**Retry** actions; integration test verifies harness source, native
code/message and `connection_changed`. Technical details use the
existing **Show details** disclosure. |
| 5–8: states, repetition, dependencies and soul | No new empty state or
confirmation; no duplicate title/body fact; connection dependency and
recovery are explicit; no humour. |
| 9: text lengths and widths | No interpolated names, new labels, string
changes or layout changes. Uses the same notice as #345; no browser or
UI test was run in this task. |
| 10: accessibility | Existing visible explanation and action labels
convey meaning without colour, icon shape or position. |
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