provider: `this-device` on a signed-in subscription prints success but stores nothing, so sync still replaces it
Title: provider: this-device on a signed-in subscription prints success but stores nothing, so sync still replaces it
Version: magpie v0.1.4533 (Linux, Docker gateway). main at be400389 shows the same code.
Surface: CLI (GUI path affected too).
Setup: two computers syncing through GitHub; one is a server where the Claude subscription is signed in and must stay on, the other has the same provider id switched off.
Steps to reproduce
- Sign a subscription in on one computer (here: Claude Code, id
claude). magpie provider this-device claude yes→ prints✓ Claude Code stays on this device: sync doesn't send it out or change it.- Check the record:
providers.jsonhas nothisDeviceon theclaudeentry, and the file's size and mtime are unchanged. - The next sync replaces the provider with the other computer's switched-off copy, which turns Claude off on the server.
Expected: the record keeps "thisDevice": true, and provider.Mirror (internal/provider/backup.go:125,139) leaves it alone as it does for a plain provider.
Actual: nothing is written; the CLI reports success.
Root cause: provider.Save routes any id in Accounts() (a signed-in subscription) through accountSettings (internal/provider/provider.go:1125), which builds the stored record and copies ~45 fields (Models, Off, Routing, KeepLogin, …) but never ThisDevice. SetThisDevice (internal/provider/backup.go:272) only sets the field and calls Save, so the flag is dropped on the way to disk. The GUI's toggle (internal/gui/providers.go:3018) calls the same SetThisDevice.
Existing coverage misses it: internal/davsync/this_device_test.go uses a plain provider (ollama), never an id in Accounts().
Patch (one line):
func accountSettings(a, pk Provider) Provider {
a.PickedFrom, a.Delisted, a.DelistedAt = pk.PickedFrom, pk.Delisted, pk.DelistedAt
...
a.PassHeaders = pk.PassHeaders
a.ThisDevice = pk.ThisDevice // sync neither sends it out nor replaces it, a subscription too
return a
}
Test sketch: in internal/provider, write a login (writeLogins([]savedLogin{{Agent: "codex", User: "[email protected]", Plan: "pro"}}), as logins_test.go does), Save a picks-only record for codex, SetThisDevice("codex", true), then assert Stored() has ThisDevice set. On the current code it stays false.
Why it matters: this is the mechanism that exists today for exactly the case in #2966 — a subscription signed in on one computer among several that sync. It silently no-ops there, so the only workarounds are turning the providers part off on that computer or patching the file by hand (which the next save of that provider undoes).
provider: keep this-device on a signed-in account through Save
- Fork branch:
Gaoshou101:fix/account-this-device-7229(commit1e4737fd6) - Compare: https://github.com/yetone/magpie/compare/main...Gaoshou101:fix/account-this-device-7229
Fixes #7229
Root cause
Save routes any id in Accounts() (a signed-in subscription) through accountSettings (internal/provider/provider.go:1125), which copies the ~45 user-set fields onto the stored record — but never ThisDevice. SetThisDevice (internal/provider/backup.go:272) only sets the field and calls Save, so the flag was dropped on the way to providers.json while the CLI printed success. On the next sync the provider was replaced with the other computer's copy (Mirror, backup.go:125), switching a signed-in subscription off — exactly #2966's setup, today.
Change
One line plus its why-comment: accountSettings now copies a.ThisDevice = pk.ThisDevice like the rest of the picks. The flag lands on disk for an account as it already does for a plain provider, and Mirror's existing ThisDevice handling keeps it home from then on.
Test
New internal/provider/account_this_device_test.go (TestAccountThisDeviceKept), following the existing account-settings test pattern: with a written Codex/Copilot sign-in (signIn), SetThisDevice(id, true) must leave the flag in Stored() — Red before (stayed false for both accounts, reproducing the no-op), Green after — and SetThisDevice(id, false) clears it again, so nothing sticks behind the test's back.
$ go test -tags nogui ./internal/provider/ -run 'TestAccountThisDeviceKept' -count=1
ok github.com/yetone/magpie/internal/provider 0.520s
$ go test -tags nogui ./internal/provider/ -run 'TestAccount|TestDav|TestThis|TestSaved|TestSync' -count=1
ok github.com/yetone/magpie/internal/provider 11.344s
$ go test -tags nogui ./internal/davsync/ -count=1
ok github.com/yetone/magpie/internal/davsync 110.560s
Static: GOOS=linux and GOOS=windows go vet -tags nogui ./internal/provider/ clean; gofmt -l empty; git diff --check clean.
The patch follows the patch sketch in the issue; commit carries Co-authored-by: Dunqing per docs/contributors.md.