Skip to content

fix: break the small-model same-parameter compress failure loop early (#156) - #370

Merged
ranxianglei merged 1 commit into
masterfrom
2026-08-31_break-repeat-compress-fail-loop
Sep 6, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-08-31_break-repeat-compress-fail-loop

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Fixes the most serious part of #156: a small model (~2B) getting stuck re-submitting the exact same failing compress call (identical args) every round, burning all MAX_LOOP_ROUNDS (10) real upstream calls with zero success before completing gracefully.

Compress validation is deterministic — byte-identical args fail identically. So a re-submission of an already-failed call can never succeed; re-requesting only burns a real upstream call for an identical result.

How

runCompressLoop (src/loop/core.ts) now tracks the canonical args of every compress/decompress that fails this loop (failedSignatures). If a round is only failed compress/decompress calls and one of them re-submits args that already failed in a prior round, the loop breaks early (graceful completion) instead of running to the limit.

Safety properties:

  • Match is on canonicalized args (parsed + recursively key-sorted), so key-order/whitespace differences between two attempts do not defeat the match.
  • Fires only when the model is doing nothing but repeating failures. A successful compress, or any other proxy call (e.g. acp_status) in the same round, suppresses the break — so a model that is making progress is never cut off.
  • The model still gets one full chance to see a failure and correct it (the break fires on the second identical submission, not the first).

This directly stops the round 4→10 连续 7 轮 pattern from the issue, and also stops the loop from burning rounds on repeated identical hallucinated refs (#156 part 2) / repeated too-short-summary failures (part 3).

Files

  • src/loop/core.ts — canonicalArgs/sortKeys helpers, failedSignatures set, early-break after the MAX_LOOP_ROUNDS check.
  • tests/loop-core.test.ts — regression test (identical failing compress → breaks early, fetchCalls < MAX_LOOP_ROUNDS-1) + guard test (failing compress alongside another proxy call → does NOT break early, runs to the limit).
  • tests/fix-stream.test.ts — the abort-signal control test now varies the summary per round so it does not trip the new early-break (its intent is to prove the abort signal, not loop logic, stops re-requests).

Pre-flight

  • npm run typecheck (src, tsconfig.build.json): pass
  • npm test: 852/852 pass
  • npm run build: pass (dist self-contained)
  • No new type errors in the touched test files (verified against clean master — the 6 pre-existing test-file errors are unchanged and not part of the CI gate).

E2E note

tests/e2e/e2e-codex.test.ts could not be run in this environment (no codex binary — spawn codex ENOENT — and no local upstream at 127.0.0.1:8199). The change is in src/loop/, so please run the E2E (or the manual-dispatch CI e2e) before merging. The unit tests exercise the modified runCompressLoop directly via createResponsesAdapter() (the same Responses path the E2E drives), and all pass.

Out of scope (model-quality, not proxy-fixable)

#156 parts 2–4 (hallucinated refs, numeric-constraint memory, tag echo) are small-model capability issues. The proxy already surfaces clear validation errors and a tag-echo warning; this PR adds the missing piece — not wasting upstream calls on futile identical retries.

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-08-31_break-repeat-compress-fail-loop (bae19fa)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-370

Each push to this PR publishes a new version under the pr-370 npm tag.

Option B — Download artifact

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

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · vllm-qwen/qwen3.8-27b

[bot] Reviewed PR #370 (branch 2026-08-31_break-repeat-compress-fail-loop). I checked out the branch and re-ran the full pre-flight myself — every claim holds.

Pre-flight (verified by me, not taken on faith)

  • npm run typecheck (tsconfig.build.json): ✅ pass
  • npm test: ✅ 852/852 pass, 0 fail
  • npm run build: ✅ pass (dist/index.js 2.55 MB, self-contained)
  • Touched test files (tests/loop-core.test.ts, tests/fix-stream.test.ts): zero new type errors. Full tsc --noEmit = 188 errors on both master and this branch; the 6 errors in the two touched files are identical in type/count (one fix-stream fetch-cast error just moved 184→195 from the added lines). The CI gate (tsconfig.build.json) excludes tests, so it's clean.

Code review — correct

  • Placement is right: the new block sits after the round >= MAX_LOOP_ROUNDS graceful-termination and after the !reRequest early-return, so reRequest is guaranteed true there.
  • canonicalArgs/sortKeys (parse + recursive key-sort + re-stringify, raw fallback on parse failure) and the ${name}\u0000${args} signature (null-byte separator) are sound — key-order/whitespace variations won't defeat a match.
  • Break condition is precise: fires only when all of this round's proxy results are failed compress/decompress and one repeats a prior failure. A successful compress or any other proxy call (acp_status/search_context) suppresses it → a model making progress is never cut off. Fires on the 2nd identical submission (1st is recorded), so the model still gets one full chance to correct.
  • emitCompletion({ finishReason: "length", usage }) matches the existing graceful-termination path (core.ts:449).
  • Every compress failure path emits FAILED (stream.ts:231/271/306), so 小模型(2B级)compress 循环空转:同参数重复失败烧满 10 轮 + 幻觉 ref + 摘要长度约束不遵守 #156 parts 1 & 3 (Summary-too-short, content-too-small) and the hallucinated-ref path (part 2, via r.errors→line 271) are all covered.
  • The two new tests are non-vacuous: they drive the real runCompressLoop via createResponsesAdapter() (the same Responses path as the E2E) with genuinely-failing compresses. Regression asserts fetchCalls < MAX_LOOP_ROUNDS-1 (1 with fix vs 9 without); guard asserts fetchCalls === MAX_LOOP_ROUNDS-1 (no early break when acp_status is present).

Minor (non-blocking)

  1. reRequest && at core.ts:459 is redundant (already guaranteed true at that point) — harmless/defensive, no action needed.
  2. Decompress "block not found" ([Block b5 not found], decompress-shared.ts:75) doesn't contain FAILED, so a repeated identical decompress-of-missing-block won't early-break. Pre-existing convention gap (the old anyCompressFailed at core.ts:398 has the same blind spot), and decompress-not-found loops are far rarer than the compress loops 小模型(2B级)compress 循环空转:同参数重复失败烧满 10 轮 + 幻觉 ref + 摘要长度约束不遵守 #156 targets. Optional follow-up: have resolveDecompress emit [decompress FAILED: …] for consistency. Not a blocker.

Merge gate (not a code defect)

  • The E2E (tests/e2e/e2e-codex.test.ts) genuinely can't run here — I verified there's no codex binary and no local upstream at 127.0.0.1:8199. Since the change is in src/loop/, AGENTS.md requires the E2E (or the manual-dispatch CI e2e) to be green before merge. The unit tests cover the modified runCompressLoop via the same Responses adapter, but the real-client E2E is the only coverage for codex wire quirks / retry loops.

Verdict: LGTM on the code and tests — all pre-flight claims independently verified. Please run the E2E (or manual-dispatch CI e2e) before merging. I won't merge the PR (human-only per AGENTS.md).

…#156)

Rebased onto current master (v0.1.84); core.ts had evolved (+168/-44 since
v0.1.65) but kept the same run-to-MAX_LOOP_ROUNDS behavior with no
repeat-detection, so the issue still reproduces on the live version.

A small model can get stuck re-submitting the EXACT same failing compress
call (identical args) every round. Compress validation is deterministic, so
an identical call fails identically — re-requesting only burns a real upstream
call for an identical result. Previously the loop ran to MAX_LOOP_ROUNDS (10
real upstream calls) before completing gracefully.

runCompressLoop (src/loop/core.ts) now tracks the canonical args of every
compress/decompress that fails this loop. If a round is ONLY failed
compress/decompress calls and one of them re-submits args that already failed,
the loop breaks early (graceful completion) instead of running to the limit.

- Match is on canonicalized args (parsed + keys sorted), so key-order/whitespace
  differences do not defeat it.
- Fires only when the model is doing nothing but repeating failures: a
  successful compress or any other proxy call in the round suppresses the break.
- The model still gets one full chance to see a failure and correct it (break
  fires on the SECOND identical submission, verified at round 2 in tests).

Files:
- src/loop/core.ts: canonicalArgs/sortKeys + failedSignatures + early break
- tests/loop-core.test.ts: regression test (breaks early) + guard test
- tests/fix-stream.test.ts: abort-signal control test varies summary per round
@ranxianglei
ranxianglei force-pushed the 2026-08-31_break-repeat-compress-fail-loop branch from b5931d6 to bae19fa Compare September 4, 2026 12:47
@ranxianglei

Copy link
Copy Markdown
Owner Author

Review 结论:✅ 可合并(本环境补齐了缺的 E2E 验证)

代码 review 通过,逻辑与声明一致:

  • 门控正确:只在 re-request 轮(reRequest && realCalls===0)且该轮 proxy 调用全部是失败的 compress/decompress 时才可能触发——同轮有任何成功调用/其它 proxy 调用(acp_status 等)不会断,推进中的模型不会被误杀 ✓
  • canonicalArgs(parse + 递归排序 key + re-stringify):key 顺序/空白差异不会让匹配失效;非 JSON 参数回退原串(可接受的窄边角)✓
  • 断点在第二次相同提交:模型有完整一次机会看到失败并修正 ✓
  • finishReason: "length" + emitCompletion 与既有 MAX_LOOP_ROUNDS 优雅收尾路径(:560/:570)完全一致,不会产生退化空 completion ✓
  • result.includes("FAILED") 判据与 master 既有惯例一致(anyCompressFailed @ core.ts:483)✓
  • failedSignatures 不清空是正确的:break 只在当前执行也失败时触发,历史签名仍是有效的卡死信号 ✓
  • 连带修正 tests/fix-stream.test.ts 很关键:原 control 测试用静态重复参数,会被新逻辑在第 2 轮断掉、破坏其测 abort 信号的意图;改为每轮变化 summary,意图保真 ✓

验证(master e710eb0 = #545/#547/#548 合并后)

ework 上次说 E2E 跑不了(无 codex / 无上游)。本环境两者都有,已补齐:

无阻塞项,建议合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · qwen3.8-27b

[bot] 收到,谢谢把缺的 E2E 补齐——那正是我上一轮唯一挂起的合并门(本沙箱无 codex / 无上游,跑不了)。你在有真实 codex + Responses 上游的环境里跑了四阶段(warmup→load→ACP compress→purity)全过,这个门我采信(此环境无法复现)。

另外:我最初 review 时 master 还停在 035e6ec,之后 #539/#541/#545/#547/#548 陆续合入(当前 e710eb0,测试数 852→1049)。所以我又在当前 master上独立复核了一遍,结论与你一致:

对当前 master (e710eb0) 的独立复核

结论:代码逻辑、单测、以及你补上的 E2E 四阶段都通过,无阻塞项。同意可合并。

按 AGENTS.md,我不能合并 PR(合并是人类专属操作)。请你自行合并:#370

@ranxianglei
ranxianglei merged commit 0d951d8 into master Sep 6, 2026
6 checks passed
@ranxianglei
ranxianglei deleted the 2026-08-31_break-repeat-compress-fail-loop branch October 15, 2026 05:32
ranxianglei pushed a commit that referenced this pull request Oct 17, 2026
…tionable (#3302)

- pruneRefsToLiveIds records pruned refs into state.deadRefs (deduped, sorted) so both producers (compaction archive, zombie reap) feed the kernel tombstone path

- failure receipt falls back to the last nudge's compressible-range table when no live decision exists, instead of 'Call acp_status before retrying'

- loop logs a one-shot warning when a fixed-endpoint/varying-endpoint compress probe family is detected (#370 breaker stays identical-args only)

- stale-ref cause text and FOLD BASE GENERATION MISMATCH body no longer assert cross-session origin
ranxianglei pushed a commit that referenced this pull request Oct 17, 2026
…tionable (#3302)

- pruneRefsToLiveIds records pruned refs into state.deadRefs (deduped, sorted) so both producers (compaction archive, zombie reap) feed the kernel tombstone path

- failure receipt falls back to the last nudge's compressible-range table when no live decision exists, instead of 'Call acp_status before retrying'

- loop logs a one-shot warning when a fixed-endpoint/varying-endpoint compress probe family is detected (#370 breaker stays identical-args only)

- stale-ref cause text and FOLD BASE GENERATION MISMATCH body no longer assert cross-session origin
ranxianglei pushed a commit that referenced this pull request Oct 17, 2026
…tionable (#3302)

- pruneRefsToLiveIds records pruned refs into state.deadRefs (deduped, sorted) so both producers (compaction archive, zombie reap) feed the kernel tombstone path

- failure receipt falls back to the last nudge's compressible-range table when no live decision exists, instead of 'Call acp_status before retrying'

- loop logs a one-shot warning when a fixed-endpoint/varying-endpoint compress probe family is detected (#370 breaker stays identical-args only)

- stale-ref cause text and FOLD BASE GENERATION MISMATCH body no longer assert cross-session origin
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