Repository navigation
fix(overflow): arm self-heal on ambiguous no-body 4xx errors - #215
Conversation
📦 Built Extension ArtifactBranch: Option A — Install from npm PR tag (recommended)pi install npm:billion-context-pi@pr-215Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pi-pr215.tgz
pi install ./packageThis comment is automatically updated on each push. |
|
Review round 1 (agent reviewer — verdict: ship):
Minor:
|
|
分诊(队列清理 #484): KEEP-VALID。 缺口在 master 上仍真实存在: 设计上对误报的防备是周全的:仅当 N 次连续 no-body 4xx(自上次成功 turn 起)+ 与记录的 sent-view 估算互证后才 arm,arm 后 boost 前仍查 guard。 rebase 风险:重。 |
c355c4e to
55e549f
Compare
✅ Rebased onto current master and force-pushed — branch How the two hooks were replayed (manual re-application per triage):
Verification on the rebased head:
PR is ready for human merge. 中文摘要:已按分诊把 #215 的两个钩子手工重放到重写后的 master(sent-view 记录点改用排除 armed floor 的 guard basis,避免紧急压缩后无条件再 arm;message_end 逻辑原样重放到新位置),本地测试与干净 master 失败集一致、新增 10 个用例全过、GitHub CI 全绿,可以合并。 |
Rebased onto master @ 72d8771 (queue cleanup #484 triage: KEEP-VALID). Both hooks manually replayed against the rewritten code: - wireContextTransform (#257/#455/#289 floors/calibration): noteSentView now records a guard basis = max(calibrated sent-view, provider-usage floor) — deliberately WITHOUT the armed 95% floor, so the ratio guard sees real size evidence and cannot re-arm unconditionally right after an emergency (original intent of "recorded before the armed boost"). - wireOverflowSelfHeal (moved to src/index.ts): message_end restructure verbatim from c355c4e — success resets the consecutive count, no-body 4xx arms only via OverflowEpisode.onNoBody4xx() corroboration. Verified on rebased head: typecheck clean; full suite failure set byte-identical to clean master (82 pre-existing sandbox failures from read-only /tmp mounts); +10 new overflow tests all pass; build OK.
55e549f to
819e415
Compare
fix(overflow): arm self-heal on ambiguous no-body 4xx errors
Problem
Real incident (2026-08-23): an ACP-managed pi session dead-looped. A 50,358-char bash
toolResult(~31,475 tokens, ~24% of the effective 131,072-token window) pushed the request past sglang'sinput + max_tokens ≤ 262,144hard cap. Every subsequent request returned400 status code (no body)forever:compress— the ACP loop never shrank the context.OVERFLOW_MARKERtext markers (maximum context length is N,prompt is too long, …), and a bodyless 4xx carries none of them.OVERFLOW_PATTERNSends with/^4(?:00|13)\s*(?:status code)?\s*\(no body\)/i), but the extension-side marker set deliberately never matched it — for good reason: OpenAI-compatible providers return the exact same no-body 400 for non-overflow reasons (invalid model, malformed request; seesrc/messages.ts:80-82), so treating it as an unconditional overflow risks false positives.Fix
Treat pi's bodyless
4xx ... (no body)error text as a possible overflow signal, and arm the emergency self-heal (forced ≥95% usage → kernel emergency nudge + tool-result truncate) only when at least one false-positive guard holds:NO_BODY_ARM_RATIO) of the effective limit — the same pct basis already logged per turn (tokenCount / config.modelContextLimit, recorded per request in thecontextevent, before the armed boost so the guard sees the real estimate).OverflowEpisode), recovering the dead-loop even when the estimate under-reports (the incident ran at ~24%: the sent-view estimate cannot see the provider'sinput+max_tokensaccounting).When the body has no parseable limit number (always, for a bodyless error), no window is learned — the armed emergency uses the already-resolved effective limit, so arming never fails for lack of a parsed number.
The classic text-marker arm path (
inspectOverflowMessage→ learn window + arm) is unchanged.Files changed
src/overflow-selfheal.tsNO_BODY_4XX_MARKER+isNoBody4xxError()(mirrors pi-ai's anchored regex);NO_BODY_ARM_RATIO = 0.5;OverflowEpisode.noteSentView/noteSuccess/onNoBody4xx()(returns{arm, consecutive, ratio});reset()clears the new state. Guard state is runtime/in-memory like thearmedflag — not persisted to acp.json (justified in comment: a resumed session re-establishes both within one turn; a persisted count would arm against a fresh session whose first request may succeed).src/index.tswireContextTransform: recordnoteSentView(tokenCount, config.modelContextLimit)before the armed boost.wireOverflowSelfHeal(message_end): non-error assistant turns callnoteSuccess(); error turns run the classic marker path unchanged, else the no-body path with the two guards; arms + logsno-body-arm(consecutive, ratio) + UI notify.tests/overflow-selfheal.test.tsCHANGELOG.mdTests
npm run typecheck✅ · full suitenpm test✅ 422 pass / 0 fail (was 412; +10):isNoBody4xxErrormatches400/413 status code (no body),400 (no body),413(no body); rejects429/500/404 (no body), quota text, empty, and prefixed text (anchored, like pi-ai).>=case).maximum context length is 262144 ...→ still arms via the text-marker path, window parsed (regression).OverflowEpisode.reset()clears sent-view + count; fresh episode (no recorded sent view) does not arm on the first hit.Notes
isThrottleError) is unaffected (a no-body 4xx never matched its throttle phrases).