fix(cli): prevent fork bomb when dogfooding agentnative against itself#7
Merged
brettdavies merged 3 commits intodevfrom Apr 2, 2026
Merged
fix(cli): prevent fork bomb when dogfooding agentnative against itself#7brettdavies merged 3 commits intodevfrom
brettdavies merged 3 commits intodevfrom
Conversation
Bare invocation (`agentnative` with no subcommand) defaulted to `check .`, which caused exponential process growth when behavioral checks probed the binary — NonInteractiveCheck's bare probe triggered a full recursive check suite. The tool violated its own P1 (non-interactive) principle. Two root cause fixes: - Add `arg_required_else_help = true` to Cli so bare invocation prints help and exits instantly, like brew/gh/kubectl - Remove bare subcommand probing from json_output.rs — always use --help/--version suffixes, never `subcmd --output json` bare Also: remove AGENTNATIVE_CHECK sentinel (no longer needed), add subcommand probing to JsonOutputCheck (finds --output on subcommands like `check`), document dogfooding safety rules in CLAUDE.md. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
clap's arg_required_else_help prints help to stderr and exits 2, not stdout with exit 0. Match the actual behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When --output/--format is detected in help text but safe probes (--help/--version suffixes) can't validate JSON output, report WARN instead of FAIL. Most CLIs ignore --output when --help is present, so this is a probe limitation, not a tool deficiency. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
brettdavies
added a commit
that referenced
this pull request
Apr 16, 2026
#7) ## Summary Bare invocation (`agentnative` with no subcommand) defaulted to `check .`, causing exponential process growth when behavioral checks probed the binary. NonInteractiveCheck's bare probe triggered a full recursive check suite, and JsonOutputCheck probed subcommands bare (`check --output json`), compounding the recursion. The tool violated its own P1 (non-interactive) principle. Two root cause fixes, no depth tracking machinery: - `arg_required_else_help = true` — bare invocation prints help and exits instantly (like brew/gh/kubectl) - Remove bare subcommand probing — always use `--help`/`--version` suffixes in json_output.rs ## Changelog ### Fixed - Fix fork bomb when running `agentnative check .` against itself (dogfooding) - Fix bare invocation (`agentnative` with no args) to print help instead of running a full check suite ### Changed - Change json-output check to WARN (from FAIL) when `--output` flag is detected but safe probes can't validate JSON output (most CLIs ignore `--output` when `--help` is present) ### Documentation - Add Dogfooding Safety section to CLAUDE.md documenting the two safety rules for behavioral checks ## Type of Change - [x] `fix`: Bug fix (non-breaking change which fixes an issue) ## Related Issues/Stories - Plan: `docs/plans/2026-04-02-001-fix-fork-bomb-dogfood-safety-plan.md` ## Testing - [x] Unit tests added/updated - [x] Integration tests added/updated - [x] Manual testing completed - [x] All tests passing **Test Summary:** - Unit tests: 233 passing - Integration tests: 12 passing (including dogfood tests completing in ~5s, previously 60s+) - Manual: verified bare invocation, dogfood check, json output, quiet mode, principle filter, cross-binary checks, bogus subcommands, completions — all instant, zero recursion ## Files Modified **Modified:** - `src/cli.rs` — add `arg_required_else_help = true` (1 line, the primary fix) - `src/main.rs` — `None` branch → `unreachable!()`, remove unused `PathBuf` import - `src/checks/behavioral/json_output.rs` — add subcommand probing, remove bare `&[]` from safe_suffixes, demote unvalidatable probes to WARN - `src/checks/behavioral/non_interactive.rs` — remove `is_child`/`AGENTNATIVE_CHECK` branching, always probe bare - `src/runner.rs` — remove `AGENTNATIVE_CHECK=1` from child process env - `tests/integration.rs` — add `test_bare_invocation_prints_help` regression test - `CLAUDE.md` — add Dogfooding Safety section ## Breaking Changes - [x] Breaking changes described below: Bare `agentnative` (no subcommand) now prints help and exits 2 instead of running `check .`. Users must type `agentnative check .` explicitly. This matches standard CLI conventions (brew, gh, kubectl). ## Deployment Notes - [x] No special deployment steps required ## Checklist - [x] Code follows project conventions and style guidelines - [x] Commit messages follow [Conventional Commits](https://www.conventionalcommits.org/) - [x] Self-review of code completed - [x] Tests added/updated and passing - [x] No new warnings or errors introduced - [x] Changes are backward compatible (or breaking changes documented) ## Post-Deploy Monitoring & Validation No additional operational monitoring required — CLI tool with no runtime/server component. --------- Co-authored-by: Claude Opus 4.6 (1M context) <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.
Summary
Fixed a recursive fork bomb when running
agentnative check .against itself. TheNonInteractiveCheckprobed the target binary bare (no args), which on agentnative triggeredcheck .recursively. The fix ensures bare invocation prints help viaarg_required_else_help, and subcommand probing uses--help/--versionsuffixes only.Changelog
Fixed
agentnative check .against itselfType of Change
fix: Bug fix (non-breaking change which fixes an issue)Files Modified
Modified:
CLAUDE.md— document dogfooding safety rules and fork bomb preventionsrc/checks/behavioral/json_output.rs— demote probe failure to warn instead of hard errorsrc/checks/behavioral/non_interactive.rs— probe with--help/--versionsuffixes only, never baresrc/cli.rs— addarg_required_else_help = trueto prevent bare recursive invocationsrc/main.rs— bare invocation exits code 2 with help on stderrsrc/runner.rs— propagate updated check behaviortests/integration.rs— add integration tests for fork bomb preventionChecklist