Repository navigation
Merged
Conversation
…de across concurrent SessionEnd hooks (#487, #488) #483 seeded $_END_LOG with a header before its subshell opens it, which fixed that bug but left session-end-*.log outside save-session.sh's only retention (`find ... -empty -delete`) forever -- one file per session, never reclaimed. Add a second, age-keyed sweep (thresholds.autonomous_log_retention_days, default 7) over both logs/autonomous file classes, independent of emptiness. session-end-hook.sh named that same log from a second-granularity timestamp alone, so two SessionEnd hooks for the same project ending in the same wall-clock second resolved to one path and interleaved their output. Suffix the filename with the hook's own PID (session-end-<HHMMSS>-<PID>.log); scripts/doctor.sh's session-end-*.log glob (#370's SessionEnd-liveness check) needed no change, pinned by a new regression test against its own fixture. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…d_370.py docstrings Self-review of a9855f5 by a spawned reviewer: the module docstring and test_marker_present_reports_ok_and_never_a_session_end_problem's own docstring still described logs/autonomous/session-end-<HHMMSS>.log (no PID) after the file's own new test (test_marker_with_pid_suffix_still_reports_ok) had already documented the post-#488 shape correctly. No assertions referenced the stale string, so nothing was mis-pinned -- prose only. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…497) #497 measured that 92 of 101 module-level pytestmark skips in this repo key on sys.platform == "win32" rather than tests/_bash_runner.py's resolve_bash() (PR #432's Git-Bash-discovery route, meant to retire exactly that pattern) -- windows-latest runs 40% of the suite and reports success either way. tests/test_autonomous_log_retention_487.py and tests/test_session_end_log_names_488.py, added an hour before #497 was filed, were two more instances of the same copy. Converted both to resolve_bash(), following tests/test_hook_cwd_leak_417.py and tests/test_transcript_path_leak_424.py. Neither reference file needed to reap a backgrounded subshell; these two do (session-end-hook.sh backgrounds save-session.sh and returns immediately), and the shared _reap() they previously imported from test_session_end_hook_345.py uses `os.kill(pid, 0)` -- a POSIX liveness idiom that Windows maps to GenerateConsoleCtrlEvent(0, pid), a different operation, and one _reap() has itself never run under because test_session_end_hook_345.py still carries the blanket skip. Rather than extend an untested-on-Windows POSIX assumption to a new platform surface, both files define a local, portable liveness probe (os.kill on POSIX, tasklist on Windows) and their own _run_hook using the resolved bash instead of a bare "bash" (which can silently resolve to the WSL launcher rather than Git Bash on a Windows PATH). test_session_end_hook_345.py's own blanket skip, and the other 90 module skips #497 counts, are unconverted and out of scope here. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… the hook never ran on windows-latest (job 100051322749) PR #499's windows-latest/3.11 leg: 4 failed, all in the two files this lane converted onto resolve_bash() last round -- two distinct-looking symptoms (an aged log surviving the sweep; the autonomous directory missing entirely) that share one cause. Both files' local `_run_hook` invoked bash with `str(hook)` -- a plain str() of a pathlib.Path, which on Windows is backslash-separated. That string becomes `$0`/`BASH_SOURCE[0]` inside session-end-hook.sh, which derives its own script directory with `_HOOK_DIR="${BASH_SOURCE[0]%/*}"` -- a bash parameter expansion that only recognises the ASCII '/' as a separator, documented on that exact line as sharing `dirname`'s own no-slash fallback. A purely-backslash path leaves nothing to strip, so `_HOOK_DIR` becomes ".", every subsequent `source "$_HOOK_DIR/whatever.sh"` resolves against the bash process's own working directory (pytest's, not the scripts directory), `resolve-paths.sh` is not found there, and `REMEMBER_PATHS_SOFT_FAIL=1 source ... || exit 0` exits the ENTIRE hook immediately -- before mkdir, before the flush, before the sweep the first symptom blamed and before the directory the second symptom blamed. Confirmed mechanically with real bash (both `${VAR%/*}` and `dirname` return "." for a fabricated backslash-only path, and sourcing a fabricated resolve-paths.sh from a foreign CWD reproduces the exact "No such file or directory" -> `|| exit 0` chain) -- not observed on Windows directly, since none is available here, but this is the same bash whose parameter-expansion semantics do not vary by OS. This is a TEST FIXTURE bug, not a production one: save-session.sh's retention sweep was never reached to be exercised at all. tests/test_hooks_json.py already works around the identical issue for session-start-hook.sh by forward-slashing every path handed to Git Bash; both converted files now do the same via a local `_posix_path` helper, applied to the invoked script path and to CLAUDE_PLUGIN_ROOT/CLAUDE_PROJECT_DIR/HOME. Also fixed while in the same function: test_session_end_log_names_488.py's own `_freeze_hhmmss` joined its PATH shim with a hardcoded ":" ahead of an env["PATH"] that is semicolon-separated on Windows -- os.pathsep instead, so the join stays valid for whichever separator that platform's PATH actually uses before Git Bash performs its own MSYS conversion at startup. Reasoned, not observed (no Windows leg to run this fix against directly): the CI re-run is the actual verification. No production files changed. Re-ran locally (macOS, real bash -- _posix_path is a no-op there): the four named test files, 19 passed in 8.38s, unchanged from before this fix. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…-latest (job 100054224050) PR #499's three Windows legs (3.10/3.11/3.12): the two BASH_SOURCE path fixes from the last round worked -- the hook now runs for real, and tests/test_session_end_log_names_488.py's own assertions prove it: the produced session-end-<HHMMSS>-<PID>.log files are correctly PID-suffixed, #488's actual fix. But the frozen clock never took -- the files carry the real wall-clock HHMMSS (e.g. session-end-224452-116.log), not the frozen "123456"/"000000" _freeze_hhmmss's shim asks for. Python's own os.chmod on native Windows only ever toggles the read-only attribute (there is no POSIX execute bit on that platform for it to set), so a `date` shim built by Path.write_text()+Path.chmod(0o755) from a native Windows Python process may carry none of whatever Git Bash / MSYS2 checks for when resolving an extensionless PATH entry. Two changes: - _freeze_hhmmss now ALSO asks bash itself (already resolved as BASH, real Git Bash on Windows) to chmod the shim, going through MSYS2's own permission layer instead of Windows Python's -- best-effort, no assertion on the result. - A new _assert_shim_took_or_skip, called right after each hook run and before any assertion that depends on the frozen value: if the frozen HHMMSS does not appear in any produced filename, it skips THAT specific test with a stated reason rather than asserting a false failure against #488's own fix, which the same run's own output already proves works. Reasoned, not observed -- no Windows machine available here to confirm either the bash-chmod attempt or, if it still does not work, that the skip path fires cleanly; the CI re-run is the actual verification. Locally (macOS, real bash -- neither change alters behaviour there): the four named test files, 19 passed, unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Sep 1, 2026
…ites, NDC/retention coupling (#487, #498, #502, #503) test_must_fire_an_old_nonempty_session_end_log_is_swept was red on all four windows-latest legs while its own positive controls in the same fixture (test_must_fire_a_fresh_nonempty_log_survives_the_same_sweep, test_must_fire_retention_window_is_configurable) passed -- disproving #502's original find-shadowing theory (a fully shadowed find would have failed the config-override case identically). Replaced both `find -empty -delete` / `find -mtime "+N" -delete` sweeps in save-session.sh with a portable stat-based loop (GNU-first-then-BSD-fallback, the same pattern session-start-hook.sh already uses for its own -mmin sweep and documents as the fix for find's real PATH-shadowing risk on Windows Git Bash), which removes both the shadowing exposure #502 raised and find's own platform-specific -mtime day-rounding as places for a silent Windows-only off-by-one to hide. #502: both sweeps discarded find's exit status via bare 2>/dev/null, making a failing find indistinguishable from "nothing to delete." The new loop checks every stat read and every removal and reports a WARNING through the same log() path save-session.sh:428 already uses for its own fall-throughs, rather than swallowing failure into silent success. #498: the housekeeping lived inside `if [ "$RUN_NDC" = true ]; then ... fi` by accident of placement, so features.ndc_compression=false silently disabled ALL logs/autonomous/ retention too, with autonomous_log_retention_days configured and doing nothing. Moved the sweep outside that block so it runs on every ordinary flush regardless of NDC compression -- the "move sweeps outside the RUN_NDC block" option from the issue, chosen because giving housekeeping its own cooldown marker would have added a second timer for behaviour that should simply always run, and documenting the coupling as intentional was not an honest description of what an operator setting that flag actually wants. #503: session-end-hook.sh's mkdir -p for logs/autonomous/ and the printf that seeds its own flush log were both unchecked (2>/dev/null, no exit check). A failed write left the log absent or empty exactly as if it had never opened, reclaimed by the next flush's own -empty sweep and silently reintroducing #483's original bug -- with doctor.sh's SessionEnd-liveness check then misdirecting an operator toward a hook-registration problem that does not exist. Both writes now check status and report a WARNING. Every fix has a test that is red against the pre-fix code and green after (confirmed locally via `git stash` on the touched file, not merely asserted) -- test_must_fire_reclaim_survives_ndc_compression_disabled for #498, test_must_fire_seed_write_failure_is_reported (with a must-not-fire positive control) for #503. The Windows-specific root cause of the original CI failure and the effect of the stat-based rewrite are REASONED, not OBSERVED: there is no Windows box in this environment to confirm against, and the fix follows an already-proven pattern in this same codebase for the identical PATH-shadowing concern rather than a guess. README's config table and three changelog.d fragments (#498, #502, #503) document all three; #487/#488's own fragments already cover the original defects. Lands on the existing fix/487 branch, updating the still-open PR #499 rather than opening a new one. Co-Authored-By: Max <noreply>
…NDC prose (self-review) Self-review (Explore + oss:auditor, spawned against the prior commit) raised four findings: - oss:auditor: the new #503 test class landed in tests/test_session_end_hook_345.py, whose module-level pytestmark is still the blanket `sys.platform == "win32"` skip #497 narrowed everywhere else in this suite -- so on the four windows-latest legs, exactly the platform this whole PR's own root-cause narrative is about, the #503 test reports `skipped`, which renders identically green to "ran and passed." Relocated it into tests/test_autonomous_log_retention_487.py, which already carries the narrowed `BASH is None` skip and the Windows-safe `_run_hook`/ `_posix_path` harness #497 built for this exact reason. Re-confirmed red-before-fix / green-after by swapping in the pre-#503 session-end-hook.sh via `git show <parent>:...` and back. - Explore: three stale-prose findings, all now inaccurate about a mechanism this same diff replaced -- session-end-hook.sh's own comment still named `find ... -empty -delete` and "NDC step" after the sweep moved out of NDC and off find entirely; changelog.d/483.fixed.md and changelog.d/487.fixed.md (still-pending fragments landing in the same release batch as 498/502/503's) described the pre-rewrite mechanism as current; README's own retention row kept "unchanged" describing a now-merged single-pass sweep. Fixed all four in place, pointing the older fragments at the current ones rather than restating the mechanism twice. Not fixed, reported for filing: Explore also flagged that moving the sweep outside RUN_NDC drops its previous ~hourly NDC-cooldown throttle down to the ~2-minute save cooldown, a real but unmeasured frequency increase (and, on a persistently blocked directory, unthrottled WARNING spam) that needs its own design decision rather than a rider on this fix. Co-Authored-By: Max <noreply>
# Conflicts: # changelog.d/483.fixed.md
…glob (#487, #488, #498, #502, #503) PR #499's windows-latest legs (jobs 100831279309/100831279212/100831279264/ 100831279230) left every backdated logs/autonomous/*.log in place, at every retention setting, with NDC compression on or off -- the retention sweep's own glob matched nothing at all on that platform. resolve-paths.sh's _remember_normalize_win_path (#263/#448) rewrites CLAUDE_PROJECT_DIR to a fully backslash-separated Windows-native form on msys/cygwin, and REMEMBER_DIR inherits that shape end to end (lib-memory-dir.sh's legacy "${proj}/${data_dir}"). Every ordinary file op downstream (mkdir -p, >>, stat, rm -f) still works with that string on Windows, because the MSYS runtime translates it. bash's own glob does not: it recognises only '/' as a path-component boundary on every platform, including Windows Git Bash, so a directory argument with no real '/' in it can never match a real subtree -- the loop never touched a single file. Forward-slashes only the directory argument fed to the glob (REMEMBER_DIR itself is untouched, so nothing else that depends on its Windows-native form is affected); a no-op on POSIX, where it never contains a backslash to begin with. tests/test_autonomous_log_retention_487.py pins the mechanism directly and portably: the real housekeeping block is extracted verbatim from save-session.sh (never retyped) and run against a synthetic backslash-laden REMEMBER_DIR string, since a genuinely Windows-native REMEMBER_DIR cannot be constructed on POSIX at all (POSIX open()/mkdir treat backslash as an ordinary filename character, not a separator, so the two platforms would stop disagreeing and the bug would not reproduce end to end). Confirmed red against the pre-fix script (extraction itself fails -- the marker this test looks for does not exist yet) and green after. Two adjacent, pre-existing instances of the identical class -- a bash-glob directory argument built from REMEMBER_DIR, with an unquoted trailing `*` that bash itself must expand -- are reported to the maintainer for filing rather than fixed here (different subsystem, outside this issue's own footprint): run-consolidation.sh:103 and session-start-hook.sh:1395. Co-Authored-By: Max <noreply>
…uoting (self-review) Two findings from the Explore self-review pass against 5aeb536: 1. `_remember_auto_dir="${REMEMBER_DIR//\\//}"` was applied unconditionally. Backslash is an ordinary, legal filename character on POSIX, and `_remember_normalize_win_path` (resolve-paths.sh) -- the function that actually puts backslashes into REMEMBER_DIR in the first place -- is itself gated to msys/cygwin only. An unconditional normalization would silently mangle a real POSIX project directory whose name happens to contain a literal backslash into a different, generally nonexistent path. Gated the fix the same way, on `case "$OSTYPE" in msys|cygwin)`. 2. The new test's `_run_extracted_block` embedded `remember_dir` via an f-string `!r}`, which is Python-repr escaping: a string containing backslashes has each one doubled in its printed form, and bash's own single-quoted strings do no backslash processing at all, so the test was actually feeding the extracted block a double-backslash-separated path rather than the genuine single-backslash Windows-native shape #448 produces. Switched to `shlex.quote`, which preserves the string byte for byte inside bash single quotes. Both fixes needed a corresponding test update: `_run_extracted_block` now takes an `ostype` kwarg so the backslash-separated test can set `OSTYPE=msys` (matching the fix's own gate), and a new test (`test_must_not_fire_control_a_posix_backslash_named_dir_is_left_untouched`) pins the gate itself -- a backslash-laden REMEMBER_DIR that WOULD resolve to the real fixture directory if normalized must be left alone (and therefore leave the stale file in place) whenever $OSTYPE is not msys/cygwin. Re-verified: 9/9 tests in tests/test_autonomous_log_retention_487.py green. Co-Authored-By: Max <noreply>
… sweep Local forced-OSTYPE=msys harness passes 9/9 but real windows-latest CI is still red after the prior round's fix landed. Add temporary DEBUG printf lines to scripts/save-session.sh's housekeeping block (OSTYPE, REMEMBER_DIR, the normalized glob directory, and the glob's own expansion) so the next CI run reveals what these actually are on a real runner, rather than iterating on hypotheses. To be removed once the real mechanism is understood. Co-Authored-By: Max <noreply>
The DEBUG printf lines added in 56c599e landed in the run's own session-end-*.log file on real CI (the flush runs backgrounded, so its stderr never reaches this subprocess's own captured output) -- the previous CI run's job log carried zero DEBUG lines because nothing ever read that file back. Add _dump_dir() and use it in place of the bare filename listing so the next CI run's assertion failure text carries every autonomous/ file's own content, DEBUG lines included. Co-Authored-By: Max <noreply>
CI round 2 (job 100882326987): the fresh session-end-*.log had only its own seeded header line, none of the DEBUG stderr lines added at the housekeeping block -- save-session.sh is not reaching that code at all on real Windows. save-session.sh's own log() writes to logs/memory-YYYY-MM-DD.log, not stdout/stderr, and its `trap ... ERR` reports an early failure the same way -- neither was visible before. _dump_dir now also dumps logs/ itself so the next CI run's failure text shows where execution actually stopped. Co-Authored-By: Max <noreply>
…irect
CI round 3 (job 100883634009): logs/memory-*.log carries only
session-end-hook.sh's OWN "[hook] session-end: reason=..." line --
save-session.sh never wrote its own first log() call ("save-session:
PROJECT_DIR=..."), and hook-errors.log is empty too (no ERR-trap
report, no non-zero $_flush_status report). Either save-session.sh
never runs on real Windows, or it fails so early -- before log.sh is
even sourced -- that its own ERR trap cannot call log() to report it,
and stderr from _resolve_paths_fail somehow never reaches $_END_LOG.
Add explicit debug writes with their OWN redirect
(tmp/debug-487.log), independent of the `( ... ) >> "$_END_LOG" 2>&1 &`
grouping, so a problem with that grouping itself cannot also hide
these. _dump_dir now surfaces that file too.
Co-Authored-By: Max <noreply>
…ompletion CI round 3 (job 100884873570) confirmed the subshell DOES start (tmp/debug-487.log shows "subshell started") and $OSTYPE is "cygwin" on this real runner -- but the "exited status=" line that prints right after `bash "$SAVE_SCRIPT" --force` returns never showed up within the existing 30s _pid_alive wait, and the retention sweep had not run yet by the time the test asserted. Two candidate explanations, not yet distinguished: cygwin's own PIDs may not correspond to the native Windows PIDs `tasklist` queries (so _pid_alive already reports "not alive" long before the real process actually finishes), or the real flush genuinely takes longer than 30s under Windows subprocess-spawn overhead (save-session.sh forks many child processes per run). Either way, trusting process liveness at all is the weak link -- poll for the debug marker itself (unambiguous evidence the flush actually returned), independent of _pid_alive, up to 90s more. Co-Authored-By: Max <noreply>
CI round 4 (job 100887017483 and siblings) confirmed the 3 "must fire" end-to-end retention tests now PASS on real Windows once the test harness waits on an unambiguous completion signal instead of PID liveness -- the backslash-glob normalization landed in the prior round was already correct. Root cause: on a real windows-latest runner, $OSTYPE reports "cygwin", and the test harness's own `_pid_alive` (tasklist-based) reports the backgrounded flush as "not alive" almost immediately, long before the real flush actually finishes -- so assertions ran against a still-in-flight flush, not a broken sweep. - scripts/save-session.sh: revert the temporary DEBUG printf lines from the earlier diagnostic round -- no longer needed, the mechanism is understood and the housekeeping block itself was never the problem. - scripts/session-end-hook.sh: replace the ad-hoc debug-487.log writes with a permanent, opt-in REMEMBER_TEST_COMPLETION_MARKER -- unset in every real session (zero cost), and when a test sets it, the hook appends an unambiguous "flush exited status=N" line once `bash "$SAVE_SCRIPT"` actually returns, independent of any PID or process-table lookup. - tests/test_autonomous_log_retention_487.py: `_run_hook` now sets REMEMBER_TEST_COMPLETION_MARKER and polls it (30s budget) instead of trusting `_pid_alive` alone; `_pid_alive` is kept as a fast first pass. Also fixes a second, independent test bug the CI evidence surfaced: the OSTYPE-gate negative control left $OSTYPE at "whatever this test's own platform reports", which is msys/cygwin BY DEFAULT on real Windows (bash's own compiled default, not something "unset" escapes) -- forces `ostype="linux-gnu"` explicitly so the control actually exercises "not Windows Git Bash" on every platform, including the one it exists to guard. 9/9 local (forced-harness + real end-to-end via _run_hook), 92s -> 33s after tightening the completion-marker wait window from 90s to 30s (TestSeedWriteFailureIsReported's own positive fixture makes the flush unable to start at all, so it always pays the full window; kept that cost bounded rather than eliminating the wait). Co-Authored-By: Max <noreply>
…ed block
CI round 5 (job 100892436094, and the same failure on the other 3
windows-latest legs): with the completion-marker wait landed, all 4
previously-flaky "must fire" real end-to-end tests now pass -- only
the OSTYPE-gate negative control still failed, and NOT for the reason
its own prior fix assumed. Forcing `env["OSTYPE"] = "linux-gnu"` for
the subprocess has no effect at all on a real windows-latest runner:
Git Bash there resets $OSTYPE to its own compiled default ("cygwin")
regardless of what the parent environment carries, so the block
normalized the backslash-laden REMEMBER_DIR exactly as it would with
$OSTYPE genuinely unset -- the control was still testing "OSTYPE=cygwin"
in disguise, on the one platform it exists to guard against.
`local OSTYPE=...` inside a wrapping function is a shell-scoping
mechanism, not an environment-inheritance one, and is not subject to
whatever makes Git Bash reassert its own OSTYPE from the process
environment (readonly -p confirms OSTYPE is not a bash-readonly
special to begin with). _run_extracted_block now shadows $OSTYPE this
way instead of through the subprocess env.
9/9 local (33s, same as the prior round -- TestSeedWriteFailureIsReported
still pays its own 30s window for the reason documented there).
Co-Authored-By: Max <noreply>
…able there CI round 6 (job 100895310415 and siblings): the `local OSTYPE=...` shadow from the prior round did not fix the control either -- same failure, same message. Two independent override mechanisms (an env var, and now a `local` shadow inside a wrapping function) both left the extracted block reading the real windows-latest runner's actual $OSTYPE (cygwin) instead of the forced value. That is consistent with Git Bash on Windows treating $OSTYPE as effectively immutable at runtime, regardless of how a caller tries to set it -- this test's own premise (exercise the housekeeping block with $OSTYPE genuinely NOT saying Windows Git Bash) cannot be constructed while actually running under Windows Git Bash. Skip it there, loudly, with the CI evidence recorded in the reason string, rather than leave it passing vacuously against a value it never actually forced. The fix's own OSTYPE gate is still exercised for real by the msys- and forward-slash-REMEMBER_DIR cases in the same class, which assert the POSITIVE direction and do not depend on overriding OSTYPE away from its real value. 9/9 local (1 now skipped on... nothing, locally -- the skip is win32 only, so this stays 9 ran/9 passed on macOS/Linux; real Windows CI will show 8 passed, 1 skipped). Co-Authored-By: Max <noreply>
…ut/write paths Explore's self-review of the CI-iteration diff (4034cbe..dc8bf6c) found 3 real, low/medium findings; oss:auditor found none. All three fixed here rather than filed -- same subsystem, one function each, mechanism understood: 1. tests/test_autonomous_log_retention_487.py: _run_hook's marker-wait loop could silently degrade to an unmonitored 30s sleep with no signal distinguishing "marker observed" from "deadline expired". Now tracks whether the marker was actually seen and prints a note to stderr when it was not (never a hard assertion -- TestSeedWriteFailureIsReported's own positive fixture is the one case where the marker legitimately never appears, by design). 2. Same file: _dump_dir's own docstring names the completion-marker wait as its reason for existing, but never actually dumped completion-marker.log itself -- the one file that would show whether a future failure here is a timing issue or a real regression. Now included. 3. scripts/session-end-hook.sh: the two REMEMBER_TEST_COMPLETION_MARKER writes were unguarded, unlike the neighboring $_END_LOG seed write they were modeled on. Left unguarded deliberately rather than routed through report_error() -- that writes to hook-errors.log, a file TestSeedWriteFailureIsReported's own tests assert the contents of, and this block is test-only opt-in scaffolding that must never add a line there. Documented instead: a failed marker write already surfaces via bash's own redirection-failure message to this block's enclosing stderr (result.stderr for the first write, $_END_LOG -- now dumped per finding 2 -- for the second). 18/18 local (this file + test_session_end_hook_345.py + test_session_end_log_swept_483.py), bash -n clean, changelog fragments unchanged and still check clean (6 fragments, this round touched no shipped behavior). Co-Authored-By: Max <noreply>
Co-Authored-By: Max <noreply>
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.
Summary
PR #499 (fix/487) was RED on all 4 windows-latest CI legs. The failing test asserted that an 8-day-old, non-empty
session-end-*.loginlogs/autonomous/gets reclaimed bysave-session.sh's own housekeeping -- it did not, on Windows only. This PR fixes that plus three issues already assigned to this lane in the same area: #498, #502, #503.Investigation
The originally-filed theory (#502) was that
findis fully PATH-shadowed on Windows Git Bash by Windows' own System32 find.exe. That theory is disproven by the job log itself: the SAME fixture's own positive controls -- a fresh log surviving the sweep, and a shorter explicit retention window correctly reclaiming a 2-day-old log -- ran the identicalfind -mtime "+N" -deleteline on the identical Windows legs and PASSED. A fully shadowedfindcould not pass one invocation of that line and fail another. I could not pin down the exact Windows-only mechanism with certainty (no Windows box available in this environment); the full trail of what was ruled out is in the branch note.Fix
findwith stderr discarded and no exit check -- the one command this repo documents by name as PATH-shadowed on Windows Git Bash #502: replaced bothfind -empty -deleteandfind -mtime "+N" -deleteinsave-session.sh's housekeeping with a portablestat-based loop (GNU-then-BSD fallback), the same patternsession-start-hook.shalready uses and documents for its own-mminsweep, citingfind's real PATH-shadowing risk on Windows Git Bash. Removes both the shadowing exposure andfind's own platform-specific-mtimeday-rounding as places for a silent off-by-one to hide. Every read/removal is now checked and a failure logs a WARNING (previously2>/dev/nullwith no exit check, so a failingfindwas indistinguishable from "nothing to delete").if [ "$RUN_NDC" = true ]; then ... fi, sofeatures.ndc_compression=falsesilently disabled log retention too. Moved outside that block to run unconditionally on every ordinary flush.session-end-hook.sh'smkdir -pforlogs/autonomous/and theprintfseeding its own flush-log header were both unchecked. A failed write silently reintroduced save-session.sh deletes the session-end log the running flush is writing into, so the failure WARNING names a path that does not exist #483's original bug (no on-disk trace SessionEnd ever fired) withdoctor.shmisdirecting an operator toward a non-existent hook-registration problem. Both writes now check status and report a WARNING.This PR's own root-cause claim, graded
REASONED, not OBSERVED: there is no Windows box available in this environment to confirm the fix clears the four red legs. The fix removes
find's exposure entirely (both the documented shadowing risk and its own day-rounding arithmetic) rather than confirming the exact original defect. If CI is still red after this, the defect is something this reasoning missed and needs someone who can run Git Bash on Windows directly.Self-review
Spawned
Explore+oss:auditoragainst the first commit.oss:auditorfound the new #503 test had landed under a file whose module-levelpytestmarkstill blanket-skipssys.platform == "win32"-- exactly the platform this whole PR is about -- so it would have reportedskipped, rendering as green coverage that did not exist. Relocated it to reuse the already Windows-safe harness intest_autonomous_log_retention_487.py.Explorefound three stale-prose spots (a comment, two pending changelog fragments, one README clause) still describing the pre-rewritefind/NDC-gated mechanism after this diff replaced it -- fixed all three. One further finding -- moving the sweep outsideRUN_NDCalso drops its previous ~hourly NDC-cooldown throttle to the tighter ~2-minute save cooldown, a real but unmeasured frequency increase, and unthrottled WARNING repetition on a persistently-blocked directory -- is reported below rather than fixed, since it needs its own design decision.Below-bar / report-for-filing
RUN_NDC(Log retention for logs/autonomous/ lives inside save-session.sh's RUN_NDC block, so features.ndc_compression=false disables housekeeping that has nothing to do with compression #498) trades its previous ~hourlycooldowns.ndc_secondsthrottle for the tighter ~2-minutecooldowns.save_secondsone -- roughly a 30x increase in how oftenlogs/autonomous/is globbed andstat'd per flush, and, on a persistently blocked/unwritable directory, the new WARNING log line now repeats on every flush instead of at most once an hour. Not a correctness bug, but a real, unmeasured operational cost (log noise, filesystem chatter) that deserves its own decision (a debounce on the WARNING, or an early-exit when the directory is empty) rather than a rider on this fix.Test plan
tests/test_autonomous_log_retention_487.py-- red before the fix (confirmed viagit stash/git show <parent>:...on just the touched script), green after, for all four sub-cases: the original After #483's fix, logs/autonomous/session-end-*.log is never reclaimed: the -empty sweep was that directory's only retention #487 age sweep, the NDC-disabled case (Log retention for logs/autonomous/ lives inside save-session.sh's RUN_NDC block, so features.ndc_compression=false disables housekeeping that has nothing to do with compression #498), and the seed-write-failure case (#486's own fix is an unchecked write: if the seed fails, doctor.sh reports the hook as never having fired #503, now living here rather than under the win32-skipped file).tests/test_session_end_hook_345.py-- unchanged behavior confirmed still green.save-session.sh/session-end-hook.sh(815 tests) pass locally (macOS).python3 .oss/assemble_changelog.py --checkpasses with the three new + two edited fragments.Closes #487
Closes #488
Closes #498
Closes #502
Closes #503