Skip to content

diag(#695): which bracket-range shapes diverge under Turkish collation - #698

Closed
fdaviddpt wants to merge 1 commit into
mainfrom
diag/695-range-matrix
Closed

fdaviddpt wants to merge 1 commit into
mainfrom
diag/695-range-matrix

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Throwaway diagnostic. Do not merge. Red on purpose -- the table is the
output, same shape as the #689 diagnostics.

#695 established one divergence: [A-Z] does not match I under glibc
tr_TR. Every other bracket range in scripts/ is spelled differently --
[a-zA-Z], [A-Za-z0-9._-], the negated case form, the
${v//[!a-zA-Z0-9]/-} substitution form -- and whether those also drop i/I
decides how many sites actually need LC_ALL=C.

macOS cannot answer it: all six shapes behave identically there across C,
en_US.UTF-8 and tr_TR.UTF-8, because darwin's libc does not collate ranges
the way glibc does. So this gets the matrix off a Linux runner once, and the
branch is deleted.

Part of #695

[AI-generated]

…llation

Red on purpose, like the #689 diagnostics: the table is the output.

#695 established one divergence -- [A-Z] does not match I under glibc
tr_TR. Every other bracket range in scripts/ is spelled differently
([a-zA-Z], [A-Za-z0-9._-], the negated case form, the substitution form),
and whether those also drop i/I decides how many sites need LC_ALL=C.
macOS cannot answer it: all six shapes behave identically there across C,
en_US.UTF-8 and tr_TR.UTF-8, because darwin libc does not collate ranges
the way glibc does.

Throwaway branch. Delete once the matrix is read.

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

Copy link
Copy Markdown
Contributor Author

Matrix read and recorded: only [[ =~ ]] collates on glibc; case patterns and ${v//[!...]/} compare bytes and did not move under tr_TR. Both failure directions are real in the regex path -- [A-Z] loses I, [A-Za-z] gains é. Carried into #699 (PR body, and the docstrings of tests/test_locale_ranges_695.py and tests/test_id_guards_locale_695.py), which is scoped to what this measured rather than to what I assumed before running it. Throwaway branch, deleting.

@fdaviddpt fdaviddpt closed this Sep 15, 2026
fdaviddpt added a commit that referenced this pull request Sep 15, 2026
…lation

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

Two halves.

The scanner (tests/test_locale_ranges_695.py) reads source on every
platform and reports every ASCII letter range in a shipped shell script
that is not matched under LC_ALL=C. It is red on 14 sites today. Three
places in this tree already carried the fix before #695 -- config(),
_remember_cfg_flatten_cache_valid_value, lib-slug.sh's LC_ALL=C sed --
each found separately, one bug report at a time; this is the general
form, so the next one is a finding at authoring time instead.

The behavioural half (tests/test_id_guards_locale_695.py) covers the two
sites #698's measured matrix showed actually break, both reached through
`[[ =~ ]]`:

  _remember_cfg_flatten_cache_valid_line -- a config key carrying an `I`
  makes its cache line read as malformed, so the config-data cache is
  refused and every hook re-reads and re-flattens the config, forever,
  silently. A performance floor nothing reports.

  _remember_normalize_win_path -- drive `I:` stops being recognised, and
  its `tr '[:lower:]' '[:upper:]'` maps a lower-case `i:` drive to a
  dotted `İ` under Turkish rules: two bytes where one ASCII letter has
  to go.

What #698 measured, on ubuntu-latest / bash 5.2 / localedef-built
tr_TR.UTF-8, and why the scope is what it is:

  [[ =~ ]] over [A-Z], [a-z], [a-zA-Z], [A-Za-z0-9_]   loses I and i
  [[ =~ ]] over [A-Za-z]                               GAINS é
  case patterns, and ${v//[!...]/}                     do not move

Both failure directions are real, and only the regex path collates;
bash's own glob matcher compares bytes. The `case` guards are therefore
listed in the scanner's allowlist with that measurement as their stated
reason rather than excluded from the scan -- one libc and one bash is
not a licence to stop looking, and POSIX does permit a case range to
collate.

The locale probe both modules share accepts a locale only after watching
this machine's bash fail under it, and builds one with localedef when
the runner ships none.

Part of #695

Co-Authored-By: Max <noreply>
fdaviddpt added a commit that referenced this pull request Sep 15, 2026
…at hold them

Green half of the previous commit's red.

Thirteen `local LC_ALL=C` insertions, each scoped to one function and
restoring the caller's locale on return. Two of them are live bugs that
#698's measured matrix identified, both reached through `[[ =~ ]]`:

  _remember_cfg_flatten_cache_valid_line (scripts/log.sh) validated each
  config-data cache line against ^_RCFG_[A-Za-z0-9_]+=. A config key
  carrying an I made the line read as malformed under Turkish collation,
  so the cache was refused and every hook fell back to re-reading and
  re-flattening the config on every invocation, permanently, with nothing
  said. Confirmed red on the ubuntu legs of the previous commit: VALID
  became REJECTED.

  _remember_normalize_win_path (scripts/resolve-paths.sh, mirrored in
  scripts/lib-env-cache.sh) stopped recognising the drive I:, and its
  `tr '[:lower:]' '[:upper:]'` mapped a lower-case i: drive to a dotted
  İ under Turkish case rules -- two bytes where one ASCII letter has to
  go. Forcing C fixes the range and the case mapping together.

The other eleven are `case` and substitution sites, which the matrix
cleared: only the regex path collates. One line makes them immune anyway
and leaves the scanner no exception to carry.

Also here, because the previous commit's CI said so rather than because
I reasoned it:

  The drive-letter legs failed with exit 127, not with a wrong answer --
  `_remember_normalize_win_path` is `unset -f`'d at resolve-paths.sh:340
  once resolution is done, so sourcing the script does not leave it
  callable. Extracted by regex instead, the same route
  tests/test_save_session_marker_unreadable_625.py already takes for
  ts_marker_read and for the same recorded reason. Paired with two new
  C-locale legs that run on every platform, so a harness that stops
  working fails loudly everywhere instead of skipping in silence -- which
  is exactly how it hid the first time.

  scripts/lib-memory-dir.sh is byte-pinned against origin/main
  (tests/test_case_divergence_298.py), so both insertions into it are
  declared in _SANCTIONED_DIVERGENCE with their reason, the way #429 and
  #662 already are.

Part of #695

Co-Authored-By: Max <noreply>
fdaviddpt added a commit that referenced this pull request Sep 15, 2026
… a scanner (#699)

* test(#695): pin that a bracket range must not follow the locale's collation

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

Two halves.

The scanner (tests/test_locale_ranges_695.py) reads source on every
platform and reports every ASCII letter range in a shipped shell script
that is not matched under LC_ALL=C. It is red on 14 sites today. Three
places in this tree already carried the fix before #695 -- config(),
_remember_cfg_flatten_cache_valid_value, lib-slug.sh's LC_ALL=C sed --
each found separately, one bug report at a time; this is the general
form, so the next one is a finding at authoring time instead.

The behavioural half (tests/test_id_guards_locale_695.py) covers the two
sites #698's measured matrix showed actually break, both reached through
`[[ =~ ]]`:

  _remember_cfg_flatten_cache_valid_line -- a config key carrying an `I`
  makes its cache line read as malformed, so the config-data cache is
  refused and every hook re-reads and re-flattens the config, forever,
  silently. A performance floor nothing reports.

  _remember_normalize_win_path -- drive `I:` stops being recognised, and
  its `tr '[:lower:]' '[:upper:]'` maps a lower-case `i:` drive to a
  dotted `İ` under Turkish rules: two bytes where one ASCII letter has
  to go.

What #698 measured, on ubuntu-latest / bash 5.2 / localedef-built
tr_TR.UTF-8, and why the scope is what it is:

  [[ =~ ]] over [A-Z], [a-z], [a-zA-Z], [A-Za-z0-9_]   loses I and i
  [[ =~ ]] over [A-Za-z]                               GAINS é
  case patterns, and ${v//[!...]/}                     do not move

Both failure directions are real, and only the regex path collates;
bash's own glob matcher compares bytes. The `case` guards are therefore
listed in the scanner's allowlist with that measurement as their stated
reason rather than excluded from the scan -- one libc and one bash is
not a licence to stop looking, and POSIX does permit a case range to
collate.

The locale probe both modules share accepts a locale only after watching
this machine's bash fail under it, and builds one with localedef when
the runner ships none.

Part of #695

Co-Authored-By: Max <noreply>

* fix(#695): force byte-wise bracket ranges, scoped to the functions that hold them

Green half of the previous commit's red.

Thirteen `local LC_ALL=C` insertions, each scoped to one function and
restoring the caller's locale on return. Two of them are live bugs that
#698's measured matrix identified, both reached through `[[ =~ ]]`:

  _remember_cfg_flatten_cache_valid_line (scripts/log.sh) validated each
  config-data cache line against ^_RCFG_[A-Za-z0-9_]+=. A config key
  carrying an I made the line read as malformed under Turkish collation,
  so the cache was refused and every hook fell back to re-reading and
  re-flattening the config on every invocation, permanently, with nothing
  said. Confirmed red on the ubuntu legs of the previous commit: VALID
  became REJECTED.

  _remember_normalize_win_path (scripts/resolve-paths.sh, mirrored in
  scripts/lib-env-cache.sh) stopped recognising the drive I:, and its
  `tr '[:lower:]' '[:upper:]'` mapped a lower-case i: drive to a dotted
  İ under Turkish case rules -- two bytes where one ASCII letter has to
  go. Forcing C fixes the range and the case mapping together.

The other eleven are `case` and substitution sites, which the matrix
cleared: only the regex path collates. One line makes them immune anyway
and leaves the scanner no exception to carry.

Also here, because the previous commit's CI said so rather than because
I reasoned it:

  The drive-letter legs failed with exit 127, not with a wrong answer --
  `_remember_normalize_win_path` is `unset -f`'d at resolve-paths.sh:340
  once resolution is done, so sourcing the script does not leave it
  callable. Extracted by regex instead, the same route
  tests/test_save_session_marker_unreadable_625.py already takes for
  ts_marker_read and for the same recorded reason. Paired with two new
  C-locale legs that run on every platform, so a harness that stops
  working fails loudly everywhere instead of skipping in silence -- which
  is exactly how it hid the first time.

  scripts/lib-memory-dir.sh is byte-pinned against origin/main
  (tests/test_case_divergence_298.py), so both insertions into it are
  declared in _SANCTIONED_DIVERGENCE with their reason, the way #429 and
  #662 already are.

Part of #695

Co-Authored-By: Max <noreply>
fdaviddpt added a commit that referenced this pull request Sep 24, 2026
The top-level LC_ALL save/restore around the allowlist `case` was not a
guard test_locale_ranges_695 recognises, and restored an unset LC_ALL as
set-but-empty. `case` patterns are measured not to collate (#698), so use
the same plain `case` as session-start-hook.sh:294 and list the site in
the same ALLOWLIST under _CASE.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
fdaviddpt added a commit that referenced this pull request Sep 24, 2026
…ed session's handoff (#739)

* fix(#738): thread the session id through write-handoff.sh instead of a project-wide last-writer-wins pointer

`handoff_mode: "per_session"` published the resolved handoff target to one
shared file, `tmp/handoff-path`, overwritten on every SessionStart. The last
session to start owned that pointer, so an earlier session's later
/remember could silently write into a more-recently-started session's
remember.<id>.md. write-handoff.sh never received a session id, so it had
no way to tell.

session-start-hook.sh now also publishes a copy keyed by that session's own
id, tmp/handoff-path.<session_id>; write-handoff.sh identifies its own
session via CLAUDE_CODE_SESSION_ID (a live env var Claude Code sets for the
Bash tool, never a value the model supplies) and prefers that copy over the
shared pointer whenever it exists, falling back exactly as before when no
session id reaches it. The new per-session hint files are pruned the same
way #373 already prunes remember.delivered.<session_id> records.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* test(#738): make the new module importable on Python 3.9

`str | None` in a signature is evaluated at definition time on 3.9 and
failed collection on every CI leg. Postpone annotation evaluation.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(#738): sanitize the session id the way #270's sibling does

The top-level LC_ALL save/restore around the allowlist `case` was not a
guard test_locale_ranges_695 recognises, and restored an unset LC_ALL as
set-but-empty. `case` patterns are measured not to collate (#698), so use
the same plain `case` as session-start-hook.sh:294 and list the site in
the same ALLOWLIST under _CASE.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
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