Repository navigation
fix(sdk): treat a JSON null hook reason as no reason - #6580
Merged
Merged
Conversation
Closed
75 of 86 tasks
all-hands-bot
approved these changes
Nov 8, 2026
all-hands-bot
left a comment
Collaborator
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: In scope for this repository. The change is confined to SDK hook-output parsing (openhands-sdk/openhands/sdk/hooks/executor.py), which this repo owns per AGENTS.md, and it matches the linked issue #6348 sub-item "a JSON null reason is stringified to "None" instead of being treated as no reason" (issue currently open, labeled bug / priority:medium / ready-for-dev).
Verified on head f89e37a14:
- Both parsers now treat a JSON
nullreason as no reason:_parse_decision(prompt/agent hook path) and the command-hook stdout parser. Non-null values still stringify exactly as before, so there is no observable behavior change outside the reported bug. Noneis a valid value at every consumer:HookResult.reasonandHookExecutionEvent.reasonarestr | None,_truncate_hook_log(None)returnsNone,get_blocking_reasonskips falsy reasons,conversation_hooksfalls back to"Blocked by hook",UserRejectObservation.rejection_reasonis nullable, and the generated TypeScript schema declaresreason?: string | null. No layer receives a type it did not already accept.- Regression test
test_null_reason_is_not_stringifiedgenuinely fails on the merge base (e4160d118,reason='None') and passes on this head; it uses the file's existingpython_commandhelper, so it is Windows-safe (windows-latest CI passes). uv run pytest tests/sdk/hooks/→ 153 passed on this head;ruff check/formatandpre-commit(ruff, pycodestyle, pyright) clean on the touched files. All GitHub Actions checks pass on this exact head.
Non-blocking observation, out of this PR's claimed scope: the sibling field additionalContext on line ~601 still stringifies a JSON null to "None" — pre-existing on main, not part of the issue's menu item, and no blocker here.
✅ APPROVED
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.
HUMAN:
Fixed the null-reason handling from #6348. I reviewed the diff and the test; a hook that reports no reason must not tell the model the reason is "None".
AGENT:
Why
Both hook-output parsers did
str(data["reason"]). A hook that emits{"decision": "deny", "reason": null}therefore produced the string"None", which reaches the model as the stated reason for the block. The same conversion applied to the agent-hook path.Summary
nullreason as "no reason" (None) in both parsers, keeping the string conversion for actual scalar values.test_null_reason_is_not_stringifiedfrom theworktree-test-edge-casesbranch (commit f2fcf6e) without itsxfail(strict=True)marker, per the [Bug]: Edge-case tests expose ~70 bugs across the SDK, agent server, tools and workspaces #6348 menu's acceptance criteria. The test uses the file's existingpython_commandhelper rather than a shellecho, so it runs on Windows too.Issue Number
Part of #6348 (menu sub-item: "a JSON null reason is stringified to "None" instead of being treated as no reason")
How to Test
Before this change
result.reason == "None"; after, it isNonewhile the decision is stilldenyand the call is blocked.tests/sdk/hooks/is 152 passed with one pre-existing failure (test_string_decisions_still_parse), which fails the same way on unpatchedmain.ruff check/formaton the touched files are clean.Type
Notes
None.