Skip to content

fix: surface truncated upstream streams instead of silent end_turn - #239

Merged
ranxianglei merged 2 commits into
masterfrom
2026-08-25_truncation-visibility
Aug 25, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-08-25_truncation-visibility

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Follow-up to #221 / PR #222.

What the reporter still sees

After PR #222 (thinking-replay fix), the agent no longer stops right after every ACP marker, but stops still occur, seemingly while the model outputs its long conclusion (#221 latest comment).

Root cause of this residual failure mode

If the relay drops the SSE stream mid-generation — before message_delta/message_stop (long conclusions are exactly where flaky relays truncate) — the loop's round ended with:

  • no done event → finishReason === undefined
  • emitCompletion({ finishReason: undefined }) defaulted stop_reason to a clean end_turn

So the client received a protocol-clean turn end in the middle of the conclusion text: no error, no retry, the agent just silently stops. This matches "stops while outputting the conclusion".

Fix

Detect abnormal round termination (no done event in the round) and, in the terminal branch:

  • emit an explicit [acp-proxy: upstream stream truncated (no completion event; round N, X text chars + Y reasoning chars received)] error block (still ends the SSE cleanly), and
  • log at error level ([acp-loop] upstream stream truncated ...)

Truncation is now visible and diagnosable instead of masquerading as a normal turn end. Kept master's suppressCompletion passthrough semantics intact.

Tests

tests/upstream-truncation.test.ts (3 tests):

  • truncated final round → partial text still delivered + visible [acp-proxy: upstream stream truncated error + clean end_turn
  • control: complete stream → no false-positive error
  • compress round followed by truncated conclusion round → round 2 identified in the error

Full suite: 596 pass, typecheck + build clean.

Refs #221

Follow-up to #221 (PR #222): the reporter still sees the agent stop
while outputting a long conclusion. If the relay drops the SSE stream
mid-generation (before message_delta/message_stop), the loop received
no done event, finishReason stayed undefined, and emitCompletion
defaulted it to a clean end_turn — the client then ended the turn
mid-text with no indication anything went wrong, which reads as the
agent silently stopping.

Detect the abnormal termination (no done event in the round) and emit
an explicit [acp-proxy: upstream stream truncated (...)] error block
plus an error-level log, so truncation is visible and diagnosable
instead of masquerading as a normal turn end.

Refs #221
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-08-25_truncation-visibility (7a96709)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-239

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

Option B — Download artifact

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

This comment is automatically updated on each push.

@ranxianglei
ranxianglei merged commit d462ef8 into master Aug 25, 2026
6 checks passed
ranxianglei pushed a commit that referenced this pull request Aug 26, 2026
A relay cutting a long-running request (e.g. MiniMax-M3 thinking
server-side for minutes) before any token is emitted ends the upstream
SSE with no completion event and zero content. PR #239 made that visible
but the agent still stopped, because the proxy surfaced the error and
terminated the turn.

A truncation that produced no text/reasoning is a clean re-send: nothing
reached the client, so the loop re-requests the same body and continues.
The retry is treated as a later round so message_start is not re-emitted
and no prefix is duplicated. Bounded by BILI_TRUNCATION_RETRY_MAX
(default 2 retries; 0 restores the fail-fast error). A partial-content
truncation is deliberately NOT retried (the model would regenerate from
scratch and duplicate the already-streamed prefix) and still surfaces the
visible error.
@ranxianglei
ranxianglei deleted the 2026-08-25_truncation-visibility branch October 15, 2026 05:32
cskwork pushed a commit to cskwork/billion-context that referenced this pull request Oct 21, 2026
…ei#221)

A relay cutting a long-running request (e.g. MiniMax-M3 thinking
server-side for minutes) before any token is emitted ends the upstream
SSE with no completion event and zero content. PR ranxianglei#239 made that visible
but the agent still stopped, because the proxy surfaced the error and
terminated the turn.

A truncation that produced no text/reasoning is a clean re-send: nothing
reached the client, so the loop re-requests the same body and continues.
The retry is treated as a later round so message_start is not re-emitted
and no prefix is duplicated. Bounded by BILI_TRUNCATION_RETRY_MAX
(default 2 retries; 0 restores the fail-fast error). A partial-content
truncation is deliberately NOT retried (the model would regenerate from
scratch and duplicate the already-streamed prefix) and still surfaces the
visible error.
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