Skip to content

[PR] test: make log-retention generation stamps timezone-faithful - #6763

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-15_log-retention-tz-stamp
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-15_log-retention-tz-stamp

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Found while reviewing #6742 (pre-existing on master, unrelated to that PR's diff).

Problem

writeGeneration in tests/log-retention.test.ts planted head lines as UTC wall-clock strings with the Z stripped (new Date(at).toISOString().slice(0, 23)). The coverage reader (STAMP_RE + Date.parse in src/log-retention-coverage.ts) treats a zone-less stamp as LOCAL time, so in any non-UTC zone the measured span shifts by the offset.

The 40h-vs-48h boundary test ("out-of-order stamps are NOT evidence of missing history", tests/log-retention.test.ts:185) flips in positive-offset zones ≥ 8h: the now-40h oldest stamp reads back 8h earlier, the span reaches the 48h target, and the targetSpanMet === false assertion fails.

Repro: TZ=Asia/Shanghai node --import tsx --test tests/log-retention.test.ts on master → 1 failure; TZ=UTC → 23/23. The real logger (logTimestamp, src/logger.ts:408) writes local wall-clock time with no zone suffix, so the test was fabricating a line shape the logger never produces in a non-UTC zone.

Change

Stamp the planted head line with logTimestamp(new Date(at)) — the real writer's own formatter. Planted lines now round-trip exactly in every zone. Test-only: no runtime, wire, config or dependency changes.

Verification

  • tests/log-retention.test.ts 23/23 under TZ=UTC+8 (local), TZ=UTC and TZ=America/New_York
  • npm run typecheck clean
  • Full-suite verdict left to CI on the pushed head

…them

writeGeneration planted head lines as UTC wall-clock strings with the Z
stripped; the coverage reader (STAMP_RE + Date.parse) treats a zone-less
stamp as local time, so in any non-UTC zone the measured span shifted by
the offset. The 40h-vs-48h boundary test ("out-of-order stamps are NOT
evidence of missing history") flipped in UTC+8: the 40h oldest stamp
read back 8h earlier, the span reached the 48h target, and the
targetSpanMet=false assertion failed.

Found while reviewing #6742; pre-existing on master, unrelated to that
PR's diff. Use logTimestamp - the real writer's formatter - so the
planted lines round-trip exactly in every zone. Verified 23/23 under
UTC+8, UTC and America/New_York.
@ranxianglei ranxianglei added bug Something isn't working p3 scope/ci labels Nov 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-15_log-retention-tz-stamp (9a2adcf)

Latest build — install this exact version

npm install -g billion-context@0.0.10026-pr.6763.22fffd6

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
9a2adcf billion-context@0.0.10026-pr.6763.22fffd6 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr6763.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title test: make log-retention generation stamps timezone-faithful [PR] test: make log-retention generation stamps timezone-faithful Nov 14, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复 — 检索 open PR/issue,只有本 PR 触及 log-retention 测试的时间戳时区问题,无并行修复。

Reviewed PR #6763 (test-only: tests/log-retention.test.ts, +6/−1). The fix is correct and I verified it by running the suite across timezones.

What I verified

  • Bug is real and correctly diagnosed. On the PR base (8964c1fe), writeGeneration planted head lines as UTC wall-clock with the Z stripped (new Date(at).toISOString().slice(0, 23)). The coverage reader (STAMP_RE + Date.parse, src/log-retention-coverage.ts:47,111) parses a zone-less stamp as local time, so the measured span shifts by the zone offset.
  • The fix is the right one. It stamps the head line with logTimestamp(new Date(at)) — the real logger's own formatter (src/logger.ts:408, local wall-clock, no zone suffix). Planted lines now round-trip exactly in every zone, matching the line shape the logger actually produces.
  • Ran the targeted suite (bun):
    • Base @ TZ=UTC: 23/23
    • Base @ TZ=Asia/Shanghai: 1 fail — "out-of-order stamps" (targetSpanMet flips true: 40h+8h=48h)
    • Base @ TZ=America/New_York: 2 fail — "a span reaching the target" + "an unreadable generation" (50h−5h=45h < 48h, targetSpanMet flips false)
    • Head @ TZ=UTC / Asia/Shanghai / America/New_York: 23/23 each
  • The fix is actually more complete than the description. The body only mentions the positive-offset ≥ 8h flip (the 40h test). The same root cause also flips the 50h-span tests in negative-offset zones; the fix resolves both directions.
  • No regression. Test-only. The budget-removal ordering uses directory-name stamps (generationStamp, UTC, zone-independent) + mtime — unaffected. The real logger already writes logTimestamp, so the test now matches reality. static-gates (typecheck) is green in CI.

CI status (verified live)

2 red shards, both in tests unrelated to this PR:

  • test (windows-latest, 22, 5): weak-adoption gate … (#5608 v3) fails; the log also shows ENOSPC: no space left on device (runner disk).
  • test (ubuntu-latest, 22, 3): real CLI: live marker for an unlistened port … fails.

Neither touches tests/log-retention.test.ts. These look inherited/infrastructure, not caused by this test-only change — they belong in #4599, not this PR. The PR is also behind master (rebase before merge).

Minor observation (optional, non-blocking)

tests/log-retention.test.ts:98 (the legacy .old planting in "budget deletion never prefers a newer generation") still uses the same UTC-Z-stripped format. It does not cause a failure (that test never asserts on the span), but for full consistency it could also use logTimestamp. Happy to fold it in or leave it — your call.

八问

  1. 是什么问题:测试给日志头行伪造了「UTC 墙钟去掉 Z」的时间戳,而覆盖率读取器把无时区后缀的时间戳按本地时间解析,非 UTC 时区下测量跨度因此偏移。
  2. 什么原因导致的:测试用 toISOString().slice(0,23)(UTC 墙钟去 Z)种头行,但真实 logger 写的是本地墙钟(无时区后缀);读取端按本地时间解析无后缀戳,两者在非 UTC 时区差一个偏移量。
  3. 影响范围与严重程度:仅测试,无运行时/线上影响。触发条件:非 UTC 时区跑 tests/log-retention.test.ts——正偏移 ≥8h(如 Asia/Shanghai)1 项翻红,负偏移(如 New_York)2 项翻红;UTC 下 23/23。属「测试在特定环境下假红」,非产品缺陷。
  4. 怎么修复的:头行改用真实 logger 自己的格式化器 logTimestamp(new Date(at))(本地墙钟、无时区后缀),种下去的行在每个时区都精确往返,与 logger 真实产出的行形一致。
  5. 是否有回归问题:无。纯测试改动;预算删除排序走目录名戳(UTC、时区无关)+ mtime,不受影响;真实 logger 本就写 logTimestamp,测试现在反而更贴近现实。高危模式(语义漂移/吞错/阈值漂移)逐项过:均不涉及。
  6. 是否破坏缓存:不涉及(无缓存/重试/游标/去重键改动)。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及(无新 env/config/默认值)。

判定:可合 —— 修复正确且已在三个时区实测 23/23,纯测试改动无回归。合入前 rebase 到当前 master(现 behind);两个红 shard 与本 PR 无关(基础设施/继承,归 #4599)。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p3 scope/ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant