Skip to content

fix(sdk): treat a JSON null hook reason as no reason - #6580

Merged
VascoSch92 merged 1 commit into
OpenHands:mainfrom
yftx293:fix/hook-null-reason
Nov 9, 2026
Merged

VascoSch92 merged 1 commit into
OpenHands:mainfrom
yftx293:fix/hook-null-reason

Conversation

@yftx293

@yftx293 yftx293 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

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

  • Treat a JSON null reason as "no reason" (None) in both parsers, keeping the string conversion for actual scalar values.
  • Port the pinned test test_null_reason_is_not_stringified from the worktree-test-edge-cases branch (commit f2fcf6e) without its xfail(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 existing python_command helper rather than a shell echo, 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

uv run pytest tests/sdk/hooks/test_executor.py -k null_reason

Before this change result.reason == "None"; after, it is None while the decision is still deny and 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 unpatched main. ruff check/format on the touched files are clean.

Type

  • Bug fix

Notes

None.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 null reason 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.
  • None is a valid value at every consumer: HookResult.reason and HookExecutionEvent.reason are str | None, _truncate_hook_log(None) returns None, get_blocking_reason skips falsy reasons, conversation_hooks falls back to "Blocked by hook", UserRejectObservation.rejection_reason is nullable, and the generated TypeScript schema declares reason?: string | null. No layer receives a type it did not already accept.
  • Regression test test_null_reason_is_not_stringified genuinely fails on the merge base (e4160d118, reason='None') and passes on this head; it uses the file's existing python_command helper, so it is Windows-safe (windows-latest CI passes).
  • uv run pytest tests/sdk/hooks/ → 153 passed on this head; ruff check/format and pre-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

@VascoSch92
VascoSch92 merged commit f2edde2 into OpenHands:main Nov 9, 2026
36 checks passed
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.

3 participants