Skip to content

fix(#758): guard REMEMBER_EMIT_READ_MAX like every sibling numeric knob - #772

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/758-emit-read-max-guard
Sep 25, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/758-emit-read-max-guard

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Fixes the one numeric env knob in scripts/lib-memory-context.sh that lacked the
case (''|*[!0-9]*) ... ;; esac guard every sibling knob in the same file already carries
(MEMORY_INJECT_MAX_BYTES, log.sh's _budget/_grace).

_remember_emit_file read REMEMBER_EMIT_READ_MAX straight off the environment and used it
unguarded in [ "$2" -gt "$_remember_emit_max" ]. A non-numeric value made that comparison print
"integer expression expected" (GNU bash) or "integer expected" (macOS bash) to stderr and, because
the test sits inside an if condition, fell through to the wrong branch -- sending the file down
the quadratic read path the 16 KB threshold exists to keep it off. Low severity (undocumented,
developer-only knob), but the same easy fix as its siblings.

Closes #758

Fix

Added the same guard convention already used by this file's other numeric knobs, falling back to
the documented default of 16384 on garbage input.

Tests

Red (pre-fix): test_a_non_numeric_threshold_does_not_print_to_stderr failed with the actual
macOS-bash message reproduced: [: notanumber: integer expected.

Green (post-fix): python3 -m pytest tests/test_emit_read_max_guard_758.py tests/test_unknown_size_695.py tests/test_render_is_byte_identical_660.py tests/test_locale_ranges_695.py tests/test_windows_skip_triage_497.py -q --no-cov -> 42 passed.

Full pytest (whole suite) not run locally, per this repo's own policy that CI is the gate for
the 3-OS x 4-interpreter matrix.

Follow-up commit

A second commit in this branch fixes stale prose in
.claude/jit-context/paths/00-manual/00-README.md that a self-review reviewer caught: the
declined-trap entry for 695.emit-read-max-is-an-unvalidated-knob still said the knob was "still
true, not fixed" after this PR's own fix landed. Updated to say fixed in #758.

Below-bar finding (not fixed here, on purpose)

A second self-review reviewer (oss:auditor) found that the new guard silently substitutes the
default (16384) on garbage input, with no stderr note distinguishing "garbage, defaulted" from
"never set, default applied on purpose". This mirrors an existing, unchanged sibling pattern
(MEMORY_INJECT_MAX_BYTES at line ~712) rather than introducing a new one; below-bar for this
diff, not a defect this fix created.

Docs: README.md checked, no change needed (this is an undocumented, dev-only knob, never
documented there). docs/windows-skip-triage.md updated with a row for the new bash-subprocess
test module.

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 2 commits September 25, 2026 21:02
`_remember_emit_file` read `${REMEMBER_EMIT_READ_MAX:-16384}` straight off
the environment and fed it unguarded into `[ "$2" -gt "$_remember_emit_max" ]`,
unlike MEMORY_INJECT_MAX_BYTES in the same file and log.sh's _budget/_grace.
A non-numeric value made the comparison print "integer expression expected"
to stderr and fall through (an if condition suppresses set -e) to the read
arm -- sending the file down the quadratic path the 16 KB threshold exists
to keep it off.

Add the same `case (''|*[!0-9]*) ... ;; esac` guard used by the file's other
numeric knobs, falling back to the documented default of 16384 on garbage.

Adds tests/test_emit_read_max_guard_758.py (red before the fix, green after),
a changelog.d/758.fixed.md fragment, and a windows-skip-triage.md row for the
new bash-subprocess test module.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Self-review (Explore reviewer) found `.claude/jit-context/paths/00-manual/
00-README.md`'s declined-trap entry for `695.emit-read-max-is-an-unvalidated-
knob` still asserted "still true, not fixed" about the exact guard #758's
previous commit just added -- stale prose adjacent to the diff, contradicting
the code it describes. Updates the entry to say the knob was fixed in #758.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit ce50e82 into main Sep 25, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/758-emit-read-max-guard branch September 25, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REMEMBER_EMIT_READ_MAX has no numeric guard, unlike every sibling knob in the same file

1 participant