Repository navigation
[PR] fix: bound memory for log time-window queries - #6487
Conversation
[bot] 🏷 查重: 不重复 — #6487 是关闭 #6486 的唯一 PR;无其他 open PR/issue 指向同一日志时间窗口 OOM。 Reviewed the diff, traced the selection logic by hand, and verified locally on the current head What I verified
CI: still running on the rebased head — 5 of 30 checks pending, 0 failed so far (the all-green I first saw was for the pre-rebase head 8问
判定:代码审查通过(approve)——修复正确、最小、行为保持、测试是真实回归测试,分支已对齐当前 master。等当前 head 的 CI 全绿即可合并;转绿后我再确认一句。 |
[bot] 🏷 CI 转绿确认(当前 head 结合上一条的代码审查结论:修复正确、最小、行为保持,本地 16/16 测绿 + OOM 回归实证(master SIGABRT → 修复后 |
The suite baseline preload (preload-storage-baseline.mjs) pins BILI_STORAGE_UNIFIED="legacy" for the broad corpus. After ranxianglei#6480 flipped the storage default to pure-sqlite, the notice-registry suite's visibleNotices assertions expect the pure-sqlite default notice, which is gated on unifiedSelectionIsSqlite (unified "sqlite" or absent) — the preload's "legacy" made the notice silent, so the suite was born-red on master. Pin the selection explicitly (ranxianglei#4011 lesson: a test that depends on the production default passes locally but fails in CI).
…test The dsh plugin lane (ci-e2e-dsh.yml) runs node --import tsx --test WITHOUT the preload-storage-baseline.mjs preload, so BILI_STORAGE_UNIFIED is unset and the storage mode defaults to 'full'. Under the pure-sqlite default flip (5a80e2b, ranxianglei#6480), 'full' mode turns the JSON envelope writer OFF — so the .content-store.json sidecar is never written, and the test's readdirSync(namespace) hits ENOENT. Pin BILI_STORAGE_JSON_WRITER=on in the test so the content-store sidecar is written regardless of the storage mode. This keeps the corrupted-store detection path exercised in both full and legacy modes. Closes: dsh plugin lane red on master (run 43532980164, job 132255459726)
The pure-sqlite default flip (5a80e2b, ranxianglei#6480) turns the JSON envelope writer OFF, so the .json session file this lane asserts on is never written and 'proxy must persist the session' / 'no persisted session carried compressed blocks' fail after the 20s wait. Pin the writer ON in the spawned client's env (the bootstrapped proxy inherits it) so the envelope this test was written for is still produced. Closes: native opencode lane red on master (run 43547593803, job 132302438610)
Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) as the opencode lane: the JSON envelope writer is OFF, so 'proxy must persist the session within 20000ms' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned dsh client's env (the bootstrapped proxy inherits it). Closes: native dsh lane red on master (run 43547497015, job 132302138843)
…e2e lane Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) as the opencode/dsh lanes: the JSON envelope writer is OFF, so 'session persisted' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned pi client's env (the bootstrapped proxy inherits it). Closes: pi codex-responses WS lane red on master (run 43547626291, job 132302540960)
…lane 4th lane of the pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope writer is OFF, so 'proxy must persist the session' and 'at least one persisted session must carry compressed blocks' fail — the on-disk .json session file is never written. Pin the writer ON in the spawned pi client's env (the bootstrapped proxy inherits it). Closes: pi package-native lane red on ci-fixes (run 43558179054, job 132336647955)
Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON writer is OFF, so the per-session CCR content-store sidecar (.content-store.json) that 'child persists its own companion and survives a proxy restart' asserts on is never written (0 !== 1). The earlier b1bc17b pin only covered tests/plugin-fork.test.ts, not this file. Pin the writer ON at module load (before any SessionStore is constructed). Closes: dsh plugin lane red on ci-fixes (run 43558179102, job 132336519539)
…lane Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope writer is OFF, so 'proxy must persist the session' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned opencode client's env (the bootstrapped proxy inherits it).
Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope writer is OFF, so the on-disk .json session envelope this lane asserts on (exactly ONE persisted session under the raw key) is never written. Pin the writer ON in the spawned dsh client's env.
Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope writer is OFF, so the on-disk .json session file this lane asserts on (state survival across the OLD→NEW update) is never written. Pin the writer ON in the spawned proxy's env (both update phases share envBase).
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
Verdict: APPROVE — correct, minimal, behavior-preserving fix pinned by a genuine constrained-heap regression.
Independent review (traced the selection logic and read the tests, not the PR description):
- Root cause confirmed.
windowSelection(src/web/logs-query.ts) buffered every pre-match lead-in row in an unboundedleadIn: string[]until the first hit, so a dense same-timestamp prefix (≈100 MB) grew memory to the input size, not the answer size — bypassing the streaming reader's intended bound. The fix routes pending lead-in rows into the existing fixed-capacityTailring (bounded byn) and addsTail.clear()to reset the provisional selection across (a) a timestamp discontinuity in the backward walk and (b) rotation removing every hit between the two passes (the post-loopif (!inRange) tail.clear()). - Behavior preserved. I traced the edge cases, not just the happy path:
clear()resets onlyseen;take()/counts()read only slots in[seen-kept, seen), all written after the last clear, so no stale row is ever returned andomittedstays exact.lines/isMatch/omitted/total/shownare identical to the oldleadInpath in the dense-prefix, discontinuity, and rotation cases. Only memory changed: unbounded → bounded byn. - Tests have teeth. The constrained-heap test spawns a
--max-old-space-size=64child over a ≈100 MB same-timestamp file and assertsstatus===0plus the exact output (total=1 shown=3 omitted=99998 isMatch=[F,F,T]) — it fails on the old code (SIGABRT / heap OOM) and passes here. Two semantic controls pin the discontinuity-clear and rotation-clear paths with exactomittedvalues. Therun(0)exact-match control confirms the streaming reader itself fits the heap, isolating the window-mode lead-in as the OOM producer. - No config / wire / persistence / kernel surface touched. Core fix = 3 files:
src/web/logs-query.ts,tests/web-logs-query.test.ts, andscripts/live-files.mjs(registers the process-spawning test as a live file — private temp files, no sockets). The branch also carries the sanctioned ci-fixes merge (test-onlyBILI_STORAGE_JSON_WRITER=on/BILI_STORAGE_UNIFIED=sqlitepins in 10 e2e/test lanes, fixing lanes broken by the pure-sqlite default #6480) — clearly labeled, not part of the log-query fix, flowing into master via this merge as the ci-fixes sentinel intends. - CI: green per the dispatch gate; the mirror-checks snapshot I could read was stale (frozen at 06:08 UTC, 17 still queued) and had not refreshed to the final state, so I'm relying on the dispatch "green" trigger rather than a fresh cache read.
8问
- 是什么问题:web 日志视图的时间窗口查询(
src/web/logs-query.ts的windowSelection)在首个命中之前把每一行前置上下文堆进无界leadIn数组,即使响应只保留n行;约 100 MB 同时间戳前缀撑爆 64 MB 堆(进程 SIGABRT),同一文件的精确匹配查询却正常。 - 什么原因导致的:窗口模式第二遍把"首个命中之前、时间戳 ≥ loT 的所有行"累积进无界
string[],直到首个命中才转入有界Tail环——内存随前缀(输入)大小而非答案大小增长,绕过了流式读取器本应有的内存上界。 - 影响范围与严重程度:影响
GET /__bili/logs时间窗口模式(winSec>0)且保留日志存在大前置前缀的场景;p1——可复现的进程级 OOM(整个 bili 进程崩溃,连带所有在途请求),虽在诊断视图而非核心压缩路径,但进程 OOM 属可用性缺陷。 - 怎么修复的:把待定前置行直接流进既有固定容量
Tail环(按n封顶),不再用旁路无界数组;新增Tail.clear()在时间戳断点(后向行走中断)与"两遍之间轮转删光全部命中"(循环后if (!inRange) tail.clear())时复位暂定选择;seen计数保留精确omitted而不保留被丢弃的行。 - 是否有回归问题:无。行为保持——所有情形下
lines/isMatch/omitted/total/shown不变(密集前缀、断点、轮转三类边界逐一推演,输出与旧leadIn实现逐项一致);仅内存从"无界"变为"按n封顶"。未触碰配置 schema / wire / 持久化 / kernel。 - 是否破坏缓存:不涉及——日志视图查询,无缓存/重试/游标/去重。
- 是否改了设计方向:无。保留既有两遍窗口设计与有界
Tail,只是把暂定前置行放进既有有界结构而非旁路数组。 - 是否引入了新的配置:无。
收工判定:代码审查通过(APPROVE)——修复正确、最小、行为保持,OOM 回归测试有牙(受限堆实证),分支已对齐当前 master。合并动作留给人工(agent 不合并 PR)。
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Review complete — APPROVE posted to PR #6487 (review id 5902527573, verified landed 2026-11-14T07:10:36Z). Verdict: APPROVE. The fix is correct, minimal, behavior-preserving, and teeth-tested. No kernel / wire / config / persistence touched. Merge left to human. What I verified (independent trace, not copied from prior reviews):
结构化八问(中文)
收工判定:可合(merge 留给人工)。 |
|
Thanks for the approval. The current head The fresh CI run has completed successfully, including the Ubuntu and Windows/Node 22 lanes. The current reported checks are 37 successful and 13 skipped. The merge box still has three required checks waiting for a status: |
ranxianglei
left a comment
There was a problem hiding this comment.
Re-review after new head 08fe0a45b (routine master merge) — still APPROVE.
The core fix is byte-identical to the previously-approved head 001582239: src/web/logs-query.ts and tests/web-logs-query.test.ts did not change. The new head is a routine merge of the latest master (release v0.1.214 + the gate-recorder pipe-leak fix #6671) to refresh PR validation.
What changed since my last review:
src/web/logs-query.ts(core fix): unchanged — verified byte-identical.tests/web-logs-query.test.ts(3 tests incl. the 64 MB-heap OOM regression): unchanged — still has teeth (fails on the old code, SIGABRT).scripts/live-files.mjs: +2 lines registeringtests/web-logs-query.test.tsas a live file (heap-bounded children, private files, no sockets) — correct.tests/e2e/e2e-update-state.test.ts: +5 lines, a sanctioned ci-fixes pin (BILI_STORAGE_JSON_WRITER=on) with a clear comment — the pure-sqlite default #6480 turns the JSON envelope writer off, but this lane asserts on the on-disk.jsonsession file. Test-only, not part of the log-query fix.- The rest (release v0.1.214, gate-recorder fix,
src/storage/store.ts, plugin manifests, etc.) is master content pulled in by the merge — not the PR author's work.
CI: green on the new head 08fe0a45b — 30 checks, 17 success + 13 skipped, 0 failed (mirror cache, fetched 08:43 UTC, sha matches).
Verdict: APPROVE. Correct, minimal, behavior-preserving, teeth-tested. No kernel / wire / config / persistence touched. Merge left to human.
结构化八问(中文)
- 是什么问题:日志时间窗口查询在遇到第一个匹配行之前,把每一行 lead-in 缓冲进无界的
leadIn: string[];同一时间戳的 ≈100MB 前缀会把 64MB 堆撑爆(OOM/SIGABRT)。 - 什么原因导致的:
windowSelection()用无界数组缓冲 pre-match 行,而不是复用已有的固定容量Tail环形缓冲区;当同一时间戳行数远超显示行数n时无限增长。 - 影响范围与严重程度:日志时间窗口查询端点;触发条件 = 同一时间戳行数 ≫
n(如 100000 行同戳 + 1 行命中)。p1——进程直接 OOM 崩溃,该查询完全不可用。 - 怎么修复的:lead-in 行直接
tail.push(line, false)进固定容量Tail环(上限n),新增Tail.clear(),在不连续(ts<loT)与轮转(post-loop!inRange)时清空。内存从「无界」收敛到「≤ n」。 - 是否有回归问题:无。核心修复与上一版逐字节相同;逐行追踪密集前缀 / 不连续 / 轮转三类边界,
lines/isMatch/omitted/total/shown与旧leadIn路径完全一致;只改了内存上界。未触碰配置 / 线协议 / 持久化 / 内核 / 默认值。 - 是否破坏缓存:不涉及——纯日志查询内存管理,不涉缓存 / 重试 / 增量游标 / 去重键。
- 是否改了设计方向:不涉及——在既有
Tail环机制上收敛,无架构 / 边界 / 数据流转向。 - 是否引入了新的配置:不涉及——无新 env / config / 默认值(ci-fixes 的
BILI_STORAGE_JSON_WRITER=on是测试内 pin,非产品配置面)。
收工判定:可合(merge 留给人工)。
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Re-review after new head The new head is a routine master merge (release v0.1.214 + gate-recorder pipe-leak fix #6671) to refresh PR validation. The core fix is byte-identical to the head I approved earlier ( What changed since my last review:
CI: green on the new head Verdict: APPROVE. No kernel / wire / config / persistence touched. No small findings to fix on the spot; nothing needing 🔶 需要决策. Merge left to human. 结构化八问(中文)
收工判定:可合(merge 留给人工)。 |
|
Superseded by #6677 (merged as Landed into master via the real merge commit The fix for #6486 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix. |
Closes #6486
Problem
The time-window log query buffers every line before its first match in
leadIn, even when the response only retains three lines. A dense roughly 100 MB prefix exhausts a 64 MB Node heap; an exact-match query over the same file succeeds. This bypasses the streaming reader's intended memory bound.Change
Keep provisional context in the existing fixed-capacity tail. Its total count preserves the exact
omittedvalue without retaining discarded rows. Clear that provisional selection across a timestamp discontinuity and when concurrent rotation removes every match between the two passes.No log retention policy, response schema or request/compression pipeline changes.
Validation
9674cfafbc78c50245ae0d887483d3d6ce880c15: the new constrained-heap regression fails with SIGABRT / JavaScript heap out of memory; 15 other query tests pass, including two added semantic controls. The exact-match sub-control succeeds on the same approximately 100 MB file.git diff --checkpass. The process-spawning test is registered inscripts/live-files.mjs; it uses private temporary files, no sockets or external network.Head branch:
Afloat16:2026-11-12_bounded-log-window.Current master integration
Merged upstream master
fcc2e848486cc2152e36b6658c517fbfa51ec428into this branch without textual conflicts. The published merge commit isd5dbfe5794695bcd90f11f40c728586ab8d6aba5, with the original PR headaae0b88ffee9a0cc7f0705effb6613fecc05e35das its first parent and current master as its second parent.The production fix and regression tests are unchanged. The new
tests/web-logs-query.test.tsLIVE_FILES entry was moved to the end ofscripts/live-files.mjsso all 66 existing upstream entries retain their original zone positions.Fresh integration validation on Linux x64 / Node 24.22.1, after installing the locked dependencies:
npm run typecheck,npm run build,npm run check:unused-exports,npm run check:test-import-graphandgit diff --checkpass.be78674a2f427abb193f8cfda8dc187731f90b10exactly matches the locally tested tree.The integration commit triggered hosted CI run 43377346253; its current result is available there. Complete hosted CI and real-model E2E are not claimed as passed by these local integration checks.
Review status
Linked to #6486 and ready for maintainer review. The latest integration validation includes upstream master
fcc2e848486cc2152e36b6658c517fbfa51ec428, as recorded above. Current hosted results are available in the Checks tab.Please apply the existing
ci:fulllabel to run the FULL matrix, including the required Windows / Node 24 checks. The default CORE matrix does not produce those checks.