Repository navigation
agent-guards tests: hook runs never see the agent that runs the tests - #1069
Merged
Merged
Conversation
config.test.py failed 4 of 15 when an agent ran the suites while another of its own commands ran in the background. The shared fixture ran each hook as a plain child of the test, so bg-guard walked up the process tree to that agent's real Claude Code, found the other command and blocked a Stop event the tests expect to pass quietly. bg-guard.test.py's "no claude parent" case failed the same way. guards_fixture.run_hook now starts every hook under a stand-in Claude Code (/bin/sh named `claude`, nothing else under it), or with parent=None re-parented away so no `claude` is above it at all; the whole process group is killed afterwards. A new bg-guard test runs the fixture from inside a stand-in agent with a background command: the old way blocks, both fixture modes pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
fork-kit/agent-guards/tests/config.test.pyfailed 4 of 15 once while an agent ran several suites at once in the background, then passed on rerun.Cause (reproduced every time): the shared fixture
guards_fixture.run_hookran each hook as a plain child of the test.bg-guardwalks up the process tree to the first process namedclaudeand blocks a Stop when that process has another Bash tool command running. When an agent runs the tests while another of its own commands runs in the background,bg-guardfound the agent's real Claude Code and that other command, and answered{"decision": "block"}where the tests expect a quiet pass. Exactly the 4Hookssubtests forbg-guardfail.bg-guard.test.py's "no claude parent" case failed the same way.Load or parallel runs alone never failed (5 rounds of 4 config copies plus every other suite: all green). One background
sleepbeside a single run: 4 failures, every time.What
guards_fixture.run_hookstarts every hook under a stand-in Claude Code:/bin/shwith argv[0]claude, nothing else under it, and the hook as its child rather than an exec. Withparent=Nonethe hook is re-parented away, so noclaudeis above it at all. The whole process group is killed afterwards, and a timeout still raisesTimeoutExpired.bg-guard.test.py'sparent=Falsecase usesrun_hook(..., parent=None).UnderAnAgent: it runs the fixture from inside a stand-in agent that has a background command. The old way of running a hook blocks there, and both fixture modes pass. With the fixture change taken out, this test and the "no claude parent" test both fail.No hook code changed.
Tests
General vs project
General: this is a test-fixture fix in the fork kit, and it works for any agent or CI runner. It has no project facts, paths or machine details.
🤖 Generated with Claude Code