[bug] Usage refresh never caches when five_hour is null and seven_day is present
维护者通常 5 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- bun, typescript
调研方向
阅读 LIFEOS/STATUSLINE/producers/UsageRefresh.ts 第 103 行附近的代码,并跟踪写入 usage.json 前如何验证使用量响应。使用 fetch 存根运行提供的干净工作树复现;当 five_hour 为 null 且 seven_day 为对象时,应保存缓存。检查无效响应是否仍会使最近一次已知的有效缓存保持不变。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- TypeScript
- 星标
- 20k
- 派生
- 2.5k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
danielmiessler/LifeOS 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
danielmiessler/LifeOS#2985 ·
维护者通常 5 天内回复
-
MemoryTurnStart: the 300 ms budget skipped memory retrieval on 1 in 4 prompts on a Windows install未关闭
难度 2/5 1-3 小时 新手友好度 76/100
danielmiessler/LifeOS#2983 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
danielmiessler/LifeOS#2980 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
danielmiessler/LifeOS#2977 ·
维护者通常 5 天内回复
-
难度 1/5 1 小时以内 新手友好度 84/100
danielmiessler/LifeOS#2967 ·
维护者通常 5 天内回复
查看 danielmiessler/LifeOS 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
OHDSI/Data2Evidence#3749 ·
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 63/100
维护者通常 1 天内回复
-
bug severity:low triage:confirmed triage:in-progress
难度 2/5 1-3 小时 新手友好度 76/100
Cotal-AI/Cotal#10749 · 1 条评论 ·
维护者通常 1 天内回复
-
needs-atl
难度 1/5 1 小时以内 新手友好度 88/100
GoogleChrome/modern-web-guidance-src#3726 ·
维护者通常 1 天内回复
-
e2e-failure ready-to-code
难度 2/5 1-3 小时 新手友好度 78/100
redhat-developer/rhdh-plugin-export-overlays#4935 · 1 条评论 ·
维护者通常 1 天内回复