Skip to content

feat(notifications): sync notification state through v2 - #395

Merged
Quick104 merged 1 commit into
mainfrom
apiv2-stack/47-notification-sync-v2
Sep 23, 2026
Merged

Quick104 merged 1 commit into
mainfrom
apiv2-stack/47-notification-sync-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

The iOS notification inbox catch-up now pages through GET /api/v2/notifications/sync with an owner-tagged checkpoint.

Problem

On iOS, the notification inbox catch-up after an APNs wake, a foreground push or a notification tap still calls GET /api/v1/notifications/sync. It reads one page per wake, sends a since cursor, and resets that cursor based only on the server id and profile id. The v2 client method APIv2Client.notificationSync(cursor:auth:) already existed and validated the v2 page, but nothing called it.

Solution

ApplePushNotificationSyncCoordinator now reads GET /api/v2/notifications/sync through the shared SiloAPI.shared.apiV2Client.

  • It captures the request owner (CapturedOrdinaryRequestAuth) once per sync and requires a selected profile. The v2 method sends X-Profile-Id (plus X-Profile-Token for PIN-locked profiles) inside withOwnerFence.
  • It reads page by page while page.has_more is true, up to 100 pages per sync (invariant I10). When a sync hits the cap, the coordinator logs it and the next sync resumes from the checkpoint. It never truncates silently.
  • After each page it saves sync_cursor as the checkpoint, not page.next_cursor, so the final page still moves the checkpoint forward. The checkpoint is tagged with its owner and is sent again only when sameCredentialIdentity matches. A change of account, credential generation or profile starts over from the server's initial snapshot.
  • If a page fails, the checkpoint from the last completed page stays in place. If the server rejects the cursor with the invalid_cursor problem type, the coordinator clears it and restarts from the initial snapshot once.
  • If any page returned items, the coordinator posts homeSectionsShouldRefresh once at the end, as before.
  • The coordinator now takes api and tokenStore in its initializer so tests can inject them. refreshFromRemoteNotification() still retargets the active server first, then calls sync().

Deleted: ApplePushNotificationSyncResponse, ApplePushNotificationSyncItem, ApplePushNotificationSyncWire (the v1 endpoint constant and since query), the 404/405 "endpoint not available" branch, and their two tests in ApplePushRegistrationTests. This covers inventory rows 128 and E2.

This is a read, so there is no write failure-outcome table. On any error, including an uncertain one, the sync returns false and keeps the last confirmed checkpoint. A read has no side effects to hold or replay.

Validation

  • iOS, tvOS and macOS builds pass on this branch.
  • Focused iOS tests pass: ApplePushNotificationSyncTests, ApplePushRegistrationTests and ApplePushOrderedRegistrationTests, 36 tests, 0 failures. On tvOS the new class is iOS-only, so that run only confirms the tvOS test target compiles.
  • New ApplePushNotificationSyncTests run on StubURLProtocol with a real TokenStore, HTTPClient and APIv2Client. They cover:
    • the first request sends only limit=50 and X-Profile-Id, and later syncs resume from the last sync_cursor across a has_more page
    • a failed page keeps the prior checkpoint
    • invalid_cursor restarts from the initial snapshot once
    • a profile switch drops the checkpoint
    • paging stops after 100 pages and resumes on the next sync
  • scripts/ci/check-no-api-v1.sh passes.
  • The final stack passed the full suites (iOS 1981 tests, tvOS 1792 tests, 0 failures), the macOS build and the v1 path guard, and every branch in the stack builds on its own.

Risks and follow-ups

  • The checkpoint lives in memory, as the v1 cursor did. A cold background launch starts from the server's initial snapshot. That snapshot is bounded (has_more is false), so it costs one request.
  • APNs wakes need a real device, and nobody ran one, so this PR has only compile and unit-test evidence.
  • notificationSync stays in APIv2Client.swift, where it already lived. It was not moved to a per-domain extension file.

AI disclosure

Code and description written by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code), orchestrated by a Claude Code workflow.


Part 47 of 50 in the Apple API v2 stack. Base: apiv2-stack/46-push-display-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: ebc8c984-f821-47d1-a423-a6ff75f3770d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 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-09-23T13:23:25.642459Z 576679a 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.

@greptile-apps greptile-apps 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.

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@Quick104

Copy link
Copy Markdown
Contributor Author

Code review summary

Reviewed head: a89fa96c (apiv2-stack/47-notification-sync-v2).

Process: an adversarial review of this PR's diff with each candidate finding independently verified before any fix, a simplify pass for medium and larger PRs, and a whole-stack review across contract conformance, authority and failure handling, data integrity, user-visible behavior and cross-PR integration.

Verified findings: none.

Validation: this branch builds on its own for iOS, tvOS and macOS, and its focused tests passed. The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, the macOS build and the v1 path guard. The final stack was also exercised on iOS and tvOS simulators against a v1/v2 bridge server: sign-in (password and QR), restore, browse, search, detail, favorites and watchlist, playback (direct play, transcode, subtitles, stop), audiobooks, downloads with offline playback, settings, requests, profiles, push registration and diagnostics. Server logs showed no /api/v1 request from the new builds except the retained health probe.

Remaining: no open verified findings. Merge in stack order.

Mergeability: 8/10 — conditional. The approach holds up and every verified finding is fixed. Conditions: this PR's CI must pass (it was pending at review time), and the owner still plans a physical-device check of the completed stack.

Review by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code).

@Quick104
Quick104 force-pushed the apiv2-stack/46-push-display-v2 branch from f00649d to b5c3966 Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/47-notification-sync-v2 branch from a89fa96 to 576679a Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/46-push-display-v2 branch from b5c3966 to 1888b11 Compare September 23, 2026 13:45
Base automatically changed from apiv2-stack/46-push-display-v2 to main September 23, 2026 13:45
The APNs wake, foreground-push and tap handlers caught up the inbox with
GET /api/v1/notifications/sync, read one page per wake, and kept a
`since` cursor keyed only by server and profile id. The v2 client method
`notificationSync(cursor:auth:)` already existed but had no callers.

The coordinator now captures the request owner once and reads
GET /api/v2/notifications/sync page by page, up to 100 pages per sync.
It keeps each page's `sync_cursor` (not `page.next_cursor`) tagged with
the owner that received it, so another account, credential generation or
profile starts from the server's initial snapshot. A failed page keeps the
last completed checkpoint; a rejected cursor (`invalid_cursor`) restarts
from the initial snapshot once; hitting the page bound is logged and the
next sync resumes from the checkpoint. The v1 response models, the
query helper, the 404/405 "endpoint unsupported" branch and their tests
are deleted, and new StubURLProtocol tests cover the checkpoint, owner
change, failure, rejected cursor and page bound.

Stack-PR: W5-V
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/47-notification-sync-v2 branch from 576679a to 5452dc7 Compare September 23, 2026 13:45
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Quick104
Quick104 merged commit 8cb7c53 into main Sep 23, 2026
3 of 6 checks passed
@Quick104
Quick104 deleted the apiv2-stack/47-notification-sync-v2 branch September 23, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant