Repository navigation
[PR] feat(guardrail): soft-stop repeated calls, hard-abort at backstop (#5505) - #5514
Conversation
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 检索 open+closed 未见针对「重复调用防护 / soft-stop / backstop / 第 6 次 abort」的同类条目;本 PR 专修 #5505 的 abrupt-abort 缺陷,机制唯一。(PR base = 当前 master tip ee0dcc7,非陈旧; 下面按结构化八问给结论。核心一句话:修法方向对(治的是 #5505 的根因),但把唯一的强制终止机制做成了 opt-in 且默认关 → 出厂默认配置下,重复调用防护失去了「最终会终止」的保证。 结构化八问
🔶 需要决策背景:默认配置下,重复调用防护失去了「最终会终止」的保证(master 原本第 6 次硬杀)。
我的推荐:A。 若坚持 B,必须同时:① 把 stuck-report 文案改成不含「将强制终止」的承诺;② 补一条默认路径测试,断言 count≥10 时仍为软停且 其它(非阻塞)
判定:拦下(暂不合) —— 等 owner 对 |
Update:
|
…efault-path abort (ranxianglei#5505) Alignment rework of PR ranxianglei#5514 (agreed design from issue thread: option A, opt-in single boolean under guardrails.repetition, default false = zero drift from current behavior). - The previous revision made the soft-stop UNCONDITIONAL: the 'abort' handler branch no longer called ctx.abort(), so with the flag off the turn was refused forever after call 6 and never terminated -- a silent change of the default behavior the thread explicitly ruled out. Now the whole ladder is gated: recovery off = master behavior byte-exact (call 6 still blocks AND aborts, original notice text restored); recovery on = calls 6..(abort+4) refused with a truthful stuck-report, hard backstop at abort+5 (default thresholds: soft 6-9, hard at 10). - Renamed backstopEnabled -> recovery (the flag gates the ladder, not just the backstop). - Restored the try/catch around ctx.abort() (mid-tool abort is best-effort; the block below guarantees the refusal) -- it was lost in the new hard-abort branch. - New buildRepetitionSoftStopNotice: promises forced termination at abort+5, which is true in the mode where it is delivered; the default path keeps 'The turn has been aborted.' (also true there). - Reverted diff noise: five SAFETY comments annotating pre-existing casts, behavior-neutral inputEvent rename. Kept from the PR: pendingStarts leak fix (complete() on every blocked path, behaviorally inert: blocked-call duration ~0ms << 5s long-poll reset window), complete-before-abort ordering.
…ed pendingCallCount (ranxianglei#5505) Alignment rework of PR ranxianglei#5514 test suite: - The wireRepetition harness auto-enabled backstopEnabled:true for every test, leaving ZERO coverage of the real default; removed the auto-merge so defaults exercise defaults. - Restored the default-path pins byte-exact: call 6 blocks with the original 'has been aborted' notice and ctx.abort fires exactly once (pi harness level + ranxianglei#5225 rapid-loop harness level); custom-threshold variant kills at its own abort threshold. - New explicit recovery-mode tests ({repetition:{recovery:true}}): soft stop 6-9 (no abort, /forcibly terminated/, doesNotMatch /has been aborted/) then hard abort at backstop 10; custom warn=2/ abort=3 -> soft 4-7, hard at 8. - Leak test now uses a typed RepetitionTracker.pendingCallCount getter instead of (t as any).pendingStarts.size; added a default-mode variant pinning cleanup on the final-refuse + abort paths too.
(ai: vllm-qwen/qwen3.8-27b) 已独立核验(不是采信描述):拉了新 head
结构化八问(更新)
合入前要处理(都不大;但我推不到你的 fork,见末尾)A. [新发现·最关键]
B. [必改] CONFIGURATION.md 该行已过时。
C. [必改·一行] 注释自相矛盾。 D. [建议] 测试钉住默认与边界。 现有 wire 用例经 关于推送本 PR head 在 判定:核心回归已解决、方向正确、代码干净。合入前请落 B、C(诚实性/文档,硬要求)+ A 的处置(删假声明或立项暴露);D 建议一并。这些落地即可放行——我不再就默认值拦你。(默认值那个决策已经定了, |
(ai: vllm-qwen/qwen3.8-27b) Round 3 — re-reviewed the new head What improved (verified):
The one blocker — the documented
Only the internal type Net effect: a user who follows your new CONFIGURATION.md / website yaml and sets Why CI is green while the feature is dead: your new tests call Process note: introducing an object form for a currently-boolean field is a new config shape — that needs the "config surface" section in the PR body plus owner sign-off (AGENTS config-surface discipline). It's documented in three places now without either. Concrete fix (I'd take A):
I can't push to your fork (no write access), so these are pointers rather than commits — and they're small. Happy to draft a patch on the ranxianglei side if you'd prefer. 八问(结论)
判定:设计扎实、默认零回归(比我一版的建议还稳),👍。合并前必须处理: |
|
Collaborator invitation sent to @ranxianglei for the fork. Check your email and accept the invite to gain write access to https://github.com/growlf/billion-context. Once accepted, you'll be able to push to the branch directly. |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
独立复核(head 323c62e06) — 我没有采信前几轮结论,把整条链在真实 head 上重新拉通了一遍。先给结论:默认路径干净、无回归;但这个 PR 的核心卖点(recovery 优雅终止)在生产配置栈里根本够不着——它是死代码,文档却在宣传它。 另外补一个前几轮没抓到的隐患。
我独立验证了什么(不采信描述)
- 全仓唯一生产调用点
src/agent/pi.ts:905:repetition: guardrailRepetition()—— 传的是布尔。 src/knobs.ts:339guardrailRepetition(): boolean—— 只返回布尔;loadConfigFile().guardrails?.repetition !== false会把任何对象强转成布尔,没有子字段透传、没有对应 env。src/config.ts:2261repetition?: boolean—— 类型化 schema 就是布尔,{recovery:true}在这个面里表示不出来。- 于是
resolveRepetition(true)→obj = {}→recovery = false,恒为 false。即便用户在 config 文件里手写"repetition": {"recovery": true},knob 也会把它压成布尔true丢掉对象。没有任何路径能让真实用户开起 recovery。
结构化八问
- 是什么问题:给 pi/omp 重复调用守卫加了一个 opt-in「优雅终止」模式(第 6–9 次软停、第 10 次 = abort+5 硬中止,替代原来第 6 次直接
ctx.abort())。但recovery只被内部类型GuardrailOptions.repetition接受,没接进生产配置链,所以没有真实用户能开启它——功能以死代码形式合入,而 CONFIGURATION.md(en/zh)+ process.yaml 却把它写成可用开关。 - 什么原因导致的:改动停在叶子层(
tool-guardrails.ts的类型 / resolve / handler / 文案 / 测试 / 文档),没动把用户配置送进守卫的三层管道:config.ts(schema) →knobs.ts(knob) →pi.ts(caller)。布尔一路传到resolveRepetition(true)就变空对象、recovery=false。根因=在决策层实现了新字段却没扩展 config→knob→caller 链(也没按 config-surface 规范为新字段写说明段)。 - 影响范围与严重程度:默认用户(repetition 未设 / false / true)零变化——阶梯仍是 warn@3 → final-refuse@5 → abort@6(真
ctx.abort()),已逐格验证,对今天所有用户无回归。真正受影响的是「想用 recovery 的人」:现在开不了→宣传的 opt-in 是坏的、文档在说谎。严重度不是 p1(默认仍保终止保证,无可用性/成本退化),属「功能不可用 + 文档误导」。若日后有人照文档天真地把接线补上,还会触发下面第 2 个隐患。 - 怎么修(推荐二选一,别停在半吊子状态):
- (A) 让它成真:
config.tsschema 扩成boolean | {enabled?,warn?,abort?,recovery?};knobs.guardrailRepetition()返回解析后的形状而非裸布尔;pi.ts:905透传对象;并按 config-surface 规范补说明段 + owner 对新字段的签核。 - (B) 不外露:把 CONFIGURATION.md / process.yaml 里关于 recovery 的描述撤掉,内部代码要么标注「预留、当前不可达」要么删掉,让本 PR 收敛到确实可达的部分。
现在的病根就是「宣传了但够不着」的半状态,两个方向都能治好,不能维持现状。
- (A) 让它成真:
- 是否有回归问题:默认路径逐项核对——warn@3-4 ✓、final-refuse@5(拦截不杀回合)✓、abort@6(真
ctx.abort()+ 原文案 "The turn has been aborted.")✓、慢调用(≥5s)/改参/用户输入重置 ✓、repetition:false整体关闭 ✓。新增的tracker.complete()只在 final-refuse/abort 分支按 key 清pendingStarts并把 lastCompleted 置 ≈0ms(< REPEAT_SLOW_CALL_MS=5000,不会误重置 run)——是泄漏修复、行为中性。一个新隐患(前几轮未提):recovery 模式下第 5 次(final-refuse)文案写「if the very next call is identical again, the entire turn will be ABORTED」,但下一次相同调用其实是 soft-stop(回合继续到 backstop@10)——与 PR 自称「各模式下文案都属实」自相矛盾。当前潜伏(模式够不着),一旦接线落地就会对用户发出;现有单测直接驱动 recovery 路径,所以现在就能钉住。 - 是否破坏缓存:不涉及——纯 pi-lane 守卫决策层,不碰 wire / 前缀缓存 / 账本。
- 是否改了设计方向:意图是从「到阈值即硬终止」转向「优雅软停 + backstop」,但因为挂在够不着的开关后面,实际出厂的设计方向没变(默认仍 abort@6)。recovery 要不要存在 / 要不要默认开 / 要不要外露,是 owner 的产品决策(#5505 也把文案可配性列为待定),不该被隐式拍板。
- 是否引入了新的配置:内部加了
GuardrailOptions.repetition.recovery?: boolean,但没有落到用户可见的 config/env 面(schema/knob/caller 全是布尔)——这正是它够不着的原因。若走方案 (A),guardrails.repetition.recovery才成为真正的用户字段(需 config-surface 段 + 签核);目前没有任何对应 env。
探针证据(recovery 模式,逐调用)
call 5 -> final-refuse block=true 文案声称「回合将被 ABORTED」 | 实际 ctx.abort() 次数: 0
call 6 -> soft-stop block=true (「下一次相同调用」其实只是软停,回合没死)
...
call 10 -> hard-abort block=true 此时才第一次 ctx.abort()
即:final-refuse 对「下一次就 ABORTED」的承诺在 recovery 模式下为假。修法:让 buildRepetitionFinalRefuseNotice 感知模式——recovery 下把「the entire turn will be ABORTED」换成「identical calls will keep being refused and the turn will be forcibly terminated at {backstop}」,并加一条断言 recovery 下第 5 次 reason 不含 /will be ABORTED/i 的回归测试。
判定:REQUEST_CHANGES
默认路径质量高、无回归,这部分我没有异议。拦下的两点都在「可达性 / 诚实性」上:①核心功能够不着(必须二选一收口);②recovery 文案虚报(接线前先钉住)。两者都不大、都不需要重做机制,补齐即可合入。
(CI 依派发信息为绿;我的本地定向探针确认了上述逻辑,全量套件以远程 CI 为准。)
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) PR #5514(upstream)/ 内部 #5516 已审完 → REQUEST_CHANGES(正式 review 已提交:pullrequestreview-5733383345)。 独立复核(没采信前几轮,在真实 head
默认路径干净、无回归(warn@3 → final-refuse@5 → abort@6 逐格验证,原文案保留;新增 |
…onfig file (ranxianglei#5505) Aligns with maintainer feedback on PR ranxianglei#5514 (request changes). Changes: - config.ts:2261 — repetition type: boolean | { enabled?, warn?, abort?, recovery? } - knobs.ts:339 — guardrailRepetition() returns boolean | object shape - tool-guardrails.ts:266 — text fix: "take stronger action" instead of "ABORTED" - process.yaml — 4 sub-field entries + main entry type: "boolean | object" - Auto-generated: CONFIGURATION.md, CONFIGURATION.zh-CN.md via gen-config-docs.mjs Fixes maintainer review items: 1. Recovery mode now reachable (config → knobs → pi chain passes objects) 2. Final-refuse text truthful for both default and recovery modes Verification: - config-surface guard: ✓ (182 leaf fields, 34 CLI flags) - npx tsc --noEmit: clean - npm run build: success (ESM dist/index.js 5.57 MB) - All 25 tests pass (11 tool-guardrails-pi + 14 issue5225)
|
@ranxianglei I've pushed the Option A changes that make mode reachable via config file: Changes:
Verification:
Collaborator invite: I've sent a GitHub collaborator invite to your account () for write access to the fork so you can merge this PR. Please accept the invite at https://github.com/growlf/billion-context/invitations This PR is now ready for your review. Thank you for the detailed feedback — Option A is exactly what was needed. |
|
@ranxianglei I've pushed the Option A changes that make Changes:
Verification:
Collaborator invite: I've sent a GitHub collaborator invite to your account ( This PR is now ready for your review. Thank you for the detailed feedback. |
…nxianglei#5505) When the repetition guard hits the abort threshold (call 6), the guard called ctx.abort() which killed the turn abruptly — the model received no stuck-report and host kernel state was interrupted. Replace the abrupt abort with a structured { block: true, reason } return that: - Blocks the tool execution (same as before) - Delivers a model-visible refusal message - Lets the turn end through the normal host path Also fix the contradictory message text that still said "The turn has been aborted." despite the new graceful behavior. Changes: - Remove ctx.abort() from abort handler in wireToolGuardrails - Update buildRepetitionAbortNotice to say "normal host path" - Update tests: abortCalls 1 -> 0, add new graceful-end test - Improve inline comment accuracy Fixes ranxianglei#5505
…ngStarts leak fix - Add backstopEnabled: boolean config (default: false, opt-in) - Hard backstop count: abortThreshold + 5 (call 10 for default thresholds) - Soft stop at calls > abort && < backstop: blocked, no ctx.abort (ranxianglei#5505) - Hard abort at calls >= backstop: blocked + ctx.abort() (forced termination) - Add tracker.complete(e.toolCallId) in both abort branches (pendingStarts leak fix) - Rewrite buildRepetitionAbortNotice with truthful stuck-report text - SAFETY comments on all 'x as unknown as T' casts - Update all RepetitionTracker tests and wireRepetition harness - Test: default thresholds soft-stop calls 6-9, hard-abort at call 10 - Test: custom (warn=2, abort=3) soft-stop calls 4-7, hard-abort at call 8
ranxianglei#5505) - Replace ctx.abort() at call 6 with soft stop: { block: true, reason } without executing ctx.abort(), so the turn survives with a truthful stuck-report (no false claims about turn ending on its own). - Add hard backstop at count >= abortThreshold + 5: refuses AND calls ctx.abort() (forced termination for non-compliant models). - Call tracker.complete(e.toolCallId) in every branch that returns { block: true, reason } before any ctx.abort() (so a throwing abort cannot skip the cleanup; 0ms duration < 5s threshold, safe). - Rewrite stuck-report text to be truthful and actionable. - Add negative assertions: stuck-report must not claim 'turn ends on its own'. - backstopEnabled: boolean opt-in (default: false). Tests: merged into existing repetition tests; covers all escalation levels, arg-change reset, custom thresholds, slow-call reset, and truthful text assertions.
…anxianglei#5505) Add a RepetitionTracker test that simulates the full escalation ladder (warn → final-refuse → soft-stop → hard-abort) and verifies that handler-initiated complete() calls keep pendingStarts empty after each blocked call — no leaks.
…guarantee)
With backstopEnabled defaulting to false, non-compliant models could
loop indefinitely (only soft stop, no hard abort). The maintainer's
requirement that the termination guarantee be retained from the factory
is now met: soft stop at 6-9, hard abort at 10 by default.
Users who want unbounded soft-stop can set
repetition: { backstopEnabled: false }.
Signed-off-by: growlf <growlf@thenetyeti.com>
…efault-path abort (ranxianglei#5505) Alignment rework of PR ranxianglei#5514 (agreed design from issue thread: option A, opt-in single boolean under guardrails.repetition, default false = zero drift from current behavior). - The previous revision made the soft-stop UNCONDITIONAL: the 'abort' handler branch no longer called ctx.abort(), so with the flag off the turn was refused forever after call 6 and never terminated -- a silent change of the default behavior the thread explicitly ruled out. Now the whole ladder is gated: recovery off = master behavior byte-exact (call 6 still blocks AND aborts, original notice text restored); recovery on = calls 6..(abort+4) refused with a truthful stuck-report, hard backstop at abort+5 (default thresholds: soft 6-9, hard at 10). - Renamed backstopEnabled -> recovery (the flag gates the ladder, not just the backstop). - Restored the try/catch around ctx.abort() (mid-tool abort is best-effort; the block below guarantees the refusal) -- it was lost in the new hard-abort branch. - New buildRepetitionSoftStopNotice: promises forced termination at abort+5, which is true in the mode where it is delivered; the default path keeps 'The turn has been aborted.' (also true there). - Reverted diff noise: five SAFETY comments annotating pre-existing casts, behavior-neutral inputEvent rename. Kept from the PR: pendingStarts leak fix (complete() on every blocked path, behaviorally inert: blocked-call duration ~0ms << 5s long-poll reset window), complete-before-abort ordering.
…ed pendingCallCount (ranxianglei#5505) Alignment rework of PR ranxianglei#5514 test suite: - The wireRepetition harness auto-enabled backstopEnabled:true for every test, leaving ZERO coverage of the real default; removed the auto-merge so defaults exercise defaults. - Restored the default-path pins byte-exact: call 6 blocks with the original 'has been aborted' notice and ctx.abort fires exactly once (pi harness level + ranxianglei#5225 rapid-loop harness level); custom-threshold variant kills at its own abort threshold. - New explicit recovery-mode tests ({repetition:{recovery:true}}): soft stop 6-9 (no abort, /forcibly terminated/, doesNotMatch /has been aborted/) then hard abort at backstop 10; custom warn=2/ abort=3 -> soft 4-7, hard at 8. - Leak test now uses a typed RepetitionTracker.pendingCallCount getter instead of (t as any).pendingStarts.size; added a default-mode variant pinning cleanup on the final-refuse + abort paths too.
…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.
…onfig file (ranxianglei#5505) Aligns with maintainer feedback on PR ranxianglei#5514 (request changes). Changes: - config.ts:2261 — repetition type: boolean | { enabled?, warn?, abort?, recovery? } - knobs.ts:339 — guardrailRepetition() returns boolean | object shape - tool-guardrails.ts:266 — text fix: "take stronger action" instead of "ABORTED" - process.yaml — 4 sub-field entries + main entry type: "boolean | object" - Auto-generated: CONFIGURATION.md, CONFIGURATION.zh-CN.md via gen-config-docs.mjs Fixes maintainer review items: 1. Recovery mode now reachable (config → knobs → pi chain passes objects) 2. Final-refuse text truthful for both default and recovery modes Verification: - config-surface guard: ✓ (182 leaf fields, 34 CLI flags) - npx tsc --noEmit: clean - npm run build: success (ESM dist/index.js 5.57 MB) - All 25 tests pass (11 tool-guardrails-pi + 14 issue5225)
20fda18 to
aa48eb7
Compare
…iew)
guardrailRepetition() normalized file value false -> true, so the
documented opt-out (repetition: false in the config file) silently
RE-ENABLED the loop-breaker. Master's own contract test
tests/knobs-config-precedence.test.ts:423 ('file tier') fails on the
PR head without this fix. Pass boolean/object forms through untouched.
ranxianglei
left a comment
There was a problem hiding this comment.
Review 结论:一个真 bug(已在分支上直接修掉)+ 其余可合。修复提交:c7868ed9(已把 master 合回分支,新 head 0aac0cc8)。
修掉的 bug(小问题,按 house rule 11 直接修)
src/knobs.ts guardrailRepetition():
// 原码:文件里 repetition:false → 返回 TRUE → 循环破除器被静默【重新打开】
return val !== undefined && val !== false ? val : true;文档(CONFIGURATION.md/zh + process.yaml)和 issue 都写着「false 或 env 0 关闭」,但对象形式落地时把布尔 false 的归一化写反了:配置文件写 repetition: false 的用户,守卫反而会被打开。master 自带的契约测试 tests/knobs-config-precedence.test.ts:423(断言 file tier 返回 false)在 PR head 上实测红(AssertionError: file tier,本地复现)。修法:undefined→true、boolean/object 原样透传,一行级改动。修后三个套件本地 73/73 全绿(knobs 优先级 + tool-guardrails-pi + issue5225-repetition-poll)。
实现本身的质量(没动的部分)
- 决策阶梯正确:recovery 下 count>abort 且 <abort+5 = soft-stop(拒+卡死报告+回合保留),count≥abort+5 = hard-abort(ctx.abort),默认模式行为与旧版逐字节一致(阶梯前两条只在 recovery 时命中)。
- 顺带修了一个真泄漏:所有 block 路径(final-refuse/soft-stop/hard-abort/旧 abort)补了
tracker.complete(e.toolCallId)——被拦的调用不会触发 tool_result,pendingStarts 原来会无限累积;注释论证了 0ms < REPEAT_SLOW_CALL_MS(5s) 不会误触发长轮询重置,成立。这条对默认模式也生效,是行为改善不是破坏。 - 通知文案的真伪处理到位:软停不再谎称 "The turn has been aborted"(有 doesNotMatch 回归钉),硬停/默认 abort 保留 "has been aborted" 并有 match 钉住;final-refuse 改成中性的 "take stronger action"(recovery 下必须这样才为真)。
- 测试覆盖够:tracker 层(pendingCallCount 不变式、recovery+默认两种模式的完整生命周期)+ wire 层(软停窗口不 abort、backstop 恰好一次 abort、自定义阈值 warn=2/abort=3→backstop 8)+ 通知文案真伪。
- 配置面:recovery 子字段仅文件可用(env 只认布尔)是合理收窄,CONFIGURATION.md/zh 按仓库惯例从 process.yaml 种子再生成,新增行排序和 file-only 标记符合现有格式;docs-sync 检查会背书。
小观察(不构成阻塞,不动手)
- env 表里
BILI_GUARDRAIL_REPETITION (boolean truthy/disabled only …)把注解塞进了变量名列,略挤,但生成器输出就这样,无碍。 pendingCallCountgetter 是为不变式测试暴露的类表面,无害且文档化了有界性承诺。
状态与建议
head 0aac0cc8 的 CI 正在重跑(synchronize 触发)。needs-decision 的两个点我认为都站得住:①recovery 默认 false(纯 opt-in,零存量影响)②backstop 固定 +5(窗口有限、终止保证不变)。CI 绿后可以直接合(已有「马上合并」label)。合并顺序建议:本 PR 独立,无依赖。
…anglei#5514 review) The (boolean truthy/disabled only...) annotation sat in the process.yaml env: field and was rendered verbatim into every table's env-name column; tools/gen-config-docs.mjs check-coverage exact-matches that column against the env names read in src/, so it reported BILI_GUARDRAIL_REPETITION as UNDOCUMENTED and red the docs-coverage job on this PR head while master stays green (reproduced locally both ways). The note is already carried by the desc fields ('object sub-fields are file-only'), so the seed now names the variable plainly and the artifacts regenerate clean.
ranxianglei
left a comment
There was a problem hiding this comment.
第二个直修(docs-coverage 红):提交 a7beb0d3,新 head。
- 现象:docs-coverage job 挂,
tools/gen-config-docs.mjs check-coverage报UNDOCUMENTED env vars read in src/: BILI_GUARDRAIL_REPETITION。 - 根因(本 PR 自带回归,master 本地实测绿、PR head 实测红,双向复现):
website/config-reference/process.yaml的env:字段被写成了BILI_GUARDRAIL_REPETITION (boolean truthy/disabled only — object form is file-only)——生成器把这串原样渲染进四张表的"变量名列",而 check-coverage 对这一列做精确匹配代码里的 env 名,于是带注解的名字匹配不上,裸名反而变成"未文档化"。 - 修法:注解信息 desc_en/zh 里本就有("对象子字段仅限配置文件(不通过环境变量暴露)"),seed 的 env 字段改回纯变量名,
generate重新生成全部产物(md EN/ZH 各两行)。本地验证:check-coverage→coverage ok: 195 env names + 59 top-level keys;generate→ i18n ok、零漂移。 - 至此两个直修齐了:
c7868ed9(knobs false 归一化)+a7beb0d3(docs seed),外加把 master 合回分支。等新头 CI 全绿即可合。
ranxianglei
left a comment
There was a problem hiding this comment.
第三个红是 flake(非代码问题),已触发失败分片重跑:job test (windows-latest, 22, 3) → tests/issue3380-dsh-rereg-selflock.test.ts:285。
证据链:
- 断言原文:
retryAt sits on the 80ms ladder step (got -13ms)—— retry 间隔是确定值(基线 20ms × 第 3 档 4 倍 = 80ms),断言拿墙钟retryAt - Date.now()∈ [30,95] 校验;差值 -13ms 说明 runner 在"设置 retryAt"和"读时钟"之间卡了 >93ms,纯环境抖动。 - 该测试属 DSH 注册自愈子系统(#3380),本 PR diff(守卫器/knobs/配置文档)与其零交集,不 import、不共享路径。
- 同一代码状态(上一轮 head
0aac0cc8,两轮之间只隔一个纯文档提交)在同一分片是绿的;本地 linux 跑该文件 6/6 全过。
已 rerun-failed-jobs(run 41656154138)。若重跑仍挂在同一行,再深查(那就是另一个故事了)。
Summary
Fixes #5505 — adds an opt-in recovery mode to the pi/omp repetition guard: instead of the turn being abruptly killed by
ctx.abort()on the first identical repeat after the final refusal, repeated calls are refused one at a time with a truthful stuck-report while the turn stays alive, and a hard backstop (abortThreshold + 5, default: call 10) retains the termination guarantee.Behavior Changes
Default (
repetition.recoveryunset orfalse) — unchanged from masterOpt-in (
"repetition": { "recovery": true }) — graceful ladderCustom thresholds (e.g.,
abort=3): soft-stop calls 4-7, hard abort at call 8.Technical Details
guardrails.repetition.recovery(default:false, object form only, no env var — same file-only surface as its siblingsenabled/warn/abort).recovery: trueswitches the whole escalation ladder to soft-stop mode;falsekeeps today's behavior byte-exact.tracker.complete(e.toolCallId)is called beforectx.abort()in the hard-abort branch (so a throwing abort cannot skip cleanup) and added to the final-refuse branch (pendingStarts leak fix — blocked calls never fire a tool_result, so the map would accumulate entries forever without it).Config surface
New key:
guardrails.repetition.recovery(boolean, defaultfalse).BILI_GUARDRAIL_REPETITION/guardrails.repetitionboolean only enables/disables the guard, and the object form already carriesenabled/warn/abort; there is no slot for the post-final-refusal escalation policy.website/config-reference/process.yamlunder the parent entry desc (house pattern per [PR] Repeated invocation guard: on the 5th occurrence, warn only without killing the turn; terminate on the next violation (# | 重复调用守卫:第 5 次只警告不杀回合,再犯一次才终止 (#5225) #5327);CONFIGURATION.md/CONFIGURATION.zh-CN.mdregenerated viatools/gen-config-docs.mjs. No new env var. Migration: none (off by default).Behavior-change disclosure
None for existing deployments: the default remains kill-on-repeat-after-refusal (call 6 with default thresholds) with the original notice text restored verbatim. The new mode is strictly additive behind the opt-in flag. (An intermediate revision briefly shipped the new mode as the default; the alignment rework below keeps the agreed opt-in default — flipping it on fleet-wide is a one-character decision the owner can make explicitly later.)
Verification
tests/tool-guardrails-pi.test.ts+tests/issue5225-repetition-poll.test.ts(default-path pins restored byte-exact + explicit recovery-mode tests incl. custom thresholds + pendingStarts cleanup pinned through a typed accessor)npm run typecheck); full-suite verdict = CI on the pushed headCommits
c6736eca— replace ctx.abort() with graceful turn endf80ff8a7— backstop at abort+5 + pendingStarts leak fix6e3d8feb— fix complete() order + add final-refuse cleanup45122079— test: verify pendingStarts stays empty for blocked callsff975d85— default backstopEnabled to true (retains termination guarantee)339854b4— alignment rework (reviewer): gate the whole ladder behind opt-inrecovery, restore default-path abort + original notice text, restore lost try/catch around ctx.abort(), drop diff noisecbed9a02— alignment rework (reviewer): restore byte-exact default-path test pins, add explicit recovery-mode tests, typed pendingCallCount accessor5971355e— alignment rework (reviewer): register guardrails.repetition.recovery in config reference (process.yaml + regenerated CONFIGURATION docs)