fix(shell): make mktemp templates work on BSD mktemp (macOS)#30
Closed
josemoreno801-netizen wants to merge 1 commit intoDigital-Process-Tools:mainfrom
Closed
Conversation
BSD mktemp (shipped on macOS) requires XXXXXX to be at the very end of the template — any trailing characters (`.txt`, `.json`, `.md`) are not treated as a suffix. The call either fails with `mkstemp: File exists` once the literal path has been materialized once, or returns the literal unrandomized path, defeating mktemp's purpose. GNU mktemp accepts the suffix, which is why this has been dormant in upstream on Linux CI and only surfaces on macOS when `save-session.sh --force` bypasses the min-messages threshold. Drop the trailing extensions from all 10 mktemp call sites: - scripts/save-session.sh (5): TMP_LAST_ENTRY, TMP_PROMPT, HAIKU_STDERR, NDC_PROMPT, NDC_ERR - scripts/run-tests.sh (5): TMP_POS, TMP_EXTRACT_F, TMP_LAST_F, TMP_PROMPT_F, TMP_MEM, TMP_NDC The files are only read back through the variable, so the lost extension has no functional impact. Verified end-to-end on macOS: `bash scripts/save-session.sh --force` now succeeds; pytest still 199/199 @ 99% coverage. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2 tasks
fdaviddpt
pushed a commit
that referenced
this pull request
Apr 25, 2026
BSD mktemp (macOS) treats characters after XXXXXX as literal — it creates a file named exactly 'foo-XXXXXX.txt' with no randomization. The first call succeeds silently, the second fails with 'File exists'. This is both a collision bug and a security issue (predictable names). Remove .txt/.json/.md extensions from all 11 mktemp calls in save-session.sh (5) and run-tests.sh (6). Added tests: BSD mktemp reproduction, guard against future extensions in scripts. Inspired by josemoreno801-netizen's PR #30. Closes #30 scope. Co-Authored-By: Max <noreply>
Contributor
|
This was addressed in #33 commit 4 which takes the same approach (removing extensions after XXXXXX) plus adds a guard test to prevent future regressions. Thank you @josemoreno801-netizen for the sharp macOS debugging! The BSD mktemp behavior is particularly insidious — it silently creates a non-random filename on the first call, then fails on the second. Your clear symptom description ('mkstemp: File exists') made reproduction straightforward. You've also got PRs #25 and #26 still open — we'll review those next. Thanks for the sustained contributions to the project! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
On macOS,
bash scripts/save-session.sh --forcefails immediately with:…aborting the entire save pipeline. Same failure mode in
scripts/run-tests.shsection 5.Root cause
GNU
mktemp(Linux) tolerates characters after theXXXXXXsuffix and silently treats them as a literal suffix on the generated name. BSDmktemp(macOS default) does not —man mktempsays:Templates like
mktemp /tmp/remember-prompt-XXXXXX.txtare therefore invalid on BSD;mktemperrors out withmkstemp: File exists.Fix
11 templates across two scripts had characters after
XXXXXX:scripts/save-session.sh— 5 sites (TMP_LAST_ENTRY,TMP_PROMPT,HAIKU_STDERR,NDC_PROMPT,NDC_ERR)scripts/run-tests.sh— 6 sites (TMP_POS,TMP_EXTRACT_F,TMP_LAST_F,TMP_PROMPT_F,TMP_MEM,TMP_NDC)All
XXXXXX.{txt,json,md}→XXXXXX. The temp files are short-lived (cleaned up viatrap) and never opened by extension-sensitive tools, so dropping the suffix has no functional impact on Linux; it makes the templates valid on BSD.Verification
bash scripts/save-session.sh --forcenow completes the save pipeline end-to-end.bash scripts/run-tests.shno longer fails section 5 sub-tests onmktemp.Conflict note for maintainer
PR #29 (Windows session-dir slug + Python detection) also modifies
scripts/save-session.shandscripts/run-tests.sh. The two PRs touch overlappingmktemplines but with different intent. Suggested merge order:main(mktemp lines now end atXXXXXX); the rebase should be mechanical.Happy to rebase if a different order is preferred.