From a8ecf4020e3b9fedd1ff5cc1de64c0bfc4f5810b Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 21 Oct 2026 07:11:33 +0800 Subject: [PATCH] provider: a check-in file that can't be read or parsed stops the check-in readCheckins, the reader every daily check-in shares (WorkBuddy, Trae CN, MiniMax Code, Qoder and the plugins' own), took a file it couldn't read or parse as empty. The next check-in then asked the vendor again for every account and wrote its answers over the file: an account could be checked in twice in one day, and the entries it couldn't read were lost. readCheckins now returns an error for a file that is there but can't be read, or doesn't parse into entries (cut short, zeroed, empty, `[]`, `null`). A file not there is still empty. On the error: - checkiner.checkinNow asks nothing and writes nothing. Each account it would look at is `failed` with the reason (the path and why), so the loop tries again after 30 minutes and a press (GUI, TUI, `magpie accounts checkin`) says why. The error is logged once while it stays the same. - The readers that only show results (WithCheckins, *Checkins(), PluginCheckins) go through shownCheckins, which gives what last read from the file in this process, so a card keeps its last good data. - adoptLegacyPluginCheckins' own strict copy of the read now uses readCheckins too. Docs: providers-accounts.md no longer lists check-in marks among the caches written over; provider-plugins.md says the plugin file's case. Test: TestCheckinUnreadableFileLeftAlone writes a cut-short, zeroed, empty, `[]` and `null` workbuddy-checkin.json, runs the loop and a press against a fake WorkBuddy, and checks no status or claim request went out, the file is byte for byte unchanged, and the result says the path; a folder in place of plugin-checkin.json does the same through a plugin checkiner. TestCheckinMissingFileIsEmpty and TestCheckinUnreadableKeepsLastGood cover the other two sides. Broken by hand (checkinNow taking the error as an empty map again): the test went red, every case claimed (Asked true), and green once restored. Run in a worktree at origin/main 62a1df801, sandbox HOME (testenv): - gofmt -l . : clean - go vet ./... (darwin), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... : all exit 0 - set -o pipefail; go test -timeout 45m ./... : exit 0, 68 packages ok, none failed (internal/gateway 613s, internal/agent 529s, internal/provider 262s) No red seen, so no issue filed. --- docs/subsystems/provider-plugins.md | 2 +- docs/subsystems/providers-accounts.md | 2 +- internal/provider/checkin.go | 27 ++++- internal/provider/checkin_unreadable_test.go | 118 +++++++++++++++++++ internal/provider/minimax_checkin.go | 2 +- internal/provider/plugin_checkin.go | 19 +-- internal/provider/plugin_checkin_test.go | 6 +- internal/provider/qoder_checkin.go | 2 +- internal/provider/qoder_checkin_test.go | 2 +- internal/provider/trae_checkin.go | 2 +- internal/provider/workbuddy_checkin.go | 76 ++++++++++-- 11 files changed, 227 insertions(+), 31 deletions(-) create mode 100644 internal/provider/checkin_unreadable_test.go diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md index fd9f0747f..f08b93796 100644 --- a/docs/subsystems/provider-plugins.md +++ b/docs/subsystems/provider-plugins.md @@ -44,7 +44,7 @@ A plugin can press its vendor's daily check-in (签到) itself: its `auth` hook The hook returns `{outcome, credit?, streak?, message?}`. `outcome` is one of `claimed` (checked in now), `done` (already in today), `ineligible`, `inactive` (no check-in event now), `captcha` or `failed`. A throw, or an outcome not in that list, is `failed` with the reason. `captcha` means the vendor wants a captcha: magpie never solves one, and says "check in in its own app" instead. A plugin must not solve captchas either. -[`plugin_checkin.go`](../../internal/provider/plugin_checkin.go) runs these through the same `checkiner` as the built-in check-ins ([`checkin.go`](../../internal/provider/checkin.go)): each signed-in, in-use account once a Beijing day, the first look 2 minutes after start and then every 30 minutes, a `failed` asked again after 30 minutes, every other outcome settled for the day. Results are kept in `plugin-checkin.json` by `provider|` (`pluginCheckinKey`: the key `plugin-auth.json` keeps the sign-in under, `autoclaw` or `autoclaw#x1y2z3`), never by the display name: two sign-ins can share a name (AutoClaw's default can't be changed), and keyed by it only the first of them was ever checked in, by the loop or *Check in now* (plugins#254). The sign-in key holds over a refresh and over signing in to the same account again (`settle` in `host.js` puts it back under its key); a sign-in made after one was signed out the same day may take the freed key, and with it that day's result. An entry kept by `provider|` before then is carried over once the plugin's accounts are listed (`adoptLegacyPluginCheckins`): a check-in goes to the first sign-in in use of that name, the one the old key asked, and only to it, so its namesakes are asked and none twice; an `Off` in `settings.CheckinOff` goes to every sign-in of that name, since none of them was checked in while it was off. A `plugin-checkin.json` that can't be read or parsed is left as it is and carried over once it reads. A failure is recorded as failed and never resets an account, a key or a previous day's result. Each account's Usage card has the check-in row (`checkinBy: "plugin:"`), and Settings → Usage has a Plugins tab with a Daily check-in switch per provider (`settings.PluginCheckins`, `POST /api/settings/plugin-checkin {provider, on}`; *Check in now* is `POST /api/usage/plugin-checkin {provider}`). `magpie accounts checkin` and `c` on the TUI's Usage page include them. Every check-in, built-in or a plugin's, also skips an account listed in `settings.CheckinOff` by its file key (#1902): `checkinNow` asks nothing for it, by the loop or a press, `CheckinAccounts()` lists each account with its own `on` for Settings (`checkinAccounts`, a row each under the vendor's switch when it has two or more, `POST /api/settings/checkin-account {key, on}`), and its card carries `checkinOff`. +[`plugin_checkin.go`](../../internal/provider/plugin_checkin.go) runs these through the same `checkiner` as the built-in check-ins ([`checkin.go`](../../internal/provider/checkin.go)): each signed-in, in-use account once a Beijing day, the first look 2 minutes after start and then every 30 minutes, a `failed` asked again after 30 minutes, every other outcome settled for the day. Results are kept in `plugin-checkin.json` by `provider|` (`pluginCheckinKey`: the key `plugin-auth.json` keeps the sign-in under, `autoclaw` or `autoclaw#x1y2z3`), never by the display name: two sign-ins can share a name (AutoClaw's default can't be changed), and keyed by it only the first of them was ever checked in, by the loop or *Check in now* (plugins#254). The sign-in key holds over a refresh and over signing in to the same account again (`settle` in `host.js` puts it back under its key); a sign-in made after one was signed out the same day may take the freed key, and with it that day's result. An entry kept by `provider|` before then is carried over once the plugin's accounts are listed (`adoptLegacyPluginCheckins`): a check-in goes to the first sign-in in use of that name, the one the old key asked, and only to it, so its namesakes are asked and none twice; an `Off` in `settings.CheckinOff` goes to every sign-in of that name, since none of them was checked in while it was off. A `plugin-checkin.json` that can't be read or parsed is left as it is and carried over once it reads; until then no plugin account is checked in, and each says why (`readCheckins`, as for every vendor's check-in file). A failure is recorded as failed and never resets an account, a key or a previous day's result. Each account's Usage card has the check-in row (`checkinBy: "plugin:"`), and Settings → Usage has a Plugins tab with a Daily check-in switch per provider (`settings.PluginCheckins`, `POST /api/settings/plugin-checkin {provider, on}`; *Check in now* is `POST /api/usage/plugin-checkin {provider}`). `magpie accounts checkin` and `c` on the TUI's Usage page include them. Every check-in, built-in or a plugin's, also skips an account listed in `settings.CheckinOff` by its file key (#1902): `checkinNow` asks nothing for it, by the loop or a press, `CheckinAccounts()` lists each account with its own `on` for Settings (`checkinAccounts`, a row each under the vendor's switch when it has two or more, `POST /api/settings/checkin-account {key, on}`), and its card carries `checkinOff`. The switch is off by default. For a provider whose vendor magpie checked in through the plugin's fetch before (WorkBuddy, Trae CN, MiniMax Code, Qoder), it follows that vendor's existing switch until set on its own, and magpie's own check-in leaves that provider's accounts to the plugin (`pluginChecksIn`), so an account is never checked in twice. diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md index f95a3eda0..033014368 100644 --- a/docs/subsystems/providers-accounts.md +++ b/docs/subsystems/providers-accounts.md @@ -216,7 +216,7 @@ and `TestHistoricalWindowHoldsUsesEachWindowsOwnReading`. - An unreadable `providers.json` is an error, never an empty list. Saving over an empty list would lose every provider. - When `logins.json` cannot be decoded as saved accounts, reads keep the accounts read before. Before saving a change, `lastgood.Keep` ([lastgood.go](../../internal/lastgood/lastgood.go)) keeps the file there now: as `logins.json.bak`, its last good generation, when it reads, or copied aside as `logins.json.bad-