Skip to content

fix(notifications): let an iPhone recover push after a reinstall - #3352

Merged
Quick104 merged 6 commits into
Silo-Server:mainfrom
Rhainland:fix/3348-push-reinstall
Nov 2, 2026
Merged

Quick104 merged 6 commits into
Silo-Server:mainfrom
Rhainland:fix/3348-push-reinstall

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #3348
Related issue: N/A
Validation tasks: unblocks #1234 C2; unblocks Silo-Server/silo-apple#336 C1 and C2 (not run yet)

In the reported case, the reinstalled iOS app kept its device ID but sent a new push installation key. The server binds each Apple installation to the key from its first registration, so every later registration fails with 403 permission_denied. Nothing on the server cleared that binding, and the contract said there was no recovery, so push stayed broken until someone deleted the rows by hand.

This change tells the owning account why it was refused and gives it a way to clear its own installation. Another account is still refused, and its refusal does not change.

Approach

  • A registration whose key does not match the stored one now answers 403 with the problem type push_installation_key_mismatch, but only when the caller's account owns the installation. Another account still gets permission_denied, so the new code says nothing about who owns a device ID. The status and the refusal are the same as before, so current apps behave as they do today.
  • New operation POST /api/v2/devices/push/apple/reset (resetApplePushInstallation). It needs a current login session of the owning account and the app's current installation key. Under the existing installation lock, it deletes the device's Apple push rows (their queued attempts cascade) and clears the stored key and generation. The installation keeps its account, so until the owner registers again, another account's ordered or legacy registration for that device ID is still refused. The owner's next registration then binds the new key at any generation. It answers {"reset": true} when it cleared something, {"reset": false} when there was nothing to clear or the installation is already bound to the sent key, and 403 permission_denied for another account's installation. Because of the same-key no-op, a retried reset cannot undo the registration that followed it.
  • The reset clears the installation row instead of deleting it. A registration waiting on the lock then reads a cleared installation instead of finding no row.
  • getApplePushRegistrationCapabilities gains installation_reset_available. All changes are additive to /api/v2, and no migration is needed: ownership comes from the user_id the installation row already stores.
  • docs/notifications-push-api.md documents the recovery flow and replaces the "no recovery" sentence for Apple. Android installations are unchanged and still have no recovery path.
  • The recovery only works once the iOS app handles the new code. fix(notifications): recover Apple push after the installation key changes silo-apple#977 calls the reset and registers again when it sees push_installation_key_mismatch and the capability reports installation_reset_available. It also confirms how the reported case happens: the app keys its installation record by server address but shares the device ID across servers, so re-adding a server under another address creates a new key for the same device ID. jellycompat has no Apple push registration, so it needs no change.

