From 916d33b19f06881b2faa03c059337a82e5e16f4c Mon Sep 17 00:00:00 2001 From: ZCode Date: Sat, 7 Nov 2026 23:08:23 -0600 Subject: [PATCH] hotfix: alert on mid-window restores that roll the window forward MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CC-215's mid-window gates require the reported period end to hold still, so a restore where the vendor moves the end forward was missed entirely.  Two tests regressed with merged PR #378: the courtesy reset that rolls the window forward alerted nothing, and an early reset whose period end moved with a restore-sized rise alerted nothing either.  CI does not run swift tests on pushes to main, so both slipped through. Add a third route to the forward-jump rule: with the end still ahead, a restore-sized rise (vendorRestoreRise) that lands at or above the courtesy ceiling and started at or below it proves the reset.  A rolling slide cannot meet it: its climb is gradual, so one poll's rise past the ceiling never carries a 30-point rise with it. Fixes CC-218.  Owner 2026-11-07. --- Sources/QuotaCore/ResetAlarmTracker.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sources/QuotaCore/ResetAlarmTracker.swift b/Sources/QuotaCore/ResetAlarmTracker.swift index 4fbf52fc..10bfa26a 100644 --- a/Sources/QuotaCore/ResetAlarmTracker.swift +++ b/Sources/QuotaCore/ResetAlarmTracker.swift @@ -504,8 +504,27 @@ public struct ResetAlarmTracker: Sendable { // 3:48 pm, 5:03 pm and later false MiniMax and Antigravity // 5h alerts). Across a passed end the climb keeps settling // small early moves as before. + // A mid-window restore may also roll the window forward: the + // vendor reissues the period instead of holding it where it + // was. The evidence is the same shape the held-end rules + // below trust, sized up — a restore-sized rise that lands + // substantially restored. A rolling slide cannot meet it: + // its climb is gradual, so a single poll's rise past the + // ceiling never carries a 30-point rise with it (CC-215's + // false alerts moved a few points to a few tens of points + // across the boundary, never thirty). Owner 2026-11-07 + // (CC-218): a reset that moved the window end was missed + // entirely by the held-end rules. + let rolledRestore = reading.flatMap { current in + window.lastRemaining.map { + current >= ResetAlarmPolicy.courtesyRestoreCeiling + && $0 <= ResetAlarmPolicy.courtesyRestoreCeiling + && current >= $0 + ResetAlarmPolicy.vendorRestoreRise + } + } ?? false let forwardJump = jump > required || (jump > ResetAlarmPolicy.resetDriftTolerance && climbed && hasPassed) + || (!hasPassed && rolledRestore) if forwardJump { isReset = true // When the window had *not* reached its own scheduled end,