Skip to content

fix: ten stale "0600 per PID" comments/docstrings, made false by #429's mktemp switch (#437) - #455

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/437
Aug 29, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/437

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #437.

#429 replaced the merged config file's PID-suffixed literal path (remember-config-$$.json) with an unpredictable mktemp name to close a symlink-planting TOCTOU. That left several comments and one test docstring describing the file as 0600 per PID -- a filename the code no longer generates.

What the issue's own grep undercounted

#429's own grep (per PID) found five site groups (six lines): scripts/log.sh:78,392, tests/test_log_sh.py:874, README.md:276, scripts/post-tool-hook.sh:73,178. Grepping the concept instead -- mode, per-PID claim, EXIT trap, lib-memory-dir.sh's creation contract -- across the whole tree (excluding CHANGELOG.md, an assembled historical record left untouched) turned up ten stale sites, not five: the original six lines plus two comments in tests/test_session_end_hook_345.py that named the old literal path directly, and (found only during self-review, below) one comment in scripts/bootstrap-dirs.sh and one docstring in tests/test_trap_quoting_375.py.

The judgment call, and where it went wrong the first time

Not every per-PID/$$-shaped comment in the tree is stale -- several describe the fix itself (scripts/lib-memory-dir.sh's own #429 comment, scripts/lib-env-cache.sh, tests/test_case_divergence_298.py's _SANCTIONED_DIVERGENCE old-code snapshot) and are correctly left alone.

Self-review (an Explore reviewer and the oss:auditor, run independently against the first commit) both caught a real gap in my first pass: scripts/bootstrap-dirs.sh's own #362 relocation logic renames the mktemp file back to a PID-suffixed name ($REMEMBER_DIR/tmp/remember-config-$$.json) before scripts/log.sh and scripts/post-tool-hook.sh ever read it -- safe there because that directory is private rather than shared, so the TOCTOU concern doesn't reapply, but it means those two scripts' comments (and README.md's matching sentence), as I first wrote them, overclaimed "unpredictable mktemp name" for a file that is, by the time those scripts see it, PID-suffixed again. Confirmed empirically: sourcing detect-tools.sh -> bootstrap-dirs.sh -> log.sh end to end produced a final REMEMBER_CONFIG at .../tmp/remember-config-<pid>.json, not an XXXXXX-shaped name. Fixed in the second commit: those four sites (plus README.md) now say 0600, fresh every invocation -- true at both stages -- while sites describing lib-memory-dir.sh's own write specifically (tests/test_log_sh.py, the new test below) keep the more precise wording, since that part is accurate there.

The new assertion

tests/test_layered_config.py gained test_merged_config_is_0600_and_not_pid_named, which runs lib-memory-dir.sh via subprocess and pins both the file mode (0600) and the mktemp-shaped basename, with a paired negative control against the exact old remember-config-<digits>.json shape. Confirmed red against the pre-#429 code (scripts/lib-memory-dir.sh as of d2cf399^) and green against current code.

Docs

README.md (this lane's only docs_targets entry) updated -- one sentence corrected, matching #443's existing Codex-section content elsewhere in the file, which was not touched.

Tests

Full suite: 1828 passed, 43 skipped, 0 failed (pytest -q, ~8 minutes). Fragment checked with .oss/assemble_changelog.py --check: ok.

Review

Spawned an Explore reviewer and oss:auditor in parallel against the first commit; both returned real findings, both addressed in the second commit (see above). No findings judged below the bar.

fdaviddpt and others added 3 commits August 29, 2026 11:11
…made false (#437)

#429 replaced the merged config file's PID-suffixed literal path
(remember-config-$$.json) with an unpredictable mktemp name to close a
symlink-planting TOCTOU. That left "0600 per PID" describing a
filename the code no longer generates in scripts/log.sh (x2),
scripts/post-tool-hook.sh (x2), tests/test_log_sh.py, README.md, and
-- not counted by #429's own grep -- two sites in
tests/test_session_end_hook_345.py that named the old literal path
directly. All eight now describe the current mechanism: 0600, an
unpredictable mktemp name, one per invocation, under an EXIT trap.
CHANGELOG.md's own two matches are left alone as the historical
record of past releases.

tests/test_layered_config.py gains
test_merged_config_is_0600_and_not_pid_named, pinning both the mode
and the mktemp-shaped basename so a regression to either the old
literal path or a permissive mode fails a test rather than only
reading stale in a comment. Confirmed red against the pre-#429
shape (scripts/lib-memory-dir.sh as of d2cf399^) and green against
current code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ng "unpredictable" for the relocated path

Both spawned reviewers (Explore and oss:auditor) independently found the
same gap: `bootstrap-dirs.sh`'s own #362 relocation renames the merged
config's mktemp file back to a PID-suffixed name under `REMEMBER_DIR/tmp`
before `log.sh` and `post-tool-hook.sh` ever read it -- private
directory, so no TOCTOU risk, but it meant "unpredictable mktemp name"
in those two scripts' own comments (and the matching README.md sentence)
overclaimed what the file they actually operate on looks like. Both now
say "0600, fresh every invocation" instead, which holds at both stages.
Sites that describe lib-memory-dir.sh's own write specifically --
tests/test_log_sh.py, tests/test_layered_config.py's new assertion --
keep the more precise "unpredictable mktemp name" wording, since that
part is accurate there.

Confirmed empirically (not just read): sourcing detect-tools.sh ->
bootstrap-dirs.sh -> log.sh end to end in a scratch project produces a
final REMEMBER_CONFIG at $REMEMBER_DIR/tmp/remember-config-<pid>.json,
not an XXXXXX-shaped mktemp name.

Also swept two sites the concept-grep missed the first time:
scripts/bootstrap-dirs.sh's own #362-relocation comment named the old
$SYS_TMPDIR/remember-config-$$.json path as lib-memory-dir.sh's current
output, and tests/test_trap_quoting_375.py's docstring made the same
claim about lib-memory-dir.sh's own trap target.

tests/test_session_end_hook_345.py's two comments now describe the full
two-stage path (mktemp write, then bootstrap-dirs.sh relocation) rather
than stopping at the first stage, since session-end-hook.sh's own
sourcing order (bootstrap-dirs.sh before log.sh) means the relocated
path is what env["REMEMBER_CONFIG"] actually is by the time these tests
run.

Full suite: 1828 passed, 43 skipped, 0 failed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ing test_umask.py

CI's ubuntu-latest/3.12 leg went red on the new test from #437:
REMEMBER_CONFIG_MODE came back holding GNU stat's "File: ..." block
instead of an octal mode. The probe tried `stat -f '%Lp' ... || stat -c
'%a' ...` -- BSD-first. On Linux, `stat -f` means "filesystem status",
not "format": it exits 0 and prints the wrong thing, so `||` never
reaches the GNU branch that would have worked. Green locally (macOS,
where `stat -c` is the option that fails) said nothing about this.

tests/test_umask.py already solved this exact problem, twice, including
for this exact file (TestMergedConfigPermissions pins REMEMBER_CONFIG's
mode too): `stat -c '%a' ... 2>/dev/null || stat -f '%Lp' ...`, GNU
first. Matched that idiom instead of inventing a third spelling.

Re-confirmed red/green the same way as the first time: checked out
scripts/lib-memory-dir.sh as of d2cf399^ (pre-#429) into the worktree,
ran the new test -- AssertionError: remember-config-23537.json against
the basename regex, same failure shape as before, mode assertion
untouched since 0600 predates #429 too -- then restored the current
file (git diff clean) and reran: 1 passed. Full suite: 1828 passed, 43
skipped, 0 failed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@fdaviddpt
fdaviddpt merged commit 7e86245 into main Aug 29, 2026
13 checks passed
@fdaviddpt
fdaviddpt deleted the fix/437 branch August 29, 2026 10:44
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.

Five sites still describe the merged config as "0600 per PID", which #429 stopped being true

1 participant