Validation

  • Follow-up 494100c: repeated resets check ownership while the installation is at generation zero. The existing database test now covers a foreign account and an owner retry; the foreign-account assertion fails on d7712a7 and passes with the fix. Focused reset, upsert, and retirement database tests pass; changed-line lint reports 0 issues.

  • Reproduced on origin/main against a local build with a real login: same device_id, new key, generation 1 and then 2, both refused with permission_denied.

  • On the fix build, the same steps on the same kind of data: the owner gets push_installation_key_mismatch; reset, then registration with the new key at generation 1, returns 200; a retried reset returns {"reset": false} and leaves the new registration in place; a second account is refused for registration and reset (403 permission_denied); the original key still works before the reset.

  • New database tests cover owner reset and re-registration, refusal for another account (also between the reset and the owner's next registration, through the ordered and legacy writers), the replayed reset, an unknown device, and a registration queued behind a reset. A transport test covers the new problem code, the reset route's session requirement and the capability field. Both database tests are listed in scripts/ci/db-contracts.txt and pass through the dbpins runner.

  • Go gate: build, gofmt, vet, make lint-changed, router-recovery lint, route inventory, migration ledger, scenario catalogs, offline routes, OpenAPI, web types, fixtures, local paths, case collisions, size ratchet, bidi, migrations and v1 route freeze all pass. make test-go passes except two jellycompat Dolby Vision tests (TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute, TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped), which fail the same way on the base commit.

  • make verify-apiv2-contract reports both changes as additive. It also refused two stale approvals from feat(diagnostics): accept the roku platform #3298 that match no change against main (the check runs only when openapi.json changes), so this pull request removes them.

  • Web: the regenerated API types pass typecheck, ESLint and Prettier. No web code changed.

Evidence

Evidence: none, no user-visible change

API before and after, same steps (registration with a new key from the owning account, then a second account):

Before: main at 63ef34b. After: this branch at 04c5169 (later commits only change the contract approvals file and docs).

origin/main:
POST /api/v2/devices/push/apple  (owner, new key)   -> 403 permission_denied
POST /api/v2/devices/push/apple  (other account)    -> 403 permission_denied
POST /api/v2/devices/push/apple/reset               -> 404 not_found
GET  /api/v2/devices/push/apple/capabilities        -> 200 {"state":"available","registration_available":true}   (no installation_reset_available)

fix:
GET  /api/v2/devices/push/apple/capabilities        -> 200 {"state":"available","registration_available":true,"installation_reset_available":true}
POST /api/v2/devices/push/apple  (owner, new key)   -> 403 push_installation_key_mismatch
POST /api/v2/devices/push/apple  (other account)    -> 403 permission_denied
POST /api/v2/devices/push/apple/reset (other)       -> 403 permission_denied
POST /api/v2/devices/push/apple/reset (owner)       -> 200 {"reset":true}
POST /api/v2/devices/push/apple  (owner, new key, generation 1) -> 200
POST /api/v2/devices/push/apple/reset (owner, retry) -> 200 {"reset":false}

Risks

  • Security: any login session of the owning account, from any of its profiles, can now clear that account's installation for a device ID. That account could already register the device. The reset deletes push rows but cannot recall a provider request already sent. Another account cannot reset or take over the installation, and display tokens and API keys cannot reset.
  • A second account can tell from the reset's 403 that some other account owns a device ID it already knows. Registration already gives the same answer.
  • Compatibility: additive v2 changes only. Older iOS builds keep treating the 403 as before.

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 (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code, Codex CLI
  • Model(s): claude-opus-5-5; gpt-6.1-sol (code review); gpt-6-astra (Codex in T3 Code, repeated-reset follow-up)
  • Involvement: Fully AI-generated, human verified
  • Maintainer review: Claude Code (claude-opus-5-5) with a Codex (gpt-6.1-sol) round reviewed 31e1688 and added d7712a7, which keeps a reset installation reserved for its account; see the review summary comment.
  • Adversarial review: independent reviews by claude-opus-5-5 and gpt-6.1-sol on correctness, repository standards and the maintainer's scope, reconciled against the code. Both found no correctness bugs and no spec gaps. Fixed: the reset receipt's description claimed any generation would bind after a same-key no-op; it now says that generation order still applies in that case. Kept: the reset answers 403 for another account's installation, as the scope requires, and registration already reveals the same thing. Not changed: a fourth copy of the device ID check, left so this change does not touch validators that another open pull request edits.

Note

Add owner-only Apple push installation reset endpoint

...

Macroscope summarized 774ea3b.

A reinstalled iOS app keeps its device ID but sends a new installation key,
and every Apple push registration was refused with a generic 403 that nothing
on the server could clear.

A registration whose key does not match now gets 403
push_installation_key_mismatch when the caller's account owns the
installation; another account still gets permission_denied. The owning
account can call POST /api/v2/devices/push/apple/reset
(resetApplePushInstallation) with its login session and current key. Under
the installation lock the reset deletes the device's Apple push rows and
clears the stored key, owner and generation, so the next registration binds
the new key from any generation. A reset is refused for another account's
installation and is a no-op when the installation is already bound to the
sent key, so a retried reset cannot undo the registration after it. The
Apple capability reports installation_reset_available.
@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Nov 1, 2026
@silo-kody

silo-kody Bot commented Nov 1, 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 Nov 1, 2026

Copy link
Copy Markdown

The API excerpts cover the owner mismatch and reset flow, but do not show the changed capability response. Please add before-and-after excerpts for the same capabilities request, and identify the exact build or commit for each API excerpt.

  • internal/apiv2/notification_apple_push.go: installation_reset_available lacks before-and-after API evidence.

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

Posted via Macroscope — Visible change evidence

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 34 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: cd4bea15-7c19-4978-a070-b2ac706ef4c6
Commits

Reviewing files that changed from the base of the PR and between d7712a7 and 774ea3b.

Files selected for processing: 3
  • docs/notifications-push-api.md
  • internal/notifications/apple_push_ordering.go
  • internal/notifications/push_devices_test.go

No actionable comments were generated in the recent review.

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: 7ebab889-fc0a-4ecb-b8d2-e48b898e7f2f
Commits

Reviewing files that changed from the base of the PR and between 31e1688 and d7712a7.

Files selected for processing: 4
  • docs/notifications-push-api.md
  • internal/notifications/apple_push_ordering.go
  • internal/notifications/push_devices.go
  • internal/notifications/push_devices_test.go

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

Walkthrough

The API adds an authenticated Apple push installation reset operation. The owning account can clear an installation binding and its Apple push registrations after a key mismatch. The API reports reset availability and distinguishes owner key mismatches from proof failures for other accounts.

Changes: Apple push installation reset

Layer / File(s) Summary
Reset API contract and recovery guidance
contracts/api/v2/openapi.json, contracts/api/v2/fixtures/*, web/src/api/v2/*, docs/notifications-push-api.md, internal/contractledger/ledger_test.go
The API contracts add reset request and receipt schemas, the reset route, and a capability field. Client API schemas map the route. The guide describes reset outcomes and re-registration behavior. The contract ledger records retry behavior.
Installation ownership and reset state
internal/notifications/apple_push_ordering.go, internal/notifications/push_devices.go, internal/notifications/push_devices_test.go, internal/notifications/push_legacy_ownership_test.go, scripts/ci/db-contracts.txt
Registration reports a distinct mismatch for the owning account. Reset checks ownership and the submitted key, then clears the binding and Apple push rows when the key differs. The installation remains reserved to its owner. Database tests cover ownership, retries, and ordering.
Authenticated reset endpoint and wiring
internal/apiv2/notification_apple_push.go, internal/apiv2/notification_apple_push_test.go, internal/apiv2/problem.go, internal/apiv2/router.go, internal/api/router.go, internal/api/testdata/media_routes.txt
The endpoint requires a current login session and an available reset service. It passes the session user, device ID, and installation key to the service. The API maps mismatch errors and reports reset availability.
Diagnostic-report approval entries
contracts/api/v2/breaking-approvals.json
The approvals for listAdminDiagnosticReports and getAdminDiagnosticReport were removed. The approvals list is now empty.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant iOSClient
  participant ApplePushResetEndpoint
  participant PushDeviceService
  participant PushDeviceRepository
  participant Database
  iOSClient->>ApplePushResetEndpoint: POST reset with device ID and installation key
  ApplePushResetEndpoint->>ApplePushResetEndpoint: Validate current login session
  ApplePushResetEndpoint->>PushDeviceService: Reset installation for session user
  PushDeviceService->>PushDeviceRepository: ResetApplePushInstallation
  PushDeviceRepository->>Database: Lock installation and check owner and key
  PushDeviceRepository->>Database: Clear binding and Apple registrations
  ApplePushResetEndpoint-->>iOSClient: Return reset result or mapped error
Loading

Possibly related issues

  • Silo-Server/silo-server#3348 — The change adds an owner-authorized reset and a distinct mismatch response for the reported reinstall registration failure.

Suggested reviewers: quick104

Merge Risk: Low · previous review d7712

A reset can report success to another account even though subsequent registration is refused. The impact is bounded, but the response should be corrected.

Security architecture risk: Moderate · up to d7712

Updated servers preserve installation ownership during recovery. However, older server versions do not recognize the new cleared-but-reserved state. During a mixed-version upgrade or rollback, another signed-in account could claim a resetting device and block its owner's recovery. Deployment safeguards preventing that sequence were not established.

Retained concerns

  • Medium · security · inferred: The new cleared-but-owned installation state is not protected by base-version writers. If an older API writer remains active after reset, or a cleared reservation survives a downgrade, another authenticated account knowing the device ID can submit an ordered registration with its own key. The older writer sees generation zero and no foreign destination rows, then overwrites the retained owner. Updated writers prevent this, but reset availability is determined locally and the supplied evidence does not establish a deployment barrier preventing the incompatible sequence.
Security review details

Security Blast Radius

  • inferred — The version-skew attack is scoped to known device IDs left in the reset state and reachable through an older writer sharing their database. It requires another authenticated account but not the victim's installation key. The established outcome is installation-ownership replacement and blocked recovery; victim-notification disclosure was not established.

Security Findings and Attack Paths

  • inferred — A successful owner reset removes the destination rows that base writers use to recognize foreign ownership. An attacker registration through an older ordered writer can then pass the generation-zero check and persist the attacker's account and key. Fully upgraded writers reject that same sequence using the retained user_id.

Trust Boundaries and Controls

  • observed — The new route derives account identity from authenticated claims, applies profile-scoped gates, and requires a bounded access-token session. Production authentication checks session activity on each request, while reset persistence checks ownership before changing an active binding. Display credentials and session-less API keys cannot authorize reset.

Resilience and Maintainability Implications

  • observed — Transactional deletion removes queued attempts, but a worker that already loaded a destination can continue to provider dispatch. This delivery limitation predates reset in the registration replacement path, and the guide explicitly disclaims immediate remote-delivery revocation; it is not retained as a new security concern.

Hardening Proposals

  • proposed — Gate reset activation until every writer sharing installation state enforces retained-owner reservations, and define a downgrade barrier while cleared reservations remain. A database-enforced reservation could alternatively make that guarantee independent of application-version agreement.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the change: an iPhone can recover Apple push after a reinstall. The changeset adds a distinct key-mismatch error, an owner-scoped reset operation (POST /api/v2/devices/push/apple/reset…
Linked Issues check Passed Issue #3348 requires recovery for the owning account or an actionable server error. The PR implements both. ApplyApplePushAndFinalize returns push_installation_key_mismatch to the owning account w…
Out of Scope Changes check Passed The changed API schemas, generated web API definitions, router wiring, route fixtures, capability field, problem type, documentation, service and repository code, and tests support the Apple recovery …
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Description check Passed The pull request description directly describes the Apple push installation reset API, ownership behavior, capability changes, documentation updates, tests, and validation results covered by the chang…
Full details: Title check

Explanation

The title names the change: an iPhone can recover Apple push after a reinstall. The changeset adds a distinct key-mismatch error, an owner-scoped reset operation (POST /api/v2/devices/push/apple/reset), a capability flag, and the supporting storage logic, so the title matches the main change. The title is 64 characters and follows the conventional type(scope) form, which is concise and specific enough for a teammate scanning history.

Full details: Linked Issues check

Explanation

Issue #3348 requires recovery for the owning account or an actionable server error. The PR implements both. ApplyApplePushAndFinalize returns push_installation_key_mismatch to the owning account when the key differs. Other accounts still receive permission_denied. POST /api/v2/devices/push/apple/reset requires a current session, the device ID, and the installation key. The reset clears Apple registration state under the installation lock and retains the owner reservation. The owner can register again. Same-key retries are no-ops. Database tests cover reset, ownership, replay, unknown devices, legacy and ordered registration, and lock ordering. Transport tests cover the problem type, session checks, reset responses, and the capability field. Android changes are not required by #3348.

Full details: Out of Scope Changes check

Explanation

The changed API schemas, generated web API definitions, router wiring, route fixtures, capability field, problem type, documentation, service and repository code, and tests support the Apple recovery behavior in #3348. The removal of two stale API contract approvals is outside the Apple code area, but the PR ties it to the additive OpenAPI contract check triggered by this API change. The repository summary provides no demonstrated unrelated behavior change. Android and Jellyfin-compatible client behavior remains unchanged.

Full details: Docstring Coverage

Explanation

Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 11 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The pull request description directly describes the Apple push installation reset API, ownership behavior, capability changes, documentation updates, tests, and validation results covered by the changeset.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@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 1, 2026
@coderabbitai coderabbitai Bot added the size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. label Nov 1, 2026
@silo-triage silo-triage Bot removed the size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. label Nov 1, 2026

@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: 1


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: 84534e2e-9f80-4820-ad7f-4c14a2ddadf2
Commits

Reviewing files that changed from the base of the PR and between 63ef34b and 04c5169.

Files selected for processing: 16
  • contracts/api/v2/fixtures/apple_push_registration_capability.json
  • contracts/api/v2/openapi.json
  • docs/notifications-push-api.md
  • internal/api/router.go
  • internal/api/testdata/media_routes.txt
  • internal/apiv2/notification_apple_push.go
  • internal/apiv2/notification_apple_push_test.go
  • internal/apiv2/problem.go
  • internal/apiv2/router.go
  • internal/contractledger/ledger_test.go
  • internal/notifications/apple_push_ordering.go
  • internal/notifications/push_devices_test.go
  • internal/notifications/push_legacy_ownership_test.go
  • scripts/ci/db-contracts.txt
  • web/src/api/v2/operations.ts
  • web/src/api/v2/schema.ts

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

Comment thread docs/notifications-push-api.md Resolved
The two approvals added for the roku diagnostics platform (Silo-Server#3298) match
no change against main any more, and the v2 contract check refuses stale
approvals whenever openapi.json changes.
@silo-kody

silo-kody Bot commented Nov 1, 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 ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

@macroscopeapp

macroscopeapp Bot commented Nov 1, 2026

Copy link
Copy Markdown

The Validation tasks: line omits Server task #1234 C2. That case explicitly covers device registration, and this PR changes the owner-key mismatch response and adds the reset/re-registration path. The task's Results table is still Not run, so there is no earlier result to invalidate; please include the pending server case alongside the iOS cases.

Suggested fix:

Validation tasks: none passed; reaches #1234 C2 and Silo-Server/silo-apple#336 C1 and C2 (not run yet)

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

…account

A reset cleared the installation's owner along with its key and
generation, and deleted the device's Apple push rows. Until the owner
registered again, any account that knew the device_id could bind the
installation through ordered bootstrap or the legacy writer, and the
owner could then neither register nor reset.

The reset now keeps the installation's account. Ordered bootstrap and
the legacy Apple writer refuse another account while that reservation
holds. The owner still registers with any key at any positive
generation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Quick104 Quick104 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.

Review of 31e1688: one verified defect and one docs gap. I'm fixing both in a commit on this branch, so there's no need to change them yourself. A summary with scores follows as a separate comment.

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

Comment thread docs/notifications-push-api.md Resolved
@silo-kody

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

Quick104 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 31e1688, base 63ef34b. The fix is d7712a7, pushed as an ordinary commit on this branch. Main has moved to 81ae2ce, and the branch still merges cleanly.

Fit: 8/10 · Readiness: 8/10 — conditional (assuming CI is green)

  • Fit: A reinstalled iPhone that never gets push again is a real 1.0 defect in a core feature, and only the server can safely release the old binding. The change adds three permanent /api/v2 surfaces: an operation, a problem type, and a capability field. That is the main stretch. It is justified, because the server cannot tell a reinstall from another account without the owner's say.
  • Readiness: The approach is sound, and the one defect the review found is fixed and proven by a test. Two conditions remain. Nobody has run a live check of the fixed behavior on a deployed server. A retirement can also land during the recovery window, which is described below.

Fixed on this branch

  • A reset left the installation open to any account (high). The reset cleared user_id and deleted the device's Apple push rows. Until the owner registered again, any account that knew the device_id could bind it, through ordered bootstrap or the legacy Apple writer. The owner could then neither register nor reset. The reset now keeps the account, and both writers refuse another account while that holds. The added assertions in TestApplePushInstallationResetDB fail on 31e1688 and pass on d7712a7. CodeRabbit's security review raised the same window.
  • The reset's 403 had more causes than the doc listed (low). A non-canonical key and a token without a current login session also get permission_denied. The doc now names both.

Left for the maintainers

  • Retirement during the recovery window. After a reset, the installation is at generation 0. A session-less retirement that arrives before the owner's next registration answers removed and records nothing. A registration still in flight from before the retirement then binds and turns delivery back on. Main behaves the same way for an installation that has never registered. The reset makes that state reachable again for a bound device, but only within the owner's own recovery sequence. Closing this would mean storing the new key during the reset, so a matching retirement could record its generation. That is a larger change to the retirement contract.
  • The reset does not check the session again after taking the lock. Registration does, because it mints a display token under the lock. For the reset, the request middleware has already checked the session, and the worst a session revoked mid-request can do is delete its own account's Apple registrations. I left it as is.

Checks

  • Tests: The PR's new tests don't build on the base, because they call the new reset code, so none of them failed on the base. The added reservation assertions failed on 31e1688. Against a migrated local Postgres, ./internal/notifications, the Apple push tests in ./internal/apiv2, go build ./..., go vet on the touched packages, and make lint-changed pass on d7712a7.
  • Validated features: The board was unreadable in this run, so I couldn't confirm which cases have passed. The task bodies show Notifications — Server #1234 C2 and Notifications — iOS silo-apple#336 C1 and C2 as not run. The change reaches Notifications — Server #1234 C2 (registration after a reinstall) and the iOS registration cases. I found no regression.
  • User manual: No siloserver.org page covers iOS push registration or its recovery, so the manual needs no change.
  • Apple and Android: fix(notifications): recover Apple push after the installation key changes silo-apple#977 is the Apple pair, and users only get the recovery once it ships. Android installations keep their binding without a reset path, as the doc states. I didn't check whether a reinstalled Android app keeps its device_id.
  • Breaking-change approvals: internal/contractspec fails CI on an approval that matches no change, and the feat(diagnostics): accept the roku platform #3298 enum change is already on main. Removing the two approvals is required.
  • Cross-provider review: One round by Codex (gpt-6.1-sol) on 31e1688. It found the same unowned-reset defect, now fixed. It also raised the retirement window and the missing re-check after the lock, both described above.

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

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

if _, err = tx.Exec(ctx, `DELETE FROM push_devices WHERE device_id=$1 AND platform=$2`, cmd.DeviceID, PushPlatformApple); err != nil {
return false, err
}
if _, err = tx.Exec(ctx, `UPDATE apple_push_installations SET installation_key_hash='',generation=0,profile_id='',intent_hash='',registration_id='',server_device_id='',push_mode='' WHERE device_id=$1`, cmd.DeviceID); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

Ownership-check bypass in internal/notifications/apple_push_ordering.go occurs because retaining user_id on reset creates a foreign-owned generation-zero state, and ResetApplePushInstallation returns a successful no-op for generation == 0 before checking ownership, giving a different account 200 {"reset":false} instead of the documented 403. Check a nonzero stored owner before returning for generation zero, while preserving the no-op for unowned installations.

Prompt for LLM

File internal/notifications/apple_push_ordering.go:

Line 362:

Ownership-check bypass in internal/notifications/apple_push_ordering.go occurs because retaining user_id on reset creates a foreign-owned generation-zero state, and ResetApplePushInstallation returns a successful no-op for generation == 0 before checking ownership, giving a different account 200 {"reset":false} instead of the documented 403. Check a nonzero stored owner before returning for generation zero, while preserving the no-op for unowned installations.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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.

Confirmed on d7712a7: the reset returned before the ownership check for a reserved generation-zero installation. I added assertions to the existing database test for a foreign-account reset and the owner's idempotent retry. The foreign-account assertion fails on that head. I am moving the ownership check ahead of the generation-zero return; an unowned placeholder still returns a no-op. — Codex in T3 Code, gpt-6-astra

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That addresses the reported bypass. The ordering should be:

  1. Acquire the installation lock and handle any error.
  2. Read the stored owner and reject a nonzero owner different from the caller, even when generation is zero.
  3. Return a no-op for generation zero, preserving the behavior for an unowned placeholder and the owner’s retry.
  4. Continue with the existing same-key check and reset logic.

The added assertions target the regression: a foreign-account reset must remain 403 permission_denied after the owner resets, while the owner’s repeated reset returns {"reset":false}. The failing assertion on d7712a7 confirms the original finding; passing it after the change would verify this case.

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.

Fixed in 494100c. Reset now checks the stored owner before returning for a reserved generation-zero installation; an unowned generation-zero placeholder remains a no-op. The added foreign-account assertion fails on d7712a7 and passes with this fix. Owner retry, unknown-installation reset, Apple upsert, and Apple retirement checks pass against disposable Postgres, and make lint-changed reports 0 issues. — Codex in T3 Code, gpt-6-astra

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the reported change and test results, 494100c addresses this finding: ownership is checked before the generation-zero no-op, so a foreign account is still rejected after the owner resets, while owner retries and unowned placeholders remain no-ops.

The regression assertion failing on d7712a7 and passing with the fix directly covers the reported bypass. No further change is needed for this finding based on that evidence.

@silo-kody

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

silo-kody Bot commented Nov 1, 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 ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

@Quick104

Quick104 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

CodeRabbit follow-up on the summary covering d7712a7:

The foreign-account reset response is fixed in 494100c. Kody confirmed that fix, and the regression assertion fails before it and passes afterwards.

The older-writer concern is valid by source inspection: the earlier generation-zero path checks destination rows and can overwrite a retained owner after reset deletes those rows. The current writers reject this. I have not run a mixed-version deployment test.

774ea3b documents the compatibility requirement in docs/notifications-push-api.md: upgrade every API writer before allowing resets, and treat installation_reset_available as local to the responding server. It also links the existing backup-and-rollback policy, which requires restoring the pre-upgrade database when recovering to an older release. This documents an operational requirement; it adds no automatic cluster-wide gate. The incompatible mixed-version sequence remains unsafe.

This follow-up changes documentation only. git diff --check and make verify-local-paths pass. The earlier code verification remains applicable; CI on the new head is pending.

— Codex in T3 Code, gpt-6-astra

@Quick104

Quick104 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

The Go test failure on 774ea3b is the existing playback cleanup race tracked in #3361: TestRelayMovePreservesMandatoryAudio/legacy=true reports unconfirmed rehome status=502, cleanup=0. No other test failure appears in this job, and the notifications package passed.

The same failure was reproduced on the unmodified CI base during this review batch. The single retry also failed only on that same test: https://github.com/Silo-Server/silo-server/actions/runs/41359012025/job/125007720831. The aggregate CI result only propagated the Go failure. Required CI remains red; no further retry was requested.

— Codex in T3 Code, gpt-6-astra

@Quick104
Quick104 merged commit baf9d42 into Silo-Server:main Nov 2, 2026
31 of 35 checks passed
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/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.

[bug] iOS push registration permanently fails with 403 after reinstalling the app (stale apple_push_installations row)

2 participants