Files
magpie/internal/gateway/wall.go
T
yetone 8769a5819a gateway: a rest ends at the time it shows, after the Mac slept (plugins#1126)
A rest's end came from time.Now().Add(d), which carries Go's monotonic
reading, and restOf and Retry-After compared by it. On macOS that clock
stops while the computer sleeps, so a WorkBuddy AI rest to 00:40 still
held at 09:57 the next day: 17h22m past its end, against 17h26m of
sleep in pmset's log over the same span (Xiang-Player's measurements).

onWall drops the monotonic reading. It is applied where magpie keeps a
deadline for minutes to days: the three places a rest's end is set
(restAfterMarked, restSlow, restDrawer), Codex's held refusal, Claude's
quota shelf, a Codex window's reset and a search key's rest. Shorter
waits (a request's patience, ten-minute shuns) are left as they are; a
sleep can only stretch them by their own length.

TestRestsKeepTheWallClock records a rest through the quota and 500
paths, a slow start and a search key, and checks none counts on the
monotonic clock.

Run on mica at this tree: go vet ./internal/gateway (darwin, linux,
windows); go test ./internal/gateway -count=1 -timeout 45m: ok (883s).
Broken by hand: onWall returning t unchanged turns the test red on all
four paths.
Not tried: a real Mac sleeping past a rest; a test can't sleep the
machine.

At the pushed head (rebased on 42cc55701, which adds internal/provider/quota_shown.go): go vet ./internal/gateway ./internal/provider and go test ./internal/gateway -run "Rest|TestOneRequestDoesNotClimbTheBackoff": ok.
2026-11-14 19:44:23 +08:00

13 lines
590 B
Go

package gateway
import "time"
// onWall gives t on the wall clock alone, for a deadline magpie keeps for
// minutes to days: a rest, a hold, a window's reset. A time from
// time.Now() also carries the monotonic clock, and Go compares two such
// times by it; on macOS it stops while the computer sleeps, so a rest set
// before a night's sleep ran that night longer than the time it shows
// (plugins#1126: a rest to 00:40 still held at 09:57). On the wall clock
// alone, Before, After, Sub and time.Until read the time it says.
func onWall(t time.Time) time.Time { return t.Round(0) }