You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(apiv2): answer out-of-range monitor bounds with 422 at the member - #4074
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."}
$ 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)
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
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>.
ClosesSilo-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.
ClosesSilo-Server#4068
Co-Authored-By: Claude Opus 5.5 <[email protected]>
silo-triageBot
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
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.
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: 4
Check name
Status
Explanation
Title check
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
[#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
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
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.
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-triageBot
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
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api-v2API v2 / Huma migration program (epic #135); long-running, stacked by phasebugSomething isn't workinggoPull requests that update go codepriority: P2Limited scope, workaround exists, or polishsize/S0–49 added + deleted lines (all files); change volume, not priority.stackedBase is another open PR; merge in stack order named in the body
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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}answeredmax_storage_bytesbelow zero, or more than 10,000season_numbers, with400 malformed_request("Invalid monitor storage or season bounds.") and no member. Creating a monitor with the same values answers422 validation_failedat the member with codeout_of_range, because the create body carriesminimum:"0"andmaxItems:"10000"schema tags.docs/architecture/api-contract.mdmaps input validation to422.Built on #4064, which has merged;
mainis merged into this branch (d062956), so the diff shows only this PR's change. This PR can merge in any order.Approach
validation_failed, the member's location, codeout_of_range, and the same detail text (expected number >= 0,expected array length <= 10000). Both bounds out of range give both errors.Patch[T]members, the issue's first option.make verify-apiv2-contractreports that as a breaking change (request-property-min-set,request-property-max-items-set) that needs an entry inbreaking-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 testpasses forinternal/apiv2, andmake verify-apiv2-openapireports the document current.TestSubscriptionMutationTransportexpects 422 atbody.max_storage_bytesandbody.season_numbers, and compares each error with what create answers for the same value. With the old bounds check put back, it fails withstatus = 400, want 422.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), baseab30ed69d(#4064, merged asce410616b) and this PR at175041776. Theinstancemember is left out, and the 10,001-item body is shortened.Create, for reference (unchanged):
Patch, before:
Patch, after:
Risks
/api/v2isn't locked yet.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Fix out-of-range monitor bounds to return 422 with member-level errors
max_storage_bytes(negative) andseason_numbers(over 10,000 entries) into a newsubscriptionPatchBoundsProblemhelper in download_subscription_mutations.goout_of_rangeerror inside aTypeValidationFailedproblem, instead of the previous generic malformed-request problemMacroscope summarized d062956.