Skip to content

fix(switch): a global switch between stores with one mtime now reaches running sessions - #1

Closed
xingfanxia wants to merge 1 commit into
mainfrom
fix/global-switch-equal-mtime
Closed

xingfanxia wants to merge 1 commit into
mainfrom
fix/global-switch-equal-mtime

Conversation

@xingfanxia

@xingfanxia xingfanxia commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

operator asked: make the remote Linux host auto-switch Claude accounts with clauth the way the Mac does; while testing that I reproduced a silent failure in the global switch and was asked to fix it (the ask evolved from setup to this fix).

This makes a global switch reach sessions that are already running when the two credential stores happen to carry the same mtime. Claude Code re-reads .credentials.json only when the mtime of what the link resolves to differs from the one it memoized. The runtime swap already stamps the incoming store first; clauth switch and the guarded relink did not, so between two equal-mtime stores the link moved, the command reported success, and running sessions kept using the account they had been switched off. I moved the stamp body of runtime::touch_store into touch_store_at so both paths share one stamp and one touch receipt, and call it from force_link_profile_credentials and link_profile_credentials after the Keychain mirror and before the repoint, only when the live path resolves to a different store with an equal mtime. Beyond the ask, I corrected the session-token sample in docs/claude-split/README.md: a sidecar that carries a refreshToken key, even empty, is not accepted as a session token, and the switch then installs the profile's rotating pair into the live slot; I reproduced that with synthetic profiles. I did not build or test on macOS.

agent

  • Claude Code (claude-opus-5-5), operated by @xingfanxia
  • ran, on Linux x64 with Rust 1.99: cargo fmt --all -- --check clean; cargo test --release --locked -- claude:: runtime:: profile_cache:: 387 passed, 0 failed, including three new tests; cargo clippy --locked --all-targets --all-features --release -- -D warnings fails at two places this change does not touch. Full suite not run. operator verification: unknown
  • unsure: propagating a failed stamp as a failed switch instead of repointing anyway; and macOS, where the new call runs after the Keychain mirror but was never executed
commands and details
  • New tests: global_switch_between_equal_mtime_stores_stays_visible_to_running_sessions (A→B→A), guarded_relink_between_equal_mtime_stores_stays_visible_to_running_sessions, global_switch_leaves_a_store_alone_when_its_mtime_already_differs.
  • End to end: synthetic profiles in an isolated home, fake bearers, a local HTTP sink, one long-lived Claude Code 2.1.289 process (the native CLI and the binary bundled in the agent SDK), sidecars forced to one mtime, clauth switch A→B→A. The sink saw A, A, A before this change and A, B, A with it.
  • clippy failures on this toolchain: src/daemon/api/mod.rs:144 (deprecated fetch_update) and src/fallback.rs:1775 (needless borrow).

…s running sessions

Claude Code re-reads .credentials.json only when the mtime of what the link
resolves to differs from the one it memoized. The runtime swap already moves
the incoming store mtime first; the global switch (clauth switch, and the
guarded relink) did not, so between two stores carrying the same mtime the
link moved, the switch reported success, and running sessions kept
authenticating as the account they had been switched off.

Both relinks now stamp the incoming store through the same touch and receipt
the runtime swap uses, only when the live path resolves to a different store
with an equal mtime, after the Keychain mirror and before the repoint.

Also corrects the session-token sample in docs/claude-split: a sidecar that
carries a refreshToken key, even empty, is not accepted and the switch then
installs the rotating pair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xingfanxia

Copy link
Copy Markdown
Owner Author

Superseded: the fix landed on fork main as 40ebca4 + faad403 (ported from upstream PR uwuclxdy#175).

@xingfanxia xingfanxia closed this Nov 10, 2026
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