Repository navigation
fix(sdk): treat a non-string hook decision as no decision - #4773
Conversation
A command hook that exits 0 and prints {"decision": null} came back as a
failure:
HookResult(success=False, exit_code=-1,
error="Hook execution failed: 'NoneType' object has no attribute 'lower'")
JSON null parses to None and .lower() was called on it. Only
JSONDecodeError is caught around that block, so the AttributeError
reached the outer handler, which discarded the captured subprocess result
and reported a synthetic exit -1 for a process that had exited 0.
It is not specific to null: {"decision": 1} fails the same way with
'int' object has no attribute 'lower'.
Check for a string instead, so any other shape means the hook expressed
no decision. The agent-hook path already went through str() for the same
reason.
Closes OpenHands#4766
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
⏳ Review waiting on checksThe current head
No action is needed. The scheduled scan retries once every check on the head reports a conclusion. This is an automated check - no AI was used to generate this comment. |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope
This is an SDK bug fix in openhands-sdk/openhands/sdk/hooks/executor.py, which this repository owns. No product/architecture decision is needed.
What I verified
- Root cause is real. On the base commit, a command hook that exits 0 and emits
{"decision": null}(or any non-string) raisedAttributeErroron.lower(); onlyJSONDecodeErrorwas caught, so the outerexcept Exceptiondiscarded the captured subprocess result and returnedsuccess=False, exit_code=-1. - Fix behaves as claimed on head (
1be3a67a). Running the PR's repro shows{"decision": null}and{"decision": 1}now returnsuccess=True, exit_code=0, decision=None, while{"decision": "allow"}/"deny"still map toHookDecision.ALLOW/HookDecision.DENY(deny still setsblocked=True). - Tests. The 3 new tests pass; the full
tests/sdk/hooks/suite on head is 145 passed / 1 failed, and that one failure (TestAsyncHookExecution::test_execute_async_hook_process_tracked) reproduces identically on the base commit6a1e4d0f— a pre-existing flake unrelated to this diff. The extra async failures I saw in one local run did not reproduce on the base or in CI and are likewise unrelated. - CI. All check runs on head
1be3a67aaresuccess/skipped(53 runs), includingsdk-tests,pre-commit,coverage-report,windows-tests, andintegration-test.
Notes (non-blocking)
_parse_decision (agent/prompt hooks) uses str(data.get("decision", "")).lower(), so null there becomes "None", an invalid decision that falls open with success=False. The command path now treats the same payload as success=True, decision=None. That asymmetry predates this PR and is consistent with the command path's existing handling of a missing decision key, so it does not block this change — but it is worth keeping in mind if HookResult.success semantics are ever unified across hook types.
No material issues found. The change is minimal, matches the command-hook exit-code contract documented on HookResult, and preserves decision parsing.
✅ APPROVED
Co-authored-by: openhands <openhands@all-hands.dev>
neubig
left a comment
There was a problem hiding this comment.
This review was submitted by an AI agent (OpenHands) on behalf of @neubig.
The issue is valid and the implementation is the narrowest correct fix: command-hook decision is optional, non-string values now mean no decision, and the actual subprocess success, exit code, stdout, and stderr are preserved. Existing allow/deny behavior remains unchanged.
I also simplified the redundant historical commentary in commit 9aea74cd; no behavior or assertions changed. Focused verification on the updated head passed: 58 hook-executor tests, Ruff lint, Ruff formatting, and git diff --check.
Approved for merge.
|
Thanks @neubig. The red pre-commit isn't the change: the baseline check runs |
HUMAN:
Ran a hook printing {"decision": null} and one printing a number; both now come back as no decision with the real exit code instead of a synthetic -1.
AGENT:
Why
A command hook that exits 0 and prints
{"decision": null}came back as a failure:JSON
nullparses toNoneand.lower()was called on it. OnlyJSONDecodeErroris caught around that block, so theAttributeErrorreached the outer handler, which discarded the captured subprocess result and reported a synthetic exit-1for a process that had exited 0.It is not specific to
null— any non-string fails the same way:Summary
executor.py:416already goes throughstr()for the same reason; this is the sibling that did not.I left the
except json.JSONDecodeErroras it is. Widening it would hide the next bug of this kind rather than fix it; the point here is not to raise.Issue Number
Closes #4766
How to Test
On this branch all three come back
success=True exit=0, withHookDecision.ALLOWonly for the string.Two of the three new tests fail on
main:Video/Screenshots
Not applicable — no GUI surface; the console output above is the evidence.
Design Doc
Not added; the change is one type check.