Skip to content

fix: short-circuit identical compress failures (#156) - #182

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-08-21_compress-shortcircuit
Open

fix: short-circuit identical compress failures (#156)#182
ranxianglei wants to merge 1 commit into
masterfrom
2026-08-21_compress-shortcircuit

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem (#156)

Field logs from a 2B model (Codex + Responses, v0.1.27): the model retried the same failed compress range with the same validation error (Summary too short (28 chars…) ×6) for all 10 loop rounds. Every retry was a real upstream call — up to 10 wasted requests + tokens per session, with zero chance of the model self-correcting since it re-sent byte-identical arguments.

Fix

1. Identical-failure short-circuit (src/loop/core.ts)

compressFailureSignature() fingerprints each round's failed compress calls: requested refs (startRef..endRef, from parseCompressInput) + the failure text with volatile digits collapsed (so 28 chars and 31 chars count as the same failure class). After two consecutive rounds with an identical signature, runCompressLoop completes gracefully (finishReason: "length", same as the round-limit path) instead of re-requesting a third time.

  • Distinct failures (model varies its range or error class) keep the loop alive — no premature stop.
  • Any non-failing round resets the signature, so success → repeat-failure sequences still get their two chances.
  • Logs [acp-loop] compress loop short-circuited (identical failure twice): … for observability.

2. Actionable 0-ranges failure text (src/stream.ts)

no valid ranges parsed now tells the model how to recover: each range needs string startId/endId refs plus a summary, and acp_status lists currently valid refs.

Test adaptation

tests/fix-stream.test.ts client-abort control arm replayed a byte-identical failing round, which the new short-circuit now (correctly) stops after 2 rounds. The fetch mock now varies the failing range per round so the control still measures what it was built to measure: without an abort signal, the loop runs to the round limit.

Tests

  • New tests/compress-shortcircuit.test.ts (3): identical failure twice → exactly one re-request; distinct failures → loop continues; 0-ranges failure carries acp_status guidance.
  • Full suite: 515/515 pass; tsc --noEmit clean.

Fixes #156 (items ① and ②; ③ shipped in v0.1.44 via compress.prompts; ④ tag-echo stripping tracked separately).

A small model (2B) retried the same failed compress range with the same
validation error for all 10 loop rounds — each retry a real upstream
call (issue #156 field logs). runCompressLoop now fingerprints failed
compress calls per round (requested refs + failure text with volatile
numbers collapsed) and completes gracefully after two consecutive
identical failures instead of re-requesting a third time. Distinct
failures still keep the loop alive.

Also makes the 0-ranges compression failure message actionable: each
range needs string startId/endId refs plus a summary; acp_status lists
currently valid refs.
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.

小模型(2B级)compress 循环空转:同参数重复失败烧满 10 轮 + 幻觉 ref + 摘要长度约束不遵守

1 participant