Skip to content

Fix #1083: pin the resolved store at SessionStart instead of guessing from cwd - #1093

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/1083
Nov 1, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/1083

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #1083

Problem

write-handoff.sh and doctor.sh resolved which project store a session's note belongs to by walking up from the current directory to the nearest git toplevel, disambiguating with a session-keyed hint file where one existed. That walk is structurally blind to three shapes:

  1. A repository or submodule inside another repository -- the walk stops at the inner toplevel and never sees the outer project's store.
  2. A sibling folder with no .git at all -- the walk never even starts.
  3. A resumed session that moved to a different folder, or any folder the ancestor chain from the current directory never passes through.

A same-second write also defeated the previous freshest-mtime tie-break outright (mtime is whole seconds, worse on FAT).

Fix

SessionStart now pins the resolved REMEMBER_DIR at a session-keyed pointer file outside every project store: ~/.remember/tmp/session-store/<session_id>. It is written with a plain redirect into a temp file in the same directory, then an atomic rename -- overwritten on every start, including --resume.

write-handoff.sh and doctor.sh now read that pointer first, through one new shared library (scripts/lib-session-store.sh) that both scripts source -- replacing the pasted copy of the ancestor-walk logic doctor.sh previously carried. When the pointer is present, resolution never guesses from the current directory at all, closing all three gaps above.

The ancestor walk survives only as a fallback for a session that started before this pointer existed. In that fallback, when more than one ancestor claims the session, write-handoff.sh now refuses outright (REFUSED: more than one candidate store matched this session...) rather than guessing by mtime. doctor.sh, whose whole job is to always report something, prints a WARN instead and still shows its best-effort fallback.

The existing stale-hint reaper in session-start-hook.sh is extended with a second sweep for these new pointers (a separate function, since the pointer's filename shape -- flat, under a directory shared across every project -- differs from the existing <prefix>.<session-id> sweep under one project's own tmp/).

The REMEMBER_DIR_UNSAFE guard (#1064/#920) is respected: the pointer is never written when the resolved store is unsafe, and a pointer value is re-validated against the same shape predicate before being trusted.

Sequencing

The issue's own sequencing note asked that this not land while session-start-hook.sh was being concurrently edited by the #1046/#1047/#1052 and #1079/#1060 lanes. Both are already merged into main (commits 735e65c and e0379ca), so this branches from a base where that condition is satisfied.

Tests

New file tests/test_session_store_pointer_1083.py (21 tests) covers all six cases named in the issue's scope comment, each with a positive control:

  1. Resume into a child/sibling, then cd elsewhere entirely.
  2. A repository/submodule inside another repository.
  3. A non-git sibling, and a git sibling with no hint.
  4. Two hints written in the same second (pointer makes the tie irrelevant; a positive control shows the no-pointer fallback now refuses on the same tie rather than guessing).
  5. An external ~/.remember/{slug} store.
  6. A Windows-path case (TestWindowsPathShapeRunsOnEveryPlatform) that is not skipif(win32) -- it drives the shared library's own shape predicate directly as pure bash string matching, which runs identically on every platform, including windows-latest.

tests/test_write_handoff_subdirectory_project_776.py's TestFreshestHintWinsOnResume1058Review class is updated: its two ambiguous-candidate tests now assert REFUSED (the #1083 ruling) instead of the old freshest-mtime tie-break; its third, single-candidate test is unaffected and unchanged.

tests/test_locale_ranges_695.py's allowlist line numbers for scripts/write-handoff.sh and scripts/doctor.sh are updated to match where their local LC_ALL=C-guarded bracket ranges moved to after this diff's insertions.

Red before the fix

Before the pointer mechanism existed, a manual reproduction of the nested-repo and non-git-sibling cases misrouted the note to the wrong (or no) store; the two TestFreshestHintWinsOnResume1058Review tests failed with the old expectations once the ambiguous-refuse behavior was wired in (AssertionError: ... REFUSED: more than one candidate... where the test expected returncode == 0).

Green after the fix

$ python3 -m pytest tests/test_write_handoff_subdirectory_project_776.py tests/test_doctor_subdirectory_project_827.py tests/test_locale_ranges_695.py tests/test_arith_base_lint_332.py tests/test_scanner_shapes_source_898.py tests/test_strip_shell_comments_900.py tests/test_release_branch_check_900.py tests/test_session_store_pointer_1083.py -q
549 passed

Re-run with PATH forced to /bin:/usr/bin (bash 3.2, macOS's shipped bash) -- same 549 passed. Each shipped script also syntax-checked clean under /bin/bash -n (bash 3.2).

The hook-size budget (python3 .github/scripts/compile_hooks.py) is unaffected: session-start-hook.sh compiles to 106362 bytes, under the 122880-byte cap, since the shared resolver library is sourced only by write-handoff.sh/doctor.sh (neither is one of the four budget-constrained hook scripts) -- session-start-hook.sh itself only gained the small inline pointer-write and reaper-extension blocks.

Not run locally

The full pytest suite and check_release_tree.py against a real built tree were not run locally -- CI covers the full matrix; the targeted set above, plus the cross-cutting guard tests the issue's own brief named, is the local evidence.

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 3 commits November 1, 2026 16:05
… from cwd

write-handoff.sh and doctor.sh used an ancestor walk, bounded by the
innermost git toplevel, to disambiguate which store a session's note
belongs to -- structurally blind to a resumed session's hint at a sibling
directory, a nested repo/submodule one level in, and a non-git sibling the
walk never even entered for.

SessionStart now pins the resolved REMEMBER_DIR at a session-keyed pointer
outside every project store ($HOME/.remember/tmp/session-store/<session-id>),
written with a plain redirect and an atomic rename, overwritten on every
start including --resume. write-handoff.sh and doctor.sh read that pointer
first, through one shared resolver library (scripts/lib-session-store.sh)
that replaces each script's own pasted copy of the ancestor-walk logic. The
ancestor walk survives only as a fallback for a session that predates the
pointer, and now refuses outright when more than one candidate store
matches, rather than tie-breaking by mtime -- a same-second write defeated
that tie-break outright. The existing stale-hint reaper in
session-start-hook.sh is extended to sweep these pointers too.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…p, Windows test, plain-language changelog

1. The session-store pointer reaper swept by "no transcript under THIS
   project's SESSIONS_DIR", which is correct for the per-project reaper it
   was modelled on but wrong for a directory shared by every project: a
   live session started in a DIFFERENT project had no transcript under
   this one's folder at all, so its pointer was deleted the moment any
   other project's SessionStart happened to run. Sweeps by age alone now
   (REMEMBER_SESSION_STORE_POINTER_MAX_AGE_S, default 7 days).

2. A start that does not (re)write the pointer -- REMEMBER_DIR_UNSAFE, or
   the write itself failing -- used to leave an earlier start's pointer
   for the same session id in place, so write-handoff.sh still read a
   store this start never vouched for, bypassing #1064's own unsafe-store
   refusal. The pointer is now deleted whenever a start does not
   successfully republish it. Tested (resume onto an unsafe store).

3. The Windows-path shape test lived inside a module whose own
   module-level skipif(win32) pytest applies to every item regardless of
   a class's own docstring. Moved to its own file,
   tests/test_session_store_shape_windows_1083.py, with no skip, and
   triaged the parent module's remaining blanket skip in
   docs/windows-skip-triage.md (the CI check that enforces that list
   caught the omission).

4. The pointer reaper's foreground stat-per-foreign-pointer cost is moved
   to the same deferred/background phase this file already uses for other
   cleanup that nothing downstream of the current start reads back. The
   comment overclaiming "no new forks" is corrected.

5. changelog.d/1083.fixed.md rewritten for a non-technical reader.

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

First CI round on windows-latest showed the literal string "bash" there
resolving to the WSL launcher, which prints "Windows Subsystem for Linux
has no installed distributions" and exits nonzero -- exactly the hazard
tests/_bash_runner.py's own module docstring documents, and that several
other test files already route around via resolve_bash()/find_git_bash().
Switched to that helper, and moved the value under test onto stdin
(octal-escaped via bash_octal/printf '%b') rather than argv -- argv is not
trusted on Windows either, since Git Bash rebuilds it from the raw Windows
command line itself (run_bash_file's own docstring).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@fdaviddpt
fdaviddpt merged commit 0e6888f into main Nov 1, 2026
19 checks passed
@fdaviddpt
fdaviddpt deleted the fix/1083 branch November 1, 2026 17:15
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.

write-handoff.sh/remember still misroutes for nested repos and no-git siblings -- pin the store at SessionStart instead of guessing from cwd

1 participant