Skip to content

fix: restore every adopted client, not just opencode - #64

Merged
fylorn merged 1 commit into
devfrom
fix/restore-all-client-id
Sep 20, 2026
Merged

fylorn merged 1 commit into
devfrom
fix/restore-all-client-id

Conversation

@fylorn

@fylorn fylorn commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

The bug

restore_all in src-tauri/src/lib.rs looped over the detected clients and asked core to restore each one by its display name:

for c in list.clients.iter().filter(|c| c.adopted_at_ms.is_some()) {
    let r = state.control.restore(&c.name).await;

Core routes /clients/{id}/restore and resolves it by id (tw-control/src/clients.rs, find(id)). The two differ for four of the five adoptable clients:

id name "Restore all" did
claude-code Claude Code fails locally — invalid uri character (the space)
codex Codex CLI fails locally — same
zed Zed 404 未知的客户端 Zed
aider Aider 404 未知的客户端 Aider
opencode opencode works — id and name are the same string

So "Restore all" restored exactly one client, and uninstall — which reuses restore_all — inherited it. That is where it matters: the step that hands the user's other software back before the app goes away reported four failures out of five and left those clients pointing at a gateway that was about to disappear.

The single-client button was never affected; Clients.tsx passes plan.c.id. The bug only appeared on the path a user takes once, at the moment they have decided to leave.

The fix

Address core by id, keep the display name for what the user reads (RestoreOutcome.client is unchanged, so the toast and the uninstall log still say "Claude Code"). tw_api::DetectedClient carries both fields, so nothing new is needed from core.

The choice is factored into restore_targets(), which returns (id, name) pairs for the adopted clients — that gives the test a seam to pin which field goes into the URL, which is the whole of this bug.

Test

restore_addresses_a_client_by_id_and_reports_it_by_name keeps opencode in the fixture on purpose: an id that happens to equal its name is exactly what made the wrong field look like it worked. Reverting the fix fails it with

  left: [("Claude Code", "Claude Code"), ("opencode", "opencode"), ("Zed", "Zed")]
 right: [("claude-code", "Claude Code"), ("opencode", "opencode"), ("zed", "Zed")]

The fixture is built from the JSON core actually sends, so the field names id / name / adopted_at_ms are pinned too, and an unrelated field being added to DetectedClient does not break the test.

Checked in src-tauri: cargo clippy --all-targets -- -D warnings clean, cargo test 105 passed.

Also

restore_all's doc comment had been sitting on quit_app since #12, with the two docs mashed into one block. Moved back.

🤖 Generated with Claude Code

"Restore all" on the Clients page, and the uninstall flow that reuses it,
looped over the detected clients and asked core to restore each one by its
display name. Core routes /clients/{id}/restore and looks clients up by id,
so only opencode was ever restored — it is the one client whose id and
display name are the same string. "Claude Code" and "Codex CLI" failed
before the request left the app, because a space cannot go into a URI;
"Zed" and "Aider" came back 404 "unknown client Zed".

Uninstall inherited all of it, and that is where it hurt: the step meant to
hand the user's other software back before this app goes away reported four
failures out of five and left those clients pointing at a gateway that was
about to disappear. The single-client button was never affected — it passes
c.id — so the bug only showed on the path a user takes once, at the moment
they have decided to leave.

Address core by id and keep the display name for what the user reads. The
choice now happens in restore_targets(), which returns (id, name) pairs for
the adopted clients, so a test can pin which field goes into the URL. That
test keeps opencode in the fixture on purpose: an id that happens to equal
its name is what made the wrong field look like it worked.

Also move restore_all's doc comment back onto restore_all — it had been
sitting on quit_app since #12.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 02e17e1 into dev Sep 20, 2026
2 checks passed
@fylorn
fylorn deleted the fix/restore-all-client-id branch September 20, 2026 01:54
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