Skip to content

fix(sections): row preview explains a rejected config, not a 500 - #5686

Open
darthShadow wants to merge 1 commit into
Silo-Server:mainfrom
darthShadow:fix/section-preview-validation
Open

darthShadow wants to merge 1 commit into
Silo-Server:mainfrom
darthShadow:fix/section-preview-validation

Conversation

@darthShadow

@darthShadow darthShadow commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none changed. The change reaches #1140 C1 and #1141 C1 (rows created through the admin API and the web row builder). The rows those cases added still save and preview as before; only a config that saving rejects now gets a 422 from the preview.
Depends on: Silo-Server/silo-translations#206 (the new string), which merges first.

Other clients: N/A (the admin row preview and its form are web-only; the new message text reaches other clients only through the existing validation problem)

In the web admin's Add row and Edit row forms, the live preview answered 500 for a row config that saving rejects, such as a Smart row sorted by random or a last_air_date rule whose value is not a date. The form then said "The preview didn't load. The row still saves.", which was wrong: saving that row fails. The preview now runs the same config check as saving and shows the server's reason, for example "The preview can't show this row: sort.field is not supported". The shipped "New in 4K" preset, which the save check also rejected, now saves and previews.

This affects administrators building Home and library rows, and any client calling previewAdminSection.

Approach

  • previewAdminSection runs validateSectionConfig, the check single-row creation runs, before any query. A rejected config gets the same 422 validation_failed problem that saving returns.
  • validateSectionConfig parsed every row's config as a query definition. For row types whose config holds the recipe's own parameters, that parse read "New in 4K"'s {"format":"4k","sort":"recent"} as a legacy query sort and rejected it. sections.ReadsQueryDefinition now names the row types that read a query definition, and the other types leave their config to the recipe's check, which creation, bulk creation and edits already run.
  • Validator, decoder and recipe messages no longer repeat the value they rejected, as docs/architecture/api-contract.md requires ("Rejected values are never echoed."). They name the key or the position instead, and a rejected duration says which form is accepted. A seasonal theme key still appears in a message, but only after it matched the theme catalog exactly.
  • The web row form shows a 422 validation_failed in its own state with the new string web.home.addRow.preview.rejected. Any other failure keeps the generic message. In a translated interface the reason is the translated field-error text, as for other v2 problems.
  • docs/architecture/api-contract.md and docs/catalog-api.md now say the preview runs the save checks, including the rule that an administrator row of collections lists server collections only.

The three parts ship together because the preview now runs the save check: that put the check's messages in front of the administrator and made "New in 4K" fail in the same form. Saving keeps its statuses, problem types and field codes, and only its message text changes. The preview answers 422 where it answered 500.

Validation

  • Handler tests: the preview rejects a random sort and a non-date last_air_date value before any query runs, without repeating the value, and still previews a valid Smart row; every format_showcase preset passes the save check and "New in 4K" previews; row types that read a query definition still reject {"sort":"recent"}. All pass with this change. The rejection and preset tests fail on main. The "New in 4K" preview test fails when the preview runs the save check without the fix for row types that hold recipe parameters. The query-definition test passes on both, as a guard.
  • Message tests: the query-definition parser (9 cases) and every recipe's validator and parameter decoder (45 subtests) reject bad input without the rejected value in the message. Both failed on main and pass now.
  • Web: a row form test shows the server's reason for a 422 validation_failed, without "The row still saves", and the generic message for any other failure. It failed with main's row preview code and passes now.
  • Not covered by a test: the path from the handler's 400 through the v2 problem mapper to the text in the form. The captures below show that path on a running server.
  • Environment: a containerized build against a migrated PostgreSQL 18 database.
  • The full check list in CONTRIBUTING.md "Validate your change" passes: build, vet, gofmt, lint-changed, Go tests with PostgreSQL, contract, generated-file and migration checks, web lint, format, build, budget and tests.
  • Not run: make verify-actionlint, make verify-shellcheck and make verify-prometheus-rules. The change touches no workflow, shell script or Prometheus rule.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-5686/

