Skip to content

fix: close the three follow-ups from the review pass - #195

Merged
fdaviddpt merged 6 commits into
mainfrom
max/review-followups
Jul 27, 2026
Merged

fdaviddpt merged 6 commits into
mainfrom
max/review-followups

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #190. Closes #186. Closes #194.

All three came out of adversarial reviews of the previous batch. Each was filed rather than fixed in place because it was a different question from the PR it surfaced in; this closes all three.

#190 — a call that fails still spent tokens

Every accounting path in the pipeline hangs off a returned result, and a timeout or non-zero exit returns none. So a run where the model timed out repeatedly showed errors in the log and zero reported cost — "it failed for free". It did not: a client-side timeout aborts a call the API has already been billing, and a mid-stream error has already consumed input.

Usage now comes out of the JSON the CLI writes to stdout on failure when it carries any, and is reported as explicitly unknown when it does not. Zero is a lie; unknown is not.

#186 — malformed UTF-8 disagreed with the decoder

The sed byte table is exact for well-formed UTF-8 and gives one dash per byte for anything else, where the real decoder folds an ill-formed sequence into a single replacement character. macOS enforces well-formed UTF-8 and Windows paths come from UTF-16 — but Linux enforces nothing, so a legacy-encoded or corrupted directory name resolved to a slug Claude Code never created.

Those paths now go to pipeline/slug.py, which owns a real decoder. The cost is bounded deliberately: a path pays a subprocess only if it is both non-ASCII and actually ill-formed, and an ASCII path never reaches even the iconv check — this function runs on every tool call, and trading that for a rare correctness fix would be a bad deal.

One thing that took a try to notice: argv arrives surrogate-escaped, so the first version of this delegated to Python and Python counted the bad bytes exactly the way sed did. The CLI now decodes back through the filesystem encoding first, which is what actually applies the maximal-subpart rule. Without that line the whole delegation buys nothing — and it looked like it worked.

#194 — do the two builders name the same directory?

lib-slug.sh hands bash a POSIX path; extract.py hands Python a native one. On Windows those are different strings, and I argued in the last review that identical strings is the wrong invariant — each consumer needs the form its own runtime can open. The right invariant is that both name the same directory, and nobody had established that.

So the test creates the directory from the Python side and asks bash, through its own builder, whether it is there. On the Windows runner that is an answer rather than an argument, which is the whole complaint #169 was filed with.

Tests

Three go red against pre-fix code for #190, four for #186 — including one asserting that well-formed paths never shell out, because a performance regression traded for a correctness fix is still a regression.

Full suite: 861 passed, 41 skipped.

vsajan added 3 commits July 27, 2026 05:39
#190 — a call that fails still spent tokens, and nothing recorded it. Every
accounting path hangs off a returned result; a timeout or non-zero exit returns
none, so a run that timed out repeatedly showed errors and zero cost. That reads
as "it failed for free", which is the same invisibility #178 and #180 were
about. Usage now comes out of the JSON the CLI writes to stdout on failure when
it carries any, and is reported as explicitly unknown when it does not. Zero is
a lie; unknown is not.

#186 — the sed byte table is exact for well-formed UTF-8 and wrong for anything
else, giving one dash per byte where the decoder folds an ill-formed sequence
into one replacement character. Linux permits such filenames. Those paths now go
to pipeline/slug.py, which owns a real decoder — but only a path that is both
non-ASCII AND actually ill-formed pays a subprocess, and an ASCII path never
reaches the check at all, because this runs on every tool call. The CLI decodes
argv back through the filesystem encoding first: without that, Python counts the
bad bytes exactly the way sed did and the delegation buys nothing. That took a
try to notice.

#194 — the two builders produce different strings for the same Windows
CLAUDE_CONFIG_DIR. Identical strings is the wrong invariant: each consumer needs
the form its own runtime can open. "Same directory" is the right one, and it was
unestablished. A test creates the directory from the Python side and asks bash,
through its own builder, whether it is there — a real answer on the Windows
runner rather than more reasoning from a Mac.

Three tests go red against the pre-fix code for #190, four for #186 (including
one asserting well-formed paths never shell out).

Full suite 861 passed, 41 skipped.

Co-Authored-By: Max <noreply>
Benching my own claim caught two things.

The check cost ~6ms on EVERY non-ASCII path, on every platform, on every tool
call — and macOS enforces well-formed UTF-8 while Windows paths come from
UTF-16, so neither can produce the input it looks for. It now runs on Linux
only, gated on $OSTYPE, which is a bash variable rather than a fork.
REMEMBER_UTF8_STRICT=1 forces it on so the behaviour is still testable
elsewhere; a fix nobody can exercise locally is a fix nobody maintains.

And the test asserting "well-formed paths never reach the subprocess" watched
for python3 only, so it passed while iconv forked on every accented path. It
now shadows BOTH binaries — and delegates to the real ones rather than failing,
because a stub iconv that always exits 1 makes every path look ill-formed,
which is how the first version 'found' a well-formed path reaching the decoder.

Measured, 200 calls each:

  platform      ASCII    valid non-ASCII    ill-formed
  non-Linux     2.1ms    2.1ms              2.2ms
  Linux         2.0ms    8.7ms              71ms

Full suite 863 passed, 41 skipped.

Co-Authored-By: Max <noreply>
$'\\000' expands to NOTHING — bash cannot hold a NUL in a string — so
`*[!$'\\000'-$'\\177']*` silently degenerated into `[!-\\177]`, i.e. "any
character except - and DEL". It reads as the tightest possible test and was the
loosest one: every ASCII path matched, and every ASCII path forked iconv.

Caught by the fork probe from the previous commit, which is the entire argument
for writing that probe rather than trusting the glob by eye.

Range now starts at \\001. A NUL cannot appear in an argv string, so nothing is
lost. DEL and the C0 controls are correctly excluded — they are always valid
single-byte ASCII and could never be the multi-byte fragment this looks for
(the reviewer's nitpick on the earlier form).

  /tmp/plain-ascii   no fork
  /tmp/a<DEL>b       no fork
  /tmp/café          iconv

Full suite 863 passed, 41 skipped.

Co-Authored-By: Max <noreply>
@fdaviddpt

Copy link
Copy Markdown
Contributor Author

Your blocker was right, and it was already fixed by the time the verdict landed — I benched my own claim while you were reviewing and found the same thing. Which is awkward for you: you reviewed 52be04f, and the checkout you were reading was being edited underneath you. That is my fault and I have taken the lesson (review a committed SHA in a copy, never a worktree I am still working in).

Where it ended up:

  • The check is now gated on $OSTYPE — a bash variable, not a fork — so it runs on Linux only, which is the one platform that can produce an ill-formed filename. macOS and Windows pay nothing at all. REMEMBER_UTF8_STRICT=1 forces it on, because a fix nobody can exercise off Linux is a fix nobody maintains.
  • Your nitpick about DEL and the C0 controls is fixed too — the glob now tests for a byte ≥ 0x80 rather than "outside space..~".
  • And that change caught a much worse bug than the one it was for: $'\\000' expands to nothing, because bash cannot hold a NUL in a string. So *[!$'\\000'-$'\\177']* degenerated into [!-\\177] — "any character except - and DEL" — matching essentially every path. It reads as the tightest possible test and was the loosest one. Every ASCII path forked iconv.

That last one was found by the fork probe, not by reading the glob, which is the whole argument for the probe: I replaced my Python-only marker with one that shadows both iconv and python3 and delegates to the real binaries — a stub that merely fails changes the behaviour it is measuring, which is how the first version 'found' a well-formed path reaching the decoder.

Measured, 200 calls each:

ASCII valid non-ASCII ill-formed
macOS / Windows 1.9ms 1.9ms 2.2ms
Linux 1.9ms 7.5ms 74ms

The CHANGELOG now states this rather than the version you correctly called false.

Full suite 863 passed, 41 skipped.

vsajan added 3 commits July 27, 2026 06:31
Review point: the ms figures in lib-slug.sh and the CHANGELOG were a claim with
nothing behind them — unfalsifiable numbers baked into permanent docs. Now
scripts/bench-slug.sh produces them, on the reader's machine, either as their
platform behaves or with REMEMBER_UTF8_STRICT=1 to see what Linux does.

Worth keeping for its own sake: benching this found two bugs that reading it
did not — an iconv fork on every non-ASCII path where it can never be needed,
and a glob that matched almost everything.

Also from the same review: ${OSTYPE:-} is now guarded. bash always sets it, but
this file is sourced by callers running under set -u and one unguarded expansion
there takes the hook down. Not reachable through any current entry point;
one character to make it not matter.

Full suite 863 passed, 41 skipped.

Co-Authored-By: Max <noreply>
CI found this; my machine never would have. A bracket RANGE is matched by
COLLATION order, not byte value, so `[!\\001-\\177]` means whatever the ambient
locale says. The same expression answered correctly here and matched every
ASCII path on the macOS CI runner — a fork per tool call, on the platform that
can never need the check at all.

This file already documents the identical trap for `[a-z]` in its sed program,
which is what makes it embarrassing rather than surprising.

Detection now runs under LC_ALL=C, with the verdict stashed in a flag before the
locale is restored — the branch can return early, and leaving a caller's LC_ALL
set to C would be a worse bug than the one being fixed.

New test asserts an ASCII path forks nothing under C, POSIX, en_US.UTF-8 and
C.UTF-8. Locale was the dimension the fork probe was missing.

Full suite 863 passed, 41 skipped.

Co-Authored-By: Max <noreply>
Review of the delta: the test added to make the last review's
'unfalsifiable claim' complaint go away was itself unfalsifiable — it passes
against the pre-fix code, and a sweep of all 55 installed locales under bash 3.2
could not reproduce the misdetection at all.

The reviewer is right, and the correction is to the claim rather than the code.
What is established is empirical: three consecutive macOS CI runs red on this
same test (30235721355, 30236170724, 30237326112) and green on the run that
forced byte semantics (30237861167). What is NOT established is the mechanism —
collation order is the obvious candidate and this file already documents that
trap for [a-z], but the runner differs from a local bash 3.2 in some way I have
not identified.

So the comment and the test docstring now say 'empirically necessary, mechanism
unconfirmed' and 'do not read a pass here as proof', instead of asserting a
diagnosis I cannot demonstrate. LC_ALL=C stays: it is free and correct either
way.

Also from the same review: bench-slug.sh exits 2 on an unresolvable PYTHON
rather than printing an empty table and exiting 0, which read as 'no measurable
cost'.

Full suite 867 passed, 41 skipped.

Co-Authored-By: Max <noreply>
@fdaviddpt

Copy link
Copy Markdown
Contributor Author

You caught the important thing: I wrote a test to answer the previous review's "unfalsifiable claim" complaint, and the test was itself unfalsifiable. It passes against the pre-fix code. That is the same defect one level up, and your file-swap proof is exactly right.

But the fix is not decoration, and here is the evidence I should have put in the commit instead of a diagnosis:

run commit macOS
30235721355 1a5b032 (Linux gate) fail
30236170724 1780266 (\001 glob) fail
30237326112 fa888af (bench) fail
30237861167 6ec61de (LC_ALL=C) pass

Same test, three consecutive red runs on macos-latest, green on the run that forced byte semantics and nothing else. So the change is empirically necessary.

What I cannot demonstrate is why. Collation was my explanation and it is the obvious candidate — this file already documents that trap for [a-z] in its sed program — but your 55-locale sweep under bash 3.2 says it does not reproduce there, and I have no bash ≥4 on this machine to test the other half of the hypothesis. The runner differs in some way I have not identified.

So I have corrected the claim rather than the code:

  • the code comment now reads "empirically necessary, mechanism unconfirmed", with the four run IDs so the next person can check rather than trust me
  • the test docstring says it is defense-in-depth, that the four locales are not known to be the ones that differ, and "do not read a pass here as proof the underlying bug is gone"
  • the CHANGELOG says the same

LC_ALL=C stays. It is free, it is correct regardless of mechanism, and the CI record says it matters.

Your PYTHON= nitpick is fixed too — the benchmark exits 2 instead of printing an empty table and exiting 0, which read as "no measurable cost".

Full suite 867 passed, 41 skipped.

@fdaviddpt
fdaviddpt merged commit b1d3cd6 into main Jul 27, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the max/review-followups branch July 27, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants