Repository navigation
[PR] fix: invariant judge flags stranded tool-use/tool-result pairs at egress (#4862) - #5003
Closed
ranxianglei wants to merge 2 commits into
Closed
ranxianglei wants to merge 2 commits into
ranxianglei wants to merge 2 commits into
Conversation
…ess (#4862) #4862 leaves one mechanism after #4774 removes its trigger: the outbound invariant judge (I1/I2) never checks tool_use/tool_result pairing, so a payload whose pair a misapplied fold split still earns a "clean fold verdict" while upstream 400s on every retry. Add I3 (exit pairing) to src/invariant-judge.ts: - pairingOrphans() scans one side of the wire for stranded calls (no result before the next assistant turn) and stranded results (no call at all); - attribution-gated: only BILI-introduced breaks count — an orphan whose twin is already orphaned inbound matches via stableEqual (CCR/crush/truncation substitutes, re-minted ids per KDD#11), keeping client-originated state and codec-dependent id gaps out of the violation set; - advisory only: same arm/disarm as I1/I2, warns through the existing sink, never blocks traffic or touches bytes. Tests: 7 unit rows (POS: paired round-trip, openai multi-message answers, carrier inside answer region, verbatim client orphan, re-minted orphan; NEG: the #4862 carrier-replaces-result-side shape, stranded result) plus an e2e live proof on the real anthropic codec. The existing suite caught one false positive during development (CCR placeholder twin) — fixed by riding stableEqual instead of raw text signatures. Part of #4862 (egress-gap sub-defect; trigger removal = #4774).
Contributor
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.6550-pr.5003.233a1d8This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5003.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…nvention (#5003 review) Review nit: the I3 block, pairingOrphans() and the re-touched exemption-overflow/return lines landed at 4-space indent against the module's 2-space style, adding whitespace churn to the diff. Whitespace-only, zero behavior change (git diff -w empty).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
#4862's production logs showed the exact failure shape this closes:
invariant-judgereported clean fold verdict on every request that upstream then rejected with 400tool_use ids were found without tool_result blocks immediately after. The judge's I1/I2 invariants cover rewrite/drop/insert/fold-boundary drift but never tool-pairing integrity — provider validity outlives the fold boundary, so a misapplied fold can strand one side of a pair while I1/I2 stay green.#4774 removes the known trigger source (header-less claude-code subagents no longer ride the parent session id); this PR closes the residual egress gap named in its review: any future path that splits a pair now surfaces as a judge violation instead of a silent clean verdict.
How
src/invariant-judge.tsgains I3 (exit pairing):pairingOrphans()scans one side of the wire for stranded calls (tool-call id with no tool-result before the next assistant turn) and stranded results (tool-result id with no call anywhere).stableEqual), so CCR/crush/truncation substitutes and re-minted ids (KDD#11) match by content, never by raw bytes or id.invariantJudgeEnabledarm/disarm, warns through the existing sink, never blocks traffic, never touches bytes.Behavior change disclosure
clean ... verdict(debug); first signal is the upstream 400I1/I2 violation: unpaired-tool-call/unpaired-tool-result(warn) before egressNo traffic behavior, wire bytes, config surface, or persistence change — observability only, on the existing default-armed advisory layer.
Tests
tests/invariant-judge.test.ts, both directions per gate discipline: POS (paired round-trip; openai multi-message parallel answers; summary carrier inside the answer region; verbatim client-originated orphan; re-minted orphan — KDD#11) and NEG (the exact [Bug][claude] 0.1.207: subagent requests fail with 400 "tool_use ids were found without tool_result blocks" right after a fold in the parent session #4862 shape: carrier replaces only the result side while I1/I2 stay green → red via pairing; stranded result direction).tests/invariant-judge-e2e.test.tson the REAL anthropic codec: pairedtool_use/tool_resultround-trip stays clean (proves both codecs preservetoolCallId), fault-injected stranded call firesunpaired-tool-call.stableEqual; all pre-existing judge tests pass unchanged.Duplicate screening
查重: 无 — searched open+closed issues/PRs for an invariant-judge pairing/egress-gap entry; none exists. Related: #4862 (symptom + checklist), #4774 (trigger removal), #3842/#3938 (judge design), #2821/#4186 (identity/exemption doctrine reused here).
Part of #4862.