Skip to content

fix(cli): prevent fork bomb when dogfooding agentnative against itself#7

Merged
brettdavies merged 3 commits intodevfrom
fix/fork-bomb-depth-guard
Apr 2, 2026
Merged

fix(cli): prevent fork bomb when dogfooding agentnative against itself#7
brettdavies merged 3 commits intodevfrom
fix/fork-bomb-depth-guard

Conversation

@brettdavies
Copy link
Copy Markdown
Owner

@brettdavies brettdavies commented Apr 2, 2026

Summary

Fixed a recursive fork bomb when running agentnative check . against itself. The NonInteractiveCheck probed the target binary bare (no args), which on agentnative triggered check . recursively. The fix ensures bare invocation prints help via arg_required_else_help, and subcommand probing uses --help/--version suffixes only.

Changelog

Fixed

  • Fix recursive fork bomb when dogfooding agentnative check . against itself

Type of Change

  • fix: Bug fix (non-breaking change which fixes an issue)

Files Modified

Modified:

  • CLAUDE.md — document dogfooding safety rules and fork bomb prevention
  • src/checks/behavioral/json_output.rs — demote probe failure to warn instead of hard error
  • src/checks/behavioral/non_interactive.rs — probe with --help/--version suffixes only, never bare
  • src/cli.rs — add arg_required_else_help = true to prevent bare recursive invocation
  • src/main.rs — bare invocation exits code 2 with help on stderr
  • src/runner.rs — propagate updated check behavior
  • tests/integration.rs — add integration tests for fork bomb prevention

Checklist

  • Code follows project conventions and style guidelines
  • Commit messages follow Conventional Commits
  • Self-review of code completed
  • Tests added/updated and passing
  • No new warnings or errors introduced
  • Changes are backward compatible (or breaking changes documented)

brettdavies and others added 3 commits April 2, 2026 15:19
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 brettdavies merged commit 6fb1f72 into dev Apr 2, 2026
6 checks passed
@brettdavies brettdavies deleted the fix/fork-bomb-depth-guard branch April 2, 2026 21:05
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>
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