[Bug]: goal-mode PreToolUse gate exits rc=1 with no decision on an unreadable event instead of the documented fail-closed deny
Preflight
- [x] I searched existing issues and discussions for this behavior.
- [x] This report is not an unpatched security vulnerability.
- [x] The report and attachments contain no credentials or private/internal material.
Issue origin
Observed or reproduced in a real environment
LoopX version or commit
adb247e5f (current main when filed)
Host or runtime surface
Claude Code
LoopX area
Host or runtime integration
Problem
The opt-in Claude Code goal-mode hardening gate (--harden, loopx/claude_goal_mode/hooks/goal_policy.py) documents itself as fail-closed: when the deterministic should_run probe cannot be reached, a non-read-only tool is denied, "so a flaky/broken control plane pauses delivery instead of running ungated". The event read is the one boundary outside that rule. Any stdin the hook cannot turn into a usable PreToolUse event makes it exit rc=1 with a traceback and print no decision.
Claude Code treats a hook that exits with a code other than 0 or 2 as a non-blocking error (<hook name> hook error / Failed with non-blocking status code: ...) and continues the tool call through the normal permission flow, so the gate disappears exactly when the hook could not verify anything — for an unattended /loop session that is an ungated tool call. #6166 pinning the adapter's stdio named this as its deliberately deferred successor ("hardening it into an explicit deny is a separate, independently reviewable change").
Who is affected: anyone running the opt-in --harden gate (project- or user-scoped install) while goal-mode is armed. Impact: an unreadable event silently drops the should_run / write_scope decision for that call instead of pausing it.
Input classes that do this today (each reproduced against adb247e5f by running the shipped script as Claude Code does: own process, event on stdin):
| Input | Cause | rc / stdout / stderr (raw) |
|---|---|---|
| Non-UTF-8 stdin byte | strict stdin pin (#6166) raises UnicodeDecodeError at sys.stdin.read() |
rc=1, stdout empty, UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte |
Malformed JSON ({not json) |
json.loads fails -> ev = {} -> active_context(None) |
rc=1, stdout empty, TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'NoneType' |
JSON that is not an object ([]) |
ev.get on a list |
rc=1, stdout empty, AttributeError: 'list' object has no attribute 'get' |
Object without a usable session cwd ({"tool_name": "Bash"}, also "workspace" not an object) |
active_context(None) / .get on a str |
rc=1, stdout empty, same TypeError / AttributeError: 'str' object has no attribute 'get' |
Minimal reproduction
- Check out
loopx-project/loopxatadb247e5f. - Create a scratch armed project: a
.loopx/registry.jsonwith one goal, run the hook withLOOPX_GOAL_FORCE=1(the adapter's test switch) from that directory. - Pipe any payload from the table above into the shipped gate exactly as Claude Code invokes it:
python loopx/claude_goal_mode/hooks/goal_policy.py < payload - Observe
rc=1, no decision on stdout, a traceback on stderr.
Expected behavior
Any event the hook cannot read is answered with an explicit decision — {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": ...}} — the same fail-closed rule the unreachable should_run probe already applies, so Claude Code blocks the call instead of proceeding without a gate. A valid event in a project where goal-mode is off must keep answering {} (defer to the normal permission flow).
Actual behavior
rc=1, no stdout decision, traceback on stderr; Claude Code reports the hook as a non-blocking error and the tool call continues.
Sanitized diagnostics
stdin b"{not json" -> rc=1, stdout empty
stderr: TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'NoneType'
stdin b"\xff\xfe{" -> rc=1, stdout empty
stderr: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Additional context
- Follow-up to #6166 (merged), which pinned the adapter's stdio and listed this as its named successor; the reproduction above is encoding-independent (the malformed-JSON and no-
cwdclasses fail on a UTF-8 host too). - The Claude Code hooks reference defines the exit-code contract used above (exit codes other than 0/2 are non-blocking errors) and also offers
onFailure: "block"per hook (Claude Code v2.1.295+), which the--hardenblock does not set. A hook-level deny is version-independent and takes effect for existing installs without re-running--harden. - AI disclosure: this report was drafted with AI assistance at the account owner's request, under their direction and review. The reproduction and raw outputs above are real runs of the shipped script.