Skip to content

fix(#695): safe_eval drops every bridge variable containing I under Turkish collation - #697

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/695-safe-eval-locale
Sep 15, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/695-safe-eval-locale

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

What breaks

safe_eval (scripts/log.sh) is the only bridge between the Python pipeline and
the shell. It matches KEY=VALUE with ^([A-Z_][A-Z0-9_]*)=. [A-Z] is a POSIX
bracket range, matched by the locale's collation order rather than by byte
value, and Turkish collation (tr_TR; az_AZ the same) does not place I inside
A..Z.

So on a Turkish-locale host every bridge variable whose name carries an I is
silently skipped -- EXTRACT_FILE, POSITION, SKIP_LINES -- while the counts
(EXCHANGE_COUNT, HUMAN_COUNT, no I) still arrive. The counts pass the
"0 exchanges" gate, and the run reaches build-prompt with an empty path:

FileNotFoundError: [Errno 2] No such file or directory: ''

The reporter's hook-errors.log holds 5,071 of these. No save has ever completed
on that host, whose only unusual property is its language. Reported in #695 and
confirmed against the code here.

The commits

Test first, red on purpose. The first commit adds the regression test and no
fix at all, so the red run on this PR is the evidence that the test would not
pass with the code doing nothing. The fix follows in the next commit.

Observed vs reasoned

Stated plainly, per CLAUDE.md:

  • Reasoned, not observed locally: macOS's libc does not reproduce this.
    [[ "I" =~ ^[A-Z]+$ ]] still matches under tr_TR.UTF-8 on darwin -- checked
    on this machine. This is glibc collation behaviour, so the Linux legs of this
    PR's matrix are the only place it is actually observed.
  • The test never picks a locale by name. A candidate is accepted only after
    the test watches this machine's own bash fail the [A-Z] match on I under
    it, so a runner that cannot reproduce the bug can never report a pass about it.
  • GitHub's Linux runners ship only C.UTF-8 and en_US.UTF-8, so the probe
    falls back to compiling tr_TR/az_AZ with localedef into a scratch
    LOCPATH (no root needed). Without that step the legs would skip on the exact
    platform where the bug lives, and the module would assert nothing anywhere.
    Whether localedef and the tr_TR source files are present on
    ubuntu-latest is reasoned until this PR's run says so; if it turns out
    they are not, the legs skip loudly rather than passing vacuously.

Paired controls

Per CLAUDE.md, every "must not happen" is paired with a "must happen":

  • HUMAN_COUNT (no I) must arrive on the same input -- a lost EXTRACT_FILE
    would otherwise only mean the harness never ran safe_eval at all.
  • LC_ALL must read back as the caller's own after the function returns.
  • Two default-locale legs pin that the C locale is not bought by widening what
    safe_eval accepts: a lowercase name stays rejected, a bare command stays
    unexecuted.

Part of #695

[AI-generated]

…A-Z]

Red on purpose. The fix is not in this commit.

safe_eval is the only bridge between the Python pipeline and the shell,
and it matches KEY=VALUE with ^([A-Z_][A-Z0-9_]*)=. [A-Z] is a POSIX
bracket RANGE, matched by the locale's collation rather than by byte
value, and Turkish collation does not place I inside A..Z. Under tr_TR
every bridge variable whose name carries an I -- EXTRACT_FILE, POSITION,
SKIP_LINES -- is silently skipped, while the counts (no I) still arrive
and pass the "0 exchanges" gate. The run reaches build-prompt with an
empty path and dies on FileNotFoundError. One reporter's
hook-errors.log holds 5,071 of them: no save has ever completed on that
host, whose only unusual property is its language.

The locale is chosen by observed behaviour, never by name: a candidate
is accepted only after this machine's own bash is watched failing the
[A-Z] match on I under it. macOS's libc does not reproduce this at all
(checked: tr_TR.UTF-8 there still matches), and GitHub's Linux runners
ship only C.UTF-8 and en_US.UTF-8, so the probe falls back to compiling
tr_TR/az_AZ with localedef into a scratch LOCPATH -- without that the
legs would skip on the one platform where the bug lives and assert
nothing anywhere.

Paired controls, per CLAUDE.md: HUMAN_COUNT (no I) must arrive on the
same input, or a lost EXTRACT_FILE would only mean the harness never
ran; LC_ALL must read back as the caller's own afterwards; and two
default-locale legs pin that the fix is not bought by widening what
safe_eval accepts (a lowercase name stays rejected, a bare command
stays unexecuted).

Part of #695

Co-Authored-By: Max <noreply>
…n it fails

Green half of the previous commit's red.

`local LC_ALL=C` in safe_eval, scoped to the function and restored on
return. [A-Z] is a POSIX bracket range matched by the locale's collation,
not by byte value; Turkish collation does not place I inside A..Z, so
EXTRACT_FILE, POSITION and SKIP_LINES were silently dropped on every
Turkish-locale host while the counts (no I) arrived intact. This is the
same trap config() and _remember_cfg_flatten_cache_valid_value already
guard against, the same way, in this same file.

Second, save-session.sh now fails CLOSED when the extract step produces
no EXTRACT_FILE. This is not a second fix for the locale bug -- it is the
statement that the bridge is load-bearing. Whatever the reason a variable
stops crossing it, the run must stop there and say which variable, rather
than walking past the "0 exchanges" gate on counts that did arrive and
surfacing three layers down as FileNotFoundError on open(''). The
cooldown marker is already written by then, so continuing does not mean
trying again later; it burns the span. One reporter collected 5,071 of
those traces, none of which named the bridge or the locale.

Observed vs reasoned, per CLAUDE.md:
- OBSERVED: all four ubuntu-latest legs of the previous commit failed on
  exactly the target assertion, tr_TR.UTF-8 resolving on the runner --
  and only that assertion: the paired positive control (HUMAN_COUNT, no
  I) stayed green there, which is the issue's own table reproduced in CI.
- OBSERVED: macOS does not reproduce it at all. The collation legs skip
  on darwin, so the local suite (2419 passed, 50 skipped) is evidence
  about the fail-closed guard and the non-regression legs, and no
  evidence at all about the locale fix.
- REASONED: the guard holds for az_AZ and any other collation that
  reorders the Latin range; only tr_TR was exercised.

Part of #695

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit 1949554 into main Sep 15, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/695-safe-eval-locale branch September 26, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant