Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

checkin: a plugin's until is when its answer stops holding (Qoder's 10:00 UTC+8)

yetonea05b3735381c
diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md
index 116a6998a..deac995d0 100644
--- a/docs/subsystems/provider-plugins.md
+++ b/docs/subsystems/provider-plugins.md
@@ -54,9 +54,9 @@ A plugin whose vendor counts no cache tokens says so with `usage.magpie_cache_un
A plugin can press its vendor's daily check-in (签到) itself: its `auth` hook gains `checkin(getAuth, provider)`, beside `usage`. The host lists the provider with `checkin: true` (`plugin.Provider.Checkin`) and answers `checkin({provider, account})` (`plugin.AccountCheckin`) by refreshing the account as `usage` does and calling the hook with the account's auth.
-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; for an outcome not in the list the reason names what the plugin answered, before its own message (`the plugin answered "yes": …`), so a plugin's wording isn't read as magpie's. `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. An `inactive` or `ineligible` result with a `message` shows it beside the fixed label ("No check-in event now · <message>") on the card, where it wraps rather than ends in "…", in Settings' check-in line and in `magpie accounts checkin`; the TUI's narrow cell says `c` says why, and `c`'s flash carries it (plugins#304). Without a message the label reads alone.
+The hook returns `{outcome, credit?, streak?, message?, until?}`. `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; for an outcome not in the list the reason names what the plugin answered, before its own message (`the plugin answered "yes": …`), so a plugin's wording isn't read as magpie's. `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. An `inactive` or `ineligible` result with a `message` shows it beside the fixed label ("No check-in event now · <message>") on the card, where it wraps rather than ends in "…", in Settings' check-in line and in `magpie accounts checkin`; the TUI's narrow cell says `c` says why, and `c`'s flash carries it (plugins#304). Without a message the label reads alone.
-[`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. A `done`, `inactive` or `ineligible` answered before noon Beijing (`checkinSureHour`) for an account magpie hasn't seen claim that Beijing day is provisional (`provisional`, #3326): a vendor whose day turns at UTC midnight (08:00 Beijing) or later still answers yesterday's "already" at 00:00, and magpie took it for today's and never asked again. The loop asks it again 30 minutes after the answer, until a claim or an answer from noon on, so at most 24 more asks a day and none once magpie claims; a press (`soon`) asks it again at once, whatever the hour, since the vendor's answer is what the press is for. A claim stamps `Claimed`, carried over while later answers that day say done, so a done after magpie's own claim is settled. Such a record is sent with `again: true` (`shown`, never kept), and the card, Settings, TUI and CLI say the vendor said already checked in and magpie asks again later, not "Checked in today", and the card keeps *Check in now*. A vendor whose day turns after noon Beijing (a US day) is not covered. The Qoder and Qoder CN plugins are the exception, as magpie's own Qoder check-in is (`recheck`, `pluginRechecks`, #2696): a campaign can open mid-day (Qoder CN's ran 10:00 to 09:59 the next day), so the loop asks again 30 minutes after the last answer whatever it was, and *Check in now* asks at once, and their card keeps *Check in now* for an `inactive` result. Every other plugin keeps the day's result. Results are kept in `plugin-checkin.json` by `provider|<sign-in key>` (`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|<display name>` 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:<provider>"`), 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}`). The press says what it came to, a count per kind (`checkinPressSaid`, #3326): claimed now with the credits, already checked in today, not available yet (`inactive`, `ineligible`, or an `again` answer), to check in in the vendor's own app, failed; a result is claimed now only when it carries `asked` (`Asked`, sent but never kept), so an account claimed earlier today counts as already. `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. A `done`, `inactive` or `ineligible` answered before noon Beijing (`checkinSureHour`) for an account magpie hasn't seen claim that Beijing day is provisional (`provisional`, #3326): a vendor whose day turns at UTC midnight (08:00 Beijing) or later still answers yesterday's "already" at 00:00, and magpie took it for today's and never asked again. The loop asks it again 30 minutes after the answer, until a claim or an answer from noon on, so at most 24 more asks a day and none once magpie claims; a press (`soon`) asks it again at once, whatever the hour, since the vendor's answer is what the press is for. A claim stamps `Claimed`, carried over while later answers that day say done, so a done after magpie's own claim is settled. Such a record is sent with `again: true` (`shown`, never kept), and the card, Settings, TUI and CLI say the vendor said already checked in and magpie asks again later, not "Checked in today", and the card keeps *Check in now*. A vendor whose day turns after noon Beijing (a US day) is not covered. The Qoder and Qoder CN plugins are the exception, as magpie's own Qoder check-in is (`recheck`, `pluginRechecks`, #2696): a campaign can open mid-day (Qoder CN's ran 10:00 to 09:59 the next day), so the loop asks again 30 minutes after the last answer whatever it was, and *Check in now* asks at once, and their card keeps *Check in now* for an `inactive` result. Every other plugin keeps the day's result. A plugin whose vendor's day turns at another hour says when in `until` (an RFC 3339 time or epoch milliseconds; `host.js` passes it on as RFC 3339, `plugin.Checkin.Until`), kept as the record's `ValidUntil`: the answer is settled only until then, whatever its outcome (`settled`), the loop wakes then rather than at its next 30-minute look (`wbCheckinLoop.tick`), and an early `done` that says it isn't provisional, since the vendor said when its day turns. Qoder's daily credits open at 10:00 UTC+8 and close at 09:59 the next day (its `/me/campaigns` `startAt`/`endAt`); the Qoder plugins from 0.2.43 answer `until` a minute past the next opening, so a check-in before 10:00, which claims or meets the day before's campaign, is asked again at 10:01, not up to half an hour later (sdytman on Discord). Times are compared as instants, so the machine's zone doesn't matter. Results are kept in `plugin-checkin.json` by `provider|<sign-in key>` (`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|<display name>` 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:<provider>"`), 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}`). The press says what it came to, a count per kind (`checkinPressSaid`, #3326): claimed now with the credits, already checked in today, not available yet (`inactive`, `ineligible`, or an `again` answer), to check in in the vendor's own app, failed; a result is claimed now only when it carries `asked` (`Asked`, sent but never kept), so an account claimed earlier today counts as already. `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.
@@ -218,7 +218,7 @@ Gateway parity tests in [`plugin_parity_test.go`](../../internal/gateway/plugin_
[`plugin_decide_test.go`](../../internal/gateway/plugin_decide_test.go) runs the fake plugin (`FAKE_DECIDE`) with a decision API: its marked and `jev-*` models are classifiers and not offered to agents, chat to one is refused, a group saves one as classifier, not beside a chat model, and a group of decision models alone, and each classifier's question reaches the fake vendor at `/v1/systemone` through the plugin's fetch. With `FAKE_DECIDE=models` the marks without `decide` change nothing.
-[`plugin_checkin_test.go`](../../internal/provider/plugin_checkin_test.go) runs the fake plugin's `auth.checkin` (`FAKE_CHECKIN`) through the schedule: off, each outcome, no second press the same day, failures only after the retry window, the next day, cards and Settings, and the vendor check-in stepping aside; `TestPluginCheckinTellsSignInsOfOneNameApart` signs in four accounts under two names, two of each (plugins#254), and checks each is checked in, kept, carded and switched off on its own, and `TestPluginCheckinCarriesOverDisplayNameEntries` upgrades a file and an `Off` kept by display name. `TestPluginCheckinQoderRechecksCampaigns` holds the Qoder plugins' recheck, by the loop and a press, after `inactive` and `done`, `TestPluginCheckinOthersSettledForTheDay` every other plugin's day from noon Beijing, and `TestPluginCheckinEarlyDoneAskedAgain` the reporter's 00:00:28 done asked again by the loop and a press (#3326); `checkin-early-done.test.cjs` covers that card; `qoder-checkin-recheck.test.cjs` covers the card's press. `plugin-checkin.test.cjs` covers the card row and the Settings tab.
+[`plugin_checkin_test.go`](../../internal/provider/plugin_checkin_test.go) runs the fake plugin's `auth.checkin` (`FAKE_CHECKIN`) through the schedule: off, each outcome, no second press the same day, failures only after the retry window, the next day, cards and Settings, and the vendor check-in stepping aside; `TestPluginCheckinTellsSignInsOfOneNameApart` signs in four accounts under two names, two of each (plugins#254), and checks each is checked in, kept, carded and switched off on its own, and `TestPluginCheckinCarriesOverDisplayNameEntries` upgrades a file and an `Off` kept by display name. `TestPluginCheckinQoderRechecksCampaigns` holds the Qoder plugins' recheck, by the loop and a press, after `inactive` and `done`, `TestPluginCheckinOthersSettledForTheDay` every other plugin's day from noon Beijing, and `TestPluginCheckinEarlyDoneAskedAgain` the reporter's 00:00:28 done asked again by the loop and a press (#3326); `TestPluginCheckinAsksAgainAtUntil` holds the clock from 09:27 Beijing through the next day's 10:30, with the machine in UTC, UTC-8 and Beijing, and checks the asks land at 09:27, 10:01, the Beijing day's turn and 10:01 again, and a failure in the 09:59 gap at 10:01; `checkin-early-done.test.cjs` covers that card; `qoder-checkin-recheck.test.cjs` covers the card's press. `plugin-checkin.test.cjs` covers the card row and the Settings tab.
[`plugin_options_test.go`](../../internal/plugin/plugin_options_test.go) loads `testdata/options` in a real host: which declared options are kept and how they are capped, the user's value over the default at start, a change read by the plugin after `SetProviderOptions` without a restart, and a models hook's list that goes by an option following it after the change. [`plugin_option_api_test.go`](../../internal/gui/plugin_option_api_test.go) covers the endpoint, a bad key, and a Settings save keeping the values. `plugin-options.test.cjs` covers the editor in Chromium and WebKit, 1100 and 420 wide, in every language.
diff --git a/internal/plugin/host.js b/internal/plugin/host.js
index 2ddda42e7..924039656 100644
--- a/internal/plugin/host.js
+++ b/internal/plugin/host.js
@@ -2461,10 +2461,13 @@ async function usageOf(provider, account) {
// "ineligible" (the account can't take part) | "inactive" (no
// check-in running) | "captcha" (the vendor asks for a captcha: the
// user checks in in its own app; never solved) | "failed",
-// credit? (what it gave), streak? (days in a row), message?
+// credit? (what it gave), streak? (days in a row), message?,
+// until? (when the vendor's own day turns: an RFC 3339 time or epoch
+// milliseconds; Qoder's daily credits open at 10:00 UTC+8)
// }
// magpie asks once a Beijing day per account while the user has it on, and
-// again later that day after a failure; a hook that throws is a failure.
+// again later that day after a failure, or at until; a hook that throws is
+// a failure.
// Run in the account's scope, a token it renews is saved to that account.
async function checkin({ provider, account, proxy }) {
return via.run(proxy ?? "", () => checkinOf(provider, account))
@@ -2482,11 +2485,14 @@ async function checkinOf(provider, account) {
const r = (await inScope(provider, key, () => a.checkin(async () => authCopy(key), JSON.parse(JSON.stringify(p))))) ?? {}
const num = (v) => (typeof v === "number" && isFinite(v) ? Math.max(0, v) : 0)
const message = typeof r.message === "string" ? r.message : ""
+ // a time that doesn't read is not told
+ const t = typeof r.until === "number" ? r.until : typeof r.until === "string" ? Date.parse(r.until) : NaN
+ const until = Number.isFinite(t) && t > 0 ? new Date(t).toISOString() : ""
if (!checkinOutcomes.includes(r.outcome)) {
const said = r.outcome === undefined || r.outcome === null ? "no outcome" : JSON.stringify(r.outcome)
- return { outcome: "failed", credit: 0, streak: 0, message: message ? `the plugin answered ${said}: ${message}` : `the plugin answered ${said}` }
+ return { outcome: "failed", credit: 0, streak: 0, message: message ? `the plugin answered ${said}: ${message}` : `the plugin answered ${said}`, until }
}
- return { outcome: r.outcome, credit: num(r.credit), streak: Math.round(num(r.streak)), message }
+ return { outcome: r.outcome, credit: num(r.credit), streak: Math.round(num(r.streak)), message, until }
}
// sdkHeaders are what the AI SDK package the model is on sends of the key.
diff --git a/internal/plugin/providers.go b/internal/plugin/providers.go
index 256c02e74..c55760b8c 100644
--- a/internal/plugin/providers.go
+++ b/internal/plugin/providers.go
@@ -1102,12 +1102,15 @@ type UsageWindow struct {
// Checkin is what came of an account's daily check-in, as the plugin's
// auth.checkin said: Outcome is one of claimed, done, ineligible,
-// inactive, captcha and failed.
+// inactive, captcha and failed. Until (RFC 3339, "" when not told) is when
+// the vendor's own day turns and the answer stops holding: Qoder's daily
+// credits open at 10:00 UTC+8, not at Beijing midnight.
type Checkin struct {
Outcome string `json:"outcome"`
Credit float64 `json:"credit"`
Streak int `json:"streak"`
Message string `json:"message"`
+ Until string `json:"until"`
}
// AccountCheckin asks the plugin to check account of provider in for the
diff --git a/internal/plugin/testdata/fake/index.js b/internal/plugin/testdata/fake/index.js
index 24a645de2..081c7fa63 100644
--- a/internal/plugin/testdata/fake/index.js
+++ b/internal/plugin/testdata/fake/index.js
@@ -267,7 +267,8 @@ export const FakePlugin = async ({ client }) => ({
// account's name/uid, so two of one name tell apart), and the
// answer said by the key: ck-claim gives 50 on a 3-day streak, ck-done
// is in already, ck-captcha is asked a captcha, ck-throw can't reach
- // the vendor, ck-odd answers no outcome magpie knows
+ // the vendor, ck-odd answers no outcome magpie knows, and ck-until
+ // answers what the test wrote to <FAKE_CHECKIN>.until ({outcome, until})
...(process.env.FAKE_CHECKIN
? {
checkin: async (getAuth) => {
@@ -285,6 +286,8 @@ export const FakePlugin = async ({ client }) => ({
throw new Error("FakeCo's check-in is down")
case "ck-odd":
return { outcome: "yes", message: "the daily credits were refreshed" }
+ case "ck-until":
+ return JSON.parse(fs.readFileSync(process.env.FAKE_CHECKIN + ".until", "utf8"))
}
return { outcome: "inactive" }
},
diff --git a/internal/provider/checkin.go b/internal/provider/checkin.go
index 0c4d9c244..870f015a7 100644
--- a/internal/provider/checkin.go
+++ b/internal/provider/checkin.go
@@ -97,8 +97,9 @@ func (c checkiner) checkinNow(ctx context.Context, soon bool) []WorkBuddyCheckin
settled = false
}
// and the loop asks again an answer that may be the vendor's
- // day before (#3326)
- if settled && prev.provisional() {
+ // day before (#3326), unless the vendor said when its day turns
+ // (ValidUntil, held to in settled)
+ if settled && prev.provisional() && prev.ValidUntil.IsZero() {
settled = now.Sub(prev.At) < wbCheckinEvery
}
if c.recheck {
diff --git a/internal/provider/plugin_checkin.go b/internal/provider/plugin_checkin.go
index 33f48e18f..bec2a7a8a 100644
--- a/internal/provider/plugin_checkin.go
+++ b/internal/provider/plugin_checkin.go
@@ -90,7 +90,13 @@ var pluginCheckinProviders = func() []pluginCheckinProvider {
if err != nil {
return wbCheckinFailed(err)
}
- return WorkBuddyCheckin{Outcome: c.Outcome, Credit: c.Credit, Streak: c.Streak, Msg: c.Message}
+ r := WorkBuddyCheckin{Outcome: c.Outcome, Credit: c.Credit, Streak: c.Streak, Msg: c.Message}
+ // the vendor's own day turns then (Qoder's 10:00
+ // UTC+8); a time that doesn't parse is not told
+ if t, err := time.Parse(time.RFC3339, c.Until); err == nil {
+ r.ValidUntil = t
+ }
+ return r
}})
}
if len(p.accounts) > 0 {
diff --git a/internal/provider/plugin_checkin_test.go b/internal/provider/plugin_checkin_test.go
index 388b4a547..4f2d959f8 100644
--- a/internal/provider/plugin_checkin_test.go
+++ b/internal/provider/plugin_checkin_test.go
@@ -663,3 +663,112 @@ func TestPluginCheckinEarlyDoneAskedAgain(t *testing.T) {
}
})
}
+
+// A plugin whose vendor's day turns at another hour says when (until):
+// Qoder's daily credits open at 10:00 UTC+8 and stay open until 09:59 the
+// next day (sdytman on Discord). A check-in before 10:00 meets the day
+// before's campaign; magpie asks again as the plugin said, a minute past
+// 10:00, not the next Beijing day, and not before, whatever the machine's
+// zone; a failure in the gap is asked again then too.
+func TestPluginCheckinAsksAgainAtUntil(t *testing.T) {
+ presses := pluginCheckinSandbox(t, "ck-until")
+ s := settings.Load()
+ s.PluginCheckins = map[string]bool{"fakeco": true}
+ if err := settings.Save(s); err != nil {
+ t.Fatal(err)
+ }
+ answer := func(outcome string, until time.Time) {
+ t.Helper()
+ b, _ := json.Marshal(map[string]any{"outcome": outcome, "credit": 100, "until": until.UTC().Format(time.RFC3339)})
+ if err := os.WriteFile(presses+".until", b, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ // the plugin's answer at t: before 10:00 Beijing, the day before's
+ // campaign (claimed at its first ask, done after), until today's 10:01
+ opens := func(at time.Time) time.Time {
+ b := at.In(beijing)
+ o := time.Date(b.Year(), b.Month(), b.Day(), 10, 1, 0, 0, beijing)
+ if !at.Before(o) {
+ o = o.AddDate(0, 0, 1)
+ }
+ return o
+ }
+ defer func(l *time.Location) { time.Local = l }(time.Local)
+ for _, zone := range []*time.Location{time.UTC, time.FixedZone("UTC-8", -8*3600), beijing} {
+ t.Run(zone.String(), func(t *testing.T) {
+ time.Local = zone
+ if err := os.Remove(pluginCheckinPath()); err != nil && !os.IsNotExist(err) {
+ t.Fatal(err)
+ }
+ _ = os.Remove(presses)
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ defer cancel()
+ now := time.Date(2026, 10, 28, 9, 27, 0, 0, beijing).In(zone)
+ c := pluginCheckiner{now: func() time.Time { return now }, only: func(id string) bool { return PluginCheckinOn(settings.Load(), id) }}
+ var l wbCheckinLoop
+ var at []string
+ claimed := map[string]bool{}
+ end := time.Date(2026, 10, 29, 10, 30, 0, 0, beijing)
+ for ; now.Before(end); now = now.Add(time.Minute) {
+ o := opens(now)
+ if campaign := o.AddDate(0, 0, -1).Format("01-02"); claimed[campaign] {
+ answer(CheckinDone, o)
+ } else {
+ answer(CheckinClaimed, o)
+ }
+ for _, r := range l.tick(ctx, c) {
+ if !r.Asked {
+ continue
+ }
+ at = append(at, now.In(beijing).Format("01-02 15:04"))
+ if r.ValidUntil.IsZero() || !r.ValidUntil.Equal(o) {
+ t.Fatalf("at %v: until %v, want %v (%+v)", now, r.ValidUntil, o, r)
+ }
+ if r.Outcome == CheckinClaimed {
+ claimed[o.AddDate(0, 0, -1).Format("01-02")] = true
+ }
+ }
+ }
+ // 09:27 claims the 10-27 campaign, 10:01 the 10-28 one, the
+ // Beijing day's turn asks once (done), 10:01 claims 10-29's
+ if want := []string{"10-28 09:27", "10-28 10:01", "10-29 00:00", "10-29 10:01"}; !slices.Equal(at, want) {
+ t.Fatalf("asked at %q, want %q", at, want)
+ }
+ if p := pressed(t, presses); len(p) != 4 {
+ t.Fatalf("pressed %q", p)
+ }
+ if len(claimed) != 3 {
+ t.Fatalf("claimed %v", claimed)
+ }
+
+ // in the gap (09:59:30, yesterday's closed, today's not open):
+ // a failure, asked again at 10:01, not half an hour on
+ _ = os.Remove(presses)
+ l = wbCheckinLoop{}
+ now = time.Date(2026, 10, 30, 9, 59, 30, 0, beijing).In(zone)
+ b, _ := json.Marshal(map[string]any{"outcome": CheckinFailed, "message": "today's credits aren't offered yet", "until": opens(now).UTC().Format(time.RFC3339)})
+ if err := os.WriteFile(presses+".until", b, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if rs := l.tick(ctx, c); len(rs) != 1 || rs[0].Outcome != CheckinFailed || !rs[0].Asked {
+ t.Fatalf("the gap: %+v", rs)
+ }
+ answer(CheckinClaimed, opens(now).AddDate(0, 0, 1))
+ var again []string
+ for now = now.Add(30 * time.Second); now.Before(time.Date(2026, 10, 30, 10, 2, 0, 0, beijing)); now = now.Add(30 * time.Second) {
+ for _, r := range l.tick(ctx, c) {
+ if r.Asked {
+ again = append(again, now.In(beijing).Format("15:04:05"))
+ }
+ }
+ }
+ if !slices.Equal(again, []string{"10:01:00"}) {
+ t.Fatalf("after the gap, asked at %q, want 10:01:00", again)
+ }
+ if p := pressed(t, presses); len(p) != 2 {
+ t.Fatalf("after the gap, pressed %q", p)
+ }
+ })
+ }
+}
diff --git a/internal/provider/workbuddy_checkin.go b/internal/provider/workbuddy_checkin.go
index 82eefbd60..b80e821d2 100644
--- a/internal/provider/workbuddy_checkin.go
+++ b/internal/provider/workbuddy_checkin.go
@@ -107,8 +107,9 @@ type WorkBuddyCheckin struct {
Credit float64 `json:"credit,omitempty"`
Streak int `json:"streak,omitempty"`
Msg string `json:"msg,omitempty"`
- // ValidUntil is a campaign's end, when a successful answer must be
- // checked again, even if the Beijing day hasn't changed.
+ // ValidUntil is a campaign's end, or when a plugin said its vendor's
+ // day turns (auth.checkin's until), when the answer must be checked
+ // again, even if the Beijing day hasn't changed.
ValidUntil time.Time `json:"until,omitzero"`
// Offline is a failure that never reached WorkBuddy, and Tries how
// many before it the same day did the same.
@@ -182,10 +183,12 @@ func (r WorkBuddyCheckin) Checked() bool {
return r.Outcome == CheckinClaimed || r.Outcome == CheckinDone
}
-// settled says whether r answers for day: it is that day's, and not a
-// failure due another try (at now; soon, at once).
+// settled says whether r answers for day: it is that day's, not past
+// ValidUntil (a plugin's vendor whose day turns at another hour said when:
+// Qoder's daily credits open at 10:00 UTC+8, sdytman on Discord), and not
+// a failure due another try (at now; soon, at once).
func (r WorkBuddyCheckin) settled(day string, now time.Time, soon bool) bool {
- if r.Day != day {
+ if r.Day != day || !r.ValidUntil.IsZero() && !now.Before(r.ValidUntil) {
return false
}
return r.Outcome != CheckinFailed || !soon && now.Sub(r.At) < r.retryAfter()
@@ -609,10 +612,15 @@ func (l *wbCheckinLoop) tick(ctx context.Context, c checkinRunner) []WorkBuddyCh
defer cancel()
rs := c.checkinNow(cx, false)
for _, r := range rs {
- if r.Outcome != CheckinFailed {
- continue
+ due := time.Time{}
+ if r.Outcome == CheckinFailed {
+ due = r.At.Add(r.retryAfter())
+ }
+ // and as the vendor's own day turns, when it said (ValidUntil)
+ if u := r.ValidUntil; u.After(now) && (due.IsZero() || u.Before(due)) {
+ due = u
}
- if due := r.At.Add(r.retryAfter()); l.again.IsZero() || due.Before(l.again) {
+ if !due.IsZero() && (l.again.IsZero() || due.Before(l.again)) {
l.again = due
}
}