Skip to content

agent-guards tests: hook runs never see the agent that runs the tests - #1069

Merged
scuttletoby merged 1 commit into
mainfrom
fix/agent-guards-tests-process-tree
Nov 23, 2026
Merged

scuttletoby merged 1 commit into
mainfrom
fix/agent-guards-tests-process-tree

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

Why

fork-kit/agent-guards/tests/config.test.py failed 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_hook ran each hook as a plain child of the test. bg-guard walks up the process tree to the first process named claude and 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-guard found the agent's real Claude Code and that other command, and answered {"decision": "block"} where the tests expect a quiet pass. Exactly the 4 Hooks subtests for bg-guard fail. 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 sleep beside a single run: 4 failures, every time.

What

  • guards_fixture.run_hook starts every hook under a stand-in Claude Code: /bin/sh with argv[0] claude, nothing else under it, and the hook as its child rather than an exec. With parent=None the hook is re-parented away, so no claude is above it at all. The whole process group is killed afterwards, and a timeout still raises TimeoutExpired.
  • bg-guard.test.py's parent=False case uses run_hook(..., parent=None).
  • New test 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

  • All 9 agent-guards suites, 343 tests: OK.
  • With one of my own commands running in the background: 20 config runs (4 at a time) plus 5 runs each of bg-guard, wiring and agent-slots, all at once: all OK. Before the fix: 4 failures in config and 1 in bg-guard on every run.

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

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>
@scuttletoby
scuttletoby merged commit 57ed0c8 into main Nov 23, 2026
30 checks passed
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.

1 participant