Repository navigation
feat: termination diagnostics on the plugin-lane truncation signal (#2328 Q2/Q4) - #2367
Conversation
3b3d083 to
603f418
Compare
…iter throw paths) The non-rewriter branch awaited dumpRaw inline, so a rejecting pipe would skip it and leave the raw-SSE dump half-written — while the plugin lane and the rewriter lane both await in their own finallys. Move the non-rewriter await into the shared safety-net finally (idempotent for the rewriter lane) so all three lanes honor the 'full upstream tail before turn close' contract on every exit path. Success-path behavior unchanged.
…2328 Q2/Q4) The #721 in-band upstream_stream_truncated error frame said a stream was cut, but never WHY it could not be completed: the pipes know the event count, the last event types, the dangling EOF buffer, the retry budget state and the upstream HTTP identity — none of it reached the client or the log. #2347 forensics had to fall back to raw-SSE dumps to tell "upstream never sent a terminal" from "the terminal's bytes never completed". - stream-error.ts: emitUpstreamTruncation takes an optional TruncationDiag; it rides the error frame as `meta` (openai/anthropic/google nested in error.meta, responses top-level meta — google keeps its numeric-code object shape) and the log line as classification + cause + full JSON. - plugin.ts: both strip pipes (chat + responses) track events/bytes/ unparseable-forwards/last-5-event-types; at EOF and read-error they build the diag and classify the cut (#2328 Q4): - no-terminal-seen — EOF/read-error with no terminal bytes in flight; - terminal-bytes-unrecognized — the dangling partial event carries the opening bytes of the wire's own terminal ([DO(ne), event: message_stop, a quoted finish_reason/finishReason chunk, response. completed-family head). Factual byte evidence only. Responses adds responseStatus + held done-family count; both add the #2171/#732 retry-budget state and the upstream status/content-type (threaded as optional UpstreamMeta from server.ts, 5 call sites). - Wire-shape note: `meta` is a NEW field on error-only frames — flagged for human review per house rule; no non-error frame changes. Tests: tests/issue2328-terminal-diag.test.ts — 8 cases across openai/ anthropic/google/responses: both classifications, cause eof/read-error, counters, upstreamMeta threading, log-line shape; existing truncation suites (#2171/#1452/#732/#1061/#1039) unchanged and green.
603f418 to
4f71fef
Compare
发生了什么
冲突解法(3 处,均为 union)
结构化七问
判定:冲突已解除,等 CI 转绿即可;wire-shape 变更(error frame 新增 |
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2547-pr.2367.bef7b67This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2367.tgz
npm install -g packageInstall instructions are refreshed on each push. |
核查证据(2026-10-07 17:1xZ):
七问(本轮为核查型唤醒):
判定:PR 保持 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.125-master.196e3b6 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Implements the remaining quarters of #2328 (Q2 + Q4). Companion to #2351 (Q1 raw-SSE dump) — both are independent now; whichever merges second gets a small
src/server.tscall-site conflict to resolve (same lines: the tee vs theupstreamMetaargument).What
The
#721in-bandupstream_stream_truncatederror frame said a stream was cut, but never why it could not be completed. The pipes already know: parsed-event count, last event types, the dangling EOF buffer, retry-budget state, upstream HTTP identity — none of it reached the client or the log (#2347 needed a raw-SSE dump to tell the two failure classes apart).Q4 — classification, computed from factual bytes at the cut (
tailLooksTerminalinsrc/plugin.ts):no-terminal-seen— clean EOF / read error, nothing terminal in flight.terminal-bytes-unrecognized— the dangling partial event carries the opening bytes of the wire's own terminal:data: [DO…,event: message_stop, a quoted (non-null)finish_reason/finishReasonchunk head,event: response.completed|failed|incomplete/"type":"response.comp…"head.Q2 — metadata (
TruncationDiaginsrc/stream-error.ts), attached to the error frame asmetaand to the log line as one grep-able JSON blob:causeeof|read-error(which pipe path fired)classificationevents,unparseableForwarded,byteslastEventTypestype;chunk/chunk:finish=<r>for type-less wires)eofBufferBytes,eofBufferHeadfinishReason(chat) /responseStatus+heldEvents(responses)visibleChars,sawStrippedEchoretryZeroByteCutSpent,retryDegenerateSpentupstreamStatus,upstreamContentTypeserver.tsvia new optionalUpstreamMetaparam (5 call sites); cites the first upstream response (aresolveFakeCompletionre-send is not reflected)Wire-shape change⚠️ (human-merge item)
metais a new field on error-only frames (openai/anthropic/google: nested aserror.meta; responses: top-levelmeta; google keeps its numeric-code{code:503,status:"UNAVAILABLE"}object shape). No non-error frame changes. Frames emitted without diag (loop adapters, otheremitUpstreamTruncationcallers) are byte-identical to before. Per house rule this PR is left for human merge even if CI is green.Tests
tests/issue2328-terminal-diag.test.ts(new, 8 cases): both classifications on all 4 wires (data: [DO,message_stophead,response.completedhead, clean EOF),cause=read-error, counters/labels,upstreamMetathreading, log-line shape,[DONE]tail contract unchanged.tsc --noEmitclean. (Two pre-existing env-dependent failures intests/plugin-agent.test.tsreproduce on master without this change.)Rebased on current master, so it sits on top of #2329's stateful SSE normalizer: byte counts see the raw upstream bytes pre-normalize; a lone-CR tail is resolved by
finalizeSseLineEndingsbefore the classification runs, so the classifier only ever sees a genuinely dangling event.Refs #2328. Human merge required (wire shape).