Skip to content

fix(apiv2): answer out-of-range monitor bounds with 422 at the member - #4074

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
rangoDJ:fix/subscription-bounds-422-4068
Nov 14, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
rangoDJ:fix/subscription-bounds-422-4068

Conversation

@rangoDJ

@rangoDJ rangoDJ commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4068
Related issue: #3720
Validation tasks: none

Other clients: Apple N/A (treats any non-200 from this PATCH as the same failure); Android N/A (doesn't call this operation); Roku N/A (same)

PATCH /api/v2/downloads/subscriptions/{id} answered max_storage_bytes below zero, or more than 10,000 season_numbers, with 400 malformed_request ("Invalid monitor storage or season bounds.") and no member. Creating a monitor with the same values answers 422 validation_failed at the member with code out_of_range, because the create body carries minimum:"0" and maxItems:"10000" schema tags. docs/architecture/api-contract.md maps input validation to 422.

Built on #4064, which has merged; main is merged into this branch (d062956), so the diff shows only this PR's change. This PR can merge in any order.

Approach

  • The patch handler answers an out-of-range bound with the problem create gives: validation_failed, the member's location, code out_of_range, and the same detail text (expected number >= 0, expected array length <= 10000). Both bounds out of range give both errors.
  • I first moved the bounds into schema tags on the Patch[T] members, the issue's first option. make verify-apiv2-contract reports that as a breaking change (request-property-min-set, request-property-max-items-set) that needs an entry in breaking-approvals.json, so the check stays in the handler and the OpenAPI document doesn't change. Documenting the bounds in the schema is left for a maintainer to approve if wanted.

Validation

  • gofmt, go vet, and the changed-package lint are clean.
  • go test passes for internal/apiv2, and make verify-apiv2-openapi reports the document current.
  • TestSubscriptionMutationTransport expects 422 at body.max_storage_bytes and body.season_numbers, and compares each error with what create answers for the same value. With the old bounds check put back, it fails with status = 400, want 422.
  • Not run: the request against a running server, and the full make test-go.

Evidence

No visible layout change. The evidence is the response body, from the transport test's handler on WSL2 (Ubuntu, go1.26.4 linux/amd64), base ab30ed69d (#4064, merged as ce410616b) and this PR at 175041776. The instance member is left out, and the 10,001-item body is shortened.

Create, for reference (unchanged):

POST max_storage_bytes=-1 -> 422 {"type":"https://siloserver.org/docs/api/v2/problems/validation_failed","title":"Validation failed","status":422,"detail":"expected number >= 0","errors":[{"location":"body.max_storage_bytes","code":"out_of_range","detail":"expected number >= 0"}]}
POST 10001 season_numbers -> 422 {"type":"https://siloserver.org/docs/api/v2/problems/validation_failed","title":"Validation failed","status":422,"detail":"expected array length <= 10000","errors":[{"location":"body.season_numbers","code":"out_of_range","detail":"expected array length <= 10000"}]}

Patch, before:

PATCH {"max_storage_bytes":-1} -> 400 {"type":"https://siloserver.org/docs/api/v2/problems/malformed_request","title":"Malformed request","status":400,"detail":"Invalid monitor storage or season bounds."}
PATCH {"season_numbers":[1,1,1,...]} -> 400 {"type":"https://siloserver.org/docs/api/v2/problems/malformed_request","title":"Malformed request","status":400,"detail":"Invalid monitor storage or season bounds."}

Patch, after:

PATCH {"max_storage_bytes":-1} -> 422 {"type":"https://siloserver.org/docs/api/v2/problems/validation_failed","title":"Validation failed","status":422,"detail":"expected number >= 0","errors":[{"location":"body.max_storage_bytes","code":"out_of_range","detail":"expected number >= 0"}]}
PATCH {"season_numbers":[1,1,1,...]} -> 422 {"type":"https://siloserver.org/docs/api/v2/problems/validation_failed","title":"Validation failed","status":422,"detail":"expected array length <= 10000","errors":[{"location":"body.season_numbers","code":"out_of_range","detail":"expected array length <= 10000"}]}
$ go test -count=1 ./internal/apiv2/
ok  	github.com/Silo-Server/silo-server/internal/apiv2	103.607s

Risks

  • A client that relied on 400 for these bounds now gets 422. No first-party client sends them, and /api/v2 isn't locked yet.
  • The detail text is copied from the framework's messages for create. If a Huma upgrade changes those, create and patch would differ in wording, though not in location or code.

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 (Claude desktop app, Code tab)
  • Tool(s): Claude Code; GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: n/a

🤖 Generated with Claude Code

Note

Fix out-of-range monitor bounds to return 422 with member-level errors

  • Extracts bounds validation for max_storage_bytes (negative) and season_numbers (over 10,000 entries) into a new subscriptionPatchBoundsProblem helper in download_subscription_mutations.go
  • Each failing member now gets an out_of_range error inside a TypeValidationFailed problem, instead of the previous generic malformed-request problem
  • Transport tests in download_subscription_mutations_test.go assert the error location, code, and detail for each bound, and match them with the create-request validation errors
  • Behavioral Change: PATCH requests with out-of-range bounds now return HTTP 422 instead of 400

Macroscope summarized d062956.

rangoDJ and others added 2 commits November 13, 2026 09:26
PATCH /api/v2/downloads/subscriptions/{id} refused an explicit null on
any monitor field with 400 malformed_request and no member name. The v2
PATCH rule in api-contract.md makes null on a member that cannot be
cleared a 422 validation_failed naming the member, as updateProfile
answers. The handler now checks the raw body with the same helper, so
each null member is named at body.<member>.

Closes Silo-Server#3720

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PATCH /api/v2/downloads/subscriptions/{id} answered max_storage_bytes
below zero, or more than 10,000 season_numbers, with 400
malformed_request and no member. Creating a monitor with the same
values answers 422 validation_failed at the member with code
out_of_range, from its schema bounds. The patch handler now answers
with the same problem, location, code and detail.

The bounds stay out of the patch schema: adding them there is a
breaking request-contract change under the contract diff.

Closes Silo-Server#4068

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 13, 2026
@silo-kody

silo-kody Bot commented Nov 13, 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 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 stacked Base is another open PR; merge in stack order named in the body labels Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

PATCH subscription updates now return member-specific validation errors for null monitor fields, negative max_storage_bytes, and season_numbers lists with more than 10,000 items. Tests compare bounds errors with the corresponding POST responses.

Changes: Subscription patch validation

Layer / File(s) Summary
Validate patch inputs and return member-specific errors
internal/apiv2/download_subscription_mutations.go, internal/apiv2/download_subscription_mutations_test.go
DownloadSubscriptionPatchInput retains the raw request body. The update handler checks null fields and delegates storage and season-count bounds checks to a helper. Tests verify member-specific errors, including ordered errors for simultaneous null mode and quality fields.

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: quick104

Merge Risk: Minimal · up to 17504

Out-of-range subscription edits now return a structured 422 validation error that names the affected field, matching the create response. No concrete merge-blocking risk was found.

Security architecture risk: Low · up to 17504

The change affects validation responses on an existing endpoint. No expanded permissions or data access were identified, but the dependency that supplies raw request bytes to validation remains unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The examined write path remains limited by subscription ID, user, profile, and device in the locked database lookup. The PR does not change this ownership predicate or add another mutation caller in the changed handler.

Trust Boundaries and Controls

  • observed — Accepted requests retain the existing access check and precondition checks. Validation errors occur before subscription lookup in both base and head, so the changed status and member details do not depend on whether the target subscription exists.

Resilience and Maintainability Implications

  • observed — The unchanged accepted-update path rechecks the ETag and UpdatedAt under a row lock, writes within a transaction, commits, and defers rollback on exit. The new rejection paths return before this transaction, adding no persisted intermediate state, reservation, or cleanup obligation.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: out-of-range monitor bounds on the PATCH subscription endpoint now return 422 validation_failed at the member. This matches the changeset summary and linked issue #406…
Linked Issues check Passed [#4068] Requirement: out-of-range PATCH bounds must return 422 validation_failed at the member, code out_of_range, matching create. The PR's own commit 1750417 adds subscriptionPatchBoundsProblem in …
Out of Scope Changes check Passed Commit history at head shows two PR-specific commits above the merge base 0387303: ab30ed6 (null-handling, #4064's commit, stated as a prerequisite) and 1750417 (this PR's bounds fix). The whole-PR…
Description check Passed The description covers the change in detail. It states that PATCH /api/v2/downloads/subscriptions/{id} returned 400 malformed_request for out-of-range max_storage_bytes and season_numbers, and that th…
Full details: Title check

Explanation

The title names the main change: out-of-range monitor bounds on the PATCH subscription endpoint now return 422 validation_failed at the member. This matches the changeset summary and linked issue #4068. The title is specific and follows the conventional-commit style.

Full details: Linked Issues check

Explanation

[#4068] Requirement: out-of-range PATCH bounds must return 422 validation_failed at the member, code out_of_range, matching create. The PR's own commit 1750417 adds subscriptionPatchBoundsProblem in internal/apiv2/download_subscription_mutations.go. It returns NewProblem(TypeValidationFailed, ...) with ProblemError entries at body.max_storage_bytes (when negative) and body.season_numbers (when over 10000), code codeOutOfRange, and the same detail strings used for create. Both bounds out of range yield both errors. The issue allows answering the handler check with a validation_failed problem at the member, so the handler approach satisfies the issue. TestSubscriptionMutationTransport is described as asserting 422 at both members and comparing with create; I did not read the test file, so this relies on the PR description and summary. Remaining uncertainty: the detail text is duplicated from create rather than shared, which the PR lists as a risk, not a requirement gap.

Full details: Out of Scope Changes check

Explanation

Commit history at head shows two PR-specific commits above the merge base 0387303: ab30ed6 (null-handling, #4064's commit, stated as a prerequisite) and 1750417 (this PR's bounds fix). The whole-PR diff against 0387303 includes the #4064 null-handling change in updateDownloadSubscription (rejectNonNullableNulls, RawBody field). That change is a separate concern. The PR objectives exclude it from #4074, and the PR states it merges first. It is not a demonstrated unrelated change of this PR's own commit. The bounds change in 1750417 is directly tied to #4068. No out-of-scope changes are established in 1750417. The test file changes that cover null handling belong to the #4064 stack.

Full details: Description check

Explanation

The description covers the change in detail. It states that PATCH /api/v2/downloads/subscriptions/{id} returned 400 malformed_request for out-of-range max_storage_bytes and season_numbers, and that the fix returns 422 validation_failed with an out_of_range error at the member, matching create. It also gives the approach (handler check, not schema tags), validation steps, before/after response evidence, risks, and the dependency on #4064. The description is related to the changeset and 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
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: b2b9b457-0e3a-413f-bfa4-a1599094f71f
Commits

Reviewing files that changed from the base of the PR and between 85d1c16 and 1750417.

Files selected for processing: 2

  • 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 4 included reviews per hour; 3 remain after this review.

Silo-Server#4064 merged as ce41061, a squash of ab30ed6, which this branch was
built on. The two conflicted in the subscription handler and its test;
this branch's side keeps Silo-Server#4064's null check and adds the bounds check.
main's copy of the files equals ab30ed6.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added size/S 0–49 added + deleted lines (all files); change volume, not priority. and removed size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Nov 13, 2026
@Quick104

Copy link
Copy Markdown
Contributor

🤖 Claude Code (claude-opus-5-5)

Review summary

Reviewed head: d06295691e

This is ready to merge. Patching a monitor with a negative max_storage_bytes or more than 10,000 season_numbers now gets the same 422 validation_failed problem that create gives: the same location, code, and detail. The review found no defects, and I pushed nothing to the branch.

What I checked

  • TestSubscriptionMutationTransport passes on this head. Run against the base, it fails with status = 400, want 422, so the test catches the bug it claims to fix.
  • With a single error, the top-level detail is promoted to that error's text, which matches create. With both bounds out of range, both errors come back in the same order Huma uses for create. Null rejection still answers 422, oversized bodies still answer 413, and validation still runs before the If-Match check, as it does on the base.
  • docs/downloads-api.md already maps an invalid subscription option to 422 validation_failed, and the OpenAPI document already lists 422 for updateDownloadSubscription. The PR brings the handler in line with both, and neither document needs a change.
  • The copied Huma wording could drift after an upgrade. The test compares each patch error with create's error for the same value, so a drift would fail CI.
  • An independent second review by a different model family (Codex, gpt-6.1-sol) found nothing.

Remaining for maintainers

  • Unrelated to this PR: subscriptionMutationProblem still answers 400 for other invalid monitor options, such as specific_seasons with no seasons, a negative season number, an unknown patch mode, or a non-series series_id. The docs map those to 422 as well. A separate fix is in progress, and I'll link its PR here when it opens.

Validated features: none affected. The Downloads / offline cases on #1168, Silo-Server/silo-apple#319, and Silo-Server/silo-android#329 don't cover monitor-edit bounds.

User manual: unaffected. siloserver.org doesn't describe these status codes.

Apple and Android: no follow-up needed. Apple's client treats any non-200 from this PATCH as a failure, and it retries only after a changed-monitor status. Code search found no Android caller.

Fit: 9/10 · Readiness: 9/10 — ready

  • Fit: the PR fixes a contract inconsistency in /api/v2 before the 1.0 lock, inside the handler that owns it. It adds no new surface.
  • Readiness: the change is small and its test fails on the base. It wasn't run against a live server, which leaves little risk for a status-code change covered at the handler boundary.

@Quick104
Quick104 merged commit 7d05bad into Silo-Server:main Nov 14, 2026
16 of 17 checks passed
@rangoDJ
rangoDJ deleted the fix/subscription-bounds-422-4068 branch November 15, 2026 00:45
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/S 0–49 added + deleted lines (all files); change volume, not priority. stacked Base is another open PR; merge in stack order named in the body

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] v2 monitor edit answers out-of-range storage and season bounds with 400 instead of 422

2 participants