Repository navigation
Merged
Conversation
…t to one line (#500, #501) #500: save-session.sh's SESSION_ID validator (`^[a-f0-9-]+$`) admitted a leading hyphen, so an option-shaped id ("-e", "--", "-adef") could reach REMEMBER_BRANCH_CMD's argv[1] and be read as a flag by whatever argument parser the operator's own resolver happens to use. Anchored the regex to `^[a-f0-9][a-f0-9-]*$` -- the single choke point every caller (CLI, session-end-hook.sh, session-start-hook.sh's recovery path) passes through before Step 3 -- rather than fixing each caller individually or adding a `--` separator at the call site (which would silently shift the documented argv[1] contract for every existing resolver). #501: REMEMBER_BRANCH_CMD's stdout became $BRANCH and was substituted verbatim into the summarizer prompt with no newline bound of its own -- $(...) only strips trailing newlines, so a multi-line resolver result would write arbitrary content at column 0 of the prompt. A multi-line result is now refused outright, falling through to the git-branch lookup and logging a WARNING the same way a non-zero exit or empty stdout already does, matching the repo's #481 convention that a configured-but-failing resolver reads as a reported fault rather than silent truncation. Both fixes are TDD: tests/test_save_session_branch_override.py gained an option-shaped-id case (parametrized -adef/--/-e) and a positive control (an ordinary hyphenated id still accepted) for #500, and a multi-line resolver case plus its positive control (a normal single-line resolver still used, still silent) for #501 -- all four new negative cases were watched red against the pre-fix code before the fix landed. README.md's REMEMBER_BRANCH_CMD row now documents both: SESSION_ID is guaranteed hex-leading before the resolver ever sees it, and the resolver's own stdout is expected to be a single line. Closes #500 Closes #501 Co-Authored-By: Max <noreply>
Self-review finding (oss:auditor, class C): the multi-line rejection landed in the previous commit only matched an embedded LF (`case ... in *$'\n'*)`). A resolver emitting a lone CR with no LF (`printf "part1\rpart2"`) is not multi-line by that check, so $(...) -- which only strips a trailing LF -- would still let it through to $BRANCH unbounded. A bare CR can reposition a naive terminal's cursor to column 0 mid-line the same way an embedded LF can, which is the exact concern #501 names, just via a different control character. Widened the case pattern to `*$'\n'*|*$'\r'*)`. New test (test_branch_cmd_carriage_return_falls_through_to_git) is written to actually observe the CR: subprocess's text=True path silently rewrites a lone '\r' to '\n' on read (Python's universal-newline translation), which would have made a naive version of this test pass whether or not the fix caught '\r' at all -- the test captures raw bytes and decodes without that translation instead. Watched red against the pre-fix case pattern, green after the widen. README.md and the #501 changelog fragment updated to mention both control characters. 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.
Closes #500
Closes #501
#500: option-shaped session_id reaches REMEMBER_BRANCH_CMD's argv[1]
scripts/save-session.sh's session-id validator (^[a-f0-9-]+$) admitted a leading hyphen, so an option-shaped id (-e,--,-adef) could reach$REMEMBER_BRANCH_CMD "$SESSION_ID"'sargv[1]and be misread as a flag by whatever argument parser the operator's own resolver uses.Fix chosen: anchor the validator, not add a
--separator at the call site.scripts/save-session.sh:197is the single choke point every caller (CLI,session-end-hook.sh'sSTDIN_SESSION_ID,session-start-hook.sh's recovery path) passes through before Step 3's branch resolution -- confirmed by the self-review's Explore pass, which grepped every caller and found none bypasses this gate. Anchoring there is cheaper than fixing each caller, and unlike inserting--before$SESSION_ID, it does not silently shift the documentedargv[1]contract for every existing resolver (a--separator would move the session id toargv[2], breaking any resolver written against the README's current$REMEMBER_BRANCH_CMD "$SESSION_ID"documentation). Regex:^[a-f0-9-]+$->^[a-f0-9][a-f0-9-]*$.#501: REMEMBER_BRANCH_CMD's stdout substituted into the summarizer prompt unbounded
REMEMBER_BRANCH_CMD's stdout becomes$BRANCHand is substituted verbatim intopipeline/prompts.py's{{BRANCH}}.$(...)only strips a trailing newline, so a resolver printing more than one line would write arbitrary content at column 0 of the prompt.Fix: reject the result outright on any embedded newline, falling through to the
git branch --show-currentlookup and logging a WARNING -- the same fall-through-and-log shape #481 already uses for a non-zero exit or empty stdout, rather than silently truncating to the first line (a truncation a reader of the log could not tell apart from the resolver only ever having meant to print one line).Self-review caught a gap in the first pass: the guard only matched an embedded LF, not a lone CR with no LF (
printf "part1\rpart2"), which a naive terminal reads as "return to column 0 mid-line" the same way an embedded LF does. Widened to catch both (*$'\n'*|*$'\r'*)). The regression test for this (test_branch_cmd_carriage_return_falls_through_to_git) captures raw subprocess bytes rather than text-mode output, because Python'ssubprocess.run(..., text=True)silently rewrites a lone\rto\non read -- a naive version of the test would have passed whether or not the fix actually caught\r.Tests
All four new negative cases (three option-shaped-id parametrizations for #500, one multi-line-resolver case for #501) plus the CR follow-up were watched red against the pre-fix code before their respective fixes landed, and green after. Positive controls pair each: an ordinary hyphenated session id is still accepted, and an ordinary single-line resolver output is still used and still silent. Targeted run (
tests/test_save_session_branch_override.pyplus five adjacent files touching session-id handling, prompt substitution and save-session gating): 120 passed. Full repotest_commandnot re-run locally, per this repo's own CLAUDE.md and the loop's #765 guidance -- CI is the merge gate.Self-review
Spawned
Exploreandoss:auditoragainst the diff.ExplorereturnedNO FINDINGS.oss:auditorreturned two findings:tests/test_save_session_branch_override.pycarries a pre-existing (issue feat(save-session): honor $REMEMBER_BRANCH env var when $PROJECT_DIR is not a git repo #88, unrelated to An option-shaped session_id reaches REMEMBER_BRANCH_CMD as argv[1], where the resolver's own parser decides what it means #500/REMEMBER_BRANCH_CMD's stdout is substituted into the summarizer prompt unbounded -- a multi-line resolver writes at column 0 of the prompt #501) module-widepytestmark = pytest.mark.skipif(sys.platform == 'win32', ...), so this diff's new test cases -- like the file's other 14 pre-existing tests -- never execute on the windows-latest CI leg, which still reports green. This repo has already fixed the identical pattern twice elsewhere (tests/test_bash_runner_432.py,tests/test_autonomous_log_retention_487.py, both migrated totests/_bash_runner.py'sresolve_bash()-narrowed skip). Recommend the same migration for this file as a separate, focused follow-up -- it is a test-infrastructure decision touching 14 unrelated pre-existing tests, needs verification against an actual windows-latest runner, and is out of this two-issue bugfix's blast radius.Docs / changelog
README.md's
REMEMBER_BRANCH_CMDrow documents both the anchoredSESSION_IDcontract and the single-line stdout expectation. Two changelog fragments (changelog.d/500.fixed.md,changelog.d/501.fixed.md).