Each pair shows the same screen with the same empty library: Before is main at 8fcf75f, After is a Silo build of this branch, both in Admin > Libraries > Home Sections > Add row.

  • Smart row preview for a rejected config, desktop and phone width. Before: "The preview didn't load. The row still saves." After: "The preview can't show this row: sort.field is not supported".
  • Saving the "New in 4K" preset. Before: saving fails with sort.field "recent" is not supported. After: the row saves and appears on Home. The preset's preview works in both builds; the after set includes it.
  • After only: the same rejected preview under the en-XA pseudo-locale. The new string is translated, and the reason is the translated generic field-error text, as the web app shows for any v2 field error in a non-English interface.

The web form offers no random sort. For the rejected-preview captures I patched the page's fetch to send sort.field: "random" in the preview request; the status (500 before, 422 after) and the reason came from the real server.

Risks

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: T3 Code running Claude Code and Codex
  • Tool(s): Claude Code, Codex, agent-browser (captures)
  • Model(s): claude-opus-5-5, claude-sonnet-5-5, gpt-6.2-sol
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Claude Opus 5.5 and GPT-6.2 Sol reviewers read the preview change against the save path and the API contract. They found that the form told an administrator a rejected draft still saves, that the 422 repeated the rejected value, and that the API docs did not say the preview runs the save check; all three are fixed here. Claude Sonnet 5.5 verifiers then checked each fix against the tests. They found recipe messages that still repeated rejected values, and that the preview would now reject "New in 4K" as saving already did; both are fixed here too.

The admin Smart-row preview skipped the config check that saving a row
runs, so a config that save rejects (a random sort, a last_air_date rule
whose value is not a date) failed inside the fetcher as a 500. Preview
now runs validateSectionConfig and answers the same validation error
before any query runs.

validateSectionConfig parsed every row's config as a query definition.
A row whose config is its recipe's own parameters, such as the shipped
"New in 4K" preset's {"sort":"recent"}, read as a legacy query sort and
could be neither saved nor previewed. sections.ReadsQueryDefinition now
names the row types that read a query definition; the other types leave
their config to the recipe.

