Skip to content

fix: nine small fixes (#328 #339 #166 #461 #610 #198 #452 #207 #174) - #746

Merged
amiddavid merged 13 commits into
mainfrom
fix/glm-small-fixes
Oct 27, 2026
Merged

amiddavid merged 13 commits into
mainfrom
fix/glm-small-fixes

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

Nine small fixes, one commit each. Written by GLM through Claude Code.
Note: PRs #327 and #336 cover the same ground as two of these commits
(#328 and #339) and are still open. This batch implements those fixes
independently; whichever merges first wins, the other can be closed.

All nine issues in the batch were done. None skipped.

What changed

  1. Stale built-in-tool allowlist lets non-managers exclude real Claude Code tools unwarned #328 — dash: 8 missing built-in tool names. builtinTools now
    classifies ArtifactCheck, ArtifactComments, ArtifactData, SendFeedback,
    ReadMcpResourceTool, ReadMcpResourceDirTool, ListMcpResourcesTool and
    DesignSync as built-in. DesignSync was the allowlist's own example of a
    "looks built-in but is not" name; that belief was wrong.
  2. FoldSearchOutput picks among multiple surviving fold candidates by byte length, not token length #339 — reformat: fold picked by bytes. FoldSearchOutput now ranks
    fold candidates by token estimate, bytes only as tiebreaker.
  3. dash: checkpoint() discards wal_checkpoint's busy result, so #115's WAL protection silently no-ops under load #166 — dash: checkpoint's busy row discarded. checkpoint() reads
    the wal_checkpoint(TRUNCATE) result row and WARNs when the checkpoint
    stayed busy, with frame counts. No outer retry loop: the pool's
    busy_timeout(5000) already retries inside the call.
  4. schema.ValidateShapeFor's tool-pairing check assumes normalized-view adjacency, false-positives on a sibling-first group #461 — schema: answered-tool-use false positive. New
    ValidateShapeGrouped answers a tool_use only inside its own wire
    group (apply.normalize drops text blocks that share a user message with a tool_result #457 WireGroup), fixing both directions of the sibling-first
    false positive. ValidateShapeFor keeps its old semantics.
  5. test(thread): cover the rewritten-tail boundary that #559 leaves untested #610 — thread: rewritten-tail boundary tests. Two tests pin the
    2*lcp == n flip and the n-3 decline of the test(thread): pin that a replaced trailing system message keeps the thread (#519) #559 rule. Test-only.
  6. test: the replay-branch Irreversible table has no completeness check, unlike gateExempt for components #198 — offload: replay-table completeness. A go/ast check fails
    when a computed-marker commitRefresh site is missing from the
    irreversible table, by file and function. Mirrors the gateExempt
    pattern. Test-only.
  7. extract_llm_sweep: sweep_stale_prefix also counts shifted message coordinates, not only stale stashes #452 — offload: shifted coordinates counted as stale prefix. New
    components.ErrCoordsShifted sentinel; the sweep gates it as
    sweep_coords_shifted, the cache-aware summarizer as
    cache_aware_summarizer_coords_shifted. Both keys added to the /stats
    golden contract. Neither exported to Prometheus yet.
  8. proxy: usage_unreadable is structurally unreachable for a streamed response, which is where a spliced window is most likely to hide the block #207 — proxy: spliced stream's missing usage read as absent.
    responseUsageWhy takes the window's spliced flag and upgrades
    usageMissAbsent to usageMissUnreadable over a spliced window. The
    usage-shape record carries spliced=true.
  9. cg SSE peek: an adjudicate leak is counted as an expand leak in sse_expand_after_stream #174 — proxy: adjudicate leak counted as expand. pass reports
    the proxy tool names it withheld; countLeak attributes each to its
    own counter (sse_adjudicate_after_stream vs the expand counter). A
    round leaking both tools counts in both.

How it was tested

Every run was on the eval box, in glm-small-fixes (fixed copy),
glm-small-fixes-main (clean origin/main) and glm-small-fixes-mut
(mutation proofs). Proof rule per fix: a new test that fails on clean
main and passes on the fix, or a mutation proof for the test-only
changes.

Check Result
gofmt -l on all changed packages clean
go vet on all changed packages rc=0
go build ./... on every one of the 9 commits rc=0 (bisectable)
Full -race suite ./components/... ./schema/... ./internal/... ./metrics/... ok (offload 173s)
Full -race suite ./dash/... ok (506s)
Full -race suite ./proxy/... ok (462s)
#328, #339, #166, #452 new tests on clean main FAIL (each names the defect)
#461, #207, #174 on clean main FAIL (do not compile: new API)
#610 mutation: drop 2*lcp <= th.n half-boundary test FAIL
#610 mutation: drop lcp < th.n-2 n-3 test FAIL
#198 mutation: rename marker at replayStale completeness check FAIL, names the site
#461 mutation: ignore the groups grouped test FAIL
#207 mutation: ignore the spliced flag test FAIL (classified absent)
#174 mutation: count all leaks as expand test FAIL (expand=1, adjudicate=0)
#452 mutation: sentinel swapped to ErrStalePrefix summarizer test FAIL

Data dependence

No feature changes its data dependence. Every change works from metadata
(counters, names, sizes, flags) only. docs/data-dependence.md needs no
update.

Skipped

None. All nine issues in the batch were fixed.

Closes #328
Closes #339
Closes #166
Closes #461
Closes #610
Closes #198
Closes #452
Closes #207
Closes #174

🤖 Generated with Claude Code

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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.311 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 a4ea9422f942 approve

Verdict: approve

Findings

None. Every changed path behaves as the commit messages claim. Fail-open holds on each path I traced.

Non-blocking

  1. schema/validate.go:106 — ValidateShapeGrouped has no caller that passes a real grouping.

    • Every caller in the repo (ValidateShape, ValidateShapeFor, the summarize shape oracle in components/offload/summarize_shape_test.go) still passes nil groups. The #461 false positive stays for all of them.
    • Issue #461 itself calls the check test-only and proposes exactly this API, so the commit matches its issue. But apply already computes a wire grouping (apply.go:1990, for summarizeSpan) and does not feed it to the validator. A future test that re-normalizes a #457-shaped transcript must know to use the new API, or the blind spot returns.
    • Fix (later PR): wire the grouping apply already computes into the shape check, or into the summarize oracle test.
  2. proxy/proxy.go:1692 — countLeak counts every non-adjudicate name as an expand leak.

    • pass takes one required proxy name plus a variadic tail. If a third proxy tool is ever added to that list, its leak lands in sse_expand_after_stream silently.
    • Fix: switch on the name against the full set pass was given, or assert membership before bucketing.
  3. proxy/usage.go:735 — spliced() reports true when nothing was dropped, in one corner.

    • total > len(head) also holds when total <= 2×sniffMax: the tail then holds every byte past the head, and bytes() is the whole body plus one injected '\n'. An absent verdict is upgraded to unreadable although no bytes were dropped.
    • The verdict stays defensible: the injected newline can break a parse, so "unreadable" is not wrong. Note only.
  4. components/reformat/searchfold.go:160 — comment says adopt "has usually just asked for the same strings".

    • adopt does no token counting; it compares bytes. The memoization pays off only when the pipeline counts the same text. Cosmetic.

What I checked

  • Read CLAUDE.md and docs/design.md, then the full diff (25 files, 9 commits) and the code around each change.
  • #174 leak split (proxy.go, ssepeek.go, metrics.go): traced called/withheld through every exit of the serve loop — the upstream-failure hand-back (proxy.go:1815), the over-retain site (proxy.go:1943), and bail() (proxy.go:1964). Each site counts once and returns. A round whose proxy call was answered in band leaves called empty on the next round, so no false count. Gating matches the old found-based code at every site; only the by-tool split is new. pass collects names in first-appearance order, deduplicated (slices.Contains), and proxyToolCallName returns "" for client tools. The new /stats keys (sse_adjudicate_after_stream, cache_aware_summarizer_coords_shifted) are in statsGoldenTopLevel, filled in Snapshot() and the /stats handler, and exempted in notExportedWhy.
  • #452 coords shift (component.go, cache_aware_summarizer.go, extract_sweep.go): rawSpanForHash returns !ok only on count mismatch or an impossible span overflow, so ErrCoordsShifted cannot mislabel a CoversSpan refusal. classifyCallErr checks the sentinels in a fixed order; no other consumer of the summarizer call's error special-cases ErrStalePrefix. The sweep's coordsShifted is set only inside usePrefixAsk, so the gate switch's default still means "no asker". Both new tests assert the asker is never consulted (calls == 0), which pins the distinction the split exists for.
  • #207 spliced usage (usage.go, proxy.go): verified sniffer.bytes()/spliced() against the struct's write path. The upgrade applies only to usageMissAbsent; a rejected block keeps its dialect verdict (test covers this). Buffered and spliced-round paths pass false, which is correct — those bodies are whole.
  • #461 grouped shape check (validate.go): traced answeredInRun grouped and ungrouped on the four test shapes. The grouped scan reads only the one wire group after the call, so a missing answer and a later-group answer still report. from == len(msgs) is guarded against the panic the comment names. len(groups) != len(msgs) collapses to nil — the documented defensive behavior.
  • #339 token pick (searchfold.go): adopt still requires strictly fewer bytes, so a byte-growing fold can never win. The new pick cannot adopt anything token-worse than the input. schema.TextTokens is memoized above a length floor, so the extra count is bounded.
  • #198 AST completeness (commitgate_irreversible_test.go): checked commitRefresh's real signature — 5 params, eff at index 2 — against the test's len(call.Args) != 5 and Args[2] classification. Both irreversibleCovered keys match real sites (extract_sweep_drop.go:sweepDrop, extract_llm.go:Offload). If the signature changes, the stale-entry check fails rather than passing vacuously. The new "sweep drop replay" subtest drives applySweepDropReplay → sweepDrop(replay=true) → commitRefresh.
  • #166 checkpoint (dash/store.go, tests): wal_checkpoint(TRUNCATE) returns busy/log/checkpointed as a row; the Scan matches. dsn puts busy_timeout(5000) first, so the in-call retry claim holds. The reader-lock test uses a second connection with a held read transaction, a mutex-guarded log buffer for -race, and asserts the post-release pass truncates.
  • #610 thread boundaries: checked both tests against rewrittenTailParent (thread.go:419) and longestPrefix (thread.go:460). 2-of-4 fails 2*lcp <= th.n; 3-of-4 passes both halves; 4-of-7 fails lcp < th.n-2. mostShared only sets Inherits, never the id, so it cannot make these tests pass or fail wrongly.
  • #328 builtin tools: the eight added names are real Claude Code tools; the map's exclusion discipline (Workflow, ScheduleWakeup stay out) is kept and documented.
  • Verified test helpers referenced by new tests exist (tool, sweepFixture, markerSummary, vuser/vcall/vresult, dsn, pkOtherT, coverageAsker, fakeCoverageAsker), and that no name collisions were introduced (lockedWriter is new).
  • Read issue #461 to confirm the shape check is test-only by the issue's own text; the API-only fix matches its proposal.
  • Live tests were not run (not approved). Static review only.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.311 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 a4ea9422f942 blocking

Verdict: blocking

Findings

  1. schema/validate.go:106 — the wire-group-aware fix is wired to no caller, so it fixes nothing
    • What fails: commit d7d8005 says "fix(schema): make the answered-tool-use check wire-group aware" and that ValidateShapeFor "still backs the ungrouped call sites". But no grouped call site exists. ValidateShapeFor (validate.go:88) delegates with nil groups, so the old semantics run everywhere. Every validator use in the repo still reports a false answered-tool-use violation on a legal sibling-first wire — a user message that holds a text block beside a tool_result (#457/#460). That is assertShapeValid over the captured-traffic and summarize end-to-end guards (apply/shape_validate_test.go:54, :93, :237), and schema.ValidateShape in components/offload/summarize_shape_test.go:129, :173, :209. apply/normalizer_siblings_test.go:317-327 still works around the validator with its own assertAnthropicWirePairing, and its comment still says the validator "does not know about wire-message grouping". The repo's shape guard therefore still cannot cover sibling-carrying transcripts, which is the exact defect the commit claims to close.
    • Proof: grep -rn "ValidateShapeGrouped" over the repo matches only schema/validate.go:88 (nil groups) and schema/validate_test.go. The PR's own test proves the false positive is live: TestValidateShapeGroupedReadsWireAdjacency (schema/validate_test.go:219-223) asserts the same sibling-first list WITHOUT groups still reports RuleAnsweredToolUse. The group view already exists at the call sites that need it: normalize returns the slots (apply/apply.go:1600) and wireGroups(slots) (apply/apply.go:1982) builds the group indices — apply/shape_validate_test.go:89 and :119 currently discard the slots (norm, _ := normalize(...)).
    • Fix: pass groups at the call sites that validate normalized Anthropic traffic. assertShapeValid should take the groups built from normalize's slots; the offload shape tests should pass the request's WireGroup (a length mismatch is already collapsed to nil, so a shifted pipeline degrades to today's behavior). Or reframe the commit as an API addition and file the wiring as its own issue.

Non-blocking

  • dash/store.go:819 — the WARN says "a reader held the lock" also when err != nil for another reason. The err attribute is logged beside it, so an operator can tell the two apart, but the message names only one cause.
  • schema/validate.go:216-227 — the grouped scan assumes msgs[from] starts a wire group, i.e. that a call never shares a group with the message after it. True for apply's normalize (an assistant message is one whole-message slot). A public-API caller passing other groups gets a silently wrong scan. A doc note or a guard would make that assumption explicit.
  • Commit d7d8005's message describes the old scan as looking "for its id anywhere in the remaining messages" and adds "the group may not end on an unanswered assistant turn". Neither matches the code: the old scan read a contiguous run of tool messages, and no group-end rule exists. A reader of the log will mislearn both the old and the new behavior.

What I checked

  • Read the full diff (25 files, +1053/-173) and the code around every hunk.
  • ErrCoordsShifted (#452): rawSpanForHash's length-mismatch path (components/offload/stale_prefix.go:26), both new guards (cache_aware_summarizer.go:902, extract_sweep.go:756-787), classifyCallErr ordering, the metrics field, the /stats handler fill, the golden key, and the notExportedWhy entry. Both new tests set RawInput one message longer, which is the only path to !rawOK; their assertions match the new control flow.
  • The adjudicate-leak split (#174): pass now reports tool names (ssepeek.go:192-243); every countLeak site (proxy.go:1815, :1943, :1964) returns right after counting, so no path double-counts; called is hoisted with withheld, so the 502 and JSON-after-stream bails attribute the previous round's tools correctly; h.agg == nil is checked inside countLeak. The end-to-end test's premises (one round, stray reaches the client) match the co-call deferral at proxy.go:2014.
  • The spliced-window usage upgrade (#207): sn.spliced() (usage.go:735) agrees with bytes()'s own head/full-body switch; only absent is upgraded; responseUsage (buffered) passes false; the shape record carries spliced.
  • searchfold (#tokens pick): adopt still requires a byte shrink, so the pick runs only among byte-smaller survivors; the returned fold is always token-<= the input; the pick stays a pure function of the text, so the cache-safety argument is unchanged; the new test asserts its own preconditions and fails the byte-first pick.
  • The commitgate completeness test (#198): both table keys match real call sites (extract_llm.go:848 in Offload, extract_sweep_drop.go:121 in sweepDrop); the three markerFull sites are correctly exempt; the AST scan covers closures inside top-level funcs.
  • The thread boundary tests (#610): traced both fixtures through longestPrefix (no match, last message differs) and rewrittenTailParent (2*lcp==n declines at n=4; lcp=n-3 declines at n=7), so the expected IDs follow from the rule.
  • The dash checkpoint fix (#166) and both tests, incl. the dsn/busy_timeout reasoning and the shared-logger lock; the builtin tool list against Claude Code's own tool set; the promexport coverage entries for both new Snapshot fields.
  • Did not run builds or tests (not approved). Go is not installed on this machine.

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]>
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]>
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]>
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]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 fixes, one commit each, pushed on top of a4ea9422:
d0a96910 (#461 wiring), cc47b176 (countLeak), bb7dc7eb (dash
WARN), 1cd49ba8 (searchfold comment). Answers to each finding below.

Reviewer 1

1. BLOCKING — ValidateShapeGrouped wired to no caller.
Fixed in d0a96910.

  • assertShapeValid (apply/shape_validate_test.go) now takes the wire
    groups built from normalize's own slots via wireGroups, so the
    captured-traffic guard and the summarize end-to-end guard judge the
    normalized list with the grouping it actually has.
  • assertAnthropicWirePairing is deleted. The split-group rebuild
    tests it backed (TestSummarizeRebuildWithASplitGroup,
    TestCacheAwareSummarizerRebuildWithASplitGroup) moved into the
    apply package itself (shape_validate_test.go), where they check
    raw-body roles via the existing assertWireRolesLegal and the
    pairing via the grouped validator — including the comment that said
    the validator "does not know about wire-message grouping", which is
    no longer true. They had to move: the file was in apply_test, the
    external test package, which cannot reach normalize/wireGroups;
    the hand-rolled gjson check existed precisely because of that
    package boundary.
  • The summarize shape oracle now keeps a sibling-first fixture whose
    WireGroup is set on the Ctx, and validates the SPLICED output
    grouped. One deviation from the letter of the suggestion: passing
    c.WireGroup directly would be vacuous here — it is in input
    coordinates and every acted turn changes the count, so the
    validator's length-mismatch rule collapses it to nil on every
    splice. outWireGroups rematches each emitted message against the
    fixture and rebuilds the grouping in emitted coordinates instead
    (the summary gets a group of its own; an ambiguous match fails the
    test rather than validating a wrong grouping).
  • Mutation proof, as requested: with the grouped branch of
    answeredInRun disabled, the rebuild tests fail
    (messages.2 [answered-tool-use] ... call_a) and the oracle fails
    on sibling-first split group keep_last=4
    (messages.2 [answered-tool-use] ... t_s) — the sibling-first
    pairing read as broken, the exact case the deleted work-around
    existed to catch. Unmutated, all pass.

Non-blocking — dash/store.go:819 WARN names one cause.
Fixed in bb7dc7eb. The message now names the fact ("dash: WAL
checkpoint did not complete"), which fits both busy=1 and
err != nil; the attributes say which. The reader-lock test asserts
the new text.

Non-blocking — validate.go grouped scan's msgs[from] assumption.
Fixed in d0a96910, as a doc note rather than a guard:
ValidateShapeGrouped's doc now states that the message after a call
must start a wire group, that apply's normalize guarantees it (an
assistant message is one whole-message slot), and that a grouping
which does not hold the property gets a silently wrong scan. Chose
the note over a guard because the violation is not detectable from
the groups slice alone at that point — it is a property of how the
caller built the groups, which is what a doc contract is for.

Non-blocking — d7d8005's commit message describes both scans wrongly.
Not rewriting history (no force-push). The correct description, now
also stated in d0a96910's message: the OLD scan reads the
CONTIGUOUS RUN of tool messages starting right after the call — it
never searched "anywhere in the remaining messages". 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, and no such rule was added.

Reviewer 2

1. ValidateShapeGrouped has no caller with a real grouping.
Fixed in d0a96910 — same wiring as answered to reviewer 1 above,
including the sibling-first fixture that keeps the oracle on the
grouped path.

2. countLeak counts every non-adjudicate name as expand.
Fixed in cc47b176. countLeak now switches on the name against the
two tools pass is given, and a name that matches neither is logged
(WARN) and counted nowhere — a third proxy tool cannot land silently
in the expand counter; it needs a counter of its own first.

3. usage.go:735 — spliced() true when nothing was dropped.
Not done, for the reason the finding itself gives: the verdict stays
defensible. The window the sniffer hands responseUsageWhy is not
the provider's body either way (it carries an injected terminator),
so "unreadable" is the honest classification for whatever parse
fails on it, and the upgrade only ever moves absent away from
blaming the provider. Tightening spliced() to also require that
bytes were actually dropped would make the sniffer's bytes() window
and its spliced() flag disagree about what "the body" is, which is
a worse trade than one conservative unreadable. Left as documented
behaviour; happy to revisit if a real transcript shows the corner
mattering.

4. searchfold.go:160 comment — "adopt has usually just asked for the same strings".
Fixed in 1cd49ba8. The comment now says what is true: adopt never
counts tokens (it compares bytes); the memoization pays off because
the input was usually counted already by the trigger and the
never-worse guard.

Test evidence for this round

  • gofmt -l, go vet, go build: clean.
  • Mutation (grouped branch disabled): the rebuild tests and the shape
    oracle fail as described above; restored, all pass.
  • Full -race, one package set per run (box, detached):
    ./apply/... ./schema/... ./components/... ok (offload 173s),
    ./proxy/... ok (463s), ./dash/... ok (499s).
  • 1cd49ba8 is comment-only; ./components/reformat/ re-ran green
    under -race on the exact final tree, the other sets on the
    code-identical parent.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.311 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 1cd49ba8c0e8 approve

Verdict: approve

Findings

None in the four new commits. Each fix does what its commit message and the reply claim.

Earlier findings

  • Mine 1 (ValidateShapeGrouped wired to no caller) — fixed in d0a96910. Verified: all three assertShapeValid call sites now pass wireGroups(slots) (apply/shape_validate_test.go:99, :243, :372); wireGroups (apply/apply.go:1989) returns nil on an unparseable slot path, which the new assertShapeValid doc names as the legacy reading. The offload oracle validates the spliced output grouped through outWireGroups, and the sibling-first fixture (wire [0,1,2,3,4,4,5]) puts the oracle on the grouped path. assertAnthropicWirePairing is gone; the rebuild tests moved into the apply package, where normalize/wireGroups are reachable. No dangling references; strconv left the imports of normalizer_siblings_test.go with its last user; replyModel does not collide with recordingModel (different test packages).
  • Mine 2 (countLeak buckets unknown names as expand) — fixed in cc47b176. Verified: the switch takes exactly the two names serve hands pass; anything else logs a WARN and counts nowhere. lg is in scope at the closure.
  • Mine 3 (spliced() true when nothing was dropped) — rejected by the author, and I accept the reason. The window bytes() hands the classifier is never the provider's body when total > len(head): it carries an injected '\n' terminator, so any parse failure over it is ours, not the provider's, and unreadable is the honest verdict. Tightening spliced() would make the window and the flag disagree about what "the body" is. The upgrade also only moves absent away from blaming the provider, never the reverse. The corner stays conservative in the safe direction.
  • Mine 4 (searchfold comment) — fixed in 1cd49ba8. Comment only; the new text matches what adopt and the memoization actually do.
  • Reviewer 1's blocking finding (same defect as my 1) — fixed in d0a96910. Agree, after checking the wiring myself as above. The mutation proof in the reply (grouped branch disabled → rebuild tests and the keep_last=4 oracle case fail with answered-tool-use) is the right proof shape, and the failing indices it names are the ones the grouped scan reads.
  • Reviewer 1's non-blocking (WARN names one cause) — fixed in bb7dc7eb. The new text "WAL checkpoint did not complete" fits both busy=1 and err != nil; the test asserts it.
  • Reviewer 1's non-blocking (msgs[from] starts a group) — fixed as a doc note in d0a96910. The note is in ValidateShapeGrouped's doc. A guard cannot detect the violation from the groups slice alone, so the doc contract is the right instrument. I checked the claim itself: apply's normalize makes each assistant message one whole-message slot, so a new group starts right after a call.
  • Reviewer 1's non-blocking (d7d8005 commit message wrong) — not rewritten, corrected in d0a96910's message. I checked the corrected description against the code: the old scan reads the contiguous run of tool messages after the call (answeredInRun's ungrouped loop), the new scan reads the result members of the one wire group that follows, and no group-end rule exists. Both statements now match the code. No force-push is the right call.

Non-blocking

  • components/offload/summarize_shape_test.go:572 — outWireGroups assumes summarize never rewrites a kept message. The rematch is reflect.DeepEqual against the original fixture. A future component that edits kept tail text makes a message unmatched, and the helper fails the test loudly (two fresh groups) rather than validating a wrong grouping. That is the documented, safe direction. Note only.

What I checked

  • Last review: round 1, a4ea942, 2026-10-27T10:23:56Z.
  • New commits read: 4 — d0a96910 fix(schema): wire the grouped shape check into its real callers; cc47b176 fix(proxy): count a leak only under the tool's own counter; bb7dc7eb fix(dash): make the checkpoint WARN fit both failure ways; 1cd49ba8 docs(reformat): say who counted the strings the memo pays off on.
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files).
  • New items since my last review: the four commits above and the author's round-1 reply comment (2026-10-27T11:04:58Z). Each answered above.
  • d0a9691 (the only commit touching more than a message): read the whole diff and the moved files. shape_validate_test.go was already package apply, so the moved tests compile against normalize, wireGroups, and BodyWithModel without new exports. config.LoadBytes, assertWireRolesLegal, and offload.WaitForAllSummariesForTest all exist and are imported. Traced the sibling-first oracle case by hand: keep_last=4 splices to [summary, call, sibling, result, keep going], outWireGroups yields [fresh, 3, 4, 4, 5], and the grouped scan answers t_s from the group-4 result — the ungrouped scan would report it, which is the mutation proof's failure. Checked the rematch's failure modes: an ambiguous match and a second unmatched message both fail the test, never validate silently. Checked the new ValidateShapeGrouped doc note against normalize's slot structure. Considered whether deleting assertAnthropicWirePairing weakens the check: its reverse direction (a result must answer the immediately preceding wire message) is stricter than seenCall, but the splice inserts nothing inside a kept tail, so the weakening cannot arise from this path.
  • cc47b17: the switch covers exactly adjudicate.ToolName and expand.ToolName, the two names serve passes to pass. The unknown-name WARN is inside the closure where lg lives. The existing leak tests keep their meaning.
  • bb7dc7e: message text and the test's asserted substring match ("WAL checkpoint did not complete"). The comment now names both failure ways. No behavior change beyond the log line.
  • 1cd49ba: comment only. The new text matches adopt's actual behavior (byte comparison, no token counting) and where the memoization pays off.
  • Confirmed the base and the nine round-1 commits are unchanged (no force-push): git diff a4ea9422..HEAD touches only the four files these commits name, plus the doc note in schema/validate.go.
  • Live tests were not run (not approved). Static review only.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.311 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 1cd49ba8c0e8 approve

Verdict: approve

Findings

None. The blocking finding from round 1 is fixed and wired correctly. The four new commits introduce no defect I could find.

Earlier findings — what happened

Mine, round 1

  1. BLOCKING — ValidateShapeGrouped wired to no caller. Fixed in d0a96910. I verified the wiring myself:

    • assertShapeValid (apply/shape_validate_test.go) now takes the groups. Both call sites build them from normalize's own slots: norm, slots := normalize(...), then wireGroups(slots). The discarded-slot smell from round 1 (norm, _ :=) is gone at both sites.
    • The move of the two split-group rebuild tests into package apply is necessary, not a choice: normalize and wireGroups are unexported, and the old file was the external apply_test package. The old hand-rolled assertAnthropicWirePairing existed only because of that boundary. Both test names exist exactly once in the repo now. recordingModel stays behind in apply_test, still used by cache_anchor_test.go and responses_test.go; the new replyModel supplies both Complete and CompleteMessages, which the cache-aware path needs.
    • The summarize oracle's outWireGroups is sound. I traced the sibling-first fixture (wire: []int{0,1,2,3,4,4,5}) through a keep_last=4 splice: emitted groups come out [0, fresh, 3, 4, 4, 5], so the call's group scan covers the sibling and the t_s result together. The ungrouped scan would report the sibling as an unanswered call — the false positive this PR exists to remove. The acted < len(fixtures) guard keeps the oracle from passing vacuously, and the fresh-id guard allows exactly one unmatched message, which is the summary.
    • One deviation from my suggested fix, and the author is right: passing c.WireGroup directly would be vacuous, because every acted splice changes the count and the validator's length-mismatch rule collapses the grouping to nil. Rematching into emitted coordinates is the correct construction.
    • The comment in apply/normalizer_siblings_test.go that said the validator "does not know about wire-message grouping" is updated.
  2. Non-blocking — dash WARN names one cause. Fixed in bb7dc7eb. The message now states the fact ("did not complete"); busy/wal_frames/checkpointed/err attributes say which. The reader-lock test asserts the new text.

  3. Non-blocking — grouped scan's msgs[from] assumption. Addressed as a doc note in d0a96910. The note states the property, who guarantees it, and what happens without it. I accept the note over a guard: the violation is not detectable from the groups slice alone at that point in the scan.

  4. Non-blocking — d7d80058 commit message wrong on both scans. Not fixed in history; corrected on record. The author declines a force-push. The correct description is now in d0a96910's message and the PR reply. Acceptable — the wrong text is immutable either way, and a reader of the log now has the correction one commit later.

Reviewer 2, round 1 (checked myself, new proof only)

  • #2, countLeak buckets every non-adjudicate name as expand. Fixed in cc47b176. The switch matches the two tools pass is given; the default logs a WARN and counts nowhere. lg is defined at proxy.go:1093, before countLeak at :1691, so the WARN compiles.
  • #3, spliced() true when nothing was dropped. Rejected by the author; I accept the rejection. In the total <= 2×sniffMax corner nothing is dropped, but the injected '\n' can still break one SSE line's parse. If the usage block sat on that line, unreadable is the honest verdict — the window broke it, not the provider. Tightening spliced() would make bytes() and spliced() disagree about what "the body" is. Reviewer 2 also marked it "Note only". Agree with reviewer 2, finding 3 — no change needed.
  • #4, searchfold comment. Fixed in 1cd49ba8, comment-only. Verified against the diff: no code change in that commit.

What I checked

  • Last review: round 1, a4ea9422f94204420d96f46684880141a870af52, 2026-10-27T10:24:19Z.
  • New commits read: 4 (d0a96910 fix(schema): wire the grouped shape check into its real callers; cc47b176 fix(proxy): count a leak only under the tool's own counter; bb7dc7eb fix(dash): make the checkpoint WARN fit both failure ways; 1cd49ba8 docs(reformat): say who counted the strings the memo pays off on).
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files).
  • New items since my last review: the author's reply comment, with each answer checked against the code.
  • Read the full round-2 diff (a4ea9422..1cd49ba8, 6 files) and the current state of every touched file, not just the hunks:
    • apply/shape_validate_test.go: package, imports, both assertShapeValid call sites, replyModel, the moved rebuild tests, and the kept assertWireRolesLegal raw-role check.
    • apply/normalizer_siblings_test.go: strconv removed was correct — json and gjson are still used at lines 207, 264, 284-285. pipe still used. No orphaned helper left behind.
    • components/offload/summarize_shape_test.go: the shapeFixture{msgs, wire} shape, the sibling-first fixture's wire indices, outWireGroups rematch logic (ambiguity fails the test; the fresh guard allows exactly one summary), and the acted vacuity guard.
    • proxy/proxy.go countLeak switch and logger scope; dash/store.go WARN text against the test assertion; searchfold comment.
  • Compile-level checks only; no builds or tests run (not approved). Go is not installed on this machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment