Repository navigation
test(thread): pin that a replaced trailing system message keeps the thread (#519) - #559
Conversation
OsherElhadad
left a comment
There was a problem hiding this comment.
Review: APPROVE at b0a742d. (Posted as a comment: GitHub does not let the author account approve.) Test-only, in internal/thread/thread_test.go.
- All three tests pass on main: a growing conversation whose replaced trailing system reminder stays on one thread, with tools declared; [hello hi] vs [hello other x] staying two threads; and unrelated conversations with reminders staying apart.
- With #499's
thread.gosubstituted, TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreads fails and the other two pass. So the PR pins exactly the over-merge that made #499 unsafe, while main already handles #519. gofmtandgo vetare clean, CI is green, and it is signed off with no AI attribution.
This approval covers b0a742d.
…hread (#519) A Claude Code request ends with a system reminder that the next turn replaces. With the tools declaration every real request carries, a growing conversation already stays on one thread (rewrittenTailParent). Pin that, and pin that two conversations sharing only their first message stay two threads, which tolerating just the last message would merge. Signed-off-by: Osher-Elhadad <[email protected]>
b0a742d to
49555a0
Compare
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 49555a0a51cf |
blocking |
Verdict: blocking
Findings
-
internal/thread/thread_test.go:820 — Test logic error in rewritten-tail boundary check
- What fails:
TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreadsclaims to test that conversations sharing only the first message stay separate, but the test uses 2-message vs 3-message conversations. The rewritten-tail logic at thread.go:419 has conditionlcp < th.n-2 || 2*lcp <= th.n. For thread with n=2 messages and lcp=1 (one shared):1 < 0is false, but2*1 <= 2is TRUE, so the thread is correctly skipped. However, the test name and comment say "only share their first message" but don't verify the boundary is exactly where claimed. - Proof: At thread.go:419, the condition
2*lcp <= th.nmeans "skip if shared count is at most half". For n=2, lcp=1:2*1 <= 2→2 <= 2→ true (skip). For n=3, lcp=1:2*1 <= 3→2 <= 3→ true (skip). The test passes but doesn't prove the "more than half" rule works at the boundary. A test with n=4, lcp=2 would hit the exact boundary:2*2 <= 4→4 <= 4→ true (skip), but n=4, lcp=3 would pass:2*3 <= 4→6 <= 4→ false (qualify). - Fix: Add a test case that exercises the exact boundary: a 4-message thread where a new request shares exactly 2 messages (half) should create a new thread, but sharing 3 messages (more than half) should qualify as rewritten tail if it also satisfies
lcp >= th.n-2.
- What fails:
-
internal/thread/thread_test.go:796 — Missing test for system message fingerprint behavior
- What fails:
TestAReplacedTrailingSystemReminderKeepsTheThreadassumes the trailing system message is included in the fingerprint and counted in message totals. The test builds conversations withconvTail()which appends a system message to the messages array. However, there is no explicit verification that the system message participates in the lcp calculation, or that changing only the system message content (while keeping all other messages identical) produces different fingerprints. - Proof: The test calls
convTail(reminder, texts...)which createslen(texts)+1messages total. For n=3 texts, that's 4 messages. The test expects the conversation to stay on one thread as it grows from 3→5→7→9 texts (4→6→8→10 total messages). Each turn shares all previous messages except the last system message. For turn 2 (6 messages) vs turn 1 (4 messages): lcp should be 3 (the 3 text messages), th.n=4. Check:3 < 4-2→3 < 2→ false. Check:2*3 <= 4→6 <= 4→ false. Both pass. But the test never verifies that the system message itself has a different fingerprint when its content changes, which is the core claim of issue #519. - Fix: Add a direct fingerprint test: two requests identical except for the trailing system message content should have different fingerprints for the last message position, but identical fingerprints for all positions before it. This proves the system message participates in the fingerprint and that changing it alone produces a different cumulative hash.
- What fails:
-
internal/thread/thread_test.go:843 — Test does not prove the defect it claims to prevent
- What fails:
TestUnrelatedConversationsWithTrailingRemindersStayTwoThreadstests that two completely unrelated conversations (sharing no messages) get separate thread IDs. This is trivial:longestPrefix()returns nil when no thread matches, soResolve()falls through tonewID()which creates a new thread. The test does not exercise the rewritten-tail logic at all, because that logic only runs whenhasTools && agentID == ""and the request does NOT match any thread by prefix. The test name suggests it's about trailing reminders, but the actual defect #519 was about conversations that DO share a prefix. - Proof: In
Resolve()at thread.go:213-217,rewrittenTailParent()is only called whenmatch == nil(no prefix match),agentCompaction == false,hasTools == true, andagentID == "". For two unrelated conversations,longestPrefix()returns nil for both, so both get new IDs vianewID()without ever callingrewrittenTailParent(). The test passes but does not prove the rewritten-tail logic correctly rejects unrelated conversations. - Fix: Replace this test with one that exercises the rewritten-tail boundary: a tools-declaring thread with n messages, followed by a header-less tools-declaring request that shares exactly n-3 messages (one less than the
n-2threshold). That request should get a new thread ID, proving the boundary check works. The current test is a no-op that would pass even ifrewrittenTailParent()were deleted.
- What fails:
Non-blocking
- The test helper
convTail()at line 796 builds a conversation with a trailing system message by appending it to the messages array. This matches how Claude Code sends requests (system messages can appear in the messages array, not just as a top-levelsystemfield). The helper is correct for its purpose. - Test naming:
TestAReplacedTrailingSystemReminderKeepsTheThreadis clear about what it tests. The other two test names could be more specific about the boundary conditions they claim to verify.
What I checked
- Read the full diff: 72 lines added to
internal/thread/thread_test.go, no implementation changes - Analyzed the rewritten-tail logic in
thread.goat lines 406-425, specifically the conditionslcp < th.n-2 || 2*lcp <= th.n - Traced through each test case to verify the lcp and th.n values against the boundary conditions
- Verified that
convTail()andconvTools()helpers produce the expected message structures - Checked that the tests exercise the code paths they claim to test by tracing through
Resolve()logic - Confirmed the tests are test-only changes with no implementation modifications, which means they test existing behavior rather than new functionality
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 49555a0a51cf |
approve |
Verdict: approve
Findings
None.
Non-blocking
None.
What I checked
- Read CLAUDE.md and docs/design.md for repo rules
- Read the full diff: 72 new lines in internal/thread/thread_test.go
- Analyzed the three new test functions and two new helper functions
- Verified test logic against the rewrittenTailParent implementation in thread.go
Test coverage analysis
The PR adds three tests for the rewrittenTailParent function that handles Claude Code's behavior of replacing trailing system messages:
-
TestAReplacedTrailingSystemReminderKeepsTheThread: Tests that a conversation growing by user/assistant pairs while replacing its trailing system reminder stays on one thread. Tests 4 turns (3, 5, 7, 9 messages). The test verifies all turns resolve to the same thread ID.
-
TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreads: Tests the boundary condition where two conversations share only their first message. Thread A has 2 messages, thread B has 3 messages sharing only the first. The rewrittenTailParent condition
lcp < th.n-2 || 2*lcp <= th.ncorrectly rejects this (lcp=1, th.n=2: 1 < 0 is false, 2*1 <= 2 is true, so skip). This prevents the #499 bug where such conversations would incorrectly join. -
TestUnrelatedConversationsWithTrailingRemindersStayTwoThreads: Tests that completely unrelated conversations with trailing reminders get separate thread IDs. Both have 3 messages but share none.
Helper functions
-
convTail: Builds a conversation with a trailing system message carrying a cache_control breakpoint, matching Claude Code's actual wire format. The stable messages are user/assistant pairs, the reminder is the volatile trailing message.
-
convTools: Adds a tools declaration to conv() output, since every real Claude Code main-agent request declares tools.
Implementation correctness
The rewrittenTailParent function (thread.go:407-427) implements the logic these tests verify:
- Finds tools threads only (main agent, not side requests)
- Excludes header threads (forked subagents)
- Requires sharing all but last 1-2 messages:
lcp < th.n-2rejects if too few shared - Requires sharing more than half:
2*lcp <= th.nrejects if at most half shared - The combined condition correctly prevents short threads from matching on just their first message
The tests cover the positive case (growing conversation stays together), the boundary case (sharing only first message splits), and the negative case (unrelated conversations split).
Limitations
The eval box SSH connection was unstable during this review. I could not run the tests live or prove them by breaking the code. The review is based on code analysis only. The logic appears sound: the test assertions match the expected behavior of rewrittenTailParent, and the boundary conditions are correctly tested.
The script refused a second round when the head did not move (exit 3). That blocks two real cases: - The reviewers could not run their tests because the eval box was down. On PRs #563 and #559, all 4 reviewers approved or blocked with no test run. - The author answered a finding with a reply and proof, and no code change. The reviewer never sees the reply. --same-head starts the next round on the same head. Each reviewer resumes its own session, and the prompt says the head did not move and what to look at. The round counts toward the budget. Without the flag, the script still exits 3, and its message now names the flag. SKILL.md: a "Same head" section says when to use it (only when the user asks) and what to post on the PR first. Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
* feat(review): let offload-review run a round on the same head The script refused a second round when the head did not move (exit 3). That blocks two real cases: - The reviewers could not run their tests because the eval box was down. On PRs #563 and #559, all 4 reviewers approved or blocked with no test run. - The author answered a finding with a reply and proof, and no code change. The reviewer never sees the reply. --same-head starts the next round on the same head. Each reviewer resumes its own session, and the prompt says the head did not move and what to look at. The round counts toward the budget. Without the flag, the script still exits 3, and its message now names the flag. SKILL.md: a "Same head" section says when to use it (only when the user asks) and what to post on the PR first. Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]> * fix(review): correct the grammar of the same-head prompt line Found by reviewer 1 of #609, round 1. Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]> --------- Signed-off-by: DAVID AMID <[email protected]>
|
Integrator (session integrator-053): test results on the eval box, and a reply to reviewer 1, round 1. Head The eval box SSH link works again. In round 1 neither reviewer could run a test. For runs over about 2 minutes, start the run detached with a done marker, as the rules file says.
Reply to reviewer 1:
The decision on findings 1 and 3 is the author's: add the tests in this PR, or file them as an issue. |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 49555a0a51cf |
approve |
Verdict: approve
Findings
None. My round 1 findings are addressed:
-
Finding 1 (missing exact boundary test): Acknowledged by integrator as a coverage gap, not a defect. The existing test
TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreadsdoes catch the mutation when|| 2*lcp <= th.nis removed. Decision on adding more coverage is the author's. -
Finding 2 (missing fingerprint test): Rejected by integrator with valid reasoning.
TestAReplacedTrailingSystemReminderKeepsTheThreadchanges only the trailing system message each turn and requires all turns to stay on one thread. If the system message did not participate in the fingerprint, the test would pass incorrectly. The test does verify the behavior. -
Finding 3 (weak test for unrelated conversations): Acknowledged by integrator as a weak test. The test exercises a trivial case (no shared messages) rather than the boundary. However,
TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreadsdoes exercise the rewritten-tail logic and catches the defect.
Test results
Ran on eval box (SSH connection now working):
| Test | Result |
|---|---|
| All 3 new tests on PR head | PASS |
TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreads on PR head |
PASS |
| Same test with ` |
The mutation test proves the PR's tests catch the defect they guard against.
Non-blocking
- Findings 1 and 3 from round 1 are coverage improvements, not blocking defects. The author may add them in this PR or file as an issue.
What I checked
- Last review: round 1, 49555a0, 2026-10-20T12:48:34Z
- New commits read: 0 (verified with
git log 49555a0a51cf..HEAD, output empty) - Read in full: 4 reviews, 1 comment, 0 inline comments
- New items since my last review:
- Integrator comment at 2026-10-20T13:35:39Z with test results and replies to my findings
- Reviewer 2's round 1 approve at 2026-10-20T12:49:24Z
- Ran tests on eval box:
- All 3 new tests pass on PR head
- Mutation test: removing
|| 2*lcp <= th.ncausesTestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreadsto fail
- Verified integrator's test results match mine
- Checked integrator's reasoning on each finding
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 49555a0a51cf |
approve |
Verdict: approve
Findings
None. My round 1 approve verdict stands.
Non-blocking
None.
What I checked
- Last review: round 1, 49555a0, 2026-10-20T12:49:24Z
- New commits read: 0 (confirmed with
git log 49555a0a51cf533768c3f5cda18b30e8ee0006cd..HEAD- empty output) - Read in full: 5 reviews, 1 comment, 0 inline comments
- New items since my last review:
- Integrator comment at 2026-10-20T13:35:39Z with test results and reply to reviewer 1
- Reviewer 1's round 1 blocking review at 2026-10-20T12:48:34Z (posted before mine)
Review of reviewer 1's findings
Reviewer 1 raised three findings, all about test coverage gaps rather than defects in the implementation:
-
Finding 1 (missing exact boundary test at 2*lcp == n): Acknowledged by integrator as missing coverage. Not a defect in the PR's tests - they correctly test the boundary conditions they claim to test. The integrator notes this is a request for more coverage, and the decision to add it in this PR or file as an issue is the author's.
-
Finding 2 (missing direct fingerprint test for system message): Rejected by integrator as blocking. The test
TestAReplacedTrailingSystemReminderKeepsTheThreadchanges only the trailing system message each turn and requires one thread. It would fail if the fingerprint did not include the system message. -
Finding 3 (weak test - unrelated conversations): Acknowledged by integrator as a weak test. The test does not reach
rewrittenTailParentbecause the conversations share no messages. However,TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreadsdoes catch the mutation.
Test execution and proof
I ran the three new tests on the PR head on the eval box. All pass:
ok github.com/rossoctl/context-guru/internal/thread 0.006s
I proved the tests by breaking the code. I removed || 2*lcp <= th.n from the condition at thread.go:419, which removes the "more than half" check. TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreads fails as expected:
--- FAIL: TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreads (0.00s)
thread_test.go:852: conversations sharing only their first message share thread ""
FAIL
This confirms the test catches the defect it is designed to prevent: without the 2*lcp <= th.n check, conversations sharing only their first message would incorrectly join into one thread.
Integrator test results
The integrator ran the same mutation test and confirmed the same result. The tests work correctly.
Conclusion
The PR adds test coverage for the rewrittenTailParent logic. The tests pass on the PR head and correctly catch the mutation when the code is broken. Reviewer 1's findings are about additional coverage that could be added, not defects in what the PR does add. The integrator's response addresses each finding appropriately.
…746) fix(dash): classify 8 real Claude Code tools as built-in The builtinTools allowlist was missing 8 tools a live Claude Code 2.1.283 session declares: ArtifactCheck, ArtifactComments, ArtifactData, SendFeedback, ReadMcpResourceTool, ReadMcpResourceDirTool, ListMcpResourcesTool and DesignSync. DesignSync was the list's own example of a name that only looks built-in. That belief was wrong. It is Claude Code's own claude.ai/design bridge. On the snapshot the removal page was measured against, it was the largest misclassified item: declared, never invoked, by 1,592 of 1,959 tool-bearing sessions. A missing name reports as `client_tool`, which says "check what declares this" instead of "do not touch". So every one of these was hidden behind the danger warning. How it was tested: TestBuiltinClassification rows for all 8 names fail on clean origin/main and pass with this change (box run, glm-small-fixes-main vs glm-small-fixes). Full ./dash/... -race suite passes. Closes #328 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(reformat): pick the search fold by tokens, not bytes FoldSearchOutput ranked fold candidates by their byte size. A fold can be bigger in bytes and still cheaper in tokens: 500 bytes of base64 or minified JSON can be fewer tokens than 200 bytes of prose. The byte order and the token order disagree exactly when it matters, so the sweep sometimes kept the more expensive output. Rank by the token estimate the sweep already uses everywhere else (internal/tokens), with byte size kept as the tiebreaker. The stored fold metadata still reports bytes, so nothing downstream changes. How it was tested: TestThePickBetweenSurvivorsJudgesTokensNotBytes fails on clean origin/main ("chose 904 bytes/331 tokens, want the token-winner: 1074 bytes/266 tokens") and passes with this change (box run, glm-small-fixes-main vs glm-small-fixes). Full ./components/reformat/... -race suite passes. Closes #339 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(dash): read and log wal_checkpoint's busy result PRAGMA wal_checkpoint(TRUNCATE) reports a busy checkpoint as a result row, not as an error. checkpoint() scanned the row and discarded it. So the WAL-bloat protection ran as a no-op exactly when a reader held the lock — which on a live dashboard is most of the time — and an operator had no way to tell a checkpoint that ran from one that was silently skipped. Read the (busy, log, checkpointed) row and WARN when the checkpoint did not complete, with the frame counts. No outer retry loop: the pool's busy_timeout(5000) already makes the single call retry the lock for up to 5 seconds internally, and stacking attempts on top of that only stacks 5-second waits (a measured 25 seconds for 5 attempts). How it was tested: TestCheckpointRetriesWhileAReaderHoldsTheLock holds a read transaction across a whole janitor pass and fails on clean origin/main at the log assertion ("a checkpoint that stayed busy for the whole retry budget left no trace"); with this change it passes, and the pass after the reader lets go truncates for real. Full ./dash/... -race suite passes. Closes #166 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(schema): make the answered-tool-use check wire-group aware ValidateShapeFor answered a tool_use by scanning for its id anywhere in the remaining messages. A provider may send the tool_result before a sibling tool_use that shares its group — the "sibling-first" wire order. The scan then found the id, but in the wrong group: a later group holding a NEW tool_use with the same shape looked answered, and a genuinely unanswered tool_use in a mid group looked fine. Both directions of the false positive. Add ValidateShapeGrouped, which takes the #457 WireGroup view alongside the flat messages and answers a tool_use only inside its own run: the tool_result must carry the same group index, and the group may not end on an unanswered assistant turn. ValidateShapeFor keeps its signature and its old semantics, and still backs the ungrouped call sites. How it was tested: TestValidateShapeGroupedReadsWireAdjacency fails to even compile on clean origin/main (undefined: ValidateShapeGrouped), and passes with this change; a mutation that ignores the groups fails the same test. Full ./schema/... and ./internal/... -race suites pass. Closes #461 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> test(thread): cover the rewritten-tail rule's two boundaries The rewritten-tail parent rule (#559, internal/thread) is `if lcp < th.n-2 || 2*lcp <= th.n { continue }`. It is one expression carrying two distinct boundaries, and neither edge had a test: nothing pins the exact point where 2*lcp == n flips the rule, and nothing pins the n-3 decline — the point just below the conversation-tail threshold where a thread must NOT be treated as a rewritten tail. Add two tests, one per boundary, each built as a minimal fixture that lands exactly on the edge. #610 asked for the coverage; the code under test is unchanged. How it was tested (mutation proofs, box run glm-small-fixes-mut): deleting `|| 2*lcp <= th.n` fails the half-boundary test; deleting `lcp < th.n-2 ||` fails the n-3 test. Both pass on the unmutated code. Full ./internal/thread/... -race suite passes. Closes #610 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> test(offload): check the replay table covers every computed-eff site commitgate marks a replayed-branch commitRefresh irreversible through a hand-maintained table in commitgate_irreversible_test.go. Nothing enforced its completeness: a new computed-eff commitRefresh call site (one whose marker argument is computed rather than the literal markerFull) could skip the table and the test would still pass, silently losing the irreversibility guarantee for that site. Add a go/ast completeness check that walks every file in the offload package, finds the commitRefresh calls whose marker argument is not the literal markerFull, and fails when any of them is missing from the table — by file and function name, the same keys the table uses. Mirrors the gateExempt pattern already used for the same class of gap. How it was tested (mutation proof, box run glm-small-fixes-mut): renaming the marker at the replayStale site in summarize.go to markerSummary fails the new check, naming summarize.go:replayStale as uncovered. Restored, it passes. Full ./components/offload/... -race suite passes. Closes #198 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(offload): count shifted coordinates apart from a stale prefix sweep_stale_prefix counted two different declines as one. A stale prefix means the stashed body was the wrong one. A shifted coordinate system means an EARLIER component changed the message count, so the span to verify against the stash could not be located at all. The remedies differ — a stale prefix is re-asked, a shifted one cannot be — so one bucket hid both. Add the sentinel components.ErrCoordsShifted beside ErrStalePrefix, and return it from rawSpanForHash when the span cannot be located because the count changed. The sweep gates it as sweep_coords_shifted; the cache-aware summarizer counts it as cache_aware_summarizer_coords_shifted. Both keys are listed in the /stats golden contract. Neither is Prometheus-exported yet (notExportedWhy says why), so no alert or dashboard changes. How it was tested: the new sweep and summarizer tests fail on clean origin/main ("a shifted coordinate system was not counted as sweep_coords_shifted", gates showed it landing in sweep_stale_prefix) and pass with this change. A mutation proof (ErrCoordsShifted swapped back to ErrStalePrefix at cache_aware_summarizer.go) fails the summarizer test. Full ./components/... and ./proxy/... -race suites pass. Closes #452 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(proxy): report a spliced stream's missing usage as unreadable When the SSE splicer withholds a turn, the usage block in the withheld bytes never reaches the client's view of the stream. responseUsageWhy classified that window as usageMissAbsent — "the provider streamed no usage" — which points the operator at the provider instead of at us. The `usage_unreadable` counter, which exists for exactly this, was unreachable on the spliced path. Give responseUsageWhy the window's spliced flag (the sniffer already knows it) and upgrade usageMissAbsent to usageMissUnreadable when the window was spliced. A usage block that was present but rejected by the dialect parsers stays a dialect finding, whatever the window did. Buffered (non-stream) bodies pass false. The usage-shape record now carries spliced=true so the reason is visible per request. How it was tested: TestASplicedStreamReportsUnreadableNotAbsent fails to compile on clean origin/main (responseUsageWhy arity) and, on a mutation that ignores the flag, fails with the window classified as absent; with this change it passes, and the recorded usage shape says spliced=true. Full ./proxy/... -race suite passes. Closes #207 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(proxy): count an adjudicate leak as itself, not as expand The SSE peek counts a proxy tool_use handed back to the client as a leak. It had one counter, sse_expand_after_stream, so an adjudicate leak landed in the expand bucket. The issue called this unattributable at two of the three bail sites, because nothing had parsed the turn when they fire. The peek knows better: it parses every event, so it can report the names it withheld. pass now returns the matched proxy tool names (first appearance, deduplicated) alongside the withheld bytes, and a countLeak closure attributes each name to its own counter — sse_adjudicate_after_stream for adjudicate, the expand counter for everything else. A round that leaks BOTH tools is counted in both, which the old boolean `found` could not express. `called` is hoisted with `withheld`, so a round that ends without running pass (an upstream failure, a JSON round after a stream) still attributes the previous round's tool_use. Both counters stay /stats-only (notExportedWhy says why) and both keys are listed in the /stats golden contract. No alert or dashboard changes. How it was tested: TestPassReportsWhichProxyToolItWithheld pins the peek's name reporting; TestAnAdjudicateLeakOnTheSSEPathIs- CountedAsItself fails on a mutation that counts every leak as expand (SSEExpandAfterStream:1, SSEAdjudicateAfterStream:0) and passes with this change. TestStatsShapeIsUnchanged and TestEverySnapshotFieldIsExportedOrExempt cover the new key. Full ./proxy/... -race suite passes. Closes #174 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(schema): wire the grouped shape check into its real callers ValidateShapeGrouped had no caller that passed a real grouping, so the #461 fix changed nothing in practice: every validator use still ran the ungrouped scan and still reported a false answered-tool-use violation on a legal sibling-first wire. For the record, the correct description of both scans (the d7d8005 commit message got this wrong, and history is not being rewritten): - The OLD scan reads the CONTIGUOUS RUN of tool messages starting right after the call. It does not search "anywhere in the remaining messages", and it never did. - The NEW grouped scan answers from the result members of the ONE wire group that follows the call. There is no "the group may not end on an unanswered assistant turn" rule; the only new rule is the group membership itself. What changed, per call site: - apply's assertShapeValid now takes the wire groups built from normalize's own slots (wireGroups), so the captured-traffic guard and the summarize end-to-end guard judge the normalized list with the grouping it actually has. - The old hand-rolled assertAnthropicWirePairing work-around in apply/normalizer_siblings_test.go is deleted. The split-group rebuild tests it backed moved into the apply package itself (shape_validate_test.go), where they check the raw-body roles via assertWireRolesLegal and the pairing via the grouped validator. - The summarize shape oracle in components/offload keeps a sibling-first fixture whose WireGroup is set on the Ctx, and validates the SPLICED output grouped: the fixture's WireGroup is in input coordinates and collapses to nil after any count change, so outWireGroups rematches each emitted message against the fixture and rebuilds the grouping in emitted coordinates. - ValidateShapeGrouped's doc now states its assumption: the message after a call starts a wire group. apply's normalize guarantees it; a grouping that does not gets a silently wrong scan. How it was tested: with the grouped branch of answeredInRun disabled (mutation), the split-group rebuild tests fail (messages.2 answered-tool-use on call_a / t_s) and the oracle fails on "sibling-first split group keep_last=4" — the sibling-first pairing read as broken, which is the exact case the deleted work-around existed to catch. Unmutated, all pass; gofmt, vet and go build clean. Ref #461 Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(proxy): count a leak only under the tool's own counter countLeak bucketed every non-adjudicate name into sse_expand_after_stream. pass takes one required proxy name plus a variadic tail, so a third proxy tool added to that list would have landed silently in the expand counter — rebuilding the conflation the #174 split exists to end. Switch on the name against the two tools pass is actually given, and log a WARN for anything else: an unknown leak is counted nowhere until it gets a counter of its own, not silently as expand. How it was tested: the existing adjudicate-leak test still passes (adjudicate counts as itself, expand stays 0); gofmt and vet clean; full ./proxy/... -race suite green. Ref #174 (review round 1, non-blocking) Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> fix(dash): make the checkpoint WARN fit both failure ways The WARN said "a reader held the lock", but it fires for two different reasons: busy=1 after the retry budget (a reader is only the most common cause), or err != nil (the pragma itself failed). The message named one cause of one of them. The message now names the fact — the checkpoint did not complete — and the attributes say which way it failed. The reader-lock test asserts the new text. How it was tested: TestCheckpointRetriesWhileAReaderHoldsTheLock passes against the new text and fails against the old one; gofmt and vet clean; full ./dash/... -race suite green. Ref #166 (review round 1, non-blocking) Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]> docs(reformat): say who counted the strings the memo pays off on The comment claimed adopt "has usually just asked for the same strings". adopt never counts tokens — it compares bytes. The memoization pays off because the INPUT string was usually counted already, by the trigger and the never-worse guard, not by adopt. Comment only; no behaviour change. ./components/reformat/ passes -race. Ref #339 (review round 1, non-blocking) Written by GLM through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]>
What
Test-only. A Claude Code request ends with a system reminder that the next turn replaces. With the
toolsdeclaration every real Claude Code request carries, a growing conversation already stays on one thread on main (rewrittenTailParent, #519). These tests pin that:TestAReplacedTrailingSystemReminderKeepsTheThread: a conversation growing by a pair each turn, trailing reminder replaced each turn, tools declared: one thread.TestTwoConversationsSharingOnlyTheFirstMessageStayTwoThreads:[hello, hi]then[hello, other, x], tools declared: two threads. A rule that tolerated only the replaced last message (the approach of fix(thread): a replaced trailing system message no longer starts a new thread every turn #499) joins them into one.TestUnrelatedConversationsWithTrailingRemindersStayTwoThreads.Evidence
All three pass on main. Applying #499's change to
thread.gokeeps the first and third passing and fails the second (the two conversations join).Known gap, not changed here
A tool-less client whose trailing system message is replaced each turn still gets a new thread every turn (
rewrittenTailParentruns for tools-declaring requests only). Not common among current traffic.