Validator, decoder and recipe messages no longer repeat the value they
rejected, as docs/architecture/api-contract.md requires ("Rejected
values are never echoed."). They name the key or the position instead,
and a rejected duration says which form is accepted. A shared
decodeParams helper gives every recipe the same decode error, in place
of the JSON decoder's text, which carries the rejected number and Go
type names. A seasonal theme key still appears in a message, but only
after it matched the catalog exactly.

The web Add and Edit row preview shows the server's reason in its own
state (web.home.addRow.preview.rejected) instead of the generic "The row
still saves" failure. Other failures keep the generic message.

Signed-off-by: Anagh Kumar Baranwal <6824881+darthShadow@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Codex (gpt-6.2-sol) <noreply@openai.com>
@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Nov 30, 2026
@silo-kody

silo-kody Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish labels Nov 30, 2026
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The change sanitizes recipe and query-configuration validation errors, applies section configuration checks during administrator previews, and displays validation rejection reasons in the row preview UI. It also updates API documentation and translation entries.

Changes: Section validation and preview errors

Layer / File(s) Summary
Query configuration errors
internal/catalog/query_builder.go, internal/catalog/query_definition.go, internal/catalog/section_config.go, internal/catalog/section_config_test.go
Query-definition parsing now returns sanitized errors for invalid fields, operators, durations, and configuration values. Tests check that errors omit rejected values while retaining relevant keys or paths.
Recipe configuration errors
internal/sections/recipes/*, internal/sections/recipes/validate_errors_test.go
Recipe validators use shared parameter decoding and no longer include rejected values in several validation errors. Tests cover invalid settings, parameter types, and malformed JSON.
Administrator preview validation
internal/sections/types.go, internal/api/handlers/admin_sections_service.go, internal/api/handlers/sections.go, internal/api/handlers/sections_test.go, docs/architecture/api-contract.md, docs/catalog-api.md
Query-definition parsing is limited to section types identified as readers. Administrator previews validate recipe and section configuration before fetching. Tests and API documentation cover the validation behavior.
Preview rejection display
web/src/hooks/queries/homeRows/useRowPreview.ts, web/src/components/homeRows/addRow/RowPreview.tsx, web/src/components/homeRows/addRow/RowPreview.test.tsx, web/src/locales/*, web/src/locales/keys.ts, .silo-translations
The preview hook maps qualifying validation failures to a rejection state. The UI displays the server reason with a new translated message; tests cover rejection and generic error states.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant previewAdminSection
  participant RecipeValidator
  participant validateSectionConfig
  participant ParseQueryDefinition
  participant PreviewFetcher
  previewAdminSection->>RecipeValidator: validate recipe configuration
  RecipeValidator-->>previewAdminSection: validation result
  previewAdminSection->>validateSectionConfig: validate section configuration
  validateSectionConfig->>ParseQueryDefinition: parse config for query-reading section types
  ParseQueryDefinition-->>validateSectionConfig: parse result
  validateSectionConfig-->>previewAdminSection: validation result
  previewAdminSection->>PreviewFetcher: fetch preview when validation passes
Loading

Suggested reviewers: quick104, rhainland

Merge Risk: Moderate · up to e625a

Rejected row previews will probably show a generic "Some values aren't valid" message instead of the specific reason, which defeats the purpose of this change. The translation catalog is also pinned to a local build and must be re-synced to a published release once silo-translations#206 merges.

Security architecture risk: Low · up to e625a

Invalid drafts are rejected before previewing, without granting additional access. The main risk is rollback: a row saved with the newly accepted preset can no longer be disabled on the older version unless its configuration is also changed.

Retained concerns

  • Trivial · reliability · inferred: After rollback to the base version, a disable-only edit of a newly saved New in 4K row fails before persistence. The older update path validates the retained configuration as a query definition on every edit, even when only the enabled flag changes. To take the row out of service after rollback, an administrator must supply a base-compatible configuration in the same update or delete the row.

View findings in the submitted review

Security review details

Security Blast Radius

  • observed — The inspected route runs with acting-admin authority. Invalid drafts now terminate before the catalog fetch, while drafts that pass validation use the same context-derived identity and access filter as before.

Trust Boundaries and Controls

  • observed — Request-supplied section type and configuration are checked before preview execution. Library ID parsing and caller-derived catalog filtering remain separate from those configuration checks; the new validation branch does not grant authority.

Hardening Proposals

  • proposed — Document how to disable or replace newly accepted rows before a downgrade, and exercise that recovery path with a saved New in 4K row.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: admin row preview now reports a rejected row config (422 validation_failed with the server's reason) instead of a 500 with a generic message. The changeset matches thi…
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.
Description check Passed The description states the problem (the web admin row preview returns 500 for configs that saving rejects), the approach (preview runs validateSectionConfig, ReadsQueryDefinition, message changes, API…
Full details: Title check

Explanation

The title names the main change: admin row preview now reports a rejected row config (422 validation_failed with the server's reason) instead of a 500 with a generic message. The changeset matches this: previewAdminSection runs validateSectionConfig, the web form gets a new rejected state, and recipe error messages were reworked. The title follows the fix(sections) convention and is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description states the problem (the web admin row preview returns 500 for configs that saving rejects), the approach (preview runs validateSectionConfig, ReadsQueryDefinition, message changes, API doc updates), validation steps, evidence, and risks. It relates directly to the changeset, so it is not off-topic or vague.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

Architecture findings (1)

Advisory architecture findings (1)

  • Trivial — After rollback to the base version, a disable-only edit of a newly saved New in 4K row fails before persistence. The older update path validates the retained configuration as a query definition on every edit, even when only the enabled flag changes. To take the row out of service after rollback, an administrator must supply a base-compatible configuration in the same update or delete the row.
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6b10a140-6a4c-4af2-8120-374d75b9e091
Commits

Reviewing files that changed from the base of the PR and between a78b690 and e625a40.

Files selected for processing: 32

  • .silo-translations
  • docs/architecture/api-contract.md
  • docs/catalog-api.md
  • internal/api/handlers/admin_sections_service.go
  • internal/api/handlers/sections.go
  • internal/api/handlers/sections_test.go
  • internal/catalog/query_builder.go
  • internal/catalog/query_definition.go
  • internal/catalog/section_config.go
  • internal/catalog/section_config_test.go
  • internal/sections/recipes/admin_curated_list.go
  • internal/sections/recipes/collection_posters.go
  • internal/sections/recipes/custom.go
  • internal/sections/recipes/discovery.go
  • internal/sections/recipes/editorial.go
  • internal/sections/recipes/hand_picked.go
  • internal/sections/recipes/library_staples.go
  • internal/sections/recipes/mood.go
  • internal/sections/recipes/personalized.go
  • internal/sections/recipes/seasonal.go
  • internal/sections/recipes/social.go
  • internal/sections/recipes/trending_discover.go
  • internal/sections/recipes/types.go
  • internal/sections/recipes/validate_errors_test.go
  • internal/sections/types.go
  • web/src/components/homeRows/addRow/RowPreview.test.tsx
  • web/src/components/homeRows/addRow/RowPreview.tsx
  • web/src/hooks/queries/homeRows/useRowPreview.ts
  • web/src/locales/ar-XB.json
  • web/src/locales/en-XA.json
  • web/src/locales/en.json
  • web/src/locales/keys.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment on lines +29 to +44
/**
* A 422 `validation_failed` is the server saying why it cannot preview this
* draft. Any other failure says nothing about the row itself.
*/
function previewFailure(error: unknown): PreviewState {
if (
error instanceof V2ProblemError &&
error.status === 422 &&
error.problemType === "validation_failed"
) {
const reason = error.message.trim();
if (reason) return { status: "rejected", reason };
}
return { status: "error" };
}

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.

Major · Functional Correctness · Quick win

Read the server reason from errors[0].detail in previewFailure.

For a 422 validation_failed, error.message is the localized catalog sentence for error.validation_failed, not the server reason. The server sends the reason in errors[0].detail, and problemDisplayText does not use it. The row form therefore shows "Some values aren’t valid. Check them and try again." instead of the rejected config's reason.

Read the first field error's detail instead. If it is absent, keep the generic error state. The RowPreview test fixture also needs an errors entry so that it exercises the production shape.

Suggested fix

   if (
     error instanceof V2ProblemError &&
     error.status === 422 &&
     error.problemType === "validation_failed"
   ) {
-    const reason = error.message.trim();
+    const reason = error.problem.errors?.[0]?.detail?.trim();
     if (reason) return { status: "rejected", reason };
   }
Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
/**
* A 422 `validation_failed` is the server saying why it cannot preview this
* draft. Any other failure says nothing about the row itself.
*/
function previewFailure(error: unknown): PreviewState {
if (
error instanceof V2ProblemError &&
error.status === 422 &&
error.problemType === "validation_failed"
) {
const reason = error.message.trim();
if (reason) return { status: "rejected", reason };
}
return { status: "error" };
}
/**
* A 422 `validation_failed` is the server saying why it cannot preview this
* draft. Any other failure says nothing about the row itself.
*/
function previewFailure(error: unknown): PreviewState {
if (
error instanceof V2ProblemError &&
error.status === 422 &&
error.problemType === "validation_failed"
) {
const reason = error.problem.errors?.[0]?.detail?.trim();
if (reason) return { status: "rejected", reason };
}
return { status: "error" };
}

"value": "rule"
}
],
"web.home.addRow.preview.rejected": [

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.

Major · Data Integrity & Integration · Heavy lift

Pin the locale catalog to the published translation release.

.silo-translations pins version=local-d9cca058cc1a-dirty with sha256=-. The locale files, including web.home.addRow.preview.rejected in web/src/locales/ar-XB.json, come from that uncommitted local build. The PR requires re-syncing these files to the published silo-translations release that includes #206.

Until the pin names a published release, scripts/sync-translations cannot reinstall this state; the script stops at its local-build guard. Once a release is pinned, the next sync rebuilds the locale files from that release. If the release lacks web.home.addRow.preview.rejected, the key is dropped and the web typecheck can fail.

After #206 publishes, run scripts/sync-translations --version <release> and commit the regenerated locale files, keys.ts, and .silo-translations. Confirm the new key is present in the release before syncing.

Source: Coding guidelines

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

Labels

bug Something isn't working impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish size/XL 500–999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant