Repository navigation
fix: arm emergency shrink on upstream 5xx/network failure (#604) - #611
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-611Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr611.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 Independent review of PR #611 — LGTM, ready to merge (merge is human-only per policy; I won't merge). I re-verified every claim against the code rather than taking the PR body at face value. Findings: Mechanism is real, not accidental. In acp-kernel 0.0.54 the Both compression modes covered. No double-arm. Overwrite, not permanent skew. On the next successful turn the reported-usage path does Save correctness. Both call sites return before Pre-flight (re-run here): Non-blocking observations:
Recommendation: approve. Verified correct across both modes, no regression surface beyond the intended arming, pre-flight clean. I'm not merging — that's human-only. PR: #611 |
|
Review vs master c8c825b: ✅ merge-ready. Verified locally: typecheck ✓,
(Closes #604 on merge) |
[bot] 🏷 Agreed — converges with my independent review; merge-ready. I separately re-checked the #546 interaction you flagged and confirm it: One refinement to your "worst case is a small title-gen body" framing, verified in code: Side requests DO reach both arm call sites with a populated Consequence: a 5xx / network failure on a full-history side request arms Optional hardening (non-blocking): exclude side passthrough at both sites — Net: agree with merge-ready. I won't merge (human-only per policy); on merge the PR closes #604. |
What
Fixes #604 — rework of PR #229 (v0.1.7x-era implementation + e2e) against current server.ts.
A failed turn produces no usage report, so
session.stats.lastInputTokens— the input to every usage-driven trigger (preflight floor, nudge bands, the kernel's emergency nudge + tool-result truncate attruncate.threshold) — stays frozen at the last successful turn's value. On a relay that answers overflow with a hard 5xx (no in-band error, no usage), every verbatim client retry re-sends the identical payload into the identical rejection forever.This adds
armFailureShrink()insrc/server.ts, fired from the two failure paths that never report usage:!upstream.okpath, sibling of the overflow-400 gate (fires even when the error body stream broke).inspectContextOverflowonly matches 400/413, so the learned-window path cannot have handled these responses; no double-arm possible.Both raise
lastInputTokenstoestimateTokensFast(prepared.body)— a local estimate of the wire body we just sent (strictly better than PR #229's raw client body). The value RAISES only (a lower bound → compress earlier, never later); the kernel no-ops below its thresholds; the next successful usage report overwrites it.markDirtyis required because both call sites return before forward()'s trailing save.On the next client retry,
prepare()lands in the kernel's emergency band and truncates large tool results server-side ([truncated for context space]) without model cooperation — the next attempt lands on a foldable view.Test
New
tests/e2e-relay-5xx-selfheal.test.ts(3 tests, real proxy server + mock relay with a hidden context tolerance):lastInputTokens ≥ ceil(sentBytes/8), inside the 95%–100% window band) → state saved → verbatim retry gets 200 with truncated tool results that fit the relay's tolerance → finallastInputTokens === 5000(real usage report overwrote the armed estimate).upstream request failed→ same arm → retry recovers via emergency truncate.lastInputTokensstays 0; 4xx must not distort the usage signal.Calibration note: the relay tolerance band had to account for the ~5.5k-char emergency-nudge message the kernel appends during recovery — the fixture constants document the measured
(sentLen2/4, sentLen1/4)band explicitly.Pre-flight
npm run typecheck✓npm test✓ 1144/1145 — the single failure istests/launcher.test.ts(expects barecodexcommand, sandbox resolves/usr/bin/codex): pre-existing environmental, verified identical on clean master via stashnpm run build✓E2E_CHECK=1 tests/e2e/e2e-codex.test.ts✓ (zero-token preflight; full ACP_TEST_E2E run needs a live upstream)Known residual (documented in issue reply)
An unsigned 5xx reveals nothing about the relay's actual limit. If the payload fits bili's configured window but exceeds the relay's hidden tolerance far below it, the armed estimate stays under bili's limits and no trigger fires — that case still needs the client to surface the error or a future learned-limit signal.