Repository navigation
Superseded By #357 — Do Not Merge - #356
jaywedgeworth22 wants to merge 4 commits into
Conversation
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
| let previousPeriod = window.periodSeconds, | ||
| abs(observedPeriod - previousPeriod) > ResetAlarmPolicy.resetDriftTolerance { | ||
| state.windows[key] = firstReading() | ||
| return nil | ||
| } | ||
|
|
||
| if let period = observation.periodSeconds { window.periodSeconds = period } | ||
|
|
||
| let readAt = observedAt ?? now | ||
| var isReset = false | ||
| var isMidWindow = false |
There was a problem hiding this comment.
Bug: Timestamp-derived cadence changes across varying-length periods (such as 30 vs 31-day months) trigger window rebaselining, dropping genuine rollover alerts.
Severity: MEDIUM
Suggested Fix
Allow tolerance for expected calendar variations or normalize timestamp-derived periods into standard calendar-month intervals before comparing cadence changes against resetDriftTolerance.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: Sources/QuotaCore/ResetAlarmTracker.swift#L462-L484
Potential issue: The cadence-change guard rebaselines the window and returns nil
whenever `observation.periodSeconds` differs from stored `periodSeconds` by more than 15
minutes. Some quota readers, such as Grok subscriptions, dynamically calculate period
tokens and durations from start and end timestamps (e.g. 30 days vs 31 days). When month
lengths change across consecutive periods, the difference exceeds `resetDriftTolerance`.
This causes `advance()` to reset the baseline via `firstReading()` instead of processing
a rollover transition, permanently dropping genuine `.newPeriod` rollover alerts and
resetting `minimumRemaining`.
Did we get this right? 👍 / 👎 to inform future reviews.
| Autofix run https://github.com/Simple-With-Us/CodeCaps/actions/runs/41678489457 started for `sentry[bot]`'s tagged request. Owner/sentry request: exempt from the per-bot cap (owner rule 2026-10-20). |
| let rose = reading.flatMap { current in | ||
| window.lastRemaining.map { current > $0 + ResetAlarmPolicy.riseEpsilon } | ||
| } ?? false | ||
| let resetHasQuotaEvidence = rose || (hasPassed && reading == nil) | ||
| if (jump > required && resetHasQuotaEvidence) | ||
| || (jump > ResetAlarmPolicy.resetDriftTolerance && climbed) { |
There was a problem hiding this comment.
Scheduled rollover missed with first measured reading after nil history
The check suppresses genuine resets because rose stays false when window.lastRemaining is nil, so resetHasQuotaEvidence blocks the hasPassed path. Treat missing window.lastRemaining as quota evidence when reading is present.
Prompt for LLM
File Sources/QuotaCore/ResetAlarmTracker.swift, lines 504-509:
Scheduled rollover missed with first measured reading after nil history
Scheduled rollover with first measured percentage after nil history never fires because rose is false when lastRemaining is nil. Genuine hasPassed jump with reading set but no prior baseline is suppressed, missing the reset the old jump>required caught. Treat missing lastRemaining as quota evidence for the hasPassed jump path, e.g. rose when window.lastRemaining is nil and reading is non-nil.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
| // A producer may reuse a window ID while switching its cadence. Its reset time and remaining percentage no longer share the old baseline. Keep the new reading as a baseline instead of comparing across periods. | ||
| if let observedPeriod = observation.periodSeconds, | ||
| let previousPeriod = window.periodSeconds, | ||
| abs(observedPeriod - previousPeriod) > ResetAlarmPolicy.resetDriftTolerance { | ||
| state.windows[key] = firstReading() | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Cadence rebaseline drops known window identity on unstamped reading
The rebaseline discards the stored account binding because firstReading() carries nil for observation.identity, letting a later different account merge into the same window. Preserve window.identity when observation.identity is nil.
Prompt for LLM
File Sources/QuotaCore/ResetAlarmTracker.swift, lines 472-478:
Cadence rebaseline drops known window identity on unstamped reading
Cadence rebaseline replaces the window with firstReading() carrying observation.identity, wiping a known window.identity when the new reading is unstamped. Loses the account binding the identity branch preserves and lets a later different account be folded into the same window. Preserve window.identity when observation.identity is nil during the rebaseline.
Suggested code:
// A producer may reuse a window ID while switching its cadence. Its reset time and remaining percentage no longer share the old baseline. Keep the new reading as a baseline instead of comparing across periods.
if let observedPeriod = observation.periodSeconds,
let previousPeriod = window.periodSeconds,
abs(observedPeriod - previousPeriod) > ResetAlarmPolicy.resetDriftTolerance {
var baseline = firstReading()
if baseline.identity == nil { baseline.identity = window.identity }
state.windows[key] = baseline
return nil
}
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
|
The 73-test reset fix is incorporated in #357 on current main, with broader MiniMax correction and idle rollover regressions under review. This hotfix branch would trigger the old shared-machine-identity release workflow on merge, so it must not merge. Please follow #357 for the final corrected implementation. |
| let rose = reading.flatMap { current in | ||
| window.lastRemaining.map { current > $0 + ResetAlarmPolicy.riseEpsilon } | ||
| } ?? false | ||
| let resetHasQuotaEvidence = rose || (hasPassed && reading == nil) | ||
| if (jump > required && resetHasQuotaEvidence) | ||
| || (jump > ResetAlarmPolicy.resetDriftTolerance && climbed) { | ||
| isReset = true |
There was a problem hiding this comment.
Bug: Genuine period rollovers without quota increases or with nil lastRemaining fail resetHasQuotaEvidence, silently shifting the window without triggering .newPeriod.
Severity: MEDIUM
Suggested Fix
Refine resetHasQuotaEvidence so that a passed window deadline (hasPassed) with a forward jump can still qualify as a reset when lastRemaining is nil or when usage is already at maximum (e.g., reading == 100), or separate stale deadline corrections from period rollover detection.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: Sources/QuotaCore/ResetAlarmTracker.swift#L504-L510
Potential issue: In `ResetAlarmTracker.swift`, `resetHasQuotaEvidence` is set to `rose
|| (hasPassed && reading == nil)`, where `rose` requires `reading > lastRemaining +
riseEpsilon` (with `riseEpsilon = 1`) and is false when `lastRemaining` is `nil`. For a
window whose period has ended (`hasPassed`), if the remaining quota remained unchanged
(e.g., 100% to 100%), increased by <= 1 point (due to rounding), or if `lastRemaining`
was `nil`, the rollover is not detected as a reset. It silently updates the window end
date without firing `.newPeriod` or re-baselining `minimumRemaining`.
Refs CC-205
This PR stops false weekly reset alerts when a provider corrects a deadline forward without restoring quota. In
Sources/QuotaCore/ResetAlarmTracker.swift, a reused window ID whose cadence (periodSeconds) changes beyondresetDriftTolerancenow starts a new baseline instead of being compared across periods. A large forward jump inresetAtnow also requires quota evidence — a rise aboveriseEpsilonor a passed end with no readable percentage — to count as a reset, while a smaller jump with a climb aboveearlyResetRiseMarginstill counts; corrections with flat or falling quota now adopt the corrected end without emitting an alarm, but the later true scheduled rollover is still reported as.newPeriod.Tests added in this change, not reported as run: updated
testAMidCycleEventThatFellIsNeitherARefillNorAPlanChangeto expect no event for a future-end correction with falling quota and a later valid rollover, plus newtestPassedMiniMaxDeadlineCorrectionWithUnchangedQuotaDoesNotAlertAndValidRolloverDoes,testReusedWindowIdWithChangedCadenceStartsANewBaseline, andtestPreEndResetTimeCorrectionWithoutQuotaRiseIsNotAnAlarm. Runtime and deployment verification is unverified from the provided changes.Open automated review findings, described as reported and not resolved: medium issue at
ResetAlarmTracker.swift:504for a scheduled rollover missed with first measured reading after nil history, and medium issue atResetAlarmTracker.swift:472for cadence rebaseline dropping known window identity on unstamped reading.