Repository navigation
fix(codex): keep threads working after switching the connection - #345
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 7, 2026 16:50
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. |
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Existing Codex threads can fail at
turn/startafter their instance switches between Device login and Proxy. The thread selectscanopy_native, while the app-server process still defaults toopenai, producing a provider mismatch that the UI labels as a Canopy internal error.Fixes: #85
Cause and fix
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.openai; a proxy usescanopy_<instance id>. In particular,canopy_nativeis the proxy on the instance namednative, not device login. Configure the single-instance app-server'smodel_provideras well as the existingmodelProvideron thread start/resume. Credentials remain in env.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.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
bun install,bun run gen:check,bun run typecheck,bun run lint,bun run format:check, andbun run --cwd apps/web build. No proto or migration changes.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_LIVEis unset; paid live tests require1. The test container was removed.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.
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.