Skip to content

fix: preserve shell guard on helper failure - #101

Closed
nexicturbo wants to merge 1 commit into
monk-io:mainfrom
nexicturbo:agent/block-monk-helper-failure
Closed

fix: preserve shell guard on helper failure#101
nexicturbo wants to merge 1 commit into
monk-io:mainfrom
nexicturbo:agent/block-monk-helper-failure

Conversation

@nexicturbo

Copy link
Copy Markdown

Summary

  • fall back to the native PowerShell command parser when monk-agent hook block-monk fails
  • validate successful helper output before treating it as an authoritative PreToolUse decision
  • suppress broken helper output so ordinary non-Monk commands remain unaffected
  • add Windows CI coverage for nonzero and malformed-success helper behavior

Root cause

hooks/block-monk.ps1 returned immediately whenever the configured helper path existed. A helper failure propagated its exit code without producing deny JSON, and a successful but malformed response was relayed without validation. In both cases, direct monk commands bypassed the native fallback that is supposed to preserve the shell guard when the companion is unhealthy.

Impact

The guard now remains active through interrupted updates, incompatible helpers, and initialization failures. Direct monk commands are denied while ordinary commands still exit cleanly with no hook output.

Validation

  • reproduced the original nonzero-helper failure with the stock Windows net.exe
  • exercised malformed-success output with cmd.exe
  • verified both cases deny monk cluster list and allow echo monk
  • verified the installed monk-agent v0.1.45 still denies/allows the same cases
  • git diff --check
  • parsed .github/workflows/install-e2e.yml with PyYAML

Closes #100

@nexicturbo
nexicturbo marked this pull request as ready for review July 21, 2026 01:27
@nexicturbo
nexicturbo force-pushed the agent/block-monk-helper-failure branch from 95c504b to dda6472 Compare July 22, 2026 02:15
@nexicturbo

Copy link
Copy Markdown
Author

Rebased onto v0.1.46 (a4c9972). The consolidated tests/block-monk-windows.ps1 regression passes locally for a missing helper, a failing helper (net.exe), and malformed-success output (cmd.exe), while preserving the shipped command-boundary cases. Ready for maintainer workflow approval/review.

@nexicturbo

Copy link
Copy Markdown
Author

Rebased onto the current v0.1.49 branch and reconciled the newer Windows hook implementation without weakening the guard. The resolved path buffers raw stdin bytes, preserves UTF-8/BOM payloads when invoking the helper through ProcessStartInfo, and still falls back to the native parser if the helper fails or returns invalid output.

Fresh validation:

  • tests/block-monk-windows.ps1 passes
  • the installed monk-agent hook correctly denies a BOM/non-ASCII test payload
  • git diff --check passes

Current head: 5d0411ce042b2bb73059687451ec458409e53507. The PR is mergeable and ready for maintainer review.

Buffer raw stdin bytes, preserve UTF-8/BOM payloads through the helper path, and fall back to the native parser when the helper fails or returns invalid output. Cover both packaged Windows hooks with the regression matrix.
@Lachann

Lachann commented Aug 6, 2026

Copy link
Copy Markdown

Thanks for the PR — we ported this approach into the fix that shipped in v0.1.54. This PR no longer merges cleanly against current main, so I'm closing it without merging, but credit for the fix stands.

@Lachann Lachann added the accepted Accepted in Bug Bounty label Aug 6, 2026
@Lachann Lachann closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted Accepted in Bug Bounty

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug bounty] Windows block-monk guard fails open when helper errors

2 participants