Skip to content

fix(web): don't validate double-sided settings when the feature is disabled - #422

Merged
ChuckBuilds merged 2 commits into
mainfrom
claude/double-sided-disabled-validation-uplvi6
Jul 28, 2026
Merged

fix(web): don't validate double-sided settings when the feature is disabled#422
ChuckBuilds merged 2 commits into
mainfrom
claude/double-sided-disabled-validation-uplvi6

Conversation

@ChuckBuilds

@ChuckBuilds ChuckBuilds commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Pull Request

Summary

Saving anything on the Display tab failed with a 400 Double-sided copies (2) must divide chain length (3) evenly while double-sided mode was off. The Display form posts every field in one request — including double_sided_copies (default 2) and double_sided_axis — regardless of the Enabled checkbox, and the server block was gated only on "is any double-sided field present in the payload": it wrote ds_config['enabled'] but never read it. A user with chain_length: 3 and the untouched default copies: 2 was locked out of saving any display setting — brightness, GPIO slowdown, Vegas, sync. This gates the checks on the enabled flag and tidies up two related UI problems visible in the same console log.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor (no functional change)
  • Build / CI
  • Plugin work (link to the plugin)

Related issues

None filed — reported directly with the browser console output showing the 400 alongside a green "Display settings saved" toast.

What changed

web_interface/blueprints/api_v3.py — read enabled first, then branch:

  • Divisibility against chain_length / parallel is a hardware-relational check and now only runs when the feature is on. This is the check that produced the reported error.
  • Structural checks (copies parses as an int in 2–8, axis in the whitelist) still return 400 when enabled. When disabled they drop the offending value and leave the stored one untouched, so the save succeeds and the config stays well-formed.
  • Error message strings and the effective_axis resolution are unchanged; the two divisibility branches moved into a small local helper returning the message or None.

The runtime was already correct — _resolve_double_sided() returns None immediately when disabled (src/display_manager.py:109), so nothing is composited or wrapped. No change there.

web_interface/templates/v3/partials/display.html

  • Copies / Split Axis are hidden until Enabled is ticked, mirroring the existing Vegas Scroll Mode toggle. Hidden rather than disabled on purpose: disabled inputs aren't submitted, and if all three keys vanished from the payload the server block would be skipped entirely and a previously-enabled config would never be flipped to false.
  • Fixed the save toast. The form's handler read xhr.responseJSON — a jQuery property that does not exist on a native XMLHttpRequest — so it was always undefined and every save fired a green "Display settings saved", including the 400s. It now parses responseText and uses the real status code.

Test plan

  • Ran on a real Raspberry Pi with hardware
  • Ran in emulator mode (EMULATOR=true python3 run.py)
  • Ran the dev preview server (scripts/dev_server.py)
  • Ran the test suite (pytest)
  • Manually verified the affected code path in the web UI

pytest test/ --ignore=test/plugins1071 passed, 1 skipped. Two failures in test/web_interface/test_state_reconciliation.py are pre-existing — they fail identically on a clean checkout of main.

Two existing double-sided tests were asserting 200 on payloads that the divisibility check (added later, in #373) turns into 400s, so they were failing before this change:

  • test_save_double_sided_settings posted copies=2, axis=vertical against a fixture with no display.hardware, so parallel fell back to 1 and 1 % 2 != 0. It now supplies matching hardware values in the test rather than editing the shared fixture.
  • test_save_double_sided_unchecked_disables posted copies=4 with chain_length defaulting to 2. It passes as written now that a disabled save skips the check.

Added three tests: the reported regression (disabled + copies=2 + chain_length=3 → 200), unparseable/unknown values while disabled (→ 200, stored values untouched), and the check still firing when enabled (→ 400).

Not automated, worth a manual pass: toggling the Enabled checkbox shows/hides the two fields, and a failed save now shows a single red toast with no accompanying green one.

Documentation

  • I updated README.md if user-facing behavior changed
  • I updated the relevant doc in docs/ if developer behavior changed
  • I added/updated docstrings on new public functions
  • N/A — no docs needed

Plugin compatibility

  • No plugin breakage expected
  • Some plugins will need updates — listed below
  • N/A — change doesn't touch the plugin system

Plugins see the logical per-screen size through _LogicalMatrix, and that path is unchanged.

Checklist

  • My commits follow the message convention in CONTRIBUTING.md
  • I read CONTRIBUTING.md and CODE_OF_CONDUCT.md
  • I've not committed any secrets or hardcoded API keys
  • If this adds a new config key, the form in the web UI was verified — no new keys; display.double_sided is unchanged in shape

Notes for reviewer

Two divisibility rules disagree, and I left them that way. The API validates against panel counts (chain_length / parallel) while the runtime validates against physical pixels (cols*chain_length, rows*parallel, display_manager.py:128-143). So chain_length=3, copies=2 is rejected by the API but the runtime would accept it — 192 px / 2 gives a 96 px logical screen spanning 1.5 panels. The API's rule is the stricter and more physically meaningful one, so I kept both as they are, but it's worth a second opinion on whether they should be unified.

The duplicate toast is still there. web_interface/static/v3/app.js:41-51 has a global htmx:afterRequest listener that already parses responseText correctly, so any response carrying a message now produces two toasts. Repairing the form handler in place rather than deleting it was a deliberate call — it's still the only thing that reports 2xx responses whose body has no message — but deleting it would collapse both toasts into one if you'd prefer that.

The same responseJSON bug lives elsewhere. web_interface/templates/v3/partials/durations.html:14 has the identical handler, and web_interface/static/v3/js/app-shell.js reads xhr.responseJSON in four places. Left alone to keep this diff scoped to the reported issue.


Generated by Claude Code

Summary by CodeRabbit

  • New Features

    • Added clearer controls for enabling and configuring double-sided displays.
    • Double-sided settings are now shown or hidden automatically based on the selected option.
  • Bug Fixes

    • Disabled double-sided mode no longer blocks saving because of invalid or mismatched settings.
    • Enabled mode now validates copies against the display’s hardware dimensions.
    • Invalid disabled-mode values no longer overwrite previously saved settings.
    • Improved save notifications for success and error responses.

…sabled

Saving anything on the Display tab failed with a 400 when double-sided
mode was off:

    Double-sided copies (2) must divide chain length (3) evenly

The Display form posts every field in one request, including
double_sided_copies (default 2) and double_sided_axis, whether or not
the Enabled checkbox is ticked. The server block was gated only on "is
any double-sided field present in the payload" — it wrote
ds_config['enabled'] but never read it. A user with chain_length: 3 and
the untouched default copies: 2 was locked out of saving any display
setting at all: brightness, GPIO slowdown, Vegas, sync.

Gate the checks on the enabled flag:

- Divisibility against chain_length/parallel is hardware-relational and
  only runs when the feature is on.
- Structural checks (copies parses as an int in 2..8, axis in the
  whitelist) still 400 when enabled; when disabled they drop the value
  and leave the stored one untouched rather than rejecting the save.

The runtime already gated correctly (_resolve_double_sided returns None
when disabled), so nothing there changes.

Also in the Display tab:

- Hide Copies / Split Axis until Enabled is ticked, mirroring the Vegas
  Scroll pattern. Hidden rather than disabled, so the fields keep
  submitting and the server still sees an 'off' state to persist.
- Fix the save toast: the form's handler read xhr.responseJSON, a jQuery
  property that doesn't exist on a native XMLHttpRequest, so it was
  always undefined and every save reported a green "Display settings
  saved" — even the 400s. Parse responseText and use the real status.

Tests: two existing double-sided tests asserted 200 on payloads that the
divisibility check (added later, in #373) turns into 400s; the first now
supplies matching hardware values and the second passes as written now
that a disabled save skips the check. Added coverage for the reported
regression, for bad values while disabled, and for the check still
firing when enabled.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016aUvzTXpEYhNEWYQvFqQU9
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ChuckBuilds, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a0bf9726-89b8-4c0c-bbbd-b4088dc53e4a

📥 Commits

Reviewing files that changed from the base of the PR and between b7f5f84 and b67f9e4.

📒 Files selected for processing (3)
  • test/test_web_api.py
  • web_interface/blueprints/api_v3.py
  • web_interface/templates/v3/partials/display.html
📝 Walkthrough

Walkthrough

The API now validates double-sided copies and axis only when enabled, while preserving stored values for invalid disabled-mode inputs. The display form conditionally shows dependent settings, uses improved save-result handling, and adds tests for the updated behavior.

Changes

Double-Sided Configuration

Layer / File(s) Summary
Conditional API validation
web_interface/blueprints/api_v3.py
The endpoint gates copies and axis validation on the enabled state, checks copies against the selected hardware dimension, and preserves stored values for invalid disabled-mode input.
Display form behavior
web_interface/templates/v3/partials/display.html
The form hides dependent double-sided settings when disabled, toggles their visibility client-side, and derives save notifications from HTTP responses.
Validation regression coverage
test/test_web_api.py
Tests cover disabled-mode tolerance, enabled-mode divisibility rejection, hardware dimensions, and preservation of existing values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant save_main_config
  participant ConfigManager
  Browser->>save_main_config: Submit display settings
  save_main_config->>save_main_config: Coerce enabled state
  save_main_config->>save_main_config: Validate copies and axis if enabled
  save_main_config->>ConfigManager: Save accepted configuration
  ConfigManager-->>save_main_config: Save result
  save_main_config-->>Browser: HTTP response
  Browser->>Browser: Show save notification
Loading

Possibly related PRs

🚥 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 summarizes the main change: skipping double-sided validation when the feature is disabled.
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
  • Commit unit tests in branch claude/double-sided-disabled-validation-uplvi6

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
web_interface/blueprints/api_v3.py (1)

874-888: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add type annotations to the validation helper.

Annotate copies and the optional error-string return type to satisfy the project’s Python typing requirement. As per coding guidelines, “Use type hints for function parameters and return values.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web_interface/blueprints/api_v3.py` around lines 874 - 888, Add type
annotations to the nested _copies_fits_hardware helper: annotate copies as an
integer and its return value as an optional string, preserving the existing
validation logic and None/error-message behavior.

Source: Coding guidelines

test/test_web_api.py (1)

208-226: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a vertical-axis divisibility regression test.

This only proves horizontal validation uses chain_length. Add a case with chain_length=2, parallel=3, copies=2, and axis=vertical, expecting HTTP 400 and an error mentioning parallel; otherwise a dimension mix-up in the vertical branch would pass coverage. As per coding guidelines, “Test edge cases including empty data, API failures, and configuration errors.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/test_web_api.py` around lines 208 - 226, Add a regression test alongside
test_save_double_sided_enabled_enforces_divisibility using chain_length=2,
parallel=3, double_sided_copies=2, and double_sided_axis=vertical. Post to
/api/v3/config/main and assert HTTP 400, an error message mentioning parallel,
and that mock_config_manager.save_config_atomic was not called.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web_interface/templates/v3/partials/display.html`:
- Around line 617-627: Update window.showDisplaySaveResult so status is
successful only when xhr.status is within the 2xx range; treat status 0 and all
other non-2xx responses as errors. Prevent data.status from overriding this
error verdict, while preserving JSON message handling and allowing valid 2xx
responses to use the server-provided status.

---

Nitpick comments:
In `@test/test_web_api.py`:
- Around line 208-226: Add a regression test alongside
test_save_double_sided_enabled_enforces_divisibility using chain_length=2,
parallel=3, double_sided_copies=2, and double_sided_axis=vertical. Post to
/api/v3/config/main and assert HTTP 400, an error message mentioning parallel,
and that mock_config_manager.save_config_atomic was not called.

In `@web_interface/blueprints/api_v3.py`:
- Around line 874-888: Add type annotations to the nested _copies_fits_hardware
helper: annotate copies as an integer and its return value as an optional
string, preserving the existing validation logic and None/error-message
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b40098fe-3e76-4aa7-87a5-60199e429295

📥 Commits

Reviewing files that changed from the base of the PR and between 3872a68 and b7f5f84.

📒 Files selected for processing (3)
  • test/test_web_api.py
  • web_interface/blueprints/api_v3.py
  • web_interface/templates/v3/partials/display.html

Comment thread web_interface/templates/v3/partials/display.html
Review feedback on #422.

- showDisplaySaveResult tested `xhr.status >= 400` for failure, so a
  network error — which reports status 0 — was waved through as
  "Display settings saved". That's the same class of false-success bug
  this branch set out to fix. Test the 2xx range instead, and let a
  response body refine a successful verdict without overturning a
  failed one.
- Annotate the _copies_fits_hardware helper, matching the annotated
  helpers already in api_v3.py.
- Cover the vertical divisibility branch: chain_length 2 would divide
  evenly, so only parallel 3 can produce the rejection, which pins the
  branch to the right hardware dimension.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016aUvzTXpEYhNEWYQvFqQU9
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@ChuckBuilds
ChuckBuilds merged commit e2acbfb into main Jul 28, 2026
12 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.

2 participants