Skip to content

fix(apiv2): answer invalid monitor options with 422 at the member - #4159

Merged
Quick104 merged 1 commit into
mainfrom
fix/subscription-options-422-validation
Nov 14, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/subscription-options-422-validation

Conversation

@Quick104

@Quick104 Quick104 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

Other clients: Apple N/A (treats any non-200 from monitor create and edit as a failure and does not branch on the status); Android N/A (does not call the monitor routes, and its download creation does not branch on 400); Roku N/A (no downloads); Web N/A (does not call these routes)

Creating or editing a series monitor with an invalid option returns 400 malformed_request with no errors[], so a client can't tell which field to fix. The downloads contract says an invalid subscription option is 422 validation_failed with errors[].location naming the member, and that malformed_request is for malformed JSON only. This change makes the monitor routes answer that way.

The affected requests to POST /api/v2/downloads/subscriptions and PATCH /api/v2/downloads/subscriptions/{id}:

  • mode: "specific_seasons" with no season_numbers, on create or on an edit that switches to that mode
  • a season_numbers entry below 0 or above 9999 (the schema has no per-item bound)
  • an unknown mode on edit (the patch body's mode has no schema enum; create's does)
  • a series_id that names an item that is not a series, on create

POST /api/v2/downloads with series: true for an item that is not a series had the same 400 and now gets the same 422 at content_id.

Found in review of #4074.

Approach

subscriptionMutationProblem now maps each downloads error to a validation failure at its member:

Error Location Code
ErrInvalidSubscriptionMode body.mode invalid_enum
ErrSeasonsRequired body.season_numbers required
ErrInvalidSeasonNumbers body.season_numbers out_of_range
ErrNotSeries body.series_id invalid

An unknown mode on edit gets the same code and detail that create's schema enum returns, and the test checks that the two match. downloadCreationProblem maps ErrNotSeries to body.content_id the same way, so both download operations answer the same error alike.

Adding the enum to the patch body's mode schema would also catch an unknown mode, but it changes the generated contract that #3535 is editing, and the service check would still be needed. The OpenAPI already declares 422 for all three operations, so the contract artifacts don't change.

Validation

  • The new transport test cases fail on main with status = 400, want 422 and pass on this branch.
  • Focused tests: go test ./internal/apiv2/... ./internal/downloads/... pass.
  • go build ./..., go vet, gofmt, go mod tidy -diff, make lint-changed (0 issues), and make lint-router-recovery pass.
  • verify-apiv2-openapi, verify-apiv2-contract (no contract diff), verify-route-inventory, verify-apiv2-fixtures, TestCommittedArtifactMatchesRouter, verify-size-ratchet, and verify-local-paths pass.
  • make test-go: passes except two tests that run the local FFmpeg (TestRunStatsWithRealFFmpeg, TestCopyRemuxSubtitleRenditionRealFFmpeg). Both fail the same way on unmodified main on the test host.
  • Not reproduced live: the dev sandbox for this change failed to start. The defect is shown from the service code, where prepareSubscription and applySubscriptionPatch return these errors, and by the handler tests above.

Evidence

Trimmed test runs on the base and the branch, with the trigger-to-response table.

Evidence: https://evidence.siloserver.org/r/silo-server/monitor-options-422/

Risks

A client that branched on 400 for these requests would now take its 422 path. The Apple, Android, and web callers were checked and none branch on it. The status already matches what the downloads contract documents.

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: Claude Code (in T3 Code)
  • Tool(s): Claude Code subagents for code review
  • Model(s): claude-opus-5-5 (implementation and review); claude-sonnet-5-5 (cleanup review angle)
  • Involvement: Fully AI-generated (not yet human verified)
  • Adversarial review: /silo code review at high effort (three finders). It removed a test case that checked an edit response for an error the edit path cannot return. The plan round was skipped because the fix is mechanical: the defect is in a few mapping lines and adds nothing. A simplify pass aligned one error detail. A background adversarial review (gpt-6.1-sol, reviewed 11c9c4d) found nothing.

🤖 Generated with Claude Code

Monitor create and edit answered an invalid mode, missing or out-of-range
season_numbers, or a series_id that names a non-series item with 400
malformed_request and no errors[]. docs/downloads-api.md maps an invalid
subscription option to 422 validation_failed with errors[].location naming
the member, and malformed_request to malformed JSON only.

Map each downloads error to validation_failed at its member: mode
(invalid_enum, with the same detail create's schema gives), season_numbers
(required or out_of_range), and series_id (invalid). POST /downloads with
series=true on a non-series item gets the same treatment at content_id, so
both download operations answer the same error alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 14, 2026
@silo-kody

silo-kody Bot commented Nov 14, 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 ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T19:43:01.469157Z 11c9c4d PR opened
🔒 Security Review ✅ Completed 2026-11-14T19:44:26.996685Z 11c9c4d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Download creation and subscription mutation handlers now map selected service errors to field-specific validation problems. Transport tests check the returned error locations and codes.

Changes: Download request validation

Layer / File(s) Summary
Download creation validation mapping
internal/apiv2/download_create.go, internal/apiv2/download_create_test.go
ErrNotSeries now returns a validation problem at body.content_id. A transport test checks the error location and code.
Subscription mutation validation mapping
internal/apiv2/download_subscription_mutations.go, internal/apiv2/download_subscription_mutations_test.go
Mode, season, and non-series errors now return member-specific validation problems. Tests check the expected locations and codes for create and edit operations where applicable.

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

Change: Bug fix

Suggested reviewers: rangodj

Merge Risk: Minimal · up to 11c9c

Invalid monitor options and non-series downloads now return a 422 that names the offending field instead of a generic 400. The change is small, covered by new transport tests, and easy to revert, so merge risk is minimal.

Security architecture risk: Minimal · up to 11c9c

Selected invalid requests now receive field-specific 422 responses instead of generic 400 responses. The inspected changes do not expand access, weaken request controls, or alter state transitions.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated exposure change is limited to error classification and field metadata on existing download API requests. The base-to-head changes introduce no new caller, route, service authority, or persistence operation.

Trust Boundaries and Controls

  • observed — The transport continues to obtain user and profile identity from viewerIdentity rather than request-body fields. Subscription mutation calls separately receive the client-selected device and subscription identifiers, the catalog access filter, and the existing precondition callback where applicable; these inputs are unchanged by this PR.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: invalid monitor options on the subscription routes now return 422 validation failures at the offending member instead of a generic 400. The changeset maps downloads er…
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 clearly relates to the changeset. It names the affected routes (POST /api/v2/downloads/subscriptions, PATCH /api/v2/downloads/subscriptions/{id}, POST /api/v2/downloads). It explains t…
Full details: Title check

Explanation

The title names the main change: invalid monitor options on the subscription routes now return 422 validation failures at the offending member instead of a generic 400. The changeset maps downloads errors to member-level validation problems in the apiv2 handlers, which matches the title's scope.

Full details: Description check

Explanation

The description clearly relates to the changeset. It names the affected routes (POST /api/v2/downloads/subscriptions, PATCH /api/v2/downloads/subscriptions/{id}, POST /api/v2/downloads). It explains the change from 400 malformed_request to 422 validation_failed at the member for invalid monitor options, and it lists the error-to-member mapping table. It also gives validation steps, risks, and an evidence link, all of which match the summarized code and test changes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent 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: 32bb4c6c-e4f1-4ecc-ac05-c06e78646639
Commits

Reviewing files that changed from the base of the PR and between f8857fc and 11c9c4d.

Files selected for processing: 4

  • internal/apiv2/download_create.go
  • internal/apiv2/download_create_test.go
  • internal/apiv2/download_subscription_mutations.go
  • internal/apiv2/download_subscription_mutations_test.go

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

@silo-triage silo-triage Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 14, 2026
@Quick104
Quick104 merged commit e571c64 into main Nov 14, 2026
18 checks passed
@Quick104
Quick104 deleted the fix/subscription-options-422-validation branch November 14, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant