Skip to content

fix(scenes): answer a failed routine execute with a JSON error and log it - #313

Merged
Lash-L merged 1 commit into
mainfrom
fix/scene-execute-json-error
Nov 29, 2026
Merged

Lash-L merged 1 commit into
mainfrom
fix/scene-execute-json-error

Conversation

@Lash-L

@Lash-L Lash-L commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

POST /user/scene/{id}/execute (build_execute in routes/user/scene/item.py) let any exception escape. A missing scene, a scene whose steps fail to parse, or any error while preparing the steps reached Starlette as a text/plain 500, and nothing was written to api_server.log because the request line is only logged after the route returns. Clients (python-roborock, the app, Home Assistant) expect the JSON envelope and check success.

Now the route catches the error, logs it to the API logger (api_server.log; a warning for RoutineExecutionError, a traceback for anything else) and returns the same error envelope routes/user/devices/jobs.py uses:

{"success": false, "code": 500, "msg": "...", "data": null, "result": null}

The vacuum is only contacted from the background routine task after this response, so whether the vacuum is online doesn't change any of this.

Context: on a Home Assistant setup running an older build, the "Night living room" routine returned a bare 500 on every run from early November. The cause was a non-UTF-8 line in decompiled_mqtt.jsonl that the zone-range lookup read as strict UTF-8. Current main already reads that file tolerantly, so that particular crash is gone. This PR makes sure the next failure in this route is visible and well-formed instead of an untraceable plain-text 500.

Proof that it works

Tested on:

  • Vacuum model: Qrevo MaxV 2 (a87). The routine shape in the tests is the real stored routine from that setup. Nothing was executed against the vacuum.
  • Firmware version: 02.34.04
  • Server version / commit: main (d09fb0f) + this change
  • Install method: tests only, not run on a vacuum

What I did and what happened:

tests/test_scene_execute_500.py (new, 4 tests):

  • the real routine with a non-UTF-8 line in the MQTT log still executes, and its zone ranges are filled from the good lines;
  • an unknown scene id returns a JSON success: false, not text/plain;
  • an unparseable scene returns a JSON success: false and starts no routine;
  • the failure is written to api_server.log. This test fails with a module-level logger, which writes nowhere the user can see.

Full suite: 884 passed.

Open question: I couldn't confirm which error code the real cloud uses for a failed execute, so this uses 500 in the envelope, as the other routes do.

Screenshots (required for any UI change)

No UI changes.

🤖 Generated with Claude Code

…g it

build_execute let any exception escape, so a missing scene, a scene that
fails to parse, or an error while preparing its steps reached Starlette
as a text/plain 500 with nothing in api_server.log. Clients expect the
JSON envelope and check "success".

Catch the error, log it (warning for RoutineExecutionError, traceback
otherwise) and return {"success": false, "code": 500, "msg": ...}.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 29, 2026 18:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Lash-L
Lash-L merged commit 455bce3 into main Nov 29, 2026
3 checks passed
Lash-L added a commit that referenced this pull request Nov 29, 2026
Bump the package to 1.3.0-rc2 and point the opt-in Beta add-on at it.
The v1.3.0-rc1 release build failed on a flaky test (fixed in #308), so
no rc1 image was published; rc2 replaces it and adds #312, #313 and
#314. The stable add-on stays on 1.2.1.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants