Skip to content

fix(notifications): recover Apple push after the installation key changes - #977

Merged
Quick104 merged 20 commits into
Silo-Server:mainfrom
Rhainland:fix/3348-push-installation-reset
Nov 2, 2026
Merged

Quick104 merged 20 commits into
Silo-Server:mainfrom
Rhainland:fix/3348-push-installation-reset

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: Silo-Server/silo-server#3348
Validation tasks: reaches #336 C1 and C2 (neither has a result yet)

The server side of this fix is Silo-Server/silo-server#3352, now merged.

When an iPhone sends an Apple push installation key that does not match the one the server stored for its device ID, the server refuses every registration with 403. The app holds the refusal and tries again after six hours or on the next launch, and gets the same 403 each time, so notifications never come back for that server. This happens when the device ID survives but the key does not: the app loses its installation record, or the same server is added again under a different address. The second case produces a mismatch every time, because the record that holds the key is stored per server address while the device ID is shared.

silo-server#3352 tells the owning account about the mismatch with the problem type push_installation_key_mismatch and adds POST /api/v2/devices/push/apple/reset. With this change the app uses them. When the mismatch comes from the same server saved under a second address, and that address proves it reaches the same server, both addresses share one installation record and key, and nothing is reset. Otherwise the app clears its own installation on the server with its current key and registers again.

Approach

When a registration gets push_installation_key_mismatch and the server's Apple push capability reports installation_reset_available, the registrar calls resetApplePushInstallation with the current key. It then sends the same registration again with the same key at the next generation. The cleared installation accepts any positive generation, and the next one stays above everything the device sent before the reset, so a sign-out retirement still in flight, or a hold from an earlier attempt, cannot outrank or block the new registration. It makes one reset per registration attempt: a second mismatch after the reset holds the generation as any 403 does now. A reset that gets no answer (timeout, 5xx) leaves the registration pending, so the next foreground or token change tries again. The contract makes a repeated reset safe. A refused reset holds the generation.

Behaviour stays as it is for permission_denied, for servers that do not report the capability, and for display-token renewals. A mismatch on a renewal means the same server is saved under a second address and that record registered since. Resetting there would let the two records take the installation from each other on every renewal, so only a new or pending registration resets. This departs from the contract's "the app resets its own installation" for that one case. A sign-out's or server removal's off never resets either: when the removed address loses the installation to the other one, a reset would clear the address that stays saved and then turn its pushes off. That off is held as today, and the retirement queued after it still runs.

Before resetting, the registrar checks whether another saved address is the same server. A matching server_id from GET /api/v2/system/identity only picks which addresses to ask: any server can report any ID, and the installation key alone is enough to retire this device's pushes on the server that holds it. The proof is a login session: the app reads the mismatched address's own current session ID from GET /api/v2/auth/sessions, then pages through the other address's session list, with that address's own credentials, looking for it (not marked as the caller's own). The list is always read from the address whose server ID was just checked, under its own last owner, never from a third address that happened to register last on a shared record. Session IDs are random UUIDs that only the issuing backend knows, so only the same backend, or a proxy for it, lists one. Each address is asked only about its own sessions, and nothing secret goes to the other address. When the proof holds, the record moves to a Keychain item of its own that no address owns, both addresses are linked to it, and:

  • a new or pending registration is sent again with the shared key at the shared record's next generation, with no reset;
  • a display-token renewal sends nothing more and drops this address's display target, since the other address holds the installation;
  • any accepted registration removes the display targets of the other addresses that share the record, so pushes for that server keep one target and show their text;
  • removing or signing out of an address that did not register last sends nothing, so the other address keeps its pushes. If the address that registered last goes, the installation is retired as before, and the other address registers again as itself on its next background pass, because the shared record keeps each address's last owner. While another saved address still shares the record, the retirement goes to that address rather than the departing one, since a retirement can be retried for months and another server may answer at the old address by then. The route is chosen again on every attempt, and nothing is sent if the two addresses stopped sharing the record in the meantime.

A link stores the server ID it was proven for. When an address later reports a different server (a reassigned local address, a fresh install at the same URL), only its own link is dropped, along with anything left in its own slot, and it starts over with its own key. The other addresses keep the record and key. While an address still shares the record it can hold the installation for the others. Once it stops sharing, or its server refuses its session's refresh, the others register, remove and restore as themselves. A refresh that only failed for now leaves the installation where it is.

Both transports get the reset and the session check: the active server's session and a saved server's stored session. iOS only; tvOS and macOS do not register for Apple push. Android has no matching recovery path in the contract.

Validation

  • ApplePushOrderedRegistrationTests: 53 passed. The two newest cases cover a refused refresh at the address that registered last (the other address registers as itself, while a 503 refresh moves nothing), and a hold left on an address's replaced record, which no longer blocks the registration after it links. The two cases before them cover an address that later reports another server: it never sends the shared key there, even with a copy left in its own slot, and the other address keeps the record; and removing or restoring the first address after the second moved, with nothing run for the second in between. The six cases before them cover a proven second address sharing the key with one display target left; a server that claims the same server_id but fails the session check, which never receives the key (two cases: an unknown session ID, and the holder's own current session ID); removing the address that does not hold the installation; a renewal that hands the installation and target over; the other address registering again after the holder is removed; and an address that later reports another server dropping its link. Each new guard was disabled once to confirm its test fails without it.
  • Push registration unit tests at the earlier commit (ApplePushOrderedRegistrationTests, ApplePushRegistrationTests, ApplePushNotificationSyncTests): 72 passed, including cases for mismatch with and without the capability, permission_denied, reset: false, the one-reset limit, unanswered and refused resets, a lost answer after a reset that follows an earlier refused one, and a sign-out off that meets a mismatch and is held without a reset.
  • Full SiloTests suite on an iPhone 17 Pro simulator (iOS 26.5) at the final commit: 3678 tests, 3 failures, all in PlaybackProtocolV3Tests (watch-party seek). The same 3 fail on main and on this branch before the shared-record commits.
  • Builds: Silo (iOS Simulator), SiloTV (tvOS Simulator) and SiloMac (macOS) succeed.
  • scripts/ci/check-no-api-v1.sh: ok.
  • Maintainer review fixes (47ac93c, b5403a8): seven regression tests in ApplePushOrderedRegistrationTests cover an address whose stale link lends no record, a moved address's display target (also from a late answer), a restore during the teardown's lookup, a registration from the other address ending the holder's teardown (also with an off already waiting for its turn), and an allocation planned before the link ended. Each failed on the head before its fix and passes at b5403a8. The push registration suites (ApplePushOrderedRegistrationTests, ApplePushRegistrationTests, ApplePushNotificationSyncTests) pass, 89 tests, on an iPhone 17 Pro simulator (iOS 27.0). scripts/ci/check-no-api-v1.sh: ok. The full SiloTests suite and the tvOS and macOS builds were not re-run locally for these commits; CI covers them. The stale-link removal failure has no test, since it needs a Keychain delete failure.
  • Second maintainer review fixes (6d4a794, 7bbbdab, 79b2e5d, 20c3c76, f5d0541, c1348ea, 8fea10a): seven regression tests, each seen failing first. testProofComesFromTheCandidatesOwnAddressNotTheLastToRegister failed at b5403a8 (a third address claiming the first one's server ID got the shared key). testRetirementForASharedRecordGoesThroughAnAddressStillSharingIt failed at b5403a8 and at 6d4a794. testRetryReadsTheRecordAfterItsRoute failed at 7bbbdab. testHoldEndsWithTheLinkItNamedAGenerationOf failed at 79b2e5d. testSharedKeyIsCheckedAgainRightBeforeASavedAddressSends failed at 20c3c76. testSharedKeyIsCheckedAgainRightBeforeTheActiveServerSends failed at f5d0541; c1348ea adds an optional beforeDispatch hook to HTTPClient.requestData for it, which only the push registration and reset pass. testSharedKeyIsCheckedAgainBeforeTheSavedAddressFallback failed at c1348ea; 8fea10a runs the hook again before a local-route request's retry at the saved address. 20c3c76 also writes an allocation to the record slot it checked; that race between two actors has no deterministic test. At 8fea10a on an iPhone 17 Pro simulator (iOS 27.0): the full SiloTests suite passes (3696 tests, 0 failures).
  • End-to-end at 79b2e5d against an isolated server built from silo-server main (baf9d426, with #3352 merged), on a pool iPhone simulator with the same local token patch: one server saved under its IP address and its host name. The second address shared the key after the session check with no reset (403 mismatch, listSessions ×2, 200). Signing out of the address that registered last retired the installation, and the other address then registered again with the shared key. At 7bbbdab, a replaced key hash on the server led to 403 mismatch, reset 200, register 200, and a later relaunch sent nothing.
  • Local end-to-end run against a server built from silo-server#3352, on an iPhone simulator. The simulator gets no APNs device token on the test host, so a local debug patch, not part of this branch, fed a fixed token into the app's normal didRegisterForRemoteNotifications path. Everything after that (the registrar, the Keychain record and the server) ran unmodified. The steps: sign in at one address and allow notifications (registered), then reinstall the app and sign in to the same server at a second address. That creates a new key for the same device ID. The results are under Evidence.
  • A second local run for the shared record: one server reached as http://127.0.0.1:<port> and http://localhost:<port>, which the app saves as two servers. Sign in at the first address and allow notifications, then add the second address and sign in to the same account, with no reinstall. Run once with the build before the shared-record commits and once with the final build on an erased simulator. Results under Evidence.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-apple/pr-977/ (request logs from the end-to-end run at 79b2e5d against server main, and the test results at 8fea10a).

The change affects background push registration only, so the evidence is the server log from the local run described under Validation. Before: main at 3bd7573. After: this branch at d167787. A notification arriving on a device cannot be shown here: the simulator gets no APNs device token on the test host, and this change does not touch delivery. It only gets the device registered again, which the log shows.

Before, on main: every launch is refused, and the app never sends a reset.

operation_id=registerApplePushDevice      status=200                                  # first address
operation_id=registerApplePushDevice      status=403 error_code=push_installation_key_mismatch
operation_id=registerApplePushDevice      status=403 error_code=push_installation_key_mismatch   # relaunch
operation_id=registerApplePushDevice      status=403 error_code=push_installation_key_mismatch   # relaunch

After, with this branch (same steps; also seen when the fixed build is installed over the stuck one):

operation_id=registerApplePushDevice      status=403 error_code=push_installation_key_mismatch
operation_id=resetApplePushInstallation   status=200
operation_id=registerApplePushDevice      status=200

The server then holds an enabled Apple push_devices row for the device, and the installation is bound to the new key. A later relaunch sends nothing more. That run predates d751581, which changed the generation sent after the reset (the next one instead of 1); the request sequence is the same.

Same server saved under a second address, before the shared-record commits (edc0d54): the second address resets the installation, and both addresses then keep a display target.

operation_id=registerApplePushDevice      status=200                                  # first address
operation_id=registerApplePushDevice      status=403 error_code=push_installation_key_mismatch   # second address
operation_id=resetApplePushInstallation   status=200
operation_id=registerApplePushDevice      status=200

After, at this branch's head: the session check passes, and the second address registers with the first address's key at generation 2, with no reset. A relaunch sends nothing more.

operation_id=registerApplePushDevice      status=200                                  # first address
operation_id=registerApplePushDevice      status=403 error_code=push_installation_key_mismatch   # second address
operation_id=listSessions                 status=200                                  # second address: its own session
operation_id=listSessions                 status=200                                  # first address: its session list
operation_id=registerApplePushDevice      status=200

The server's apple_push_installations row for the device is at generation 2. Accepting generation 2 after generation 1 with no reset in between means the second address sent the first address's key.

Risks

  • Needs silo-server#3352 (merged). Against an older server the capability field is missing and nothing changes.
  • After a reset, the server leaves the installation at generation 0, and a retirement at generation 0 stores no fence. If the registration after a reset loses its answer and the person then signs out, a late arrival of that registration can turn pushes back on. The app can't tell this apart, so it's tracked on the server in Apple push retirement after an installation reset stores no fence, so a late registration can revive pushes silo-server#3413.
  • A reset deletes the device's Apple push rows on the server before the new registration lands. A push sent in that gap is lost.
  • With the same server saved under two addresses, a new registration from either one takes the installation from the other. That is the same last-writer rule a profile switch follows today.
  • Two addresses share a key only when both are signed in to the same account: the proof looks for one address's session in the other's list. Two different accounts on one server under two addresses keep separate records and fall back to the reset, as before.
  • Anyone who holds the person's password for the account could make a fake server pass the session check by signing in to the real one and reporting that session. That person already has the account, which can do far more than retire this device's pushes.
  • The check costs up to 11 small requests, once per address pair, while the registrar holds its turn.
  • A server saved under one address keeps its record keyed by that address, as today. If a different server later answers there, it receives that record's key. A shared record has no such owner: every address sharing it checks its reported server ID. That check reads the cached ID, which an address not in use refreshes only when it is activated or brought to the foreground, so a reassigned address is noticed then rather than at once.
  • When the other address can't be reached for the session check (a LAN address while away), the check counts as no proof and the app resets instead. Delivery recovers at once, but both addresses keep a display target, so push text stays generic until the other address renews and hands its target over.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • 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, XcodeGen, xcodebuild, xcrun simctl, AXe
  • Model(s): claude-opus-5-5; gpt-6.1-sol (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: independent reviews of the full diff by Claude Opus (claude-opus-5-5) and GPT (gpt-6.1-sol), on correctness, repository standards and the contract, reconciled. Fixed: a reset that failed for a transient reason held the registration for six hours, so it now stays pending and the next trigger resets again. Also fixed: the registrar's outcome documentation had gone stale, the reset receipt decoding was duplicated, and two comments were inaccurate. Not changed: an in-flight retirement from a second saved address of the same server could undo a recovered registration. That needs a sign-out that is cancelled while its request stalls, so it was judged unlikely. The skipped renewal case is described under Approach. Both models re-reviewed the follow-up commit and found only a comment fix, which was applied. A third commit answers two PR review comments: after a reset the app registered at generation 1, below a hold from an earlier refused reset and below a sign-out retirement that could still arrive. It now registers at the next generation. Both models reviewed that commit; the one finding, an unneeded journal reload, was removed. A fourth commit answers a further review comment: a sign-out off no longer triggers the reset. Both models reviewed it and found nothing. The shared-record commits answer the last open review comment (two display targets for one server). Both models reviewed them in three rounds. Fixed from those rounds: the other address could not register again after the address that registered last was removed or lost its session; a link was never dropped, so a different server later saved at a linked address would get the shared key; and a renewal or a record from an earlier build left an address's owner out of the shared record. Not changed: a different server later answering at the address that owns the shared record still receives its key, which a single address already does today (see Risks). Also dismissed: links in an older format, since the commit that wrote them was never released. After the push, CodeRabbit and Kody found two more cases where an address reports another server: the other address's teardown and maintenance still followed the departed address, and the address whose slot held a shared record kept sending its key. Both are fixed. The second is fixed by keeping shared records in a slot no address owns, after a first fix (handing the record over) failed review: it could be interrupted between Keychain writes, missed removed addresses, and missed link chains. Both models reviewed the last three commits in three rounds; the last round found only a doc comment, now fixed. Codex then found two more: a holder whose refresh was refused kept its saved session, so the other address never took over, and a hold on an address's replaced record could block the registration after the link for six hours. Both are fixed. Both models reviewed those fixes. They found that the first version also moved the installation on a temporary refresh failure, and that its test's token lifetime was tight; both are fixed. Declined: Kody's request to re-check both logins after each page of the session check. The check proves which backend an address reaches, which an account switch doesn't change, and every write after it already runs under the owner fence.
  • Maintainer review (Claude Code, claude-opus-5-5, with two cross-provider rounds by Codex gpt-6.1-sol) of b62d6a9 and 47ac93c found eight defects in the shared-record paths, fixed in 47ac93c and b5403a8. A second maintainer review (Claude Code, claude-opus-5-5, with two cross-provider rounds by Codex gpt-6.1-sol on 6d4a794 and 7bbbdab) fixed Codex's holder-proof finding and the pending-retirement route in 6d4a794, 7bbbdab and 79b2e5d, and two later Codex findings (an allocation written to the wrong slot after an unlink, and a hold outliving its link) in 20c3c76, and a saved or active address's key checked only before its credential lookups or a local-route fallback in f5d0541, c1348ea and 8fea10a. Declined: serializing a routed retirement's synchronous last steps with link removal, the same irreducible gap that sits between any check and the send. Declined with evidence: Kody's request for live identity proof before a routed retirement, since the alias already receives the shared key under the same check on every renewal. The server's generation-0 retirement fence moved to silo-server#3413. Details are in the review summary comment.

Note

Recover Apple push registration when the installation key changes

  • Adds an installation-reset path for the installation-key-mismatch 403: the registrar resets the installation and retries the same intent at a later generation with the same key, via new resetApplePushInstallation and loginSessions endpoints in APIv2Client.swift
  • Adds shared installation records: two saved addresses with the same proven deployment identity can link to one journal record in ApplePushInstallationJournal.swift, sharing its key and generation state. Registration, restore, unregister, and retirement in ApplePushRegistration.swift now respect shared-record ownership
  • Guards every dispatch with a beforeDispatch key-ownership check in HTTPClient.swift, so a request is not sent when its server record no longer holds the installation key
  • Risk: unregister no longer sends an off request or retires a shared installation while another saved address still holds the record; reset requests are added to the replay allowlist in APIv2RetrySafety.swift, and link chains deeper than 8 report unreadable journal state

Macroscope summarized 8fea10a.

… again

An iPhone whose installation key no longer matches the server's (the app
lost its journal, or the server was saved again under another address,
which gives a new key for the same device ID) had every push registration
refused with 403 and held forever.

Servers that report installation_reset_available now answer the owning
account with push_installation_key_mismatch. On that answer the registrar
calls resetApplePushInstallation with the current key, starts the journal
over with the same key, and registers the same intent at generation 1. It
tries this once per registration attempt; a second mismatch, a failed reset,
permission_denied, a renewal, or a server without the capability keep the
existing hold-and-retry behaviour.
A reset that times out or meets a server error now leaves the intent
pending, so the next trigger resets again, which the contract makes safe.
Only a refused reset holds the generation. Documents the reset outcome on
the registrar and shares the reset receipt decoding between transports.
@silo-triage silo-triage Bot added the size/L 200–499 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 ❌

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T05:28:32.226683Z 8fea10a New commits
ℹ️ About Codex in GitHub

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

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

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

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

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: 18c660a3-8133-4293-a67d-5bb8364d1f43
Commits

Reviewing files that changed from the base of the PR and between 47ac93c and 79b2e5d.

Files selected for processing: 3
  • iosApp/Tests/ApplePushOrderedRegistrationTests.swift
  • iosApp/iosApp/Notifications/ApplePushRegistration.swift
  • iosApp/iosApp/Notifications/ApplePushRetirement.swift

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

Walkthrough

The iOS client adds session-based proof for sharing Apple Push installation records across saved addresses. The registrar routes retirements through valid linked addresses and resets eligible installation-key mismatches before retrying at a higher generation. Tests cover sharing, ownership changes, teardown races, and reset outcomes.

Changes: Apple Push Installation Sharing and Recovery

Layer / File(s) Summary
Session proof and reset API
iosApp/iosApp/Networking/APIv2/APIv2PushModels.swift, iosApp/iosApp/Networking/APIv2/APIv2Client.swift, iosApp/iosApp/Networking/APIv2/APIv2RetrySafety.swift, iosApp/iosApp/Notifications/ApplePushRegistrationChannel.swift
The API supports paginated session retrieval and installation reset. The registration channel checks session pages for a matching non-current session and sends reset requests.
Shared installation journal
iosApp/iosApp/Notifications/ApplePushInstallationJournal.swift
The journal resolves saved-server links to shared records, stores owner history, and tracks intent ownership. It removes links when the recorded deployment identity no longer matches.
Registration sharing and mismatch recovery
iosApp/iosApp/Notifications/ApplePushRegistration.swift, iosApp/iosApp/Notifications/ApplePushDisplayTargets.swift
The registrar links records after deployment-identity and session-proof checks. It manages display targets across linked addresses and resets eligible non-teardown key mismatches before retrying at a higher generation.
Retirement routing and retries
iosApp/iosApp/Notifications/ApplePushRegistration.swift, iosApp/iosApp/Notifications/ApplePushRetirement.swift
Retirement attempts can use another saved address that still shares the record. The queue checks that the route still maps to the recorded slot before sending.
Sharing and recovery behavior tests
iosApp/Tests/ApplePushOrderedRegistrationTests.swift
The test harness configures session pages, deployment identities, reset responses, and asynchronous gates. Tests cover sharing, ownership changes, stale links, credential failures, retirement routing, teardown races, and reset outcomes.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ApplePushRegistrar
  participant ApplePushRegistrationChannel
  participant LoginSessionsAPI
  participant ApplePushInstallationJournal
  ApplePushRegistrar->>ApplePushRegistrationChannel: Check for shared backend session
  ApplePushRegistrationChannel->>LoginSessionsAPI: Fetch session pages
  LoginSessionsAPI-->>ApplePushRegistrationChannel: Return session pages
  ApplePushRegistrationChannel-->>ApplePushRegistrar: Report session match
  ApplePushRegistrar->>ApplePushInstallationJournal: Link shared installation record
  ApplePushRegistrar->>ApplePushRegistrationChannel: Register with shared installation key
Loading

Possibly related PRs

Suggested labels: api-v2, impact: usability, evidence-required

Suggested reviewers: quick104

Merge Risk: Minimal · up to 79b2e

This change lets saved addresses that reach the same server share an Apple push installation, and it recovers push registration after an installation-key mismatch. The reviewed concurrency and ownership races were fixed and have regression tests, and no unresolved defect is supported by the supplied evidence. The remaining notes are a test timing choice and a known fallback risk already listed by the maintainers. Server-side support in silo-server#3352 was not yet merged when the review was written. The author also did not demonstrate APNs delivery or rerun the full suite and tvOS/macOS builds locally.

Security architecture risk: Moderate · up to 79b2e

The recovery flow preserves notification ordering, but a previously linked address can retain access to a shared installation key after that address changes hands. Under those conditions, the new endpoint could obtain authority to disable this device’s notifications on the original server.

Retained concerns

  • Medium · security · inferred: A persisted alias can disclose the surviving deployment’s installation key after endpoint reassignment. Session proof authorizes initial sharing, but later registration and retirement routing accept the persisted link while cached deployment identity remains unchanged; failed identity discovery does not invalidate that identity. If a formerly proven address comes under another operator’s control and is selected for registration or retirement, journal-slot equality does not establish that it still reaches the proven deployment. The endpoint can receive the shared key, device ID, and generation. The documented retirement contract uses those values without login credentials. Before this PR, a second address retained its separate key rather than receiving the working key from the surviving address. Explicitly detected identity changes and slot changes are handled, but they do not cover stale identity after reassignment.
Security review details

Security Blast Radius

  • inferred — The demonstrated exposure concerns a shared Apple Push installation for one device and deployment across its linked addresses. An attacker must control an endpoint previously proven as an alias, not merely supply an arbitrary matching deployment ID. The client contract supports session-free retirement with the disclosed key; broader account, tenant, or data-store compromise is not established.

Security Findings and Attack Paths

  • inferred — After legitimate linking, a reassigned alias can retain its cached deployment identity and persisted link. If selected for a queued retirement, route selection and slot validation can succeed without a current login session or fresh backend proof, transmitting the surviving deployment’s key to the new endpoint. Tests verify protection after an identity change is supplied and the link is actually removed; that counterevidence does not establish protection when identity discovery fails or remains stale.

Trust Boundaries and Controls

  • observed — Initial sharing requires session-membership evidence beyond self-asserted deployment identity. Saved-server requests require matching account ID and epoch, and allocation and display-target writes run under owner authority. Journal-slot checks block sends after an actual unlink. These controls protect initial linking and local ownership but do not independently authenticate a persisted alias’s current deployment.

Resilience and Maintainability Implications

  • observed — Reset recovery preserves the key, advances the generation, and disables further reset/share recursion for that retry. Unknown reset outcomes remain pending. Teardown establishes its fence before suspension, while retirement allocation waits for the ordered registration turn and then advances the generation. This limits stale recovery work without relying solely on cancellation.

Hardening Proposals

  • proposed — Bind shared-key use and retirement routing to current, independently verifiable deployment authority. Where that authority cannot be established, defer transmission rather than treating cached identity or slot equality as sufficient. Revalidate the binding after asynchronous proof and before committing a new link; cover reassignment with failed identity discovery and session-free retirement in focused transition tests.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 78.95% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: recovering Apple Push registration after an installation-key mismatch.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description directly explains the Apple push installation-key mismatch recovery, reset endpoint integration, shared installation records, registration behavior, testing, and known risks. These top…
Full details: Description check

Explanation

The description directly explains the Apple push installation-key mismatch recovery, reset endpoint integration, shared installation records, registration behavior, testing, and known risks. These topics match the changeset.

Full details: Docstring Coverage

Explanation

Docstring coverage is 78.95% which is insufficient. 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 38 functions across 9 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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 bug Something isn't working priority: P2 Limited scope, workaround exists, or polish labels Nov 1, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 1, 2026

Copy link
Copy Markdown

This reset path can restore Apple push delivery, making notifications visible on iPhone, iPhone Duo (folded and open), and iPad. The Evidence section says there is no user-visible change and provides only server logs, so it does not show this effect. Please add a recording or captures showing a notification arriving for each of those device configurations, identified with the device and build or commit.

Suggested fix: No diff — add the requested notification evidence.

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

Posted via Macroscope — Visible change evidence

Comment on lines +605 to +608
// The same key, and no generation: the server accepts any
// positive generation now, and this record starts again at 1.
let fresh = ApplePushInstallationRecord(installationKey: command.installationKey, generation: 0, latest: nil)
restarted = try ApplePushInstallationJournal.plan(fresh, desired: command.intent, renewDisplayToken: false)

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 high

Generation ordering failure in iosApp/iosApp/Notifications/ApplePushRegistration.swift occurs when an aborted sign-out followed by restore resets ApplePushInstallationRecord to generation 0 and restarts registration at generation 1 with the same command.installationKey. ApplePushRetirementQueue.cancel removes only queued records, so an already-dispatched retirement with that key and a higher generation can arrive after the reset and recovered registration, causing the server to accept the stale retirement and disable pushes that restore just re-enabled.

Prompt for LLM

File iosApp/iosApp/Notifications/ApplePushRegistration.swift:

Line 605 to 608:

Generation ordering failure in iosApp/iosApp/Notifications/ApplePushRegistration.swift occurs when an aborted sign-out followed by restore resets ApplePushInstallationRecord to generation 0 and restarts registration at generation 1 with the same command.installationKey. ApplePushRetirementQueue.cancel removes only queued records, so an already-dispatched retirement with that key and a higher generation can arrive after the reset and recovered registration, causing the server to accept the stale retirement and disable pushes that restore just re-enabled.

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 Author

Choose a reason for hiding this comment

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

Agreed, and it's worse than a lost registration: once a stale retirement with a higher generation lands, a registration restarted at 1 would get 409s until the counter caught up. Fixed in d751581. After a reset the app registers at the generation after the refused one, above everything this record sent before the reset, so a retirement still in flight from before it is ordered below the new registration and refused.

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 original finding as described. Registering at the next generation, rather than restarting at 1, keeps the recovered registration above earlier retirements from the same installation record. A delayed retirement therefore cannot disable it or leave subsequent registrations receiving 409s while the counter catches up.

The separate cross-address retirement race remains outside this fix; it does not invalidate this correction.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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: 256ecc1f-50a4-4a1b-b587-a901beeb7939
Commits

Reviewing files that changed from the base of the PR and between 3bd7573 and d167787.

Files selected for processing: 7
  • iosApp/Tests/ApplePushOrderedRegistrationTests.swift
  • iosApp/iosApp/Networking/APIv2/APIv2Client.swift
  • iosApp/iosApp/Networking/APIv2/APIv2PushModels.swift
  • iosApp/iosApp/Networking/APIv2/APIv2RetrySafety.swift
  • iosApp/iosApp/Notifications/ApplePushInstallationJournal.swift
  • iosApp/iosApp/Notifications/ApplePushRegistration.swift
  • iosApp/iosApp/Notifications/ApplePushRegistrationChannel.swift

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d167787417

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +607 to +608
let fresh = ApplePushInstallationRecord(installationKey: command.installationKey, generation: 0, latest: nil)
restarted = try ApplePushInstallationJournal.plan(fresh, desired: command.intent, renewDisplayToken: false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear the old hold when restarting the installation journal

In the iOS registrar, if an earlier reset refusal held generation 1, a token/profile change can allocate generation 2 and successfully reset the installation. This restart then reuses generation 1 without clearing the old held[serverID] entry. If the post-reset registration fails with a transport error before reaching the server, dispatch returns .uncertain, but the next same-intent foreground attempt returns .notSent(reason: "held") because the old hold matches the new generation. Notifications remain unrecovered for the remainder of the six-hour hold window, unless the app is relaunched. Clear the old hold after a successful reset, or keep generations monotonic.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed: a new test reproduced it on the old code (the retry after a successful reset came back notSent(held)). Fixed in d751581 by keeping generations increasing. After a reset, the registration goes out at the generation after the refused one instead of restarting at 1. The server's cleared installation accepts any positive generation, so a hold from an earlier attempt can no longer match it.

…lation reset

After an owner reset the journal restarted at generation 1. A retirement
from a sign-out already sent at a higher generation could then land after
the new registration and switch push off, and every later registration
from the lower generation got 409. A hold left on generation 1 by an
earlier refused reset also blocked the replay of a post-reset registration
whose answer was lost, for six hours.

The registration after a reset now takes the next generation above the
highest the record has allocated. The cleared installation accepts any
positive generation, so the server still binds it, and nothing sent
before the reset can outrank it.
@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 ❌

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d751581b72

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +528 to +529
if mayResetInstallation, !command.isRenewal, Self.isInstallationKeyMismatch(error) {
return await resetInstallation(after: command, body: body, through: channel)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exclude teardown intents from installation-key recovery

If the same server is saved at two URLs and the newer entry has recovered successfully, removing the older entry can disable notifications for the surviving one when its retirement request fails in transport or exceeds retirementBudget. unregister then sends a new pushMode == "off" intent, which passes this non-renewal guard and resets the surviving entry's installation before disabling it. The surviving entry still has an accepted journal entry and current display target, so subsequent foreground attempts return .unchanged and leave pushes disabled until another intent change. An off teardown should not reclaim an installation belonging to another saved entry.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed and fixed in edc0d54. A teardown's off no longer triggers the reset. On a mismatch it gets today's hold, and the retirement queued after it still runs, so the alias that's still saved keeps the installation. testTeardownOffOnAKeyMismatchIsHeldWithoutAReset covers it; it sent a reset and came back .registered before the fix.

Comment on lines +619 to +620
return await dispatch(retry, allocating: restarted.record, body: body, through: channel,
mayResetInstallation: false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reconcile display targets when recovering a second server address

When a second saved URL for the same deployment/profile is recovered with a display token while the original URL's target remains, this retry creates two local targets. ApplePushDisplayTargetStore.save only replaces targets with the same registryServerID, so it preserves the original target. ApplePushDisplayStateReader.route then returns .ambiguousTarget at ApplePushDisplayMetadata.swift:195–196, and NotificationService skips display fetching for every push naming that server/profile. Notifications therefore retain generic content despite successful recovery, and the original URL's previously working display route also stops working. Recovery needs to reconcile legitimate alias targets while retaining the existing protection against unrelated servers claiming the same identity.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed: after the second alias recovers, both aliases hold a display target for the same server and profile, route returns .ambiguousTarget, and pushes for that server fall back to generic content.

I haven't fixed it in this PR because the direct fix weakens the identity check. Dropping other entries' targets with the same server_id after a reset trusts an ID each server reports about itself. A saved server could then claim another server's identity, trigger a reset and take over its display route. The safe options need new logic: renew each other alias with the same identity and profile after a reset, and drop only the targets whose own server answers with a mismatch. Or have an alias drop its own target when a renewal gets a mismatch, which only takes effect when the target expires. The PR lists this under Risks while a maintainer picks the approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fca323e, 83605dd and a989b95, with the journal now shared per server rather than per address.

When an address hits push_installation_key_mismatch, the app looks for another saved address that reports the same server_id. That ID only picks which address to ask. The proof is a login session: the mismatched address's own current session ID has to appear in the other address's session list, each fetched with that address's own credentials. Only the same backend can list it, so a server that merely claims the ID never receives the key.

Once proven, the two addresses share one journal record and key, and nothing is reset. An accepted registration removes the other address's display target, so one target is left per server and profile, and pushes keep their text. A renewal that hits the mismatch hands the installation and target to the other address, which also repairs a device already left with two targets.

Tests cover a proven second address, a server claiming the same ID without the proof, and the handover. An end-to-end run with one server saved under two addresses is in the PR body.

…rdown's off

When one server is saved under two addresses and the older entry is
removed, its off intent meets the surviving entry's key. Resetting there
cleared the surviving entry's installation before disabling it. A
teardown's off now keeps the hold behaviour on a key mismatch.
@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 ❌

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edc0d543ff

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let serverID = channel.owner.serverID
let mismatch = "http_403_\(Self.installationKeyMismatch)"
do {
let receipt = try await channel.reset(command.intent.body.deviceId, command.installationKey)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restore the surviving alias when the recovered entry is removed

If A is registered and a second saved URL B for the same deployment/account/profile recovers here, removing B successfully retires the only live installation while A's journal still says .accepted. Credential cleanup removes only B's display target, so A's still-current target makes needsDisplayToken false and register returns .unchanged on subsequent foregrounds with the same intent, leaving the still-saved, signed-in A without notifications. This reaches the normal .retired early return in unregister, not the off fallback protected by the new guard. Record the alias handoff so retiring the recovered entry can restore registration through a surviving saved entry.

Useful? React with 👍 / 👎.

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.

This is handled by the shared-record commits (fca323e onward), and the case still holds at b5403a8. Both addresses now share one record, which keeps each address's last owner. When the address that registered last is removed, its retirement stops the installation, and the next saved-server pass registers the surviving address again as itself with the shared key. testSurvivingAddressTakesTheSharedInstallationBackAfterTheHolderIsRemoved covers this sequence and passes at b5403a8.

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

…r's proven addresses

One server saved under two addresses has one installation for this
device, but each address kept its own journal record and key, so the
second address hit a key mismatch and, after a reset, both kept a
display target and pushes for that server lost their text.

On a key mismatch, an address now looks for another saved address that
reports the same server identity and lists this address's own login
session. Session IDs are random and only the issuing backend knows
them, so the reported identity alone never shares a key. A proven
address links its record to the other's, registers with that key at
the next generation, and a renewal hands the installation over
instead. An accepted registration removes the other addresses'
display targets, and removing an address that does not hold the
installation sends nothing.
… holder leaves

A shared installation record remembered only the owner of its latest
intent, so once the address that registered last was removed or lost
its session, the other address could not register again until it was
the active server. The record now keeps each address's last owner, and
maintenance registers a surviving address as itself when the latest
owner no longer holds its session.

A link also records the deployment identity it was proven for, and is
dropped once the address reports another deployment, so a different
server later saved at that address never gets the shared key.
…tallation record

A renewal that links to another address's record allocates no intent, and a record from an earlier build stores no owners, so the linking address's owner never reached the shared record and it could not take the installation back once the other address left. Linking now carries over the owners both records know, including each one's latest.
@silo-triage silo-triage Bot added size/XL 500–999 added + deleted lines (all files); change volume, not priority. and removed size/L 200–499 added + deleted lines (all files); change volume, not priority. labels 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 ❌

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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: b20509e9-417e-4712-9b3e-0842c678b502
Commits

Reviewing files that changed from the base of the PR and between d167787 and a989b95.

Files selected for processing: 7
  • iosApp/Tests/ApplePushOrderedRegistrationTests.swift
  • iosApp/iosApp/Networking/APIv2/APIv2Client.swift
  • iosApp/iosApp/Networking/APIv2/APIv2PushModels.swift
  • iosApp/iosApp/Notifications/ApplePushDisplayTargets.swift
  • iosApp/iosApp/Notifications/ApplePushInstallationJournal.swift
  • iosApp/iosApp/Notifications/ApplePushRegistration.swift
  • iosApp/iosApp/Notifications/ApplePushRegistrationChannel.swift

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

Comment on lines +210 to +212
func dropLink(of serverID: String, unlessProvenFor identity: String) throws {
guard let link = try storedLink(of: serverID), link.provenServerID != identity else { return }
guard keychain.delete(Self.linkAccount(for: serverID)) else { throw JournalError.writeFailed }

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 critical

Deployment isolation fails when the address owning a shared record changes deployments because dropLink returns immediately for an address with no outgoing link, leaving other addresses attached to its record. With B linked to A, registering A against a replacement deployment overwrites B's shared installation state, removes B's display target through sharingRecord, and makes saved-server maintenance follow A's owner instead of B's original deployment; preserve the original deployment's record for its remaining aliases when detaching the record-owning address.

Prompt for LLM

File iosApp/iosApp/Notifications/ApplePushInstallationJournal.swift:

Line 210 to 212:

Deployment isolation fails when the address owning a shared record changes deployments because `dropLink` returns immediately for an address with no outgoing link, leaving other addresses attached to its record. With B linked to A, registering A against a replacement deployment overwrites B's shared installation state, removes B's display target through `sharingRecord`, and makes saved-server maintenance follow A's owner instead of B's original deployment; preserve the original deployment's record for its remaining aliases when detaching the record-owning address.

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 Author

Choose a reason for hiding this comment

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

Fixed, though not with a handover: a9e444d and 5b314f7 change how a shared record is stored.

The first time a record is shared, it moves to a Keychain item of its own (shared-<UUID>) that no address owns, and both addresses get a link that records the server ID it was proven for. No address owns the record's slot any more. One that later reports another server drops only its own link, deleting anything left in its own slot first, and starts over with a new key. The other addresses keep the record, its key and their display targets.

A handover (6af5878) was tried first. It could be interrupted between Keychain writes, it missed addresses that were removed but still linked, and it missed link chains. Moving the record to a slot no address owns removes all three. testFirstAddressReportingAnotherDeploymentLeavesTheSharedRecordToTheSecond covers this case: the first address starts at generation 1 with a new key, and the second keeps registering with the shared key.

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 original finding as described; a handover isn’t required.

The important change is that every address now links to an address-independent shared record. The first address no longer has special ownership, so when its deployment identity changes, it can detach without replacing the record or disturbing the remaining addresses’ key, generation history, or display targets. Deleting its old address-local slot before unlinking also prevents stale installation state from being reused.

testFirstAddressReportingAnotherDeploymentLeavesTheSharedRecordToTheSecond targets the reported failure directly: the changed address gets a fresh key at generation 1, while the other address retains the shared key.

Based on that explanation, I consider the original concern addressed. I haven’t independently inspected the updated commits.

guard let own = try? await loginSessions(nil).currentSession?.id, !own.isEmpty else { return false }
var cursor: String?
for _ in 0..<Self.maximumSessionPages {
guard let page = try? await holder.loginSessions(cursor) else { return false }

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 Kody Rules high

Stale ownership validation allows this method to return true after either session changes: holder requests check ownership only before suspension, and this channel's owner can change while holder pages are being fetched. After each page returns, revalidate both channels against the captured owners through their authority gates before inspecting the page or accepting it as proof, and return false if either ownership check fails.

Also found in:

  • iosApp/iosApp/Notifications/ApplePushRegistrationChannel.swift:35-35

Kody rule violation: Fence asynchronous results by scope and invalidation generation

guard let page = try? await holder.loginSessions(cursor) else { return false }
do {
    try await commit({})
    try await holder.commit({})
} catch {
    return false
}
Prompt for LLM

File iosApp/iosApp/Notifications/ApplePushRegistrationChannel.swift:

Line 38:

Stale ownership validation allows this method to return true after either session changes: holder requests check ownership only before suspension, and this channel's owner can change while holder pages are being fetched. After each page returns, revalidate both channels against the captured owners through their authority gates before inspecting the page or accepting it as proof, and return false if either ownership check fails.

**Also found in:**
- `iosApp/iosApp/Notifications/ApplePushRegistrationChannel.swift:35-35`

Suggested Code:

            guard let page = try? await holder.loginSessions(cursor) else { return false }
            do {
                try await commit({})
                try await holder.commit({})
            } catch {
                return false
            }

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 Author

Choose a reason for hiding this comment

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

Not changing this one. sharesBackend proves that two addresses reach one backend: the holder lists the other address's login session. A sign-out or account switch while the pages load doesn't change which backend an address reaches, so a result read after the switch is still true. Nothing in the check writes owner-bound state. The writes that follow are the generation allocation and the display target in dispatch, and both run through channel.commit, which refuses them once the owner has changed. Re-checking after every page would add two authority checks per page and guard nothing the commit fence doesn't already guard.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed—the suggestion conflates proof of backend identity with authority to commit owner-bound changes.

A session listed by the holder still establishes that the two addresses reached the same backend, even if either session changes while the request is in flight. That result does not itself authorize a write. As you describe it, channel.commit separately fences generation allocation and display-target updates against the captured owner.

Given those commit fences, the original suggestion does not identify an unprotected mutation or show how stale proof bypasses authorization. Adding two checks after every page would invalidate a still-valid backend observation without closing a demonstrated correctness gap.

I would not require this change or treat this finding as an actionable violation of the rule.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a989b95f53

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +311 to +312
if owner.serverID != serverID, let own = record.owners?[serverID], !(await holdsSavedSession(owner)) {
owner = own

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fall back to a valid alias after the holder's session is rejected

While an unrelated server is active, if the last-registering alias's access token expires and its refresh is rejected, a surviving alias with a valid session is never tried. savedSessionAccount only checks the persisted account/epoch, and HTTPClient.renewInactiveServer leaves that slot intact on .rejected, so holdsSavedSession remains true and every alias iteration selects the unusable holder again. Consequently APNs token changes and display-token renewals cannot reach this deployment until the user activates an alias or signs in again. Fall back to the alias's recorded owner on definitive credential rejection.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in b62d6a9. The saved-server client now throws credentialRejected when the address's refresh is refused (ApproverBearer.rejected). registerSavedServers then registers once more as this address's own last owner from record.owners. A refresh that only failed for now (no answer, 5xx, provider_unavailable) still surfaces as noCredential and leaves the installation where it is, so a short outage at one address doesn't move the installation or its profile to the other. testSurvivingAddressRegistersAsItselfWhenTheHolderHasNoCredential covers both: a 503 refresh sends nothing, and a 401 refresh registers through the other address with the shared key.

Comment on lines +647 to +648
try journal.link(serverID, toRecordOf: candidate, provenFor: identity)
guard let record = try journal.load(serverID: serverID) else { return 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.

P2 Badge Clear stale holds when linking to a shared installation record

Unlike the fixed reset path, the new registerShared path can reuse a held generation from the discarded installation record: B held at generation 2 can allocate 3, link to A at generation 1, and retry at 2. If that retry fails in transport before reaching the server, the next same-intent attempt returns .notSent(reason: "held") rather than replaying the pending registration, delaying APNs-token recovery for six hours. Clear held[serverID] after a successful link, or scope holds to the installation key as well as generation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in b62d6a9: held[serverID] is cleared once the address links to the shared record, since a hold names a generation of the record it replaced. testHoldOnTheReplacedRecordDoesNotBlockTheSharedRegistration reproduces your sequence: held at 2, mismatch at 3, link, a lost answer at shared generation 2. The next attempt now replays generation 2 instead of returning notSent(held).

…eft the server

An address whose link was dropped could still be named as the last to register in the other address's record, so removing that address sent nothing and maintenance kept routing it through the departed one. The latest owner now counts as another address only while it still shares the record. When the address that owns a shared record reports another server, the addresses linked to it take over the record and key, and it starts over with its own.
@coderabbitai coderabbitai Bot added api-v2 API v2 / Huma program (epic silo-server#135) evidence-required Needs before-and-after evidence before the Evidence check passes impact: usability Core flow broken or severely blocked labels Nov 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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: 261b2f94-a9a5-4a14-b688-571f894f589a
Commits

Reviewing files that changed from the base of the PR and between b62d6a9 and 47ac93c.

Files selected for processing: 3
  • iosApp/Tests/ApplePushOrderedRegistrationTests.swift
  • iosApp/iosApp/Notifications/ApplePushInstallationJournal.swift
  • iosApp/iosApp/Notifications/ApplePushRegistration.swift

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

Follow-up review fixes for the shared installation record:

- Check that the address still resolves to the slot a command was
  planned from before sending a registration or a reset, and before
  storing the display target from its answer, so a link that ended in
  between neither sends the shared key nor brings back the moved
  address's target.
- Return the shared record's slot from the share path before its first
  await, so a link that ends during it is caught.
- Recheck a fallback `off`'s teardown once it gets its turn, so an `off`
  queued behind the other address's registration is not sent after
  that registration ended the teardown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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

Maintainer review summary

Reviewed head: 8fea10a (this rerun's fixes in 6d4a794, 7bbbdab, 79b2e5d, 20c3c76, f5d0541, c1348ea and 8fea10a, on top of b5403a8). Base: main at 3bd7573. The server half, silo-server#3352, is merged.

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

Fit 7. Same as the last round. A reinstalled iPhone, or the same server saved under a second address, never gets push back, so this closes a real gap in the core notification experience, and the fix sits at the right boundary: an owner-only reset on the server and recovery in the app. The score is held down by cost and parity. The shared-record machinery (links, per-address owners, stale-link handling, alias routing) is a large client surface for the second-address case, and Android has no matching recovery path and no linked parity issue.

Readiness 9. Every defect found in this PR's code is fixed, each with a regression test that failed first. The behavior was shown live against server main. What remains is a server-side gap tracked in its own issue, plus three accepted trade-offs listed below.

Fixed in this round

Finding Fix Test (failed before the fix)
The session proof came from the record's latest owner, which could be an address that had moved to another server. That server could vouch for a third address claiming the first one's server ID, which then got the shared key (Codex, line 717). 6d4a794: the proof is asked of the candidate's own address, whose server ID and link were just checked. testProofComesFromTheCandidatesOwnAddressNotTheLastToRegister (b5403a8)
A pending retirement for a removed linked address carried the shared key to the departed URL for up to 90 days, where another server may answer later. 6d4a794, then 7bbbdab: while another saved address still shares the record, the retirement goes there, and the route is chosen again on every attempt. testRetirementForASharedRecordGoesThroughAnAddressStillSharingIt (b5403a8 and 6d4a794)
The queue read the key before the route lookup suspended. If the departing address was added again for another server meanwhile, the retry sent the shared key there. 79b2e5d: the route is chosen first, then the record is read, and nothing is sent when the two addresses no longer share the record the route was chosen for. testRetryReadsTheRecordAfterItsRoute (7bbbdab)
The allocation's slot check and its journal write run on the TokenStore actor while the registrar can unlink the address, and the write resolved the link again. An unlink in between left the shared record and its key in the address's own slot (Codex, line 608). 20c3c76: the write goes to the slot that was checked. none: a race between two actors inside one synchronous closure, with no deterministic hook
Dropping a stale link left the address's hold, which named a generation of the shared record. The fresh record restarts at 1, so a lost first registration stayed held for six hours (Codex, line 797). 20c3c76: the hold ends with the link. testHoldEndsWithTheLinkItNamedAGenerationOf (79b2e5d)
A saved address's link was checked before the transport awaited the stored session, a token refresh and the profile token. An address that reported another server meanwhile still sent the shared key (Codex, line 636). f5d0541: the saved-server transport checks last, right before the request leaves, that the address still holds the key. A stale link is ended first. testSharedKeyIsCheckedAgainRightBeforeASavedAddressSends (20c3c76)
The same gap on the active server, whose requests go through HTTPClient. Its gate fences owner and server switches, not journal links (Codex, line 530). c1348ea: HTTPClient.requestData gains an optional beforeDispatch hook, run right before each send; the push registration and reset pass the same key check. testSharedKeyIsCheckedAgainRightBeforeTheActiveServerSends (f5d0541)
An active request that failed over a local route went again to the saved address without the check (Codex, HTTPClient.swift line 513). 8fea10a: the hook runs inside perform, ahead of its dispatch fence, and again before the saved-address retry; a refusal is rethrown as is, not as a transport failure. testSharedKeyIsCheckedAgainBeforeTheSavedAddressFallback (c1348ea)

The last two came from the cross-provider rounds. Codex (gpt-6.1-sol) reviewed 6d4a794 and 7bbbdab: round 1 found the stored-alias problem, and round 2 marked it resolved and found the read-before-route race. Both are fixed above. Round 2 found nothing else in the actor ordering, back-off bookkeeping, or the proof change. The last five rows came from the Codex GitHub reviews of 79b2e5d, 20c3c76, f5d0541 and c1348ea. Declined with evidence: serializing a routed retirement's last synchronous steps with link removal (ApplePushRetirement.swift line 251), since nothing awaits between that check and the send. Each check now sits right before its request leaves; a change in the instant between that check and URLSession taking the request can't be closed on the client. Kody's request at line 473 for live identity proof before a routed retirement was declined with evidence: the alias already receives the shared key under the same cached-ID check on every renewal, and without the route the key would go to the departed address, which is never checked.

Left for the maintainers

  • Server: a retirement after a reset stores no fence. A reset leaves the installation at generation 0, and a retirement there answers removed without storing anything. If the registration after a reset loses its answer and the person then signs out, a late arrival of that registration binds and pushes resume for a removed server. The app can't tell this case apart, so the fix belongs on the server. It's filed as silo-server#3413 with a proposed fix. It doesn't block this PR: the window needs a lost answer followed by a sign-out before the request lands.
  • Accepted trade-offs, now listed under Risks. A session check that can't reach the other address falls back to a reset: delivery recovers, but push text stays generic until the other address renews. An inactive address's cached server ID is refreshed only when it's activated or brought to the foreground. An app stopped between writing a link and removing the renewal's display target leaves two targets until the next registration from the active address, which needs the app killed between two Keychain writes.
  • The simpler proof suggested last round (a key fingerprint in the mismatch problem) is moot now that the server contract is merged.

Validated features

  • Full SiloTests at 8fea10a: 3696 tests, 0 failures. Both on an iPhone 17 Pro simulator (iOS 27.0).
  • End-to-end against an isolated server built from silo-server main (baf9d42), with the app's APNs token supplied by a local patch that isn't on the branch:
    • Second address: 403 push_installation_key_mismatch, listSessions twice, then 200 with the shared key. No reset.
    • Sign-out of the address that registered last: retirement 200, then the other address registers again with the shared key.
    • Lost key: 403 mismatch, reset 200, register 200, and a relaunch sends nothing (run at 7bbbdab; 79b2e5d only changes the retirement queue).
    • The live runs were at 79b2e5d. 20c3c76, f5d0541, c1348ea and 8fea10a change only which slot an allocation is written to, when a hold ends, and a last check before a request leaves. Those runs don't reach any of these.
    • The server log doesn't record which address a request used, so the retirement route itself is shown by the unit test, not live.

Validation status

Task #336 lists C1 and C2 as not run on iPhone and iPad, so no recorded pass can regress. I couldn't read the board itself (no project scope in this environment).

Other checks

  • User manual: unaffected. Push works the way the docs already describe, with no new setting or screen.
  • Apple and Android parity: Android also sends an ordered installation key, but the server's key-mismatch reset exists only for Apple. Whether Android gets stuck the same way after a reinstall is unconfirmed. I recommend a parity issue in silo-android.
  • Evidence: republished for 8fea10a at the page linked in the PR body.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5403a8fc6

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +715 to +717
let holder = try? journal.load(serverID: candidate)?.latest?.intent.owner,
let holderChannel = savedServers.channel(for: holder),
await channel.sharesBackend(with: holderChannel) else { continue }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Validate the holder before trusting its backend proof

If A and B share a record last registered by B, and B now reports another deployment while its old session remains saved, a third address C claiming A's server_id can pass this check using only B's replacement backend. The stale-link check above applies to candidate A, but the session proof comes from latest owner B without checking B's deployment or whether its link is stale. A backend controlling B and C can therefore supply both session responses and make registerShared send A's still-live installation key to C without contacting A. This was reproduced with the extracted proof, journal, and channel code in an isolated Swift harness. Revalidate the holder's deployment and link before using its session list to authorize sharing the candidate's record.

Useful? React with 👍 / 👎.

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. shareProvenRecord asked the record's latest owner for the session proof, and that can be another address that has moved to another server since, with its link not yet dropped. That server could vouch for a third address claiming the first address's server ID, and the third address then got the shared key.

Fixed in 6d4a794: the proof now goes through the candidate's own last owner, which is the address whose server ID and link were just checked. An address that moved is never asked. testProofComesFromTheCandidatesOwnAddressNotTheLastToRegister reproduces your sequence. At b5403a8 the third address got the first address's key and no reset was sent. Now it resets with its own key.

Verified at 79b2e5d: the push registration suites (92 tests) and the full SiloTests suite (3692 tests) pass on an iPhone 17 Pro simulator (iOS 27.0). A live run against server main confirmed the two-address sharing still works.

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

…s, and retire through one still sharing it

The session proof for a candidate address now comes from that address's
own last owner, whose deployment was just checked, rather than from the
address that registered last on the shared record. That address may have
moved to another server since, and could vouch for a third address
claiming the first one's identity.

A retirement for an address that shares its record now goes to another
saved address still sharing it, so a retry months later never carries the
shared key to whatever server answers at the departed address.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Quick104 and others added 2 commits November 1, 2026 22:26
…y attempt

A retirement for an address sharing its record was queued with another
sharing address's URL. If that address later moved to another server, a
retry still went there with the shared key. The queue now keeps the
departing address's own URL and asks the registrar for a route on each
attempt: another saved address that still shares the record, checked at
that moment, or the stored URL when none does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The retirement queue read the record's key before the route lookup
suspended. If the departing address was added again for another server
during that lookup, its link ended, the route came back empty, and the
already-read shared key went to the departing address. The queue now
chooses the route first, then reads the record, and sends nothing when
the departing address and the chosen one no longer share the record the
route was chosen for.

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

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

Comment on lines +470 to +473
guard await dropStaleLink(of: alias), sharesRecord(alias, with: entry.serverID),
let aliasURL = ServerRegistry.url(forServerId: alias),
let slot = try? journal.recordSlot(for: alias) else { continue }
return ApplePushRetirementRoute(serverURL: aliasURL, alias: alias, slot: slot)

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 Security critical

Credential exposure in retirement routing occurs because dropStaleLink treats savedServerIdentity, whose production implementation only returns the persisted verifiedServerId, as confirmation that an alias still reaches the original deployment. If the alias's address is reassigned before its next identity refresh, the route sends the shared X-Push-Installation-Key to the replacement server, exposing the credential that authorizes retirement on the original deployment; require fresh authenticated evidence that the alias still reaches that deployment before forwarding the key.

Prompt for LLM

File iosApp/iosApp/Notifications/ApplePushRegistration.swift:

Line 470 to 473:

Credential exposure in retirement routing occurs because `dropStaleLink` treats `savedServerIdentity`, whose production implementation only returns the persisted `verifiedServerId`, as confirmation that an alias still reaches the original deployment. If the alias's address is reassigned before its next identity refresh, the route sends the shared `X-Push-Installation-Key` to the replacement server, exposing the credential that authorizes retirement on the original deployment; require fresh authenticated evidence that the alias still reaches that deployment before forwarding the key.

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.

The trigger is real, but this route doesn't add the exposure, so I'm not changing it here.

  • The alias already receives the shared key under the same check. Every saved-server pass and display-token renewal for the alias (registerSavedServers, register → dispatch) sends X-Push-Installation-Key with the shared key to the alias's URL. That is gated by the same cached verifiedServerId through dropStaleLink. If the alias's address were reassigned before its next identity refresh, those requests would carry the key there first. A fresh proof on the retirement path alone wouldn't close that.
  • Without the route, the retirement goes to the departing address's own URL. That address has been removed or signed out, and its server ID is never checked again for up to 90 days of retries. The alias is still saved, and its cached ID is refreshed whenever it's activated or brought to the foreground. So the route never sends the key anywhere the default path wouldn't, and it usually sends it somewhere better checked.
  • A live check per send wouldn't be authenticated evidence either. GET /api/v2/system/identity is self-reported, and the session proof costs up to 11 requests and needs the alias's stored session.

The PR body lists the cached-ID limit under Risks, for every shared-key send. Refreshing an inactive address's server ID before any shared-key send would be a separate change across all those paths.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed—the original suggestion is not justified as a critical, retirement-route-specific blocker.

The retirement route relies on the same cached-identity trust model as the other shared-key sends. Requiring fresh proof only here would leave that broader exposure unresolved. Routing through a still-saved alias also avoids relying exclusively on a departing address that may receive retries long after removal.

One qualification: the alias’s registration or renewal is not guaranteed to run before a retirement attempt, so those paths do not prove the key was already exposed. The retirement request can still be the first disclosure after reassignment. That preserves the underlying risk, but does not establish that this route needs a standalone fix.

A fresh self-reported server_id would not provide authenticated proof either. Stronger protection should be designed consistently across all shared-key sends, with explicit handling when session-based proof is unavailable.

Given the documented limitation, I would not require this route-only change for this PR. No repository or issue changes have been made.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79b2e5dfb6

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 605 to 608
guard try journal.recordSlot(for: serverID) == slot else {
throw ApplePushInstallationJournal.JournalError.linkChanged
}
try journal.save(allocated, serverID: serverID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Persist shared allocations into the captured record slot

If maintenance for another alias unlinks this address while its allocation runs on the TokenStore actor, the link can disappear between this guard and save. ApplePushInstallationJournal.save resolves serverID again, so it writes the live shared installation key into the address's now-private slot. The later resolves check suppresses only this request: the next registration loads that copied record and sends the surviving alias's key to the replacement backend. A focused Swift harness reproduces this despite the unlink succeeding. Persist into the captured slot, or serialize unlinking with the check/write.

Useful? React with 👍 / 👎.

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 from the source. The slot check and journal.save run inside channel.commit, on the TokenStore actor. While the registrar awaits that commit, it can run dropStaleLink for this address, and save(_:serverID:) resolved the link again. An unlink that landed between the two wrote the shared record, key included, into the address's own slot, and the next registration sent that key to the server the address reaches now.

Fixed in 20c3c76: the journal gains save(_:slot:), and the allocation writes to the slot it just checked. An unlink in that gap leaves the generation in the shared record, where it belongs, and the existing resolves check stops the send. The journal's other writes (allocateRetirement, record) run on the registrar actor with no suspension between load and save, and links change only there, so they can't interleave.

There's no regression test for this one. The race is between two actors inside one synchronous closure, and the harness has no deterministic way to land the unlink between the check and the write. The push registration suites (93 tests) and the full SiloTests suite (3693 tests) pass at 20c3c76 on an iPhone 17 Pro simulator (iOS 27.0).

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

Comment on lines +796 to +797
if try journal.dropLink(of: serverID, unlessProvenFor: identity) {
displayTargets.removeTargets(registeredBy: serverID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear generation holds when dropping a shared-record link

If A has generation 1 held because its accepted registration lacked a display token, and B subsequently shares A's record and registers, held[A] remains intact. When A reports another deployment, this path removes its link but leaves that hold. A then starts a fresh journal at generation 1; if its first registration fails in transport, the next same-intent attempt returns .notSent(reason: "held") rather than replaying the pending request, blocking push recovery until the old six-hour hold expires. This sequence reproduces in a focused Swift harness. Clear the address's hold after a successful unlink, as the sharing path already does when replacing a record.

Useful? React with 👍 / 👎.

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 and fixed in 20c3c76: when dropStaleLink drops a link, it also clears that address's hold, as the sharing path already does when it replaces a record. testHoldEndsWithTheLinkItNamedAGenerationOf follows your sequence. Generation 1 is held after a registration accepted without a display token, the second address shares the record, the first address moves to another server, and its first registration there loses its answer. At 79b2e5d the replay came back notSent(held). At 20c3c76 it replays generation 1 and is accepted. The push registration suites (93 tests) and the full SiloTests suite (3693 tests) pass.

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

…a hold with its link

The allocation's slot check and its journal write run on the TokenStore
actor while the registrar can unlink the address. The write resolved the
address's link again, so an unlink that landed between the two left the
shared record, with its key, in the address's own slot, and its next
registration sent that key to the server it reaches now. The write now
goes to the slot that was checked.

Dropping a stale link also clears the address's held generation: the
hold named a generation of the shared record, and the address starts over
at generation 1, where an old hold blocked replaying a lost registration
for six hours.

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

silo-kody Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 20c3c76a5c

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +633 to 636
guard resolves(serverID, to: slot) else { return .notSent(reason: Self.linkChangedReason) }
let receipt: APIv2ApplePushRegistrationReceipt
do {
receipt = try await channel.send(command.intent.body, command.installationKey, command.generation)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Revalidate shared-record links after credential awaits

For a saved alias B sharing A's record, this guard runs before ApplePushSavedServerClient.send awaits savedSessionAccount, freshAccessToken, and savedProfileToken. If concurrent retirement maintenance detects B's replacement deployment and removes its link during those waits, the resumed transport still posts A's live shared installation key to B's replacement backend, exposing the credential that can retire A's pushes. This reproduces with the extracted registrar/channel code by pausing credential lookup and unlinking B through retryPendingRetirements. Move the link validation to the final dispatch boundary after credential lookup, serialized with unlinking, for both registration and reset requests.

Useful? React with 👍 / 👎.

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 and fixed in f5d0541. The link check before channel.send ran before ApplePushSavedServerClient.send awaited the stored session, a possible token refresh, and the profile token. An address that reported another server during those waits still sent the shared key.

The saved-server transport now takes a keyGate and runs it last, after every credential await and right before the request leaves, for both registration and reset. The registrar's gate first ends a stale link against the address's current server ID. It then confirms the address still resolves to a record holding the key the request carries. When either fails, nothing is sent and the registration comes back notSent("journal_link_changed"). The active server's requests go through HTTPClient, whose final dispatch is already fenced by its identity-transition gate.

testSharedKeyIsCheckedAgainRightBeforeASavedAddressSends pauses a saved address's registration, flips its server ID, then lets it continue. At 20c3c76 the shared key went to that address. Now nothing does. At f5d0541 on an iPhone 17 Pro simulator (iOS 27.0), the push registration suites pass (94 tests) and the full SiloTests suite passes (3694 tests).

The check still runs just before URLSession takes the request, so a change in the instant between the two isn't caught. That gap can't be closed on the client.

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

…ntial lookups

A saved address's registration or reset checked its link before the
transport awaited the stored session, a token refresh and the profile
token. If the address reported another server meanwhile, the request
still left with the shared installation key. The saved-server transport
now asks the registrar, right before the request leaves, whether the
address still holds the key it carries, after ending a stale link; when
it doesn't, nothing is sent.

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

silo-kody Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5d0541969

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +529 to +530
send: { try await api.registerApplePush($0, installationKey: $1, generation: $2, auth: owner.request) },
reset: { try await api.resetApplePushInstallation(deviceID: $0, installationKey: $1, auth: owner.request) },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Gate active-server requests after their credential awaits

When active alias B shares A's record, an auth capture/refresh inside applePushRequest can suspend after dispatch checks the slot. If maintenance for A unlinks B after it reports another deployment, these active closures still send A's live key to B's replacement backend; the HTTP owner fence checks credentials, not the journal link. The new keyGate only protects savedChannel: an extracted registrar harness blocks the equivalent saved request but still sends the active request after unlinking. Apply the same post-credential ownership check at the active dispatch boundary for registration and reset, because the leaked key can retire A's pushes.

Useful? React with 👍 / 👎.

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 and fixed in c1348ea. My earlier note that HTTPClient's identity-transition gate covers the active server was too broad. That gate fences owner and server switches, not the push journal's links. An active address that reports another server can be unlinked by a maintenance pass for the other address while its request captures or refreshes credentials.

HTTPClient.requestData gains an optional beforeDispatch hook. It runs after the credential capture and any refresh, right before each send of an owner-scoped request, including the resend after a 401 refresh. registerApplePush and resetApplePushInstallation pass the same key check the saved-server transport uses (holdsKey): end a stale link, then confirm the address still holds the key. Both transports now refuse with ApplePushRegistrationError.keyWithdrawn, and nothing is sent.

testSharedKeyIsCheckedAgainRightBeforeTheActiveServerSends pauses the active address's registration, flips its server ID, then lets it continue. At f5d0541 the shared key went out and the registration was accepted. Now it comes back notSent("journal_link_changed") and sends nothing. On an iPhone 17 Pro simulator (iOS 27.0), the full SiloTests suite passed (3695 tests) just before a refactor-only cleanup, and the push registration suites (95 tests) pass at c1348ea.

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

… credential capture

The active server's registration and reset go through HTTPClient, which
fences owner and server switches but not the push journal's links. An
address that reported another server while the request captured or
refreshed its credentials still sent the shared installation key.
HTTPClient.requestData gains an optional beforeDispatch hook, run right
before each send of an owner-scoped request; the push registration and
reset pass the same key check the saved-server transport runs.

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

silo-kody Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1348ea7d2

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

)
// The caller's last check, after the credential capture and any
// refresh above, right before the request leaves.
try await beforeDispatch?()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recheck the key before retrying on the saved address

On iOS with a LocalRoute, an active alias's POST can wait on a LAN connection and then retry the saved URL after cannotConnectToHost or a TLS failure. The added hook covers the initial dispatch and 401 retry, but the separate fallback in HTTPClient.send at lines 1619–1623 never invokes it. If retirement maintenance unlinks that alias during the LAN wait, the fallback still sends its former shared installation key to the replacement backend; this reproduces with the extracted transport. Pass the hook through and rerun it before the saved-address retry for both registration and reset.

Useful? React with 👍 / 👎.

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 and fixed in 8fea10a. The local-route fallback in HTTPClient.send went to the saved address without the hook. The hook now runs inside perform, ahead of its synchronous dispatch fence, so the fence still sits right before the send. It runs again before the saved-address retry in send. A refusal on that retry is rethrown unchanged (DispatchHookRefusal), not wrapped as a transport failure, so it doesn't mark the server unreachable.

testSharedKeyIsCheckedAgainBeforeTheSavedAddressFallback gives the active address a local route, refuses the LAN connection, and flips the address's server ID during that attempt. At c1348ea the request then went to the saved address with the shared key and was accepted. Now it comes back notSent("journal_link_changed"), and the only request is the refused LAN one. At 8fea10a on an iPhone 17 Pro simulator (iOS 27.0), the full SiloTests suite passes (3696 tests).

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

Comment on lines +249 to +251
let departing = try journal.recordSlot(for: entry.serverID)
let alias = try journal.recordSlot(for: routed.alias)
guard departing == routed.slot, alias == routed.slot else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Serialize routed retirement dispatch with link removal

If alias A reports another deployment while B's pending retirement is being routed through it, the registrar can unlink A after this comparison because attempt runs on a different actor. B still resolves to the shared record, so the following load succeeds and transport posts the shared installation key to A's replacement backend, even when another saved alias retains that live installation. This reproduces with the extracted queue and journal by pausing the record read after route validation and unlinking A. Serialize validation and starting the retirement transport with link removal; consecutive Keychain reads on the queue actor do not prevent this race.

Useful? React with 👍 / 👎.

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.

I'm not changing this one. After the route check, attempt makes only synchronous Keychain reads on the queue actor and then calls the transport. APIv2Client.retireApplePushInstallation builds the request and calls session.data(for:) with no await in between. So the window you describe is an unlink on another actor landing within those synchronous steps. That's the same irreducible gap that sits between any check and URLSession taking a request. Every other key-bearing path in this PR now checks at the same point, right before the send, and stops there.

Closing that last instant would mean holding off every unlink until each send's request has been handed to URLSession. That's a lock across two actors, and a send that never completes could block maintenance for good. The earlier versions of this path left real awaits between check and send: the route lookup, and the read before it. Those are fixed in 7bbbdab and 79b2e5d.

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

…lback

An active request that tried the local route first and then went again
to the saved address skipped the push key check on that second send. The
local attempt can wait on a LAN connection, and the address's link to a
shared record can end meanwhile. The beforeDispatch hook now runs inside
perform, ahead of its dispatch fence, and again before the saved-address
retry in send. A refusal there is rethrown as is rather than reported as
a transport failure, so it doesn't mark the server unreachable.

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma program (epic silo-server#135) bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants