[bug] Usage refresh never caches when five_hour is null and seven_day is present

Aperta Adatta ai principianti
#2,966 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 5 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bun, typescript
Ambito
backend, tooling

Direzione di ricerca

Leggi LIFEOS/STATUSLINE/producers/UsageRefresh.ts intorno alla riga 103 e segui come viene convalidata la risposta sull’utilizzo prima di scrivere usage.json. Esegui la riproduzione fornita con l’albero pulito e lo stub di fetch; dovrebbe salvare la cache quando five_hour è null e seven_day è un oggetto. Verifica che le risposte non valide continuino a lasciare intatta l’ultima cache valida nota.

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

Descrizione

Version

LifeOS 8.761.0 · attestation: 5 system file(s) differ from danielmiessler/[email protected]:

  • skills/LifeOS/SKILL.md
  • LIFEOS/TOOLS/Doctor.ts
  • LIFEOS/DOCUMENTATION/ARCHITECTURE_SUMMARY.md
  • LIFEOS/STATUSLINE/producers/UsageRefresh.ts
  • LIFEOS/STATUSLINE/producers/LocationWeather.ts
What is broken

The statusline usage refresher never saves usage.json when the usage response has five_hour: null together with a real seven_day object. The response is valid, but only five_hour is checked, so the cached value is never written and the fetch is planned again on every tick.

Where (file:line)

LIFEOS/STATUSLINE/producers/UsageRefresh.ts:103

Repro on a clean tree
// REL = LifeOS/install from a clean v8.761.0 checkout. No network: fetch is stubbed.
const { planUsageRefresh } = await import(`${process.env.REL}/LIFEOS/STATUSLINE/producers/UsageRefresh.ts`);
const { Cache } = await import(`${process.env.REL}/LIFEOS/STATUSLINE/Cache.ts`);
import { mkdtempSync, existsSync } from "node:fs";
const d = mkdtempSync("/tmp/u-");
const now = Math.floor(Date.now() / 1000);
const cache = new Cache(d, now);
const body = { five_hour: null, seven_day: { utilization: 3, resets_at: "2099-01-01T00:00:00Z" } };
async function token() { return "stub"; }
const state = { cache, now, env: {}, claude: d };
const { job } = planUsageRefresh(state, { token, realNow: () => now, fetchImpl: async () => Response.json(body) });
await job.run();
const saved = existsSync(`${d}/usage.json`);
console.log(saved ? "usage.json saved" : "usage.json NOT saved although seven_day is real");
process.exit(saved ? 0 : 1);
Negative control

Probe: bun "$REPRO/b.ts" · exit 1 · captured 2026-11-25T20:49:35.978Z

Red looks like: NOT saved although seven_day is real

usage.json NOT saved although seven_day is real
Suggested fix

Accept the payload when the response is OK and either window is an object.

--- a/LIFEOS/STATUSLINE/producers/UsageRefresh.ts
+++ b/LIFEOS/STATUSLINE/producers/UsageRefresh.ts
@@ -100,9 +100,11 @@
           }
           let body: unknown = null;
           try { body = await response.json(); } catch { /* HTML or truncated: fail closed */ }
-          const five = object(body).five_hour;
-          // Install only a real payload with a five_hour field: last-known-good is never overwritten with garbage.
-          if (five !== undefined && five !== null && five !== false) cache.put("usage.json", `${JSON.stringify({ ...object(body), fetched_at: now }, null, 2)}\n`);
+          // Install only a real payload: last-known-good is never overwritten with garbage.
+          // Local patch 2026-11-25: five_hour is null on some plans while seven_day is real, so either window object counts.
+          const isWindow = (w: unknown): boolean => typeof w === "object" && w !== null && !Array.isArray(w);
+          const { five_hour, seven_day } = object(body);
+          if (response.ok && (isWindow(five_hour) || isWindow(seven_day))) cache.put("usage.json", `${JSON.stringify({ ...object(body), fetched_at: now }, null, 2)}\n`);
         } finally { lock.release(); }
       },
     };
Verified after fix

Probe: bun "$REPRO/b.ts" · exit 0 · captured 2026-11-25T20:49:36.003Z

usage.json saved
Environment
  • OS: Ubuntu 24.04.5 LTS (x64)
  • Harness: claude-code
  • bun: 1.4.5 · git: 2.43.0
  • Doctor broken: none
Lingua principale
TypeScript
Stelle
20k
Fork
2.5k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 danielmiessler/LifeOS

Tutte le issue di danielmiessler/LifeOS

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.