mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 10:43:47 +00:00
The background tick skips the whole refresh when local session files are unchanged, but quota is server-side state, so the dock rings went stale until the popover was opened. Run the quota half on skipped ticks, still throttled by the subscription cadence. Also refresh the dock providers before the Claude/Codex awaits so a slow provider cannot delay them, anchor lastCodexRefreshAt on attempt like its siblings, and query display sleep live instead of latching a flag that a missed wake notification leaves stuck.
25 lines
998 B
Swift
25 lines
998 B
Swift
import Foundation
|
|
|
|
/// Scheduling decisions for the live quota refresh, kept out of the
|
|
/// AppKit-bound refresh loop so they are testable on their own.
|
|
enum QuotaRefreshDecision {
|
|
/// The CLI payload half of a tick is gated on local session-file mtimes.
|
|
/// Quota is server-side state (window resets, usage from other machines),
|
|
/// so a tick whose payload was skipped as unchanged still owes the quota
|
|
/// half a run; it self-throttles on SubscriptionRefreshCadence.
|
|
static func needsQuotaOnlyTick(payloadRefreshDue: Bool, payloadSkippedUnchanged: Bool) -> Bool {
|
|
payloadRefreshDue && payloadSkippedUnchanged
|
|
}
|
|
|
|
static func isDue(
|
|
force: Bool,
|
|
autoRefreshAllowed: Bool,
|
|
lastAttemptAt: Date?,
|
|
now: Date,
|
|
threshold: TimeInterval
|
|
) -> Bool {
|
|
if force { return true }
|
|
guard autoRefreshAllowed else { return false }
|
|
return now.timeIntervalSince(lastAttemptAt ?? .distantPast) >= threshold
|
|
}
|
|
}
|