Skip to content

fix(slug): one session-directory slug, and make it truncate - #187

Merged
fdaviddpt merged 1 commit into
mainfrom
max/slug-parity-157-158-174
Jul 26, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
max/slug-parity-157-158-174

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #157, #158, #174.

Three implementations of the same rule, three different answers, and one consequence each time: the plugin computes a ~/.claude/projects/<slug>/ that Claude Code never created, finds no transcript, and saves nothing without saying so. That is the fourth-and-fifth-and-sixth report of a shape this repo already knows (#144, #166).

What was wrong

#157 — nothing truncated. Past 200 characters Claude Code keeps the first 200 and appends a hash of the original path (charCodeAt, wrapped to signed 32-bit each round, base36). A project path deep enough to cross that — ordinary monorepo nesting under a long home directory — never saved anything at all.

#158 — lib-memory-dir.sh carried its own naive copy, the pre-#144 implementation with every bug #156 fixed. Not dead code: user-prompt-hook.sh reaches that file without sourcing detect-tools.sh, so in external-storage mode ({slug} in data_dir) that one hook resolved a different REMEMBER_DIR than every other. Split-brain memory hides better than a clean failure.

#174 — pipeline/extract.py used a codepoint regex. Claude Code's has no /u flag and walks UTF-16 code units, so an astral character (emoji, Extension-B kanji) costs two dashes there and one here. Live in 0.8.7, in the one copy nobody re-pointed at the fixed oracle.

The shape of the fix

pipeline/slug.py (Python) and scripts/lib-slug.sh (shell, sourced by both detect-tools.sh and lib-memory-dir.sh).

Sourcing detect-tools.sh from lib-memory-dir.sh instead is not available: it runs Python detection at source time and exit 1s when it finds none, taking its caller down with it. That is presumably why the duplicate existed in the first place.

The shell side calls the Python one for the over-long hash only — bash does not do signed-32-bit wraparound and base36 well, and only long paths pay a subprocess. Two ways that can go wrong, both handled:

  • No Python reachable → the untruncated slug. Wrong exactly as it was before rather than a crash or a bare truncation, and fix(windows): non-ASCII paths silently disabled the whole pipeline (#144, #145) #156's missing-directory warning reports it.
  • A hash that is not base36 → same fallback. It can only come from a stale or wrong-version plugin copy resolved through PIPELINE_DIR, and appending it verbatim would invent a new wrong directory instead of falling back to the old wrong one.

Tests

tests/test_slug_parity.py checks bash and Python against an independent transcription of the shipped CLI's function — not against each other — over ASCII, accents, CJK, emoji, astral kanji, embedded newlines, and lengths either side of 200. It drives the three real entry points (extract._session_dir, detect-tools.sh, and the actual {slug} resolution), not just the helpers: my first draft tested only the new modules and passed against the pre-fix code, which proved nothing.

Six test IDs go red against pre-fix code, covering the three defects (three of them are one parametrized test for #174). Full suite: 784 passed, 41 skipped.

Review

An adversarial pass fuzzed both implementations against a node oracle running the real function — 46 hand-picked plus 3000 randomized paths, lengths 0–500 — with zero mismatches, and independently verified the revert-proof claim.

It also found that the byte table's own comment overstated its guarantee: it diverges from the decoder for any lead byte missing its continuations, not only at end of string, and Linux does not enforce well-formed UTF-8 in filenames the way that comment assumed macOS and Windows do. The comment now says what is true, and the gap is tracked in #186 rather than papered over.

Three implementations, three different answers, one consequence each time: the
plugin computes a ~/.claude/projects/<slug>/ that Claude Code never created,
finds no transcript, and saves nothing without saying so.

#157 — nothing truncated. Past 200 characters Claude Code keeps the first 200
and appends a hash of the ORIGINAL path (charCodeAt, wrapped to signed 32-bit
each round, base36). A project path deep enough to cross that — ordinary
monorepo nesting under a long home directory — therefore never saved at all.

#158 — lib-memory-dir.sh carried its own naive inline copy: the pre-#144
implementation, with every bug #156 fixed. Not dead code. user-prompt-hook.sh
reaches that file without sourcing detect-tools.sh, so in external-storage mode
({slug} in data_dir) that one hook resolved a DIFFERENT REMEMBER_DIR than every
other one. Split-brain memory, which hides better than a clean failure.

#174 — pipeline/extract.py still used a codepoint regex. Claude Code's has no
/u flag and walks UTF-16 code units, so an astral character (emoji,
Extension-B kanji) costs two dashes there and one here. Live in 0.8.7, in the
one copy nobody re-pointed at the fixed oracle.

The algorithm now lives in pipeline/slug.py and scripts/lib-slug.sh, the latter
sourced by both detect-tools.sh and lib-memory-dir.sh. Sourcing detect-tools.sh
from lib-memory-dir.sh is not an option — it runs Python detection at source
time and exits 1 when it finds none, taking its caller with it, which is
presumably why the duplicate existed. The shell side calls the Python one for
the over-long hash only: bash does not do signed-32-bit wraparound and base36
well, and only long paths pay the subprocess. With no Python reachable it falls
back to the untruncated slug — wrong exactly as before rather than crashing,
and #156's warning now reports it. A hash that is not base36 is refused the
same way: it can only come from a stale or wrong-version plugin copy resolved
through PIPELINE_DIR, and appending it verbatim would invent a NEW wrong
directory instead of falling back to the old wrong one.

tests/test_slug_parity.py checks bash and Python against an independent
transcription of the shipped CLI's function rather than against each other,
over ASCII, accents, CJK, emoji, astral kanji, newlines, and lengths either
side of 200 — and drives the three real entry points, not just the helpers.
Six of its test IDs go red against the pre-fix code, covering the three
defects (three of them are one parametrized test for #174).

The byte table's own comment overstated its guarantee: it diverges from the
decoder for any lead byte missing its continuations, not only at end of string,
and Linux does not enforce well-formed UTF-8 in filenames the way the comment
assumed macOS and Windows do. Narrowed to the truth and tracked in #186.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit 8eb93b2 into main Jul 26, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the max/slug-parity-157-158-174 branch July 26, 2026 21:32
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.

session_dir_slug does not truncate at 200 chars + hash, so deep project paths silently never save

2 participants