Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(relay): reopening the app ends a finished iOS Live Activity #20265

MergedMohtashamMurshid(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/20265/headmerged by juliusmarminge View on GitHub

Problem

On iOS, the agent Live Activity can stay on the lock screen or Dynamic Island long after the work is done. To reproduce: let a thread finish, wait more than 15 minutes, tap the card, the app opens the thread, then leave the app. The card is still there, frozen on whatever it last showed. Expected: once nothing is active and the 15-minute Done window has passed, reopening the app ends the card.

When the app comes to the foreground it re-registers the card's current push token, and the relay replays the current aggregate to it (remoteRegistration.ts treats this replay as the foreground reconciliation). LiveActivities.register restamped remote_started_at to now on every registration, including re-registering the same token. The replay then reached chooseLiveActivityDelivery with an empty aggregate and a card that looked armed 0 seconds earlier. The 2-minute grace meant for brand-new cards suppressed the end, so nothing was sent and no delivery attempt was recorded. That made the replay unable to end any card.

Change

LiveActivities.register reads the device's current row first. If the incoming token is the one the device already holds, it keeps the original arming time. A new token is still stamped as freshly armed, so a newly armed card keeps its grace while the environment's first publish is in flight. The replay still clears last_aggregate_json, so a missed push within the window is still redrawn.

This is relay-only: no contract or mobile changes, and no app rebuild needed.

Scope and approval

A small, focused fix for an obvious bug, submitted under the CONTRIBUTING exception. The registration replay already exists to end a card that has nothing left to show (chooseLiveActivityDelivery ends on an empty aggregate), but because register restamped the arming time it could never reach that branch. The fix makes the existing design work; no product behavior is changed.

Not covered: if the app is never reopened, a Done card is still not ended after the 15-minute window, because nothing sends that end. That needs a product decision (a cron sweep, or sending Done as an end with a dismissal date and giving up card reuse), so it is left out.

Verification

  • New test in LiveActivities.test.ts: re-registering the current token keeps its arming time, and a different token is stamped fresh. It fails on main (the arming time is reset to the test clock's now) and passes with the fix.
  • vp test run for LiveActivities, MobileRegistrations, ApnsDeliveries and AgentActivityPublisher: 77 passed. Targeted vp lint and the relay tsc-rs --noEmit are clean.
  • End-to-end run against a throwaway Postgres 17 with the relay migrations applied. This used the real MobileRegistrations, publisher, ApnsDeliveries, signed queue jobs and processSignedJob, with APNs stubbed to return 200. The harness was not committed. Timeline: card armed 3 h earlier, then running, then completed (alerting update p10, activeCount 0, 200), finished row pruned, then foreground re-registration of the same token.
    • main: remote_started_at reset to now, replay queued nothing, no live_activity_end attempt.
    • This branch: arming time kept, replay queued live_activity_end, sent to APNs as event: end, priority 10, dismissal +15 s. relay_delivery_attempts recorded live_activity_end, status 200, apns-id set; the activity row is marked ended and its token retired.
    • Within the 15-minute window: the replay still sends a silent completed update (p5, activeCount 0, 200).
  • Not checked: production APNs delivery and an on-device run. Both need this relay deployed.

Model and harness: Claude Opus 5.5 (claude-opus-5-5) via Claude Code in T3 Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at b85b75b

      Macroscope's review found this PR approvable — This is a narrowly scoped relay bug fix that preserves the arming timestamp for an existing iOS Live Activity while retaining fresh-token behavior. It has targeted regression coverage and does not introduce schema, API, security, or deployment changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: e62af16d-0564-4dd6-a588-a86af66ba79f
      📥 Commits

      Reviewing files that changed from the base of the PR and between cfafb4bb54d244e4612f5681aad3832ea64cb0fb and b85b75be8da5a78468f4d8acb2b0f0d2ced32d42.

      📒 Files selected for processing: 2
      • infra/relay/src/agentActivity/LiveActivities.test.ts
      • infra/relay/src/agentActivity/LiveActivities.ts

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

      📝 Walkthrough

      LiveActivities.register now reads the existing activity token and start time for the user and device. It preserves the start time when the token matches and the time is non-null. Otherwise, it uses the current registration time for the insert or conflict update.

      Changes: Live activity registration

      Layer / File(s)Summary
      Read and persist the registration start time
      infra/relay/src/agentActivity/LiveActivities.ts, infra/relay/src/agentActivity/LiveActivities.test.ts
      Registration looks up the existing token and start time before writing. It preserves the start time for a matching token and uses the current registration time otherwise. Tests cover lookup order, insert and conflict-update values, aggregate baseline clearing, and a persistence failure.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to b85b7

      Reopening the app can now retain the activity’s original arming time, allowing an eligible finished activity to end. No merge-blocking issue was established.

      Security architecture risk: 🔵 Low · up to b85b7

      The change is narrowly scoped to Live Activity lifecycle timing. Authentication and request fields are unchanged, and no introduced security finding was established. Concurrent registration behavior and activity-token generation identity remain uncertainties.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • inferred — The demonstrated behavior change concerns persisted timing and end-delivery eligibility for a registered activity. It does not add request fields, a new delivery destination or additional caller privileges. Cross-user token-claim behavior is unchanged rather than newly isolated by this fix.

      Trust Boundaries and Controls

      • observed — The existing handler derives user identity from the authenticated principal, requires mobile-registration scope and verifies the DPoP thumbprint against the access token before passing the client-controlled device and activity token to registration. These controls are unchanged.

      Resilience and Maintainability Implications

      • inferred — The read, token retirement and upsert are not enclosed in a transaction. Concurrent registrations can overwrite token ownership, and interruption after retirement can make a retry arm freshly. Those failure modes existed before this PR; the new snapshot can additionally preserve stale timing metadata during an overlap. No introduced security impact was established, but production interleavings and APNs token-generation guarantees remain unverified.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary fix: reopening the app now ends a finished iOS Live Activity.
      Description checkPassedThe description covers the problem, reproduction steps, expected behavior, technical change, scope rationale, limitations, focused tests, broader verification, observed results, unverified checks, and…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Description check

      Explanation

      The description covers the problem, reproduction steps, expected behavior, technical change, scope rationale, limitations, focused tests, broader verification, observed results, unverified checks, and the required model and harness details.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge merged this992022b

    5. juliusmarminge closed this

Sign in to join this conversation.