Skip to content

save-session.sh's housekeeping calls bare find with stderr discarded and no exit check -- the one command this repo documents by name as PATH-shadowed on Windows Git Bash #502

Closed

Description

@fdaviddpt

Found by the #487/#488 lane while diagnosing PR #499's Windows CI failure, after its first diagnosis (a test fixture handing bash a native backslash path) was fixed and the symptom survived. Filed by the maintainer. Pre-existing -- the affected sweep shipped long before #487.

This repo already knows

scripts/session-start-hook.sh:1156-1161 declines to use find for exactly this reason, in its own words:

# out to `find -mmin`: `find` is the one command on this path
# with a real PATH-shadowing risk on Windows Git Bash
# (System32's find.exe can resolve ahead of MinGW's find on
# some setups and silently answers a different question), so it
# would degrade "prune" into a silent always-keep with nothing
# surfaced.

That comment describes the defect this issue reports, at a different call site, written by whoever chose stat over find there.

The call site that did not get the memo

scripts/save-session.sh:1053:

    find "${REMEMBER_DIR}/logs/autonomous" -name "*.log" -empty -delete 2>/dev/null

Bare find, stderr discarded, exit code unchecked. C:\Windows\System32\find.exe takes none of -name, -mtime or -delete, has no delete capability at all, and would fail on those arguments -- into /dev/null, with nothing read. The sweep then silently does nothing, which is precisely the "silent always-keep with nothing surfaced" the sibling comment predicts.

PR #499 adds a second, age-keyed find beside it and inherits the same exposure.

The evidence that raised it

PR #499 converted two test files off the blanket win32 skip (#497) so they run under real Git Bash. On the Windows legs, with the fixture bug fixed and the hook demonstrably running -- its own fresh session-end-<HHMMSS>-<PID>.log appears in the listing -- a planted 8-day-old log still survives, and so does a 2-day-old one against a 1-day retention window:

[WindowsPath('.../session-end-000000-11111.log'), WindowsPath('.../session-end-224306-1497.log')]

Alternatives the lane ruled out before landing here:

Grade

Reasoned, not observed. Neither the lane nor I has a Windows machine; nobody has watched which find on that runner. It is the most specific mechanism consistent with the symptom, it matches a hazard this repository documented itself, and it is stated as reasoning rather than measurement.

The cheap way to settle it is one line on the Windows leg: type -a find and find --version from inside the hook's own bash, printed rather than swallowed. If it is MinGW's find, this issue is wrong and the real cause is still open.

What a fix has to do regardless of the cause

The sweep discards stderr and ignores the exit code, so any failure -- shadowed binary, bad path, permissions -- reads exactly like a sweep that found nothing to delete. That is true on every platform and it is what let this go unnoticed until a test was allowed to run on Windows. Whatever resolves the PATH question, the sweep should say when it fails.

Ranked

misreports. Housekeeping reports success by silence while doing nothing, and logs/autonomous/ grows unbounded on the affected platform -- compounding #487, which is the same directory growing unbounded everywhere else.

Platform

Windows, Git Bash. The save-session.sh:1053 call and the session-start-hook.sh:1156 comment are observed in the tree at 53bd09b (macOS/arm64, Darwin 24.3.0); the PATH-resolution mechanism is reasoned.

Activity

  1. fdaviddpt commented on Sep 1, 2026

    @fdaviddpt
    ContributorAuthor

    The v0.25.0 release audit (round 2) was asked to challenge this issue's mechanism and did. Recording it here in full, including the half I think misses, because a confident wrong explanation is worse than an open question.

    Where the challenge lands

    Two of its three points stand:

    1. The decisive experiment is the empty logs, not the seeded one. If find were shadowed by System32\find.exe, the sweep would be a total no-op, and abandoned empty logs would accumulate on that runner too. If empty logs are still being reclaimed on the Windows leg, find works and this issue is wrong. That is one directory listing and it settles the question -- better than the type -a find probe I suggested, because it tests the behaviour rather than the resolution.

    2. The observation was taken on PR #499's tree, not on the delta. Correct, and worth stating: the filenames carry a -<PID> suffix that neither v0.24.0 nor HEAD produces -- both spell it session-end-$(_remember_date +%H%M%S).log. The suffix is #499's own fix.

    Where I think it misses

    Its third point is that a seeded log surviving the sweep is exactly what #486 designed, reproduced on macOS where no System32\find.exe exists.

    That reproduction is of the -empty sweep, and the failing test does not target it. tests/test_autonomous_log_retention_487.py plants an 8-day-old non-empty log and expects PR #499's new age-keyed find -mtime sweep to reclaim it -- a sweep that deletes by age regardless of emptiness, and one that exists only on #499's branch. So "the seeded file is non-empty by construction" does not explain the failure: the test asserts against a sweep for which emptiness is not the predicate.

    The evidence-from-#499's-tree point above is the reason why, and it cuts the other way: the new sweep is only there.

    And the same test passes on macOS in that same tree -- the lane's local run was 1947 passed. So the divergence is genuinely platform-specific, which is what put find under suspicion.

    Where that leaves it

    The PATH-shadowing mechanism is still reasoned, not observed, and now contested on one of its supports. The empty-log listing above is the cheap discriminator and should be run before anyone works this.

    What is not contested, and is worth fixing whatever the cause: save-session.sh:1053 discards stderr and ignores the exit code, so a shadowed binary, a bad path and a genuinely empty directory are indistinguishable to every reader. session-start-hook.sh:1156-1161 declines to use find at a sibling call site for exactly this reason. See also #503, which is the same shape at a third site in session-end-hook.sh.

    None of this held the v0.25.0 tag -- the audit ranked it misreports-shaped either way, non-blocking, and the affected sweep is not in the released delta.

  2. added
    cohort-4
    on Sep 1, 2026
  3. self-assigned this
    on Sep 3, 2026
  4. added
    priority:medium
    on Sep 3, 2026
  5. added 3 commits that reference this issue on Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cohort-4priority:medium

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions