Skip to content

fix(ha): reject malformed service responses - #904

Open
andriypolanski wants to merge 1 commit into
GeniePod:mainfrom
andriypolanski:fix/ha-malformed-service-response
Open

fix(ha): reject malformed service responses#904
andriypolanski wants to merge 1 commit into
GeniePod:mainfrom
andriypolanski:fix/ha-malformed-service-response

Conversation

@andriypolanski

@andriypolanski andriypolanski commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Home Assistant service calls treated every malformed non-empty response body as
Ok(Vec::new()). A proxy or malfunctioning Home Assistant instance could
therefore return 200 OK with truncated or invalid JSON and GenieClaw would
still announce success, record the physical action as executed, and add it to
the audit and undo history.

Reject malformed service-response JSON so transport success alone cannot be
mistaken for confirmed actuation success.

Changes

  • Remove the silent JSON-decoding fallback from HaClient::call_service.
  • Return a contextual error when a non-empty service response is not a JSON
    entity list.
  • Preserve compatibility with successful service calls that return an empty
    body.
  • Add a mock-server regression test for 200 OK with malformed JSON.

Real Behavior Proof

  • I have built and run the affected code locally.
  • I have verified the change end-to-end on Jetson hardware.
  • I have NOT verified on Jetson hardware, and I explain the validation gap
    below.

Tested profile / hardware:

  • jetson
  • raspberry_pi
  • portable_sbc
  • laptop
  • mac
  • CI-only / docs-only
  • Not run locally

What I ran

git diff --check

What I observed

  • git diff --check passes.
  • Rust tests were not run because this environment does not provide cargo.

Test Plan

  • Run cargo fmt --all -- --check.
  • Run cargo test -p genie-core ha::client.
  • Verify a valid JSON entity-list response succeeds.
  • Verify an empty successful response remains accepted.
  • Verify 200 OK with malformed JSON returns an error.
  • Verify a malformed response does not create an Executed audit or action
    ledger entry.
  • Verify a normal Home Assistant light action end-to-end.

Notes for Reviewers

  • HTTP status handling is unchanged; non-2xx responses were already rejected.
  • This change is intentionally limited to non-empty malformed service
    responses.
  • Errors propagate through the provider and dispatcher before success
    announcements, audit records, and undo history are created.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for malformed Home Assistant service responses.
    • Responses with a successful status but invalid JSON are now reported as errors instead of being treated as empty results.

@github-actions github-actions Bot added the bug Something isn't working label Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c4eeb560-58e0-4f0a-a84c-2dc65ee0083c

📥 Commits

Reviewing files that changed from the base of the PR and between 02a577d and f5e1637.

📒 Files selected for processing (1)
  • crates/genie-core/src/ha/client.rs

📝 Walkthrough

Walkthrough

HaClient::call_service now reports malformed JSON service responses as contextual errors rather than empty entity lists. A Tokio test verifies that an HTTP 200 response with a non-JSON body fails accordingly.

Changes

Home Assistant response validation

Layer / File(s) Summary
Service response error handling
crates/genie-core/src/ha/client.rs
call_service returns a contextual deserialization error when a successful response is not a JSON entity list, and a Tokio test verifies the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: rejecting malformed Home Assistant service responses.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant