Repository navigation
[PR] fix(diagnostics): retain bounded private log history - #5487
Conversation
(ai: vllm-qwen/qwen3.8-27b) 查重结论:不重复。 检索 open+closed 的 issue 与近期 PR(关键词:log history / retention / generations / archive / 范围确认: 外部贡献者 PR(@Maziar123,分支 现在进入深度 review(PR Review 规范):通读全窗 diff → 逐项清点被触碰路径的既有行为(回归关)→ 读镜像缓存查 CI 状态 → 必要时做最小定向复现。按结构化八问回帖结论。 |
Seed diagnostics.logRetentionHours and diagnostics.logBudgetBytes in website/config-reference/diagnostics.yaml (target 48h floor 1h / hard budget 256 MiB floor 1 MiB, env overrides, budget-wins, active-file protection, 0600/0700) and register BILI_LOG_RETENTION_HOURS / BILI_LOG_BUDGET_BYTES in LIFECYCLE.md 2.5. Generated CONFIGURATION*.md and website blocks are left untouched for the lead generator run.
|
Follow-up e3a3c42 now counts direct forensic appends toward rotation and reports current active bytes. Independent gates passed 35/35 logger/retention and 73/73 retention/reader/HTTP/ACP checks plus TypeScript and source-graph gates. A distinct multi-process shared-active-file ownership race remains and is not claimed fixed here. Its contract negotiation is #5494. |
|
(ai: vllm-qwen/qwen3.8-27b) While triaging #5494 (shared active-log rotation unlinking another writer's open generation), I found an intra-process instance of the same race class in this candidate: The runtime rotation chain in Suggested hard constraint (also required by the per-process contract discussed in #5494): reclamation must never run concurrently with the owner's pending drain of the just-sealed file — either await the drain before reclaiming, or exclude the generation sealed in the same call chain from victim selection. Regression test shape: hold an undrained buffer, force seal + reclaim, assert the buffered bytes survive. |
tripwire) tests/log-retention.test.ts spawns a one-shot sealer child against its own mkdtemp dir for the concurrent-sealing race test, so it must be registered in scripts/live-files.mjs or every CI shard aborts at boot (ranxianglei#1248 guard). No sockets are bound, so no zone port band is needed - the entry is tripwire-only. No behavior change.
(ai: vllm-qwen/qwen3.8-27b) Reviewed against 1. Your intra-process drain/race — shape confirmed; reachability is config-gated Confirmed against code:
One correction on how reachable it is. The victim loop (
So it's not "narrow" for sub-10MiB budgets — it's the common path there — while staying dormant under defaults. Either way your hard constraint is right and cheap. Recommended minimal fix (no async restructure of 2. Why CI was red — not the race; a boot tripwire (fixed & pushed) All 11 runtime shards aborted at startup before any test ran: The #1248 guard in I verified // #5487: spawns a one-shot sealer child (process.execPath) against its own
// mkdtemp dir to exercise concurrent sealing; no sockets are bound, so no
// zone port band is needed — the entry is for the SPAWN_RE tripwire alone
"tests/log-retention.test.ts",That was the only thing stopping the suite from starting; static gates (typecheck / unused-export / import-graph) and every e2e/real-client lane were already green. CI should now get past boot — if anything else turns up red once tests actually run, I'll triage it. Other findings (minor):
Test quality: strong — real negative gates (budget-wins oldest-first, live-file-over-budget never truncated/deleted, concurrent sealers never share a gen dir, 0600/0700 modes, no gen reported twice, unreadable-gen lower-bound, out-of-order stamps ≠ gaps). Not tautologies. Verdict (structured):
Not ready to merge yet: the CI gap is closed (pushed); what remains is closing the drain window — your call whether that lands in this PR or #5494. Everything else is in good shape. |
…123/billion-context into fix/private-log-retention
|
Follow-up at
Verification: nine bounded-reader/privacy suites passed 69/69 tests; typecheck and diff checks passed. This does not claim to fix the distinct cross-process active-log ownership issue tracked in #5494. |
(ai: vllm-qwen/qwen3.8-27b) Reviewed the new head Drain fix — correct, and well-pinned. Rotation now seals first, then One remaining gap — retention can wedge off on a mid-drain stream error. Checkbox reload — correct and minimal. CI — green. My Eight questions
Verdict: functionally complete and CI-green. The one item I'd close before merge is the drain-liveness hardening (settle on |
…ly end() The drain fix (13e57d5) deferred byte-budget reclamation until every replaced stream's end() completion callback fired. That callback is tied to 'finish', which never emits when the stream errors mid-drain (e.g. ENOSPC) — leaving pendingRetentionDrains wedged >0 and silently disabling reclamation forever, worst under exactly the disk-full pressure where reclaim matters most. Settle the drain from the 'close' event instead: 'close' always fires on both the clean and the error path, so reclamation can no longer be stranded. The end() callback stays as the earlier clean-path trigger; a shared idempotent settle guards against double-decrement. Adds a regression pinning the close-without-finish path.
(ai: vllm-qwen/qwen3.8-27b) I went ahead and landed the drain-liveness hardening I flagged — What changed. The drain fix ( Why it matters. Before: a log-stream error during a rotation drain (e.g. Verification (targeted local). Eight questions
Verdict: this closes the last gap from my review. The branch now has the complete drain story — data-loss window ( |
|
Confirmed at Independent verification on this head: all 14 changed suites passed (131/131 tests), and TypeScript passed. I also reproduced the original stuck retention gate before the close-backed settlement. Thanks for landing the focused fix. The separate cross-process shared-active-file issue remains tracked in #5494; this does not claim to change it. |
(ai: vllm-qwen/qwen3.8-27b) Good — thanks for the independent verification on Final shape of the PR from my review side:
#5494 (cross-process shared-active-file ownership) correctly stays out of scope here. Nothing further outstanding on my side. |
(ai: vllm-qwen/qwen3.8-27b) 结论:两个红 shard 均为既有负载敏感 flake 的假红,不是本 PR 引入的回归。零代码改动,已触发 rerun-failed-jobs,run 42202413466 现在全部 27 个 job 全绿。 八问
遗留说明(按 auto-fix lane 规则不开新 issue):#3380 断言加固(#3571 清单第 1 项)与 storage-engine-proofs 负载假红的根治均属后续设计决策范畴,已有迹可循(#3571 / #4599),待 owner 安排。已在 #4599 留一行结论。 收工判定:CI 全绿,可进入人工合并。 我无法执行 merge——请自行合并:#5487 |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
Reviewed end-to-end on head 63081baa4 (fix/private-log-retention). No kernel/, pi-subagents/, or verif/ changes. CI on head: no failures at review time (static gates passed; test shards still running).
What this PR does
Replaces the private run log's "10 MiB active + one .old" scheme with immutable, uniquely-named generations (<log>.archive/<UTCstamp>-<pid>-<seq>/bili.log) sealed by an atomic mkdir claim + rename (never copy), governed by a 48 h target under a hard 256 MiB byte budget (budget wins; the active file is never deleted). All default readers (web log view, diagnostics report, acp-cache usage) now share ONE generation enumeration and stream lines with bounded memory. Full raw export streams every readable retained row (was a silent 100 000-line tail) and aborts rather than present a truncated export as complete. Coverage is reported honestly (measured span only; continuity is always unknown).
Correctness — verified the load-bearing logic directly
- Rotation resets
bytesWritten = existingSize(src/logger.ts:257), so a fresh post-seal file cannot immediately re-seal itself. - The drain gate (
pendingRetentionDrains) settles on BOTHend()and'close', guarded single-settle — a stream that errors withoutfinishcannot wedge retention reclamation. - Budget eviction deletes oldest-first and protects the live sink (
victim = gens.find(g => !g.active)); a single over-budget active file is reported (activeOnlyExcess), never truncated. - The streaming selector preserves ctx/win/exact semantics of the old index version (checked pass-by-pass, incl. inherited timestamps and unreadable-reported-once).
- Async refactor is complete:
queryLogLinesremoved with zero dangling refs; allbuildDiagnostics/parseUsageLog/runDiffcall sites await;configureLogRetentionresolves at all four startup boundaries beforeconfigureLogger.
Tests — strong teeth, would catch regressions
logger-rotate: legacy.oldmigrated-not-lost; a 40-line burst and 12 successive rotations retain every record in order (no clobber / order loss).log-retention(+followup): budget oldest-first with active protected; coverage honesty (out-of-order stamps ≠ loss, unreadable → lower bound); a real 4-process spawn race asserting destination exclusivity — and, importantly, it does not claim byte durability for the shared-source race, which stays open as #5494; drain-gate pinning via heldend()callbacks.web-logs-viewe2e: exports 100 002 rows (> the old 100 k cap) and asserts every row conserved — pins the silent-tail fix.web-logs-query: full selector-equivalence under streaming + unreadable-surfaced-once across window passes.web-diagnostics-enrichment/web-storage-diagnostics-redaction: single-read guard (#3813) and redaction boundaries preserved under the async rewrite.
Behavior changes (intended, disclosed in CHANGELOG)
- Rotation:
bili.log+bili.log.old(≤ ~20 MiB, one gen) →bili.log+<log>.archive/<...>/bili.loggenerations under 48 h / 256 MiB budget; legacy.oldmigrated in place. - File perms:
bili.log0644 (umask-inherited) → 0600; archive dirs 0700 (privacy hardening). - Full raw download: silent 100 000-line tail → streams all readable retained rows (
x-bili-log-incompleteflags unreadable gens). warnReopenFailed: repeated failed reopens now re-unmute stderr each time (deliberate; previously only the first warn did).
New config — owner ratification requested per config-surface discipline
Two keys nested under the existing diagnostics.* family (coherent with the sibling dump caps), fully documented (CONFIGURATION.md en+zh, LIFECYCLE.md, reference/env-vars.md, website yaml, CHANGELOG):
diagnostics.logRetentionHours/BILI_LOG_RETENTION_HOURS— default 48, floor 1.diagnostics.logBudgetBytes/BILI_LOG_BUDGET_BYTES— default 268435456 (256 MiB), floor 1 MiB.
Minor (non-blocking, left as-is)
src/acp-cache-diff.tsdefault path now merges root-levelbili.logand state-dir generations (was first-existing-only). Correct for split layouts; if a caller ever passes the state dir as the acp-cache root the same active file could be counted twice. Diagnostic-only, low blast radius — flagged for awareness, no change made.src/web/diagnostics.tsuses anunreadable:["*"]sentinel on enumeration failure, which renders as "1 generation(s)" — cosmetic imprecision, still honest about incompleteness.
No kernel/ or wire/message-shape changes; loopback-gated routes only. Technically clean, well-tested, honest boundaries. Final merge remains the owner's call (new config keys + log-storage layout are human-gated per §7.4).
中文结构化八问
- 是什么问题:私有运行日志旧方案「10 MiB 活动文件 + 单个
.old」在繁忙机器上会丢掉所请求的诊断窗口;「下载完整日志」又悄悄只取最后 100000 行。 - 什么原因导致的:旧逻辑只保留两个固定文件名且轮转覆盖
.old,各读者硬编码这两个名字,完整导出又套了固定 100000 行尾帽——三者都无法表达真实保留窗口,且尾帽把截断伪装成完整。 - 影响范围与严重程度:依赖 Web 日志页 / 诊断报告 /
acp-cache用量统计查看历史的人受影响;完整导出会得到被静默截断的文件。属功能性退化(有绕行),非崩溃 / 会话丢失 / 缓存泄露 → p2。 - 怎么修复的:不可变、名字唯一的分代(原子 mkdir 抢名 + rename 不拷贝),48h 目标下叠 256MiB 硬字节预算(预算赢、活动文件永不删);所有默认读者共用同一分代枚举并流式读取(内存有界);完整导出流式发送全部可读行、发头后失败即中断;覆盖只报实测跨度、
continuity恒为 unknown。 - 是否有回归问题:已逐项核对轮转(遗留
.old迁移不丢、顺序不乱、不互相覆盖)、读取选择器(ctx/win/exact 语义等价)、诊断单次读守卫(#3813)、发布脱敏边界——均保持;stderr 重复失败重开改为每次都解除静音(有意改进)。未发现无意回归。 - 是否破坏缓存:不涉及(日志 / 诊断子系统,非前缀缓存或会话持久化格式 / 版本)。
- 是否改了设计方向:仅日志子系统内从「两个固定文件名」转向「字节预算下的不可变分代集合 + 共享枚举 + 流式读取」,边界不变、模型更稳;无跨子系统架构转向。
- 是否引入新配置:新增两个键(挂在既有
diagnostics.*家族下,已在 CONFIGURATION 中英 / LIFECYCLE / env-vars / website yaml / CHANGELOG 全量登记):diagnostics.logRetentionHours(默认 48,下限 1)、diagnostics.logBudgetBytes(默认 256MiB,下限 1MiB)。按配置面纪律提请 owner 合并时确认。
判定:可合(APPROVE)——代码干净、测试扎实、边界诚实;最终合并按 §7.4 由 owner 决定(新增配置键 + 日志存储布局属人工把关)。
(ai: vllm-qwen/qwen3.8-27b) 独立复审完成(head 已在 GitHub 提交正式 APPROVE 评审(review id 5800366616)。判定:可进入人工合并(新增配置键 + 日志存储布局按 §7.4 仍由 owner 把关)。我无法执行 merge——请自行合并:#5487 |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
Re-review of moved head 1db639fd2. The head advanced from 63081baa4 (which I approved) to 1db639fd2, but the entire delta is a single "Merge remote-tracking branch 'origin/master' into fix/private-log-retention" commit pulling in ~347 newer master commits (fastpath-v6, docs-centralization, kernel 0.0.18x, dsh-lane fixes, …). No new log-retention feature commits exist in the range.
I verified the tree, not just the commit list:
- Feature-only files are byte-identical to the approved head:
src/log-retention.ts,src/log-file-lines.ts,src/log-retention-coverage.ts+ their tests. src/logger.tsandsrc/web/logs-query.ts(drain-gate + streaming-selector homes) are untouched by master too — so the retention engine, drain gate, and selector are provably unchanged.- All wiring survived the merge coherently:
configureLogRetention(knobLogRetentionPolicy())still runs beforeconfigureLogger()at both startup sites (src/server.ts:500→503,:657→686) and in both MCP entries; knob plumbing (knobs.ts:784/798/810), the twodiagnostics.*config keys (config.ts:2414-2415), the yaml rows, thelive-files.mjs:113registration, the drain gate, and the admin export wiring (x-bili-log-incomplete,retention:status) are all present and correctly ordered. - The true PR footprint vs current master (
git diff master...head) is still exactly the 39 files / ~2775 insertions I approved — nothing else.
CI is fully green on 1db639fd2. No kernel/wire/persistence changes; behavior drift (rotation scheme, 0644→0600 perms, unbounded raw export) remains disclosed in CHANGELOG. Nothing new to fix; the prior approval carries forward to this head.
Verdict: APPROVE — ready for human merge. Merge stays owner-only (§7.4): #5487
审核结论(结构化八问)
- 是什么问题:本 PR 把私有运行日志
bili.log从「10 MiB + 单个.old」改为「10 MiB 封存分代 + 48h 目标窗口 + 256 MiB 硬预算」,并让 Web/诊断的原始导出流式化、不再静默截断。本轮只是核对 head 移动后结论是否仍成立。 - 什么原因导致的(旧行为的根因):原方案只保留一代
.old,保留窗口是「碰巧」而非「保证」;且原始导出被静默裁到 10 万行尾,用户拿不到完整保留历史。 - 影响范围与严重程度:纯诊断/可观测面,不动模型流量、wire、持久化格式;默认配置下即启用新方案。属体验改进,无回归风险面。
- 怎么修复的:自包含子系统——独立模块(封存引擎/行读取器/覆盖度)、
diagnostics.*两个键、启动边界幂等注入策略、导出走流式 ring buffer 并如实上报x-bili-log-incomplete。 - 是否有回归问题:本轮重点核过——功能文件字节级未变,
logger.ts/logs-query.ts未被 master 触碰,两处启动点「先 retention 后 logger」顺序在合并后仍正确,drain 门(pendingRetentionDrains+'close'兜底结算)仍在位。既有行为无破坏。 - 是否破坏缓存:不涉及压缩缓存/重试/增量游标;仅私有日志文件布局变化。
- 是否改了设计方向:不改架构/数据流方向;新增一个隔离的诊断子域 + 两个配置键。
- 是否引入了新的配置:是——
diagnostics.logRetentionHours(envBILI_LOG_RETENTION_HOURS,默认 48,下限 1)与diagnostics.logBudgetBytes(envBILI_LOG_BUDGET_BYTES,默认 256 MiB,下限 1 MiB),中英文档 + yaml + LIFECYCLE 齐备;按 §7.4 由 owner 把关合入。
判定:可进入人工合并。
(ai: vllm-qwen/qwen3.8-27b) Re-reviewed the moved head |
|
(ai: vllm-qwen/qwen3.8-27b) Closing the loop on my Nov 1 comment (the intra-process drain-vs-reclaim instance, reported against head e3a3c42): it was addressed on this branch before merge —
Verified in the merged tree (e606c54): src/logger.ts:210/:212/:235/:322-343/:450-453, pinned by tests/logger-rotation.test.ts:142 ("budget reclamation waits for the rotated stream to drain") and :172 ("reclamation still runs when a replaced stream closes without finishing"). The cross-process variant remains out of scope here — it is the pending contract question in #5494. |
Problem
A 10 MiB active log plus one
.oldcan lose the requested diagnostic window. Readers and the nominal full download also disagree about retained generations: the raw download silently takes a 100000-line tail.Fix
Retain immutable timestamped generations under a 48-hour target and a finite byte budget (default 256 MiB; 10 MiB segments). Budget wins, the active file is protected, files are
0600, archive directories0700, and coverage reports measured span separately from unknown continuity.Readers stream generations with bounded selectors. Full raw exports stream every readable retained line; unreadable generations are surfaced in the UI and
x-bili-log-incomplete, and a post-header failure aborts rather than presenting a truncated export as complete. Time-window query passes report each unreadable generation once. Explicit ACP--logstays single-file.Verification
104/104 retention, reader and real HTTP export checks passed; after the multi-pass warning dedup, 84/84 focused reader, UI, query and diagnostics checks passed. TypeScript, unused-export and test-import-graph gates passed. Disposable Chromium exercised the real logs UI and full download with an unreadable generation.
No continuity, historical recovery, all-platform or production-deployment claim.