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

sdytman on Discord: Qoder's daily credits start at 10:00, can the plugin's
check-in follow it? Qoder's /me/campaigns opens each day's CLAIM_BENEFIT
campaign at 10:00 and closes it at 09:59 the next day, UTC+8 (startAt and
endAt, read with a real account on 10-28; Qoder.app polls the list every 5
minutes). A check-in before 10:00 meets the day before's campaign. Since
#2696 the Qoder plugins are asked again every 30 minutes, so today's was
claimed somewhere between 10:00 and 10:30; a plain plugin was settled for
the Beijing day.

auth.checkin may now answer until (RFC 3339 or epoch ms); host.js passes
it as RFC 3339 (plugin.Checkin.Until), kept as ValidUntil. settled holds
an answer only until then, whatever its outcome; the loop wakes at it
instead of its next 30-minute look; an early done that carries it is not
provisional (#3326), as the vendor said when its day turns. Instants
throughout, so the machine's zone doesn't matter. The Qoder plugins send
until from 0.2.43 (plugins fd40b20): the check-in now lands at 10:01.

Run (mote): TestPluginCheckinAsksAgainAtUntil, minute by minute from
09:27 Beijing to the next day's 10:30, with time.Local UTC, UTC-8 and
Beijing: asks at 09:27, 10:01, 00:00 (the Beijing day), 10:01; a failure
in the 09:59 gap asked at 10:01:00 only. GOOS=linux and windows go vet;
go test -tags nogui -timeout 45m ./... all ok (76 packages). gofmt -l
clean.
Broken by hand, each red: settled ignoring ValidUntil (no 10:01 asks);
tick not waking at it (10:27 instead); provisional ignoring it (asked
every 30 minutes from 00:00 to 10:00); host.js dropping until (ValidUntil
zero).
Not tried: the Qoder plugin's recheck path with until (the fake plugin
is fakeco; the tick and settled it goes through are the same); a GUI
change (none: until isn't shown).
This commit is contained in:
yetone
2026-10-28 09:51:43 +08:00
parent f39fc3ac8b
commit a05b373538
8 changed files with 156 additions and 20 deletions
File diff suppressed because one or more lines are too long
+10 -4
View File
@@ -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.
+4 -1
View File
@@ -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
+4 -1
View File
@@ -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" }
},
+3 -2
View File
@@ -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 {
+7 -1
View File
@@ -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 {
+109
View File
@@ -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)
}
})
}
}
+16 -8
View File
@@ -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())
}
if due := r.At.Add(r.retryAfter()); l.again.IsZero() || due.Before(l.again) {
// 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.IsZero() && (l.again.IsZero() || due.Before(l.again)) {
l.again = due
}
}