Skip to content

feat: offline-auditability lines for window/metering/reconcile decisions (#2283) - #2423

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-08_observability-audit-lines
Oct 10, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-08_observability-audit-lines

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2283

Source: #2274 metering/window/reconcile auditability investigation (source-marked follow-up). Pure observation-plane additions — no change to compression semantics, wire shape, or config surface.

What each sub-defect gets

  1. Mid-session window-resolution changes become directly auditable. A per-session [window-change] info line fires when the resolution triple (model / windowSource / base-window) moves between requests (src/server.ts), placed pre output-headroom so the clampOutgoingOutput sizes max_tokens against the raw native window while preflight enforces the reserve-adjusted one — up to 25% of slack the clamp never sees #2096 per-request max_tokens reservation cannot masquerade as a base change. Fires only on an actual transition → ~0 default log volume. Directly replaces what the once-per-model [window] line could not show (a source/model switch or base rescale mid-session).
  2. Per-request usage-vs-estimate pairing. A debug-gated [usage-vs-est] line in preflightCompressIfNeeded records, on every request (not only when preflight triggers), the upstream-billed input paired with the same-payload estimateCoreMessages result, plus route / model / k̂ / baseline-grade. The call site is not pluginMode-gated, so it runs in both compression modes. This is the offline data source for the chars/4 deviation distribution behind the [决策请求] kernel nudge 双闸门 flat-50K 标定失配 <1M 窗口:慢增长会话永久饿死(#2110 RC2) #2273 RC2 calibration decision.
  3. Fold-reconcile drift lines report token volume. Each of the four drift variants (substrate-destroyed error / repair-reanchored / warn-no-repair / no-anchor-match) now appends the defaultCountTokens estimate of the mass re-entering the wire unfolded (churnTokens / claimedChurnTokens on ReconciliationPlan; repair mode nets out re-anchored mass). Quantifies Fold-state reconciliation: classify resent-history divergence (edit/fork/new/system-only) and make compression blocks re-anchorable chain units #1921's fold-rollback contribution to unbounded growth.

Behavior changes (old → new)

Additive log lines only; no decision / threshold / wire / config change:

  • NEW [window-change] info line — emitted only when the per-session resolution triple changes (rare; ~0 default volume).
  • NEW [usage-vs-est] debug line — emitted every request, but only while debug logging is on (default off).
  • CHANGED fold-reconcile drift lines — an extra (~N tok unfolded in churn region) suffix appended to 4 existing log strings; same drift conditions as before, and only when N > 0. No new log line, no level change.

No cache / retry / cursor / dedup-key invalidation touched. No config surface added — sub-defect 2 reuses the existing debug switch (no new env var or config field).

Tests

  • 3 new regression tests in tests/fold-reconcile.test.ts pinning the two new plan fields (clean-resend unset; reanchored churn == claimed == single-candidate count; unmatched real edit → full churn / zero claimed).
  • Local: typecheck ✓, build ✓, targeted tests/fold-reconcile.test.ts 28/28 ✓. Full suite + e2e deferred to CI (local-test discipline).

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-08_observability-audit-lines (003c00f)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2778-pr.2423.d437b75

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 上游冲突已解决 —— 分支已 rebase 到当前 master tip 并 force-push,本地定向门禁全绿。

处理过程:唤醒时分支基于旧 master(merge-base 850067292e),期间 master 前进 ~40 个提交。唯一文本冲突在 src/fold-reconcile.ts:master 侧 #2297 把 no-anchor-match 漂移分支从 else 改成了 else if (METADATA_DRIFT_ESCALATED !== true) 升级闩锁(一次 episode 只报一条 error,闩锁跨重启持久化,#2293),而本 PR 的 hunk 恰好要给同一组 4 条漂移日志追加 (~N tok unfolded in churn region) 后缀——同一批行两边都在改。按「意图取并」解决:保留 master 的升级闩锁守卫与新措辞,同时保留本 PR 的 token 量后缀。无信息损失:warn 被闩锁抑制时,substrate-destroyed 的 ERROR 行仍带后缀。首次 push 后 master 又落到 #2409(claude-fork-lineage,同样碰 src/server.ts)→ 再 rebase 一次(干净无冲突)后才最终 push,head 直接坐在当前 master tip 上。

结构化八问:

  1. 是什么问题:PR 分支与目标分支产生 merge 冲突(GitHub 标 dirty),阻塞合并——不是代码缺陷,是分支落后于快速移动的 master。
  2. 什么原因导致的:热文件竞争。master 的 fold-reconcile drift 告警在客户端侧删除历史场景下持续误报(计数含死块、#2193 升级后不抑制、措辞误导) #2297 重构了 reconcileFoldCoverage 同一段漂移日志块(改结构+改措辞),本 PR 在同一组字符串上加观测后缀,文本层面必然相撞;两个改动语义正交、可共存。
  3. 影响范围与严重程度:仅本 PR 分支自身的可合并状态;对用户零影响(PR 内容本身是纯增量日志行)。严重度:流程性阻塞,非产品缺陷。
  4. 怎么修复的:union-of-intent 解冲突(保 master 闩锁机制 + 保本 PR 观测后缀),rebase 到最新 master tip(de338aad1)而非停在中间版本,force-push(--force-with-lease,仅本 PR 分支,绝不碰 master)。
  5. 是否有回归问题:无。逐项过 diff 触碰路径的既有行为:① fold-reconcile 四条漂移日志——条件、级别、措辞全部保持原样,仅在 N>0 时追加后缀;master 的升级闩锁抑制逻辑完整保留(那是 master 既有行为,非本 PR 引入);② [window-change] 行只在解析三元组 (model/windowSource/base-window) 实际变化时触发,且置于 reserveOutputHeadroom 之前,clampOutgoingOutput sizes max_tokens against the raw native window while preflight enforces the reserve-adjusted one — up to 25% of slack the clamp never sees #2096 的每请求 max_tokens 预留无法伪装成 base 变化;③ [usage-vs-est] 行 debug 门控(默认关),不触碰任何决策路径。已在 rebase 后的 head 实测:typecheck ✓、tests/fold-reconcile.test.ts 39/39 ✓(含本 PR 新增 3 条回归测试)、build ✓(dist-import-annotations OK)。全量套件与 e2e 按本地测试纪律交给 CI。
  6. 是否破坏缓存:不涉及——未触碰任何缓存/重试/游标/去重键失效策略。
  7. 是否改了设计方向:不涉及——纯观测面增量,无语义/wire/config 转向。
  8. 是否引入新配置:不涉及——子缺陷 2 复用现有 debug 开关(ProxyOptions.debug),无新 env/config 字段。

当前状态:API 确认 mergeable: true,mergeStateStatus: blocked = 等新 head(a0f82b719)的 CI 检查跑完(非冲突)。冲突已清,等 CI 绿即可由人合并。

…cisions (#2283)

Observation-plane only; no change to compression semantics, wire shape, or config surface. Closes the three sub-defects from the #2274 metering/window/reconcile auditability investigation:

- fold-reconcile: expose defaultCountTokens of the re-entering unfolded mass (churnTokens / claimedChurnTokens on ReconciliationPlan) and append it to every drift variant's log line (#1921 growth contribution was id-counts only).

- server: emit a per-session [window-change] event when the resolution triple (model/source/base) moves mid-session, placed pre output-headroom so the #2096 per-request max_tokens reservation can't read as a base change.

- server: pair upstream-billed input with the same-payload estimateCoreMessages result on every request ([usage-vs-est], debug-gated) — the offline data source for the chars/4 deviation distribution behind the #2273 RC2 calibration.

Fold-reconcile tests pinned for the two new plan fields. Fixes #2283
@ranxianglei
ranxianglei force-pushed the 2026-10-08_observability-audit-lines branch from a9518e3 to c5cef5f Compare October 9, 2026 18:20
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 第二次上游冲突已解决 —— 分支已 rebase 到当前 master tip(055caad7e)并 force-push,本地定向门禁全绿。

处理过程:这次 master 的位移比上次大得多——除若干 fix 合并外,还落了一轮结构性重构:src/server.ts 从 6454 行拆成 2945 行 + src/server/*.ts 模块族(handle()、prepare-*、relay 等迁出),同时 src/fold-reconcile.ts 同一组漂移日志块又叠加了 #2396(idRewriteSuspects 检测)、#2480(newOrder/nextCanon 字段)与 byPos 位置认领。rebase 产生两类冲突:

结构化八问:

  1. 是什么问题:PR 分支再次与 master 冲突(dirty),阻塞合并——不是代码缺陷,是上轮 rebase 目标(de338aad1)在数小时内又落后了 ~10 个合并,其中含一轮文件级重构。
  2. 什么原因导致的:热文件竞争 × 结构重构叠加。master 把 src/server.ts 拆成模块族(本 PR 的两个 hunk 所在文件直接变形),又在 fold-reconcile 漂移日志块上叠加了与本 PR 同区域的观测增强([Bug][Prime/Responses] provider switch rewrites composite tool IDs and reintroduces compressed history #2396/折叠身份改为「位置为主 + 自存规范副本」:彻底终结跨协议 fold 漂移补丁链 (#2454 根因范式) #2480/byPos)——两边都在给同一批日志行加东西,语义正交但文本必撞。
  3. 影响范围与严重程度:仅本 PR 分支自身的可合并状态;对用户零影响(内容仍是纯增量日志行)。严重度:流程性阻塞。
  4. 怎么修复的:分文件策略——fold-reconcile 五处冲突全部 union-of-intent(双方新增都保留);server.ts 取 master 拆分布局为基座、两个观测行按原语义锚点逐字重植到新模块(而非机械塞回旧坐标)。force-push 用 --force-with-lease,仅动本 PR 分支。
  5. 是否有回归问题:无。逐项过 diff 触碰路径的既有行为:① 四条漂移日志——master 的 [Bug][Prime/Responses] provider switch rewrites composite tool IDs and reintroduces compressed history #2396 suspect 子句、byPos 计数、升级闩锁抑制(escalated 后每 pass 静默)、触发条件与级别全部保持,仅追加 N>0 时的 tok 后缀;② [window-change] 仍只在解析三元组 (model/windowSource/base-window) 实际迁移时触发、仍置于 output-headroom 预留之前;③ [usage-vs-est] 仍 debug 门控(默认关)、不进任何决策路径。已在 rebase 后的 head 实测:typecheck ✓、tests/fold-reconcile.test.ts 45/45 ✓(master 同期给该文件加了 6 条测试,39→45;含本 PR 的 3 条回归测试)、build ✓(dist-import-annotations OK)。全量套件与 e2e 按本地测试纪律交给 CI。
  6. 是否破坏缓存:不涉及——未触碰任何缓存/重试/游标/去重键失效策略。
  7. 是否改了设计方向:不涉及——纯观测面增量,语义与 wire 不变;代码物理位置随 master 重构落在新模块,属被动跟随,非本 PR 转向。
  8. 是否引入新配置:不涉及——子缺陷 2 复用现有 debug 开关,无新 env/config 字段。

当前状态:head c5cef5fcc 直接坐在 master tip 055caad7e 上;API 确认 mergeable: true,mergeStateStatus: blocked = 等新 head 的 CI 检查跑完(非冲突)。等 CI 绿即可由人合并。

awork added 2 commits October 10, 2026 10:39
…2570)

Found while fixing #2570: the #1933 route-change demotion line logs the
baseline origin and the current origin raw — same non-public-host leak
class as the [usage-vs-est] diagnostic. Both ride maskUrlForLog now, with
a regression test driving a usage-settling request through two routes.
@ranxianglei
ranxianglei merged commit 9ab9d40 into master Oct 10, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.212-master.9ab9d40 (rolling master tag).

npm install -g billion-context@0.0.212-master.9ab9d40  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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

Labels

None yet

Projects

None yet

1 participant