Skip to content

feat(providers): apply changes next turn and switch proxies in place - #85

Merged
nixuuu merged 1 commit into
devfrom
feat/instance-proxy-switch
Nov 4, 2026
Merged

nixuuu merged 1 commit into
devfrom
feat/instance-proxy-switch

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 4, 2026

Copy link
Copy Markdown
Member

Any provider instance (including the built-in native device login and instances with threads) can now switch between Device login and a saved Proxy in place, and every instance change applies at the next turn without interrupting running work.

Why it was locked: the UI, the gateway and a SQL constraint forbade kind changes for built-in/in-use instances, and switching reset ownLogin, which could move the session directory so existing threads could not resume.

Now

  • Switching keeps the instance id and its session storage (Claude config dir, Codex home, Grok sessions), so existing threads keep resuming. Owner-scoped and audited.
  • General rule for any instance change (connection/proxy, env vars and secrets, launch args, models, own login, Codex options): running turns and background tasks finish on the configuration they started with; new turns use the new one. Codex app-server and stale Claude/Grok processes are recycled once their instance's work finishes; new work waits for the current runtime; an idle instance restarts immediately; unrelated instances are untouched.
  • Settings: the Connection choice is no longer locked; Proxy picks a saved proxy with "Add proxy" inline; the copy explains that changes apply at the next turn. Explicitly changing the session directory or own-login choice can point at different storage — the UI and docs say so.
  • Migration 0065_instance_connections; Polish docs (worker-config, durability, proxies).

Checks: install, gen:check, typecheck, lint, format:check, check:tmp (947 pass, 152 skip, 0 fail), web build. Integration tests use local fake CLIs (no paid calls). Browser checked light/dark at desktop and phone widths.

@nixuuu
nixuuu merged commit 64664a2 into dev Nov 4, 2026
9 checks passed
@nixuuu
nixuuu deleted the feat/instance-proxy-switch branch November 4, 2026 18:27
nixuuu added a commit that referenced this pull request Nov 4, 2026
Fixes from testing bots on desktop nightly.32.

- **Sidebar freeze:** "Create your first bot" in the sidebar froze the
app through a shallow-navigation reactive cycle. Fixed; both entry
points open the wizard the same way.
- **Stale providers:** the wizard refreshes provider definitions and
model catalogs when it opens and on configuration changes, with loading
and error states instead of an empty list.
- **Eligibility by connection:** bots decide by an instance's current
connection (proxy/endpoint vs Device login), not by the id `native` —
since #85 the built-in instance can be a proxy. Device-login instances
appear disabled with the reason and a link to that instance's settings.
- **Labels:** Settings → Workers provider chips and the built-in
instance's display-name placeholder follow the current connection (no
"Native" / "Device login" for a proxy).

Fixes: #85
Fixes: #72
nixuuu added a commit that referenced this pull request Nov 5, 2026
#131)

Fixes two causes of flaky failures in
`tests/integration/instance-changes.test.ts`. Both are in the test
fixture; product code is unchanged.

1. **The caller's environment leaked in.** The in-process worker passes
its own environment to native harnesses. A shell that sets
`ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_BASE_URL` or `CLAUDE_*` (for example
an agent session) made every native turn look proxied, so the
native→proxy→native checks failed. The fixture now removes provider
variables (`ANTHROPIC_`, `CLAUDE`, `CODEX_`, `OPENAI_`, `XAI_`, `GROK_`)
while it runs and restores them on close.
2. **A half-written line was read** (the CI failure). The test polls
`probe.jsonl` while harness processes append to it. A read could catch
half a line, and the strict decoder threw `Expected a valid JSON
string`. Grok's instance switches were then never audited, so the audit
test saw 4 rows instead of 6. Only lines that end with a newline are
parsed now.

No sleeps, retries, raised timeouts or weaker assertions.

Related: #85
nixuuu added a commit that referenced this pull request Nov 7, 2026
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](https://github.com/openai/codex/blob/rust-v0.164.0/codex-rs/app-server/src/request_processors/thread_processor.rs),
[core
resume](https://github.com/openai/codex/blob/rust-v0.164.0/codex-rs/core/src/thread_manager.rs),
[provider
requirements](https://github.com/openai/codex/blob/rust-v0.164.0/codex-rs/app-server/src/config_manager.rs).
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. |
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