Skip to content

fix(push): persist client revocation until it succeeds - #8706

Open
jmecom wants to merge 16 commits into
jm/push-ingress-limitsfrom
jm/push-client-revocation
Open

jmecom wants to merge 16 commits into
jm/push-ingress-limitsfrom
jm/push-client-revocation

Conversation

@jmecom

@jmecom jmecom commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Turning off push or removing a community must retire its gateway permission and relay lease after a restart or lost response. Persist the two cleanup operations separately, so either can finish while the other is unavailable. Journal the gateway target before native revocation can erase it, and retry while the relay is disconnected. Preserve shared grants, installation/signer ownership, and stale-enrollment protection.

Validation: 67 focused Flutter tests and clean mobile analysis, covering either cleanup operation failing, restart recovery, opt-out, and shared ownership. The tests mock native callbacks; physical-device App Attest/APNs verification remains pending.

Stack (merge in order): #8673 → #8703 → #8704 → #8705 → #8706 → #8707 → #8708.

Signed-off-by: jm <jm@squareup.com>
Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: jm <jm@squareup.com>
jmecom and others added 10 commits October 29, 2026 21:17
Signed-off-by: jm <jm@squareup.com>
Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: jm <jm@squareup.com>
Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: jm <jm@squareup.com>
Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: jm <jm@squareup.com>
Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: jm <jm@squareup.com>
Signed-off-by: jm <jm@squareup.com>
* commit '4353f060f407f63cf79765a4a960aa73d18ca2de':
  test(desktop): bind duplicate voice players to message IDs

Signed-off-by: jm <jm@squareup.com>
@jmecom
jmecom removed this pull request from stack #8721 October 30, 2026 00:25
@jmecom
jmecom added this pull request to stack #8724 October 30, 2026 00:25
brow pushed a commit that referenced this pull request Nov 3, 2026
## Summary

Fix community removal failing with “Expected exactly one endpoint grant
for push lease revocation” when saved push state exists but the current
build has no cached grant, including builds without a push gateway.

When the community has a saved installation ID, journal its targeted
revocation without requiring the grant. An unknown grant expiry stays
unknown: retain cleanup credentials until the relay accepts the
revocation. Existing known-expiry cleanup and legacy grant-based
addressing remain unchanged.

### Related issue

No matching open issue found. Follows [the durable revocation
outbox](#8706).

### Testing

The new regression fails with the reported error on the preceding
implementation. It now verifies missing-grant enqueue, offline retry,
persistence across restart, the exact lease address and eventual cleanup
after acceptance. On a physical iPhone with the fix applied to the
onboarding test build, the previously failing community removal
succeeded.

Unknown-expiry records retain their signing key in secure storage until
successful revocation. Downgrading to a client that requires an integer
expiry will reject those pending records.

Signed-off-by: John Tennant <jtennant@squareup.com>
Co-authored-by: Aaron <f425b86c3b780d43f8d9cf1802429d04dd985bf92eac44fca9468b5ad3887c5e@buzz.block.builderlab.xyz>
@jmecom
jmecom marked this pull request as ready for review November 3, 2026 20:54
@jmecom
jmecom requested a review from a team as a code owner November 3, 2026 20:54

@joahg joahg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Read the outbox split into gateway-only and relay records, the shared-grant recheck at execution time, and the Swift revoke/settle paths; each cleanup is journaled before native inventory is erased. P3: records carrying a gateway target are exempt from the expiresAt purge, so a gateway rejection that never clears (e.g. a non-retryable 4xx) retries forever; worth confirming only transient errors reach that path. Physical-device App Attest/APNs verification is still pending per the description.

jmecom and others added 3 commits November 5, 2026 21:10
Signed-off-by: jm <jm@squareup.com>
Co-authored-by: Codex <noreply@openai.com>
@jmecom
jmecom removed this pull request from stack #8724 November 5, 2026 21:43
@jmecom
jmecom added this pull request to stack #9143 November 5, 2026 21:43
Signed-off-by: jm <jm@squareup.com>
Co-authored-by: Codex <noreply@openai.com>

@joahg joahg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Re-approving. Most of the new diff adapts to the base's nullable expiresAt and HostedRelayAuth. The one semantic change, journaling a relay-only revocation when a community has a pushLeaseInstallationId but no matching grant, is null-safe: grant! only runs when exactly one grant matched. P3: records with a null expiresAt retry forever against a dead relay and keep the nsec in secure storage, so a max age would bound that.

@wesbillman wesbillman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 Star Lord: changes needed at 61d992d. Source-only review; two first-pass lanes were incomplete and the corroborating second pass was not blind. Physical-device push remains unverified.

"relayOrigin": pending.relayOrigin, "relayPubkey": pending.relayPubkey,
"installationId": pending.installationId, "endpointGrant": "",
"endpointHash": pending.endpointHash, "endpointEpoch": 1,
"generation": max(1, pending.delegationGeneration), "expiresAt": pending.expiresAt,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 [P2] Preserve the pending enrollment’s known installation identity. If A and B share installation H / relay key K, B has an interrupted renewal, and A is disabled or removed while B stays enabled, this projection replaces B’s saved grant with a pending map that omits H. The Dart sharing checks then compare A’s H to B’s null and permit cleanup; revokeDelegation(settlePending: true) settles B’s renewal and revokes that resulting delegation too. B silently loses push despite remaining opted in. Export the known pending installation handle so the sharing checks protect B, and add an interrupted-renewal + sibling-opt-out regression journey.

@brow brow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 Tom's pre-review recommends rework on this head (61d992d). Three problems:

  1. An enabled sibling's delegation can be revoked. While community B has an unfinished renewal, endpointGrants in AppDelegate.swift replaces B's saved grant with the pending entry and drops gatewayInstallationHandle, so the three Dart sharing checks (enqueueCommunity, reconcileGatewayCleanup, the outbox publisher) read B as unshared when community A is turned off or removed, and revokeDelegation(settlePending: true) settles B's renewal and revokes it. B gets no push, with its switch still on, until its next renewal, reconnect or restart. Exporting one handle is not enough (B can retain one installation and have a pending replacement on another): the bridge needs both the retained and the pending (installation handle, relay signer) pairs, all three checks need their union, and an already journaled cleanup has to stay pending rather than complete while ownership is unresolved. #9161 carries the same code.
  2. A removed community's signing key is kept. The gateway-only record is record.copyWith(gatewayOnly: true), which keeps nsec, and that record is exempt from the expiry purge and has no terminal state, so the key stays in secure storage until the gateway revoke succeeds. Dropping nsec from the gateway-only copy resolves it (the publisher never uses it there).
  3. A failed opt-out leaves notifications showing. setPushNotificationsEnabled(false) now awaits the cleanup enqueue before syncCommunitySnapshot, so if the native grants read or the secure-storage write throws, the notification extension keeps the muted community in its snapshot and shows its messages with sender and text, and the immediate tombstone attempt is skipped. Exporting the snapshot before journaling resolves it.

This branch has not been deployed

No deployments
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.

4 participants