Skip to content

fix(apiv2): declare the statuses operations already return - #3046

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
blurbery:fix/apiv2-declare-returned-statuses
Oct 28, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
blurbery:fix/apiv2-declare-returned-statuses

Conversation

@blurbery

@blurbery blurbery commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

The v2 contract leaves out statuses that some handlers already return, so anything generated from contracts/api/v2/openapi.json, including the web's web/src/api/v2 types, doesn't know those responses exist. A busy recommendation trigger answers 409, a rate-limited Quick Connect poll answers 429, and catalog browsing answers 501 when the user store can't run the query, but none of those operations list the status. This change declares them on the registrations and regenerates the contract and the web types. It only adds to the contract.

What was missing:

  • 409 on:
    • the four triggerAdminRecommendation* operations (the job is already running here or on another server);
    • runAdminTask and cancelAdminTask (the task is already running, or isn't running);
    • createAdminUser (username or email taken, or an access group on a server without access groups) and impersonateAdminUser (already impersonating, or impersonation not configured);
    • cancelAdminHistoryImportRun (job_not_cancelable), createAdminHistoryImportRun (a run is already active, or the source is disabled or has no admin token), createAdminHistoryImportMapping (the external user is already mapped on that source) and deleteAdminHistoryImportSource (mappings still reference it);
    • updateAdminPluginRepository and deleteAdminPluginRepository (managed repository);
    • redetectAdminEpisodeIntro (local detection can't run);
    • deleteAdminCollection (a page section still uses it);
    • the five manual-membership operations getAdminCollectionItems, getAdminCollectionItemsOrder, reorderAdminCollectionItems, addAdminCollectionItem and removeAdminCollectionItem (collection_not_manual for a collection that isn't manual).
  • 429 on startDeviceLogin, pollDeviceLogin, cancelDeviceLogin, setupServer, signup and receiveAutoscanWebhook.
  • 501 capability_unsupported on:
    • listCatalogItems, queryCatalogItems, queryCatalogLetters and listAudiobookGroups (the user store or search index can't serve the query);
    • getCatalogSearchCapabilities (the search index result window is outside what this build can page);
    • createAdminUser (a default profile on a user store that can't create it in the same transaction).
  • 403 on listPersonalAPIKeys, which refuses API-key callers.

The X-Silo-Client-Family text on listEffectiveSettings and resolveEffectiveSettings also said the header is required when a requested key has profile_client scope. The server treats it as optional and skips that layer when it's absent, as docs/settings-api.md already says, so the parameter text now says that too.

Approach

Most of these are an Errors entry on the registration, the way the siblings that already declare theirs do it (resetAdminRecommendationEmbeddings, updateAdminUser, refreshAdminEpisodeMarkers). The five manual-membership collection operations share a small manualMembershipOperation helper.

The 429 gap came from the implied-status rule. ImpliedStatuses added 429 only for gated classes, but gateChain runs the per-endpoint limiter for a public operation that names a RateLimitBucket, so those operations could answer 429 without documenting it. login, the password resets, the public invitation operations and getDeviceLogin got around that by listing 429 themselves. ImpliedStatuses now adds 429 for any operation with a bucket; the six operations above are the only ones whose contract changes. The spec lint in internal/contractspec can't see buckets because the document doesn't carry them, so it passes false, and the check lives in internal/apiv2 instead. No raw registration names a bucket, so RawImpliedStatuses is unchanged.

TestBucketLimitedPublicOperationsDocument429 walks every registered public operation, asks gateChain whether it runs a limiter, and requires a documented 429. On main it fails for exactly those six operations.

Web code needs no change: it already branches on the runtime status for collection delete, plugin repository writes, impersonation and Quick Connect, and the regenerated types only add response entries. silo-apple and silo-android hand-write their v2 models and decode problem documents generically, and the vendored fixtures don't change, so neither needs a follow-up. jellycompat isn't affected.

Left out of this PR:

  • AdminDashboardLayout.layout and updated_at are null when no layout is saved, but the schema marks them non-nullable. Declaring them nullable is the fix, but the contract diff classes response-property-became-nullable as breaking, so I've left it for a maintainer to decide whether to approve it.
  • addCollectionItem, removeCollectionItem and reorderCollectionItems also answer 409 collection_not_manual, like their admin counterparts here. fix(collections): bound count queries and retain recovery access #2728 rewrites the addCollectionItem registration, in a hunk that covers the other two, so I've left all three to follow it rather than collide.
  • The admin collection editor and order reads (and the writes that re-read them) can also answer 409 when a concurrent write lands between their two revision reads. That looks like something the reads should handle, by retrying or answering 412, rather than a status to declare, so it isn't in here.
  • Separate issues I didn't touch: the facet typeahead limit clamp (50) against the contract's maximum of 100, downloads answering 400 where 422 is documented, Go transport schema names, and the v2 marker writes demo gate, which another PR fixes.

Validation

All on commit 43748896e, rebased on upstream main a0f8c547f:

  • go vet ./internal/apiv2/ ./internal/contractspec/: clean.
  • go test -count=1 ./internal/apiv2/: pass. The new test fails on main for the six operations and passes here.
  • go test -count=1 -run '^TestCommittedArtifactMatchesRouter$' ./internal/apiv2/: pass.
  • make verify-apiv2-openapi, make verify-apiv2-fixtures and make verify-apiv2-web-types: current. make apiv2-fixtures changed nothing, since the fixtures are response bodies.
  • BASE_REF=upstream/main make verify-apiv2-contract: spec lint passes; 34 changes, all info (response-non-success-status-added), none breaking, no approval added.
  • Not run locally, left to CI: make lint-changed and the rest of the full gate (Go and web suites, web lint and build).
  • Follow-up d6dd0aa43 only rewords two comments the CI misspell lint flagged. Checked with golangci-lint run --enable-only misspell --new-from-merge-base upstream/main ./internal/apiv2/ (0 issues), gofmt, go vet and make verify-apiv2-openapi.

Evidence

Evidence: none, no user-visible change

Server behaviour and every screen are unchanged; only the published contract and the generated web types change. For reference, the responses keys in contracts/api/v2/openapi.json for two operations, before (upstream main a0f8c547f) and after (this branch):

setupServer                           before: 201,400,406,408,409,413,415,422,500,503
                                      after:  201,400,406,408,409,413,415,422,429,500,503
triggerAdminRecommendationEmbeddings  before: 200,400,401,403,404,406,422,429,500,503
                                      after:  200,400,401,403,404,406,409,422,429,500,503

Each new entry is the shared problem response, for example:

"429": {
  "content": { "application/problem+json": { "schema": { "$ref": "#/components/schemas/Problem" } } },
  "description": "Too Many Requests"
}

Surface and build: the artifact make apiv2-openapi generates, from upstream main a0f8c547f and from this branch at 43748896e.

Risks

None at runtime: handlers behave as before, and only the document and the generated web types change. Other open PRs that regenerate openapi.json will need to regenerate again after this lands, or this one after them. #2728 adds a line beside the addAdminCollectionItem registration, so whichever lands second has a one-line conflict there.

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 says there is none.

AI Disclosure

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted with Claude Opus. I directed the task and designed the work.
  • Adversarial review: before opening, a separate read-only Claude Code agent got only the branch diff and the problem statement, traced every newly declared status to its handler, and looked for siblings left undeclared. It found nothing wrong in what was declared. Its completeness findings are in this PR: 409 on the three history import operations, 501 on createAdminUser and getCatalogSearchCapabilities, and broader wording on two comments. The personal collection membership 409s are listed under "Left out" because of fix(collections): bound count queries and retain recovery access #2728. I kept RawImpliedStatuses and the explicit 429s on login and the password resets unchanged: no raw operation names a bucket, the new test covers raw paths too, and the explicit 429s produce no contract change.

Note

Declare existing Conflict, Forbidden, and Not Implemented responses in apiv2 operation docs

  • Declares statuses that handlers already return so the OpenAPI contract matches runtime behavior: Conflict for admin creation, collection/import/task operations, and plugin repository updates; Forbidden for API-key-authenticated calls listing personal API keys; Not Implemented for unsupported catalog stores and search indexes.
  • Extends ImpliedStatuses in document.go with a rate-limited flag so bucket-limited public operations now document a 429 Too Many Requests response, verified by a new test in document_test.go.
  • Consolidates manual-membership route registration through a shared manualMembershipOperation helper in admin_collections.go and clarifies the client-family header as optional in effective settings models.
  • Regenerates openapi.json and schema.ts with the new documented statuses.
  • Behavioral Change: no handler or error-mapping logic changed; only documentation and generated artifacts differ.

Macroscope summarized d6dd0aa.

Several v2 handlers answer statuses their operation registrations never
declared, so the published contract and the generated web types left them
out:

- 409 on the recommendation triggers, runAdminTask, cancelAdminTask,
  createAdminUser, impersonateAdminUser, cancelAdminHistoryImportRun,
  createAdminHistoryImportRun, createAdminHistoryImportMapping,
  deleteAdminHistoryImportSource, plugin repository update and delete,
  redetectAdminEpisodeIntro, deleteAdminCollection and the five
  manual-membership admin collection operations.
- 501 capability_unsupported on listCatalogItems, queryCatalogItems,
  queryCatalogLetters, listAudiobookGroups, getCatalogSearchCapabilities
  and createAdminUser.
- 403 on listPersonalAPIKeys, which refuses API-key callers.

The implied-status rule added 429 only for gated classes, so public
operations that name a rate-limit bucket (device login start, poll and
cancel, setup, signup and the autoscan webhook) never documented the 429
their limiter answers. ImpliedStatuses now adds 429 for any operation with
a bucket.

The X-Silo-Client-Family text on the effective settings reads now says the
header is optional, as the server treats it.
@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Oct 25, 2026
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 5716fc54-adcc-4581-a879-c11cf7ef56b7
Commits

Reviewing files that changed from the base of the PR and between a0f8c54 and d6dd0aa.

Files selected for processing: 21
  • contracts/api/v2/openapi.json
  • internal/apiv2/admin_accounts.go
  • internal/apiv2/admin_catalog_intro.go
  • internal/apiv2/admin_collection_extras.go
  • internal/apiv2/admin_collections.go
  • internal/apiv2/admin_history_import_mappings.go
  • internal/apiv2/admin_history_import_runs.go
  • internal/apiv2/admin_history_imports.go
  • internal/apiv2/admin_plugin_repository_delete.go
  • internal/apiv2/admin_plugin_repository_update.go
  • internal/apiv2/admin_recommendations.go
  • internal/apiv2/admin_tasks.go
  • internal/apiv2/catalog_items.go
  • internal/apiv2/catalog_letters.go
  • internal/apiv2/catalog_search_capabilities.go
  • internal/apiv2/document.go
  • internal/apiv2/document_test.go
  • internal/apiv2/personal_api_keys.go
  • internal/apiv2/settings.go
  • internal/contractspec/lint.go
  • web/src/api/v2/schema.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@silo-kody

silo-kody Bot commented Oct 25, 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 ❌

@macroscopeapp

macroscopeapp Bot commented Oct 25, 2026

Copy link
Copy Markdown

The server behavior and rendered UI are unchanged; this PR only updates OpenAPI declarations and generated TypeScript types. Please add Evidence: none, no user-visible change under the Evidence heading.

Suggested fix: add the line above under ## Evidence.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@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 priority: P2 Limited scope, workaround exists, or polish labels Oct 25, 2026
@silo-kody

silo-kody Bot commented Oct 25, 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 ❌

@Quick104

Copy link
Copy Markdown
Contributor

No actionable findings at d6dd0aa4383827186135bd27581adf425c033cfd, reviewed against a0f8c547f8b66dc7e40909d4c60b39bcdf654318.

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

This fixes an existing public-contract gap at the operation registrations and shared status generator. Each added status matches a handler path. The OpenAPI diff adds 34 responses across 33 operations and corrects the client-family description on two operations. Request handling, authorization, success shapes, and required parameters retain their existing behavior.

Validation:

  • go test -count=1 ./internal/apiv2/ ./internal/contractspec/ and focused go vet passed.
  • The new TestBucketLimitedPublicOperationsDocument429 failed on the base for exactly the six missing 429 declarations and passed at the reviewed head.
  • OpenAPI regeneration, fixture validation, web type generation, web typecheck, and the contract compatibility check passed. The compatibility tool reports 34 informational additions and no breaking changes.
  • CI is green at the reviewed head. Broader Go/web checks came from CI. Database tests requiring SILO_TEST_DATABASE_URL skipped locally; no live server/device validation was performed.

Validated features: the board and Collections server task #193 show no passed behavior changed by this diff. Those recorded server results are agent API checks; human acceptance remains outstanding. The validation helper could not read the current records reliably, so the board and issue records were read directly. No formal check covers the changed files.

Validation tasks: none

Apple, Android, and web decode problem responses generically; the additions require no client changes. Jellyfin behavior is unaffected. The settings API guide already documents the optional client-family behavior. The user manual's API and rate-limit guidance remains accurate, so no manual issue is needed.

Independent review: three Codex source reviews, a final sweep, and one Claude review found no defects. No fix commits were needed.

AI disclosure: reviewed through T3 Code with the Codex harness using gpt-6.1-sol (lead at xhigh; source reviewers and validation reviewer at high), plus one read-only Claude Code review using claude-opus-5-5 at high. Tools included GitHub CLI and the repository's test and generation commands.

@Quick104
Quick104 merged commit 1470803 into Silo-Server:main Oct 28, 2026
20 checks passed
@blurbery
blurbery deleted the fix/apiv2-declare-returned-statuses branch November 6, 2026 00:01
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 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.

2 participants