Skip to content

Run the closeout fingerprint through sh - #788

Merged
jserv merged 1 commit into
sysprog21:mainfrom
onechendong:fix-closeout-tree-fingerprint
Nov 19, 2026
Merged

jserv merged 1 commit into
sysprog21:mainfrom
onechendong:fix-closeout-tree-fingerprint

Conversation

@onechendong

@onechendong onechendong commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem and behavior

On Windows, the Claude Code Stop hook scripts/agent-closeout-check.py raised at the end of every turn instead of printing its once-per-tree reminder:

File "scripts\agent-closeout-check.py", line 48, in tree
OSError: [WinError 193] %1 is not a valid Win32 application.

tree() executed scripts/tree-fingerprint.sh directly, which Windows cannot do, and a checkout without the executable bit fails the same way. scripts/test.sh took the fingerprint its receipts are matched against the same way, so such a checkout wrote no receipt for the hook to match, and two tests in tests/test_agent_workflow_hooks.py executed a script directly too. With this change the hook computes the fingerprint and prints its reminder, the gate writes a receipt it can match, and the suite passes in such a checkout. The hook runs only under Claude Code with a working python3, so it stayed silent wherever python3 resolves to the Microsoft Store stub.

Approach

Every caller of scripts/tree-fingerprint.sh runs it through sh, as check-pr-text.py and commit-draft.py already run git-commit-msg.sh: tree() in the hook, the receipt_tree= line where scripts/test.sh takes the start tree, and the tests. The test that runs the hook as a process runs it through sys.executable, as .claude/settings.json runs it through python3. With no sh on PATH, as in a PowerShell session outside Git Bash, tree() still raises FileNotFoundError; the module docstring now says so instead of promising an exit status of 0. Claude Code runs the hook under Git Bash, where sh is present, so this change leaves that case alone.

Validation

  • In a python:3.12 container (Linux 6.6, Python 3.12.16, git 2.47.3), test_the_closeout_check_runs_the_fingerprint_through_sh and test_the_start_tree_is_taken_without_the_executable_bit pass. With sh removed from tree(), the first fails with PermissionError: [Errno 13] Permission denied; with it removed from the receipt_tree= line in scripts/test.sh, the second fails with '' != '8d3a0beb...'.
  • In the same container, with the executable bit removed from both scripts/tree-fingerprint.sh and scripts/agent-closeout-check.py, the previous head failed test_a_directory_that_is_not_a_work_tree_has_no_fingerprint and test_stop_hook_never_blocks_and_ignores_a_reentrant_stop with PermissionError. scripts/run-python-tests.py tests/test_agent_workflow_hooks.py tests/test_gate_receipt.py now runs 36 tests there, all passing.
  • On Windows 11 with Python 3.12.3, the hook test fails with WinError 193 without the fix, and tests/test_agent_workflow_hooks.py now passes in full, 14 tests. The receipt test passes on Windows either way, since Git Bash runs a script that starts with #! whatever its mode, so it is the Linux run above that shows it. Four other cases in tests/test_gate_receipt.py fail on Windows on main as well and pass in the container.
  • The hook test loads its own copy of the module, as the receipt test above it does, because scripts/run-python-tests.py runs cases in parallel and other cases patch tree on the shared one. A probe holding that patch in another thread failed the shared-module version and passes this one.
  • With the change in the working tree, the Stop hook in Claude Code on Windows stopped printing the traceback.
  • ruff format --check and ruff check pass with ruff 0.15.2, the version CI pins; shfmt -d scripts/test.sh is clean with shfmt 3.8.0, the version Ubuntu 24.04 ships to CI, and sh -n scripts/test.sh parses.

Summary by cubic

Fixes the Claude Code Stop hook scripts/agent-closeout-check.py crashing at the end of every turn on Windows instead of printing its once-per-tree reminder.

The hook, scripts/test.sh, and the test helpers now run scripts/tree-fingerprint.sh through sh instead of executing it directly, which Windows cannot do and which also fails when a checkout lacks the executable bit. A checkout without the executable bit previously wrote no receipt to match, so scripts/test.sh and the stop hook now take their fingerprints the same way. Tests now invoke each script through its interpreter as well, and the hook's docstring notes it still raises with no sh on PATH. New regression tests cover both.

Written for commit 2653883. Summary will update on new commits.

View guided diff

cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@onechendong
onechendong force-pushed the fix-closeout-tree-fingerprint branch from e6eddc8 to 6924bc4 Compare November 19, 2026 16:46
jserv

This comment was marked as resolved.

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description's Approach and Validation predate the scripts/test.sh change: neither says the gate now takes its start tree through sh, and tests/test_gate_receipt.py is a third suite the diff touches.

Comment thread scripts/agent-closeout-check.py Resolved
The closeout Stop hook executed scripts/tree-fingerprint.sh directly,
which Windows cannot do: every stop raised WinError 193 instead of
printing its reminder, although the hook promises to exit 0. A checkout
without the executable bit fails the same way, and scripts/test.sh,
which takes the fingerprint its receipts are matched against, ran it
directly too, so such a checkout wrote no receipt to match. Both now
run it through sh, as check-pr-text.py and commit-draft.py already run
git-commit-msg.sh, and the tests run each script through its
interpreter as well, so the suite passes in such a checkout too. With
no sh on PATH the hook still raises, which its docstring now says.

Change-Id: I102babc02bd18450a383fe21cb30c8d617913945
@onechendong
onechendong force-pushed the fix-closeout-tree-fingerprint branch from 6924bc4 to 2653883 Compare November 19, 2026 17:12
@onechendong

Copy link
Copy Markdown
Contributor Author

@ColtenOuO The description is updated: Approach names the receipt_tree= line in scripts/test.sh and the tests, and Validation covers tests/test_gate_receipt.py.

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jserv
jserv added this pull request to the merge queue Nov 19, 2026
@jserv

jserv commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Thank @onechendong for contributing!

@jserv
jserv removed this pull request from the merge queue due to a manual request Nov 19, 2026
@jserv
jserv merged commit 900f36c into sysprog21:main Nov 19, 2026
20 checks passed
@onechendong
onechendong deleted the fix-closeout-tree-fingerprint branch November 19, 2026 19:17
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.

3 participants