Skip to content

[PR] Repeated invocation guard: on the 5th occurrence, warn only without killing the turn; terminate on the next violation (# | 重复调用守卫:第 5 次只警告不杀回合,再犯一次才终止 (#5225) - #5327

Merged
ranxianglei merged 11 commits into
masterfrom
fix/5225-repetition-escalation
Oct 31, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是啥问题?

pi/omp 插件里的重复调用守卫(防小模型死循环)在同一工具+同样参数连发第 5 次时,直接在调用执行前掐掉整个回合。但合法的等待/轮询天生就是"参数不变、结果随外部状态变":调试器 kd_wait 每 10 秒问一次、omp 任务等待器每次返回下一个完成的——第 5 次(约 40-60s)被整段杀掉,等待还没到期(Codemode、omp 两起真实报告,issue #5225)。

如何解决的?

升级链从「警告→一刀杀」改成三段式(owner 定稿):

  • 连续第 3、4 次:随结果附警告(照旧);
  • 第 5 次:abort 阈值处只拒绝这一次调用并发出明确的最后警告(reason 里写明:再重发一次同样调用整个回合终止;轮询请改一次更长等待;换任何参数/工具计数立即重置)——回合保留,模型还有一次反应机会;
  • 第 6 次(被拒后仍一字不差重发):拒绝 + ctx.abort() 杀回合(原有 kill 语义后移一位)。

真死循环保护不受削弱:最多多烧一次调用。同时修正两处误导文案("byte-for-byte identical"实为规范化排序键后相同;"re-running will not produce a new result"对轮询类不成立)。配置旋钮(guardrails.repetition,warn=3/abort=5)不变,仅语义文档化:"abort=N"= N 次发最后警告,N+1 次杀回合(process.yaml + 生成的 CONFIGURATION*.md 已同步)。

附带两处小修(都是合并遗留的既有红,非本 PR 引入)

  1. LIFECYCLE.md 补两个 env 登记:BILI_SPAWN_FINGERPRINT([Bug] Plugin bootstrap spawns a new instance while the old one still holds the port and drops proxying (goes direct): la | [Bug] 插件 bootstrap 在旧实例仍占端口时新起实例并放弃代理(goes direct):大会话随即以未压缩历史撞上游上限(400 Range of input length / 413) #4125/本仓库已合的 [PR] Two installations differing by one version no longer deadlock on the same port; traffic is no longer sent in the clear ( | 两份安装差一个版本不再死锁在同一端口上,流量不再裸奔(#4125) #5303 引入)、BILI_SESSION_CONTENT_STORE_PIN(master [PR] fold idle session content stores between requests (#4788 phase 2) #5292 引入)——两者都在 src/ 读取但未登记,导致 master 自身 lifecycle-ledger-guard 红。
  2. tests/storage-unified.test.ts:feat: Support precise timestamps for each message, allowing the model to recognize which messages are outdated and which | feat: 给每个消息支持精确时间,以让模型认识到什么消息是过期的什么是当前的新的 #4313 合入(c38777f)的两个 stub 给 CoreMessage[] 塞了带 ts 的字面量,tsc 报 TS2353×4 → stub 参数类型放宽为 (CoreMessage & { ts?: number })[]。
  3. 已知残留(不在本 PR 范围):tests/issue4313-message-timestamp-toggle.test.ts 引用 acp-kernel 当前未导出的 LEAN_HOW_TO_COMPRESS_TIMESTAMPED / CompressionState.tsStamps(kernel 产物需重建同步),master 既有的 typecheck 红,需要 feat: Support precise timestamps for each message, allowing the model to recognize which messages are outdated and which | feat: 给每个消息支持精确时间,以让模型认识到什么消息是过期的什么是当前的新的 #4313 一侧处理。

回归测试与判定

URL

issue: #5225

@ranxianglei ranxianglei changed the title 重复调用守卫:第 5 次只警告不杀回合,再犯一次才终止 (#5225) [PR] 重复调用守卫:第 5 次只警告不杀回合,再犯一次才终止 (#5225) Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: fix/5225-repetition-escalation (b76f0c9)

Latest build — install this exact version

npm install -g billion-context@0.0.7514-pr.5327.51173b3

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
b76f0c9 billion-context@0.0.7514-pr.5327.51173b3 build
3cb9346 billion-context@0.0.7505-pr.5327.0818a0b build
1c9d82b billion-context@0.0.7502-pr.5327.d4c614f build
0158ef4 billion-context@0.0.7495-pr.5327.ed5cb1f build
9bdfba8 billion-context@0.0.7492-pr.5327.b500168 build
b40e9de billion-context@0.0.7490-pr.5327.f76ca47 build
548aaa4 billion-context@0.0.7479-pr.5327.122d11f build
cc86419 billion-context@0.0.7471-pr.5327.2906fc6 build
c7e219a billion-context@0.0.7468-pr.5327.77557c2 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei force-pushed the fix/5225-repetition-escalation branch from c7e219a to cc86419 Compare October 31, 2026 08:52
@ranxianglei

Copy link
Copy Markdown
Owner Author

CI 失败处理(两处红均为 master 合并遗留,非本 PR 引入):

  1. rebase 到最新 master + 重新生成文档——New built-in chat prompt pack: default compression rules for long-term companionship / multi-session memory scenarios (e | 新增内置 chat 提示压缩包:长期陪伴 / 多会话记忆场景的默认压缩规则(compress.promptPack="chat" 启用) #5319/[PR] feat: Built-in chat prompt compression package — default compression rules for long-term companionship / multi-session m | feat: 内置 chat 提示压缩包——长期陪伴 / 多会话记忆场景的默认压缩规则(#5319) #5320(内置 chat prompt pack)在本分支分叉后才合入,生成器输出的 builtin 列表变了,CONFIGURATION.md/CONFIGURATION.zh-CN.md 两个生成物已重新生成(docs-sync 转绿)。
  2. src/codex-models.ts: CodexWindowSource 改模块内类型(2521db3)——Codex model_catalog_json installs still fall back to the 272K window — #2600 fix only reads models_cache.json #5243/[PR] Step 2 of the Four-Lane Shared Startup Lifecycle: OMP Lane Migration In (#5241 Phase 1 / PR-1b, pure move) | 四车道共享启动生命周期第二步:omp 车道迁入(#5241 阶段 1 / PR-1b,纯搬运) #5246 合入时导出了这个只在文件内使用的 type,master 自身的 unused-exports gate 就是红的(已在 master tip f6e69ae 上复现);本 PR 顺手修掉,加注释说明为何不 export。

本地验证:unused-exports clean、lifecycle-ledger-guard 绿、guardrail 单测 41/41。

@ranxianglei

Copy link
Copy Markdown
Owner Author

补两笔(前一轮矩阵红的根因与修复):

  1. 548aaa439 test(promptCache.routing is ignored by relay-affinity stamping; no way to persist per-endpoint prompt_cache_key abatement (0.1.209) #5103)——我自己漏跑的回归:本 PR 早前改了 promptCache.routing is ignored by relay-affinity stamping; no way to persist per-endpoint prompt_cache_key abatement (0.1.209) #5103 拒绝文案(注明「严格更新的目标会自动被采纳」),测试里钉旧文案的那处断言没在回归集内,更新为钉新文案。无行为变化。
  2. b40e9deed fix(store)——flushAll 那片红是 master 侧既有 bug,非本 PR 引入(我的 diff 未触及 store/session;master 最近的全量 CI 本就全 cancelled/red,没人看见)。机制:[Performance] v0.1.208 long sessions exceed 2 GiB memory and spend 14–22 seconds in local processing #4788 phase-2 在一次成功保存后把内存原始内容降成「用时从磁盘重载」的惰性代理;若此刻盘上信封写不进/已损坏,下一回合采纳新内容做差集时按 CCR content-store companion write is non-atomic — a crash mid-write silently destroys all retrievable originals #2674 纪律抛「无法重新物化」→ 整个 adopt 炸掉,新引用记不进去,会话此后每次访问都硬报错直到人工修文件。修复:旧内容重载失败(镜像与 sidecar 双双已不可读=旧字节本已不可恢复)时按「无存活旧引用」处理,新库照样完整采纳、标脏落盘,会话随瞬时故障消除而恢复。tests/store.test.ts 恢复绿。

结论:本轮 5 片矩阵红 = 我漏跑的文案钉 ×1 + master 既有红 ×1,均不涉及 guardrail 逻辑本身。

@ranxianglei
ranxianglei force-pushed the fix/5225-repetition-escalation branch from b40e9de to 9bdfba8 Compare October 31, 2026 09:46
@ranxianglei

Copy link
Copy Markdown
Owner Author

补一笔:master 在这期间又前进了(#5325/#5331/#5340 web pack 系列),已 rebase 到 d108df3;其中 #5340 带进一个未用导出 (unused-exports 红),同样顺手修掉(去掉死 export)。本轮矩阵+全部 gate 待绿。

@ranxianglei

Copy link
Copy Markdown
Owner Author

补一笔(0158ef4):rebase 后 master 新合入的 #5340(web packs)带进两处小病,顺手修:①Windows 上 npm 是 npm.cmd,无 shell 的 execFileSync 找不到 → 按平台选命令;②错误摘要一行裸 .slice(-3) 触发 text-safe 家族门 → 改 safePrefix 且去负切片字面量。issue2129 那片只在 CI 红、本地两棵树均过,按 flake 处理(复现再查)。

@ranxianglei ranxianglei changed the title [PR] 重复调用守卫:第 5 次只警告不杀回合,再犯一次才终止 (#5225) [PR] Repeated invocation guard: on the 5th occurrence, warn only without killing the turn; terminate on the next violation (# | 重复调用守卫:第 5 次只警告不杀回合,再犯一次才终止 (#5225) Oct 31, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

全绿了。最后两笔记录:

  • 1c9d82b:空提交——上一轮 u24s1 分片跑死在 runner 上(超 15 分钟上限仍无日志可取),整轮作废重开矩阵。
  • 3cb9346:Windows 上不再经 npm shim。现象:npm.cmd 直 spawn 在 GH windows runner 上 7ms 即败、stderr 全空(shim/cmd 包装的解析边缘问题)。改法=直接用正在跑的 node 执行它旁边的 node_modules/npm/bin/npm-cli.js,绕开 PATH/shim/cmd,且 pack spec 参数永不进 shell(零注入面);非 win32 路径与原来完全一致。

至此矩阵 12 腿+全部 gate 绿。本 PR 期间顺手修掉的 master 侧小病清单:#5103 文案钉漏网、store.ts flushAll 懒库恢复(#4788 phase 2)、PackInstallOptions 内部导出、pack-install 裸负切片、npm shim Windows 三件套。均独立小提交,不混入 #5225 主线。

ework-agent and others added 11 commits October 31, 2026 19:27
…and only kills the turn on the repeat after it (#5225)
…nsumed; master self-red on unused-exports)
…er (ci-fixes owns both registrations)

Rebased onto master (485c5ea). master's ci-fixes commit 0371089 already
registers BILI_SESSION_CONTENT_STORE_PIN and BILI_SPAWN_FINGERPRINT in
LIFECYCLE.md; this PR's own registrations would have landed as duplicate
rows in two different tables. Drop this branch's copies, keep the
ci-fixes-owned rows. lifecycle-ledger-guard green (171 readers / 174 entries).
@ranxianglei
ranxianglei force-pushed the fix/5225-repetition-escalation branch from 3cb9346 to b76f0c9 Compare October 31, 2026 11:31
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

核验完毕,终态全绿。 你上一条评论之后我又做了一笔收尾:master 在分支 base(d108df3)之后前进了一个提交(#5322 dns-wedge-alarm,485c5eaf),merge-tree 无冲突,但两边各自在 LIFECYCLE.md 登记了同样的两个 env(BILI_SESSION_CONTENT_STORE_PIN、BILI_SPAWN_FINGERPRINT),直接合并会在两张不同的表里各留一行重复登记。已 rebase 到当前 master 并删掉本 PR 侧重复的两行(ci-fixes 哨兵 0371089 拥有这两条登记,保留其版本),lifecycle-ledger-guard 本地绿。新 head b76f0c95b:矩阵 12 腿 + 全部 gate 绿(36 success / 13 skipped / 0 failed)。另:tests/issue5152-owner-beat-survives-host-stall.test.ts 那次单发失败(端口分配竞态形状,后续矩阵不复现)已按 flake 记入 #4599。

结构化八问

  1. 是什么问题:pi/omp 插件的重复调用守卫在第 5 次相同调用时直接杀掉整个回合——有界等待/轮询类工具(kd_wait 等)参数不变但结果跟随外部状态,合法等待在到期前就被判死循环处决(Codemode、omp 两起真实报告)。
  2. 什么原因导致的:原升级链是「警告→一击杀」两段式,把「参数相同」当作死循环证据;但有界轮询天然参数相同、结果变化,kill 点正好落在正常等待窗口内——判定维度(参数指纹)与它想抓的病症(永不进展的死循环)不匹配。
  3. 影响范围与严重程度:用等待/轮询类工具的 pi/omp 车道;特定条件功能缺陷(合法等待被杀回合),非整体不可用。
  4. 怎么修复的:升级链改三段式——第 3/4 次警告照旧;第 5 次(=abort 阈值 N)只拒绝这一次调用并附明确最后警告(回合保留,模型可反应:改一次更长等待,或换任何参数/工具计数立即重置);第 6 次(被拒后仍一字不差重发)拒绝 + ctx.abort() 杀回合。真死循环保护不受削弱(最多多烧一次调用)。同时修正两处误导文案:「byte-for-byte identical」实为规范化排序键匹配;「re-running will not produce a new result」对轮询类不成立。abort=N 语义写入 process.yaml + 生成的 CONFIGURATION*.md。
  5. 是否有回归问题:审过的既有行为——master 侧两个测试缺陷把每个 PR 的 CI 测试通道卡红(pi 工厂测试必崩 + 测试锁路径断言不兼容 Windows) #3170 missing-ctx 容错不变(测试钉住);自定义阈值(warn=2/abort=3)同构(测试钉住);非循环场景零行为变化;循环场景 kill 点从第 5 次后移到第 6 次(有意变更,见下)。顺手修复各自独立小提交:store.ts adoptContentStore(修 [Performance] v0.1.208 long sessions exceed 2 GiB memory and spend 14–22 seconds in local processing #4788 phase 2 继承 bug,tests/store.test.ts flushAll 回归钉)、Windows pack-install npm shim 绕行、PackInstallOptions 内部导出、裸负切片→safePrefix、promptCache.routing is ignored by relay-affinity stamping; no way to persist per-endpoint prompt_cache_key abatement (0.1.209) #5103 文案钉更新。
  6. 是否破坏缓存:不涉及(缓存/重试/增量游标/去重键失效策略均无影响)。
  7. 是否改了设计方向:没有——仅守卫升级链调档 + 文案纠偏,架构/边界/数据流无转向。
  8. 是否引入了新的配置:没有——knobs 不变(guardrails.repetition warn=3/abort=5),只文档化了 abort=N 的语义(N 次末警,N+1 次杀)。

行为变更披露(旧值→新值+原因)

  • 重复调用 kill 点:第 5 次拒绝+杀回合 → 第 5 次只拒该次调用(回合保留)、第 6 次拒绝+杀。原因:有界轮询参数相同结果变化,旧语义处决合法等待。
  • adoptContentStore 失败路径:旧内容重载失败抛错杀死整个 adopt(会话硬报错直到人工修文件)→ warn 日志 + 按「无存活旧引用」处理(新 store 全量采纳、标脏落盘),瞬时故障消除即恢复。原因:该点旧字节已被证明不可恢复(mirror 与 sidecar 都读不出),fail-fast 只把瞬时故障变成永久会话死亡。
  • Windows pack-install 调用方式:npm.cmd 直 spawn(GH windows runner 上 7ms 静默失败,stderr 全空)→ 用正在跑的 node 执行 <node目录>/node_modules/npm/bin/npm-cli.js(缺失回退 npm.cmd);spec 参数永不进 shell(零注入面);非 win32 路径逐字不变。原因:pack install/remove 在 Windows 上完全不可用。

判定:可合并(mergeable,CI 全绿,等你合)。

@ranxianglei
ranxianglei merged commit f9cec9f into master Oct 31, 2026
49 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.958-master.f9cec9f (rolling master tag).

npm install -g billion-context@0.0.958-master.f9cec9f  # 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.

Louie0806 added a commit to Louie0806/billion-context that referenced this pull request Oct 31, 2026
…st entry

Three follow-ups so this lane's diff contains only the thinking-leak work:

- LIFECYCLE.md: master's ranxianglei#5327 registered BILI_SESSION_CONTENT_STORE_PIN
  in the §2 standing table, and the lifecycle guard accepts that. This lane
  also added a §1 transition-ledger row for the same variable, i.e. two
  registrations for one name — the guard has no opinion, but a duplicate row
  is how registration drift starts. Kept master's §2 row only.
- tests/text-safe.test.ts: the allowlist row for
  `stderr.trim().split("\n").slice(-3)` in src/pack-install.ts is dead — master
  rewrote that code to `safePrefix((tailLines.length > 3 ? tailLines.slice(...)
  : tailLines).join(" "), 300)` (ranxianglei#5340 follow-up), so the literal no longer
  exists and the gate never consults the entry. Verified the gate is still live
  by injecting `("x").slice(-3)` back into src/pack-install.ts: 17/1 with
  `not ok 18 - family gate: no raw negative string slices outside the
  allowlist`; restored -> 18/0.

Battery after this: store 29, issue5175 34, tag-echo 79, text-safe 18,
issue5103 5, pack-install 6, memory-contentstore-lazy 8,
issue4788-resident-minimal 4, foreign-block-sweep 7, issue4666 2; the four
static gates exit 0; `npx tsc --noEmit` clean; gen-config-docs is a fixed point.
ranxianglei pushed a commit to growlf/billion-context that referenced this pull request Nov 2, 2026
…ence (ranxianglei#5505)

Config surface registration (house pattern per ranxianglei#5327: sub-behavior
documented in the parent entry desc, no separate seed key for object
sub-fields, no new env var -- file-only like enabled/warn/abort).
Regenerated CONFIGURATION.md/.zh-CN.md via tools/gen-config-docs.mjs.
growlf pushed a commit to growlf/billion-context that referenced this pull request Nov 2, 2026
…ence (ranxianglei#5505)

Config surface registration (house pattern per ranxianglei#5327: sub-behavior
documented in the parent entry desc, no separate seed key for object
sub-fields, no new env var -- file-only like enabled/warn/abort).
Regenerated CONFIGURATION.md/.zh-CN.md via tools/gen-config-docs.mjs.
ranxianglei pushed a commit to Maziar123/billion-context that referenced this pull request Nov 6, 2026
…ile existence (ranxianglei#4599)

The receiver fixture creates its .port file before the write lands; on a loaded runner the existsSync poll can win that race and read back an empty file, so Number("") === 0 tripped the assertion (CI: ubuntu-24 shard 2, run 42202673910 — second occurrence of this signature after PR ranxianglei#5327's one-off, recorded in ranxianglei#4599 as record-only). Poll until the content parses as a positive integer instead; the 15s deadline and the diagnostic message are unchanged.
ranxianglei pushed a commit that referenced this pull request Nov 10, 2026
…only, serving-immune)

- src/perf-telemetry.ts: perf_events table (WAL, retention cap 200k rows,
  ring buffer), kill switch BILI_PERF_TELEMETRY, pure-JSON mode frozen/off,
  degrade-not-throw discipline (#5327 culture)
- src/server.ts logRequestCost: structured mirror row through the single
  observation point every lane already flows through (#5408)
- src/persist.ts: arm sqlite/mysql lanes at the two sidecar-open paths,
  explicit json-mode off
- LIFECYCLE.md §2.4: BILI_PERF_TELEMETRY registered
- tests/issue5460-perf-telemetry.test.ts: 8 cases incl. pinned DDL/WAL golden
ranxianglei pushed a commit that referenced this pull request Nov 10, 2026
…only, serving-immune)

- src/perf-telemetry.ts: perf_events table (WAL, retention cap 200k rows,
  ring buffer), kill switch BILI_PERF_TELEMETRY, pure-JSON mode frozen/off,
  degrade-not-throw discipline (#5327 culture)
- src/server.ts logRequestCost: structured mirror row through the single
  observation point every lane already flows through (#5408)
- src/persist.ts: arm sqlite/mysql lanes at the two sidecar-open paths,
  explicit json-mode off
- LIFECYCLE.md §2.4: BILI_PERF_TELEMETRY registered
- tests/issue5460-perf-telemetry.test.ts: 8 cases incl. pinned DDL/WAL golden
ranxianglei pushed a commit that referenced this pull request Nov 11, 2026
…e extra payload

perfRecordRequest built payload_json via JSON.stringify OUTSIDE any guard, so a
BigInt / circular value in the exported `extra` field would throw synchronously
out of the request hot path (logRequestCost) — violating the module's stated
"degrades, never throws" / serving-immune contract (#5327/#5460). DORMANT today
(request-cost passes no extra) but the exported API invites it.

Wrap both record functions in try/catch that degrades telemetry (one-shot warn,
state.dead) rather than propagating into the caller. Matches the existing
ensureDb/insertRow degrade style. Adds a regression test pinning the
never-throw behavior (a BigInt extra must not reach the caller).
ranxianglei pushed a commit that referenced this pull request Nov 13, 2026
…only, serving-immune)

- src/perf-telemetry.ts: perf_events table (WAL, retention cap 200k rows,
  ring buffer), kill switch BILI_PERF_TELEMETRY, pure-JSON mode frozen/off,
  degrade-not-throw discipline (#5327 culture)
- src/server.ts logRequestCost: structured mirror row through the single
  observation point every lane already flows through (#5408)
- src/persist.ts: arm sqlite/mysql lanes at the two sidecar-open paths,
  explicit json-mode off
- LIFECYCLE.md §2.4: BILI_PERF_TELEMETRY registered
- tests/issue5460-perf-telemetry.test.ts: 8 cases incl. pinned DDL/WAL golden
ranxianglei pushed a commit to Louie0806/billion-context that referenced this pull request Nov 14, 2026
…ile existence (ranxianglei#4599)

The receiver fixture creates its .port file before the write lands; on a loaded runner the existsSync poll can win that race and read back an empty file, so Number("") === 0 tripped the assertion (CI: ubuntu-24 shard 2, run 42202673910 — second occurrence of this signature after PR ranxianglei#5327's one-off, recorded in ranxianglei#4599 as record-only). Poll until the content parses as a positive integer instead; the 15s deadline and the diagnostic message are unchanged.

(cherry picked from commit 8d283b9)
ranxianglei pushed a commit that referenced this pull request Nov 15, 2026
…only, serving-immune)

- src/perf-telemetry.ts: perf_events table (WAL, retention cap 200k rows,
  ring buffer), kill switch BILI_PERF_TELEMETRY, pure-JSON mode frozen/off,
  degrade-not-throw discipline (#5327 culture)
- src/server.ts logRequestCost: structured mirror row through the single
  observation point every lane already flows through (#5408)
- src/persist.ts: arm sqlite/mysql lanes at the two sidecar-open paths,
  explicit json-mode off
- LIFECYCLE.md §2.4: BILI_PERF_TELEMETRY registered
- tests/issue5460-perf-telemetry.test.ts: 8 cases incl. pinned DDL/WAL golden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant