Skip to content

fix(relay): Android pushes send a per-device hash instead of the account's user id to Google - #42459

Merged
juliusmarminge merged 1 commit into
mainfrom
t3/fcm-payload-no-clerk-id
Nov 24, 2026
Merged

juliusmarminge merged 1 commit into
mainfrom
t3/fcm-payload-no-clerk-id

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

Problem

Every Android agent-activity push sent through FCM carried the account's raw Clerk user id (user_id) in its data payload, so Google saw it on every push.

Consumers found and the decision

  • The only reader is the native handler in apps/mobile/modules/t3-agent-notifications (AgentNotifications.receive). It drops a push unless device_id and user_id match the identity stored by configure(deviceId, userId, …), so pushes still in flight for an account the install signed out of (or switched away from) do not show up.
  • No JS code reads the push data keys. The showcase payload never set user_id, and the relay smoke/watch scripts only send it.

The check is still needed, and the device id alone cannot replace it: the device id is per install, not per account. So the relay now sends user_hash = sha256("<userId>:<deviceId>"), using hashTelemetryId from @t3tools/shared. The native handler computes the same hash from its stored identity and compares the two. Hashing with the device id gives each install a different value, so the payload no longer carries an id that stays the same for an account across devices. The logic is in androidRecipientData (fcmPayloads.ts), which the delivery path and both relay scripts use.

Old clients

A build before this one only accepts a push when its raw user_id matches. Without the field, every push would be dropped silently: nothing would crash, but no notifications would arrive. To prevent that, the relay keeps sending user_id when the device's registered app_version is below 2.4.0 or missing/unparseable, along with user_hash. New builds ignore user_id. Once those old builds are gone, the fallback can be deleted. Note: this assumes the change ships in mobile 2.4.0 (app.config.ts is at 2.3.0 now). If the Android release that ships it has a different version, the threshold in androidRecipientData has to change to match.

Verification

  • vp test run src/agentActivity/FcmDeliveries.test.ts (infra/relay): 29 passed. The new case checks that a 2.4.0 device gets no user_id and gets the expected user_hash.
  • vp run check:changed: all passed (format, lint, knip, typecheck, tests).
  • I updated the Kotlin Robolectric fixtures to send the hash of user:device, but did not run them locally because this machine has no Gradle project. CI's mobile native lane covers them. The account/device-switch test still covers rejecting old pushes.

Claude Opus 5.5 via Claude Code in T3 Code.

🤖 Generated with Claude Code

…ogle

FCM data pushes carried the raw Clerk user id so the Android handler could
ignore pushes for an account the install no longer has. They now carry
user_hash = sha256("<userId>:<deviceId>"), which the native handler
recomputes from its stored identity. The raw user_id is still sent to
builds before 2.4.0 (or with no reported version), whose handler drops any
push whose user_id does not match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). 📱 Native Change Changes the native fingerprint; merging blocks production OTAs until a new store build ships. labels Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The relay now builds Android notification recipient fields with a version-aware helper. The Android receiver validates the device ID and a SHA-256 hash of the user and device IDs.

Changes: Android notification recipient identity

Layer / File(s) Summary
Build version-aware recipient fields
infra/relay/src/agentActivity/fcmPayloads.ts, infra/relay/src/agentActivity/FcmDeliveries.ts, infra/relay/src/agentActivity/FcmDeliveries.test.ts, infra/relay/scripts/android-push-smoke.ts, infra/relay/scripts/android-push-watch.ts
The new androidRecipientData helper returns the device ID and a SHA-256 hash of the user and device IDs. It includes the raw user ID unless the app version parses as 2.4.0 or later. Delivery code and both Android push scripts use the helper. A test checks the payload for app version 2.4.0.
Validate recipient identity on Android
apps/mobile/modules/t3-agent-notifications/android/src/main/java/expo/modules/t3agentnotifications/AgentNotifications.kt, apps/mobile/modules/t3-agent-notifications/android/src/test/java/expo/modules/t3agentnotifications/AgentNotificationsTest.kt
The receiver checks registration status, stored IDs, the payload device ID, and the user hash. Test payloads now provide a fixed user_hash instead of user_id.

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

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant Relay
  participant androidRecipientData
  participant FCM
  participant AgentNotifications
  Relay->>androidRecipientData: Build recipient fields using user ID, device ID, and app version
  androidRecipientData-->>Relay: Return device ID, user hash, and version-dependent user ID
  Relay->>FCM: Send notification payload
  FCM->>AgentNotifications: Deliver notification payload
  AgentNotifications->>AgentNotifications: Validate device ID and user hash
Loading

Suggested reviewers: macroscopeapp

Merge Risk: Minimal · up to 7b064

Android push payloads now carry a per-device hash instead of the raw account ID, and older app builds still receive the raw ID for compatibility. No concrete defect was found. Confirm that the mobile release ships as 2.4.0 so the compatibility cutoff matches.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Android agent-activity pushes now send a per-device hash instead of the account's user id to Google. It is a conventional commit with a fix type and a relay scope, and…
Description check Passed The description covers the problem, the change, the compatibility fallback for old clients, and verification. It follows the template's intent. The Scope section does not link an issue or state why no…
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.
Full details: Title check

Explanation

The title names the main change: Android agent-activity pushes now send a per-device hash instead of the account's user id to Google. It is a conventional commit with a fix type and a relay scope, and it matches the objectives and file changes.

Full details: Description check

Explanation

The description covers the problem, the change, the compatibility fallback for old clients, and verification. It follows the template's intent. The Scope section does not link an issue or state why none is needed. It also does not say whether a maintainer requested the PR. The description is mostly complete, so this is a non-critical gap.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between bd3e495 and 7b0649b.

Files selected for processing: 7

  • apps/mobile/modules/t3-agent-notifications/android/src/main/java/expo/modules/t3agentnotifications/AgentNotifications.kt
  • apps/mobile/modules/t3-agent-notifications/android/src/test/java/expo/modules/t3agentnotifications/AgentNotificationsTest.kt
  • infra/relay/scripts/android-push-smoke.ts
  • infra/relay/scripts/android-push-watch.ts
  • infra/relay/src/agentActivity/FcmDeliveries.test.ts
  • infra/relay/src/agentActivity/FcmDeliveries.ts
  • infra/relay/src/agentActivity/fcmPayloads.ts

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

@juliusmarminge
juliusmarminge merged commit 2a11e76 into main Nov 24, 2026
38 checks passed
@juliusmarminge
juliusmarminge deleted the t3/fcm-payload-no-clerk-id branch November 24, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📱 Native Change Changes the native fingerprint; merging blocks production OTAs until a new store build ships. size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant