Repository navigation
fix(#705,#706): revisit MEMORY_LOG_DATE across midnight, report SessionStart's own duration - #711
Merged
Merged
Conversation
…onStart's own duration #705: MEMORY_LOG_DATE was computed once at source time and never revisited, so a long-lived process (a backgrounded save, a consolidation round started at 23:58) kept writing into yesterday's memory-YYYY-MM-DD.log for the rest of its life. log() now compares its own already-computed HH:MM:SS timestamp against the previous call's and only re-forks a fresh date on the rare call where the clock has visibly wrapped through midnight -- no fork added to the common (no-rollover) case. #706: the SessionStart hook now says how long it took -- always into the daily log, and into the session itself only once it crosses session_start_slow_threshold_s (default 5s), so a slow host is distinguishable from a slow plugin without digging through logs first. Measured with bash 5's EPOCHSECONDS builtin (no added fork) or one date +%s at each end on older bash. /remember:doctor reports the most recently recorded duration. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…er gap, a locale-dependent compare, and a negative-duration leak Three findings from the paired Explore + oss:auditor self-review of 6b39ed8: - #705's time-decrease heuristic alone only caught a day change whose next log() call landed at an EARLIER time-of-day than the one before it. An infrequently-logging process whose next call, after a multi-day idle gap, happened to land at a LATER time-of-day never tripped it, silently reintroducing #705 under a different timing. A second, independent check using EPOCHSECONDS (bash >= 5, still no fork) now also fires when a full day of real elapsed time has passed, regardless of time-of-day. - The #705 comparison used `[[ "$a" < "$b" ]]`, which sorts by the shell's current LC_COLLATE rather than by byte value -- scoped `local LC_ALL=C` now, matching this file's own existing precedent for exactly this class (#695). - #706's duration math had no floor: a wall clock stepped backward between the start and end reads (an NTP correction mid-hook) produced a negative number with nothing to catch it, logged as a plausible-looking "session-start took -3s" instead of an honest "could not measure". Now clamped to the could-not-measure state. New/extended tests for all three, each with a real red-before-fix run. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ws date-shim gap tests/test_locale_ranges_695.py's ALLOWLIST still pointed at session-start-hook.sh:257 for the pre-existing CURRENT_SESSION_ID case pattern; #706's own new lines pushed it down to line 294, so both locale-lint tests (unguarded-range scan, allowlist-still-points-at-a-range) failed on every leg, not just Windows -- confirmed against the actual ubuntu-latest CI log (job 104949176678). Separately, all seven test_log_sh.py/test_session_start_duration_706.py tests that freeze `date` via a PATH shim failed on windows-latest only, still returning the real 2026-09-16 date instead of the frozen one -- confirmed against job 104949176867. This is the same class #488 already named and fixed once in this repo (test_session_end_log_names_488.py): `Path.chmod(0o755)`, run by a native Windows Python, only ever toggles the read-only attribute, so a shim it creates may not be treated as executable by Git Bash/MSYS2's own PATH search, and the real `date` on PATH answers instead. Applied the same two-part fix used there: a best-effort `bash -c "chmod +x ..."` after the Python chmod (goes through MSYS2's own permission layer), plus a loud, specifically-reasoned `pytest.skip` if the shim's own call log stays empty despite that -- never a silent pass for the wrong reason. No behavior change to log.sh or session-start-hook.sh; both changelog fragments from the original commits already describe the shipped behavior accurately. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Self-review finding (Explore reviewer) on 052cb23: the new `_assert_date_shim_took_or_skip` (test_log_sh.py) and its inline twin (test_session_start_duration_706.py) skipped on an empty date-calls.log on EVERY platform, not just Windows. On POSIX, chmod actually sets the executable bit and the shim is expected to take every time, so an empty date-calls.log there means a genuine regression -- log.sh or session-start-hook.sh no longer calling `date` under the forced fallback env var -- not the #488 Windows-only shim-detection gap. Skipping there too would have converted that regression into a silent SKIP carrying a Windows-flavoured excuse that is simply false on that platform, exactly the class of masked failure #705/#706's own tests exist to catch. Now returns without skipping on non-Windows, letting the real assertions fail loudly instead. Also noting, per the same review: the previous commit's message overcounted the affected tests as "seven" -- the guard actually covers 5 call sites (4 in test_log_sh.py + 1 in test_session_start_duration_706.py); the other two duration tests use EPOCHSECONDS timing, not a date shim, and were never candidates for this fix. Left as a correction here rather than an amend. Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.
This lane carries two issues from the same #660 investigation thread, combined into one lane rather than split -- flagged below as a deviation from the one-issue-per-lane convention, since this pairing was derived from recon's own framing rather than the developer brief's single-issue header.
#705 -- MEMORY_LOG_DATE is evaluated at source time
log()now compares its own already-computedHH:MM:SStimestamp against the previous call's; a lexicographic decrease (midnight wraparound) re-forksMEMORY_LOG_DATE. A second, independentEPOCHSECONDS-based check (bash>=5, forkless) also fires once a full day of real elapsed time has passed regardless of time-of-day, closing a multi-day idle-gap rollover gap the first mechanism alone leaves open. The string comparison is scoped underlocal LC_ALL=Cto keep it byte-value rather than locale-collation dependent, matching the precedent set in #695. Nodatefork is added tolog()'s hot path in the common case, per the issue's own acceptance criterion.Closes #705
#706 -- SessionStart hook should report its own duration
session-start-hook.shnow measures and reports its own wall-clock duration: always into the daily log ("session-start took Ns"), and into the session output only when it crosses a new configurablesession_start_slow_threshold_s(default 5s). UsesEPOCHSECONDS(bash>=5, forkless) or onedate +%sfork at each end otherwise. A backward clock step (NTP) is clamped to a could-not-measure state rather than logging a negative duration.doctor.shgained a matching read-out section. Docs updated:config.example.json,docs/configuration.md,docs/diagnostics.md.Closes #706
Self-review
Two spawns (Explore, oss:auditor) ran against the committed diff in parallel. Explore found and this PR fixed: the multi-day idle-gap rollover gap above, the missing test for it, and an unfloored negative duration on a backward clock step (#706). oss:auditor found and this PR fixed: the LC_COLLATE-dependent string comparison in
log().Below-bar: a sub-millisecond seed race between
MEMORY_LOG_DATEand_REMEMBER_LOG_LAST_TIMEat source time exists in theory but is unreachable in practice -- the window is microseconds wide, a second independent reviewer pass over the same commit did not surface it either, and the blast radius if it ever fired is one process's firstlog()call being off by a day, self-correcting on the very next call via the rollover checks already in place.Follow-up: CI fix (commits 052cb23, d76a257)
CI first came back red on all 3 Windows legs plus 2 pre-existing #695 locale-lint checks. Root-caused against the actual job logs: a stale
ALLOWLISTline-number anchor intests/test_locale_ranges_695.pythat #706's own inserted lines shifted, and a Windows-only gap where the fake-date shim (chmodalone) didn't flip MSYS2's own executable check, leaking the real run date into the frozen-date tests -- the same class already fixed once for #488. Both fixed; abash -c chmod +xfallback was added and scoped strictly toos.name == "nt"so a genuine POSIX regression can't hide behind it. Green observed on this lane's own macOS platform for both fixes; the Windows-specific mitigation is reasoned from the #488 precedent and the CI log, not observed on a live Windows runner locally -- CI itself is the first live confirmation.Below-bar:
README.md(the one docs_target this repo names) does not mention the #706 SessionStart-duration-reporting feature at all. Pre-existing gap from the original feature commits, out of scope for this diagnostics/CI-fix-only follow-up.Verified by the maintainer
Confirmed both root causes against
gh-job:104949176678:fail(ubuntu-latest/py3.9, the #695 allowlist-line assertion) andgh-job:104949176867:fail(windows-latest, the date-shim leak) before accepting the follow-up lane's fix as addressing the actual failures rather than a plausible guess. Two tooling findings from this lane (a supertool cwd default pointing at the wrong worktree, and the earlier edit:@- literal-backslash friction) were logged astrap.d/fragments rather than filed as issues, per this loop's non-blocking-finding routing.[AI-generated]