Closing the Notch during a usage check blocks usage checks for 5 minutes

Aperta Adatta ai principianti
#68 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
77/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
swift

Direzione di ricerca

Riproduci prima il problema abilitando l’utilizzo di AI, aprendo brevemente il Notch e riaprendolo; poi segui fetch e read in CatNotchCore/AiLimits.swift per confermare in che modo la cancellazione influisce sulla lettura e sul back-off. Aggiungi i due casi di cancellazione a CatNotchCoreTests/AiLimitsTests.swift, verificando che non venga impostato alcun back-off e che la lettura precedente rimanga invariata. Esegui i test esistenti di AiLimits e conferma che passano.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug good first issue ready-for-agent

[!NOTE]
This issue was raised by Claude (AI code review), not from a user report. Before you start, confirm the problem really exists: reproduce it, or trace the code path yourself. If it does not reproduce, comment here with what you checked and we will close it.

The fix ideas and file names below are suggestions, not requirements. If a different or larger change is the right fix, go with it and explain why in the PR. The maintainer will review and merge.

Labels: bug, good first issue, ready-for-agent · Difficulty: easy (about 1 to 2 hours)

Problem
The AI usage numbers on Home are fetched when the Notch opens (spec 0041 AC-1). The fetch runs in a SwiftUI .task(id:) (CatNotch/NotchBody.swift:711), so closing the Notch cancels it. The cancellation reaches URLSession.data, which throws URLError.cancelled. fetch in CatNotchCore/AiLimits.swift:214-216 turns any error into .failed(.unavailable), and read then sets blockedUntil to now plus 5 minutes (AiLimits.swift:200-202).

So hovering the Notch open and closing it quickly blocks usage checks for 5 minutes. You get stale numbers, or "Tap to retry" on a first launch with no cache. The retry tap is also ignored while a poll is in flight (CatNotch/UsageModel.swift:49, the refreshing guard), so the spinner turns and nothing is checked again.

Steps to reproduce
Turn on AI usage, hover the Notch open and move away within a second, then open it again. The numbers are not refreshed for 5 minutes.

Expected outcome
A cancelled fetch (CancellationError or URLError.cancelled) is "no reading": it does not set blockedUntil and does not replace the last good reading.

Relevant files

  • CatNotchCore/AiLimits.swift (fetch, read)
  • CatNotch/UsageModel.swift
  • CatNotchCoreTests/AiLimitsTests.swift
  • Spec: docs/specs/0041-usage-refresh-on-open.md

Acceptance criteria

  • A test in AiLimitsTests.swift where send throws CancellationError (and one with URLError(.cancelled)) shows no back-off is set and the previous reading is kept.
  • Existing AiLimits tests still pass.
Lingua principale
Swift
Stelle
1
Fork
1
Merge medio
3h 11m
PR unite (30g)
28

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di thecharydev/catnotch

Tutte le issue di thecharydev/catnotch

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.