Repository navigation
Conversation
save-session.sh's NDC generation guard (#614) read NDC_GEN_FILE at two sites with `cat "$NDC_GEN_FILE" 2>/dev/null || echo 0`, which collapses "the file does not exist yet" (legitimately generation 0) and "the read failed" (a permission or I/O error, or a reader racing the truncating write that bumps the file) to the identical 0. When both reads fail the same way, NDC_LIVE_GEN equals NDC_SRC_GEN, the mismatch check the guard exists to enforce never fires, and the commit proceeds on the byte-size check alone -- silently restoring the pre-#614 behaviour whose failure mode is content that then exists nowhere. Adds ndc_read_gen(), used at both sites, which echoes 0 only when the marker was never created and the literal string "unreadable" when it exists but could not be read -- a value a real generation number can never equal. A new elif branch in the commit gate treats "unreadable" from either read as a reason to skip the commit and log why, the same way a byte-size regression or an explicit generation mismatch already does. tests/test_ndc_commit_lock.py adds a positive control (marker genuinely absent -- commit must still proceed) paired with the negative case (marker exists as a directory, so every read of it fails -- commit must now be skipped and logged; before this fix it silently proceeded, which is what the new test caught red). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
…gen (#619) Self-review findings from the /oss:developer review pass on the #619 commit (0530b9e): `[ ! -e "$NDC_GEN_FILE" ]` follows a symlink, so it is false for both "no path was ever created here" and "a symlink was created here and its target is now gone" -- it cannot tell those apart, which reopens the exact absent-vs-unreadable ambiguity #619 closes, one layer down. `ndc_read_gen()` now also checks `-L`, so a dangling symlink falls through to the (failing) `cat` and is classified "unreadable" rather than a fresh, legitimate 0. Pinned by a new test (marker created as a symlink to a nonexistent target); red before this change, green after. Also scopes `_ndc_gen` with `local`, matching this file's other helper (`keep_rejected_text()`) -- harmless today since every call site invokes `ndc_read_gen` inside `$( )`, which already forks a subshell, but a latent trap if that ever changes. Two other findings from the same review pass are not folded into this commit and are reported to the maintainer instead: a durable-corruption skip-loop with no operator-facing recovery hint in the log line, and the identical `cat FILE 2>/dev/null || echo 0` collapsing pattern still present, unfixed, at two lower-stakes sites in this file (COOLDOWN_MARKER, NDC_MARKER) -- both are scope/design questions rather than one-line fixes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
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.
Closes #619.
save-session.sh's NDC generation guard (added by #614) read the generation counter (
NDC_GEN_FILE) at two sites withcat "$NDC_GEN_FILE" 2>/dev/null || echo 0, which collapses "the file does not exist yet" (legitimately generation 0) and "the read failed" (a permission or I/O error, or a reader racing the truncating write that bumps the counter) into the identical fallback value 0. When both reads fail the same way,NDC_LIVE_GENequalsNDC_SRC_GEN, the mismatch check the guard exists to enforce never fires, and the commit proceeds on the byte-size check alone -- silently restoring the pre-#614 behaviour whose failure mode is content that then exists nowhere.What changed
Adds
ndc_read_gen(), used at both read sites, which echoes0only when the marker was never created (-eand, after a review follow-up,-L, so a dangling symlink is not mistaken for a plain absent path) and the literal stringunreadablewhen it exists but a read of it fails or produces non-numeric content -- a value a real generation number can never equal. A newelifbranch in the commit gate treatsunreadablefrom either read as a reason to skip the commit and log why, ordered before the existing generation-mismatch check (load-bearing: anunreadable == unreadablestring match would otherwise fall through to arithmetic on a non-numeric value and abort the script).TDD
Red, before the fix (right assertion, right reason -- the marker exists as a directory so every read of it fails, and the guard silently let the commit through anyway):
Green after:
Paired with a positive control (
test_commit_proceeds_when_generation_marker_is_absent): a marker that was never created is legitimately generation 0 and must still commit.On the brief's invited pushback
The brief flagged this finding as AI-generated and reasoned-not-observed, and asked that
tests/test_save_session_gates.py:111be read first to confirm the collapse actually reaches production behaviour before building around it. Read it: that line does drive the generation file (viaSTUB_REPLACE_DURING_NDC), but only ever writes a valid numeric generation -- it never exercises a read failure, so the described collapse was real and genuinely unguarded. No pushback is warranted; the finding held up.Self-review
Two agents (
Exploreandoss:auditor) reviewed the first commit independently. The auditor came back clean across all four classes (silent absence, guard reachability, untrusted-input boundary, platform band), with one filing suggestion. The reviewer raised four findings:[ ! -e "$NDC_GEN_FILE" ]alone treats a dangling symlink the same as a plain absent path (both fail-e), reopening the same absent-vs-unreadable ambiguity one layer down. Added a-Lcheck, pinned by a new red/green test (test_commit_skips_when_generation_marker_is_a_broken_symlink).local, unlike this file's other helper function. Harmless today (every call site is inside$( ), which forks a subshell) but a latent trap; addedlocal.cat FILE 2>/dev/null || echo 0collapsing pattern is still present, unfixed, at two other sites in the same file:COOLDOWN_MARKER(scripts/save-session.sh:239) andNDC_MARKER(scripts/save-session.sh:851). Lower stakes than the generation-marker case -- a failed read there makes the cooldown look expired, i.e. fails open to running NDC/summarization more often than intended (extra Haiku calls), not to silent data loss -- and out of save-session.sh NDC generation guard (#614) collapses "file absent" and "read failed" to the same value #619's stated scope, but the same code smell and immediately adjacent.Scope notes
docs_targetsentry) needed no change: purely an internal bugfix, no user-facing behaviour or interface changed.CLAUDE.md/pyproject.tomlchange.pytest tests/test_ndc_commit_lock.py) trips a pre-existing 80% coverage-gate failure unrelated to this diff -- confirmed identical against the pre-save-session.sh NDC generation guard (#614) collapses "file absent" and "read failed" to the same value #619 baseline. Fulltest_commandwas not run locally per policy; CI is the merge gate.🤖 Generated with Claude Code
[AI-generated]