Skip to content

web: fresh install (sessions dir never existed) 500s on /__bili/overview & /__bili/sessions — #1937's "never silent empty" cannot tell "no data yet" from "misconfigured" #2180

Closed

Description

@ranxianglei

来源: #2175 (#2175) 分析 PR #2175 (side-lane regression hardening) 时发现

Repro

On any environment where the default state dir has never been created (fresh machine / fresh CI runner — ~/.local/share/billion-context/sessions absent):

  1. bili start
  2. GET /__bili/overview → 500 {"error":"failed to load session data"}
    GET /__bili/sessions → same 500
  3. Log: [acp-web] overview failed: Error: ENOENT: no such file or directory, scandir '<state>/sessions'

Reproduced locally by running tests/advisory-endpoint-parity.test.ts with HOME/XDG_DATA_HOME pointed at empty dirs (before its hermeticization in #2175, which is exactly what made all four test-matrix jobs red there — master-side pre-existing, fixed on the TEST side only).

Why it happens

walkSessionFiles() (src/web/sessions-data.ts) throws on ANY top-level readdir failure; refreshIndex() propagates it when no prior snapshot exists. #1937 deliberately pins this: vanished dir serves the stale snapshot, and a missing dir with no prior snapshot rejects loudly (tests/web-sessions.test.ts "#1937: dir breakage serves stale snapshot; missing dir rejects loudly") — the intent being "never silent empty", so a misconfigured/moved sessions path surfaces instead of showing an empty dashboard while real sessions sit elsewhere.

The over-broad part: "the whole data root was never created" (first run, zero sessions ever persisted) is indistinguishable from "path is wrong" by the current code, so a perfectly healthy fresh install reports an error on both endpoints until the first session is persisted.

Impact

Suggested direction (owner decision — this is a contract/default change)

Distinguish pristine from broken, e.g.: the entire data root (XDG_DATA_HOME/billion-context) missing → treat as "no sessions yet" → 200 with empty data; data root present but sessions dir missing/vanished → keep today's loud rejection (and the #1937 stale-snapshot behavior). An explicitly-set BILI_SESSIONS_DIR pointing nowhere could stay loud in either world. Whichever variant is chosen, update the #1937-pinned test in the same PR.

Not fixed in #2175 on purpose: changing this means re-pinning a deliberate #1937 contract — a product decision, not an agent call.

Activity

  1. ranxianglei commented on Oct 5, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 收到。已按 issue 里给出的方向开工(这是 owner 拍板的契约细化,我直接采用你 sketch 的变体):

    先跑定向验证(web-sessions 套件 + typecheck),然后开 PR。

  2. ranxianglei commented on Oct 5, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 完成。PR: #2182 (Closes #2180)

    按你 sketch 的变体实现,结构化七问:

    1. 是什么问题:全新安装(默认数据目录从未创建、零会话落盘)时 /__bili/overview 与 /__bili/sessions 持续 500——「还没有数据」被当成了「路径坏了」。
    2. 什么原因导致的:walkSessionFiles() 对任何顶层 readdir 失败都 throw,refreshIndex() 在无旧快照时原样传播。管理页面全量加载历史会话时触发堆 OOM:需要有界分页、摘要统计与详情懒加载 #1937 有意钉死 "never silent empty",但它的防御对象是「真实会话在别处、这里显示空会骗人」——而 data root 整体不存在时根本不存在「别处有会话」的可能,两类失败被同一个异常路径混在一起了。
    3. 怎么修复的:在 refreshIndex()(唯一决策点)对顶层失败做分类:新增 isPristineSessionsRoot(error) —— 仅当 BILI_SESSIONS_DIR 未设置 且 data root(XDG_DATA_HOME/billion-context)本身不存在 且错误是 ENOENT 时,视为 pristine,索引置空正常返回(→200 空数据,live pool 会话照常合并)。其余情形逐字节不变:data root 在但 sessions 子目录缺失/消失 → 旧快照 serve / 无快照 loudly reject(管理页面全量加载历史会话时触发堆 OOM:需要有界分页、摘要统计与详情懒加载 #1937 原样);显式 BILI_SESSIONS_DIR 指向不存在 → 维持 loud;EACCES 等照旧。pristine 判定不缓存,每次 poll 重新 stat,首个会话落盘后下一次请求自然恢复。
    4. 是否有回归问题:无。逐项过既有行为——vanished-dir 旧快照行为(钉死测试断言未动,仍过)、explicit-missing-dir reject(测试保留)、corrupt/junk 文件容错、warm-scan 零解码记账、paging/search、detail 懒解码,全部保持;端点级回归跑了 upstream-alerts + advisory-endpoint-parity 共 9/9 通过。唯一的有意变更就是本 issue 本身:fresh install 下两端点 500 → 200 空(detail 500 → 404),已在 PR 正文「行为变更披露」里写明旧值→新值+原因。JSON payload shape 未动,非 wire 变更。
    5. 是否破坏缓存:不涉及。索引的 (mtime,size) 失效策略未触碰;pristine 判定每次重新求值(两个廉价 syscall),不引入新缓存层;prefix cache/重试/去重键均无关。
    6. 是否改了设计方向:没有。单模块 fix(src/web/sessions-data.ts + 对应测试),不动 kernel/、不动持久化格式、不加新端点;管理页面全量加载历史会话时触发堆 OOM:需要有界分页、摘要统计与详情懒加载 #1937 的 "never silent empty" 契约保留,只是把「pristine」从它的覆盖范围里精确排除了。
    7. 是否引入了新的配置:不涉及。无新 key/env/flag,复用既有 BILI_SESSIONS_DIR / XDG_DATA_HOME 语义(PR 正文 config surface 一节已声明)。

    测试:更新 #1937 钉死测试(改名 #1937/#2180: …,原断言全部保持有效)+ 新增 withPristineEnv 辅助与两用例(pristine 全链路 resolve→首会话落盘可见;data root 存在但子目录缺失仍 loudly reject)。本地定向验证 typecheck ✓、web-sessions 15/15 ✓、端点套件 9/9 ✓,全量回归交给 CI。

    收工判定:代码完成、定向验证绿,等 CI 后可由你合并 PR #2182。

  3. added 2 commits that reference this issue on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions