Skip to content

Fix NOW_DAY_FILE FIFO hang and five more stderr-order leaks in save-session.sh (#642, #643) - #645

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/642
Sep 10, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/642

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Summary

Two issues found by PR #641's own self-review while fixing #634, both in scripts/save-session.sh.

#642 -- NOW_DAY_FILE was read via a bare cat "$NOW_DAY_FILE" 2>/dev/null | tr -d '[:space:]', unlike its siblings ndc_read_gen() (#634) and ts_marker_read() (#625), neither of which has a regular-file type check. A FIFO placed at that path hangs the whole save indefinitely (no writer, no O_NONBLOCK, no timeout anywhere in this script); a character device streams unboundedly. Fixed by guarding the read with [ -f "$NOW_DAY_FILE" ], falling through to the existing TODAY_DATE fallback that an absent or garbage-content file already took.

#643 -- five more CMD > FILE 2>/dev/null-shaped writes leak bash's own raw diagnostic when the > redirection itself fails, the same defect #635 already fixed at two other sites. Redirections process left to right, so a failing > is reported to the real stderr before 2>/dev/null ever takes effect. Grepped for the exact shape (a > followed directly by 2>/dev/null on the target's own quoted variable) and it returns exactly five lines beyond the two #635 already fixed:

All five wrapped in the same { CMD > FILE; } 2>/dev/null grouping #635 introduced.

Below-bar finding, not filed as an issue

Self-review (oss:auditor) flagged docs/windows-skip-triage.md's new row for tests/test_stderr_leak_sites_643.py landing out of alphabetical order in the table. Cosmetic only -- the table is keyed by exact filename text, not position -- so this is a below-bar finding rather than one worth a tracker issue. Fixed anyway in the follow-up commit, since the context was already loaded.

Test plan

  • tests/test_now_day_file_fifo_642.py -- extracts the NDC_DAY read block by content out of scripts/save-session.sh and runs it in isolation: a FIFO no longer hangs (5s timeout as the assertion), with positive controls for the absent-file and regular-file cases. Red against the pre-fix script (TimeoutExpired), green after.
  • tests/test_stderr_leak_sites_643.py -- extracts each of the five statements and runs it against a directory standing in for the target file (the same "Is a directory" technique tests/test_marker_write_stderr_order_635.py uses): one negative case per site (no raw diagnostic leaks) paired with one positive case (the write still succeeds against a normal target). Red against the pre-fix script (8/13 failing), green after (13/13).
  • Regression: tests/test_marker_range_guard_326.py, tests/test_ndc_day_boundary.py, tests/test_marker_write_stderr_order_635.py, tests/test_ndc_truncate_race.py, tests/test_ndc_tail_failure_no_truncate.py, tests/test_ndc_commit_atomicity.py, tests/test_ndc_commit_lock.py, tests/test_windows_skip_triage_497.py, tests/test_windows_skip_triage_no_stale_prose_counts_613.py -- all pass.
  • bash -n scripts/save-session.sh and shellcheck scripts/save-session.sh -- no new findings near the changed lines.
  • python3 .oss/assemble_changelog.py --check -- 7 fragments, both new ones (642.fixed.md, 643.fixed.md) parse clean.
  • Full pytest suite -- not run locally; CI is the merge gate for the whole matrix (13 legs, 3 OSes, 4 interpreters).

Closes #642, closes #643.

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 2 commits September 10, 2026 10:39
…ession.sh (#642, #643)

#642: NOW_DAY_FILE was read via a bare `cat "$NOW_DAY_FILE" 2>/dev/null | tr
-d "[:space:]"`, unlike its siblings ndc_read_gen() (#634) and
ts_marker_read() (#625) -- no regular-file type check. A FIFO placed at
that path hangs the read forever (no writer, no O_NONBLOCK); a character
device streams unboundedly. Guarded the read with `[ -f "$NOW_DAY_FILE" ]`,
falling through to the same TODAY_DATE fallback an absent or
garbage-content file already takes.

#643: five more `> FILE 2>/dev/null`-shaped writes leak bash's own raw
diagnostic when the `>` itself fails, the same defect #635 fixed at two
sites -- redirections process left to right, so a failing `>` is reported
to the real stderr before `2>/dev/null` ever takes effect. Found by
grepping the exact shape (a `>` followed directly by `2>/dev/null` on the
target's own quoted variable), which returns exactly these five, plus the
two #635 already fixed (excluded since their `{ ...; }` wrap no longer
matches the bare shape):

  - COOLDOWN_MARKER's self-heal write (the ELAPSED<0 branch -- distinct
    from the guarded write #635 fixed a few lines below it)
  - NDC_MARKER's self-heal write (same shape)
  - NOW_DAY_FILE's fresh-stamp write (now.md starting empty)
  - NOW_DAY_FILE's restamp write (after an NDC compression keeps bytes)
  - the NDC_TAIL truncate-and-copy `tail` write (an `if ... ; then`
    rather than `||`, same ordering defect)

All five wrapped in the same `{ ...; }` grouping #635 introduced.

Tests: tests/test_now_day_file_fifo_642.py extracts the NDC_DAY read block
by content and proves the FIFO case no longer hangs (5s timeout as the
assertion), with positive controls for the absent and regular-file cases.
tests/test_stderr_leak_sites_643.py extracts each of the five statements
and runs it against a directory standing in for the target (the same
"Is a directory" technique tests/test_marker_write_stderr_order_635.py
uses) -- one negative case per site (no raw diagnostic leaks) paired with
one positive case (the write still succeeds against a normal target).
Both files reproduce red against the pre-fix script and green after.

Changelog fragments for both issues; docs/windows-skip-triage.md rows for
the two new blanket win32-skip test modules.

Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Self-review (oss:auditor) flagged tests/test_stderr_leak_sites_643.py's row
landing between the test_ndc_* entries instead of alphabetically among the
test_st* entries. Cosmetic only -- the table is keyed by exact filename
text, not position -- but fixed while the context is loaded.

Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@fdaviddpt
fdaviddpt merged commit 07f57c1 into main Sep 10, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/642 branch September 10, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant