Skip to content

feat: register with the deployed wake gateways - #1349

Open
coreyphillips wants to merge 6 commits into
masterfrom
feat/wake-gateway-urls
Open

coreyphillips wants to merge 6 commits into
masterfrom
feat/wake-gateway-urls

Conversation

@coreyphillips

@coreyphillips coreyphillips commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1354
Part of #1238
Twin: synonymdev/bitkit-android#1944

Points builds at the deployed wake gateways (synonymdev/wake#2). Draft until a device test against staging and prod passes.

Description

  • Env.wakeGatewayUrl: mainnet uses https://wake.bitkit.to, regtest https://wake.staging.bitkit.to, and testnet and signet stay off. The debug WAKE_GATEWAY_URL override still wins.
  • Unit tests run on regtest, so they get no gateway.
  • WakeRegistrar sends an unchanged registration again once it is 30 days old (WakeTimestamp.registrationMaxAgeSecs). The gateway retires a device with no accepted push or registration for 270 days and presence does not count, so a wallet that got no wake for about nine months would stop receiving wakes until its token changed. Same fix as fix: register wakes again before the gateway retires the device bitkit-android#1958, from jvsena42's review of #1944. The cached device is dropped before every send, so a renewal whose send fails goes again on the next try, and a return to the foreground checks whether the renewal is due, since the scene registers again only when its inputs change (both from ben-kaufman's review).

Out of Scope

Design

N/A: no UI changes.

Preview

N/A

QA Notes

Setup

A debug build (regtest) on a device, without WAKE_GATEWAY_URL, with notifications on.

Journeys

N/A: not drivable; see Manual Tests.

Manual Tests

  • 1. Open Dev Settings, Wake → Gateway shows https://wake.staging.bitkit.to, and Device shows the registration
  • 2. Tap Send Test Wake → the alert shows: needs a device and real APNs

Automated Checks

  • added WakeRegistrationTests.swift: each network maps to its gateway
  • updated WakeRegistrationTests.swift: unit tests have no gateway
  • added WakeRegistrationTests.swift: a registration 271 days old is sent again
  • added WakeRegistrationTests.swift: an unchanged registration stays unchanged until 30 days, then registers once and starts a new age
  • added WakeRegistrationTests.swift: isRegistrationDue at its boundaries, with no recorded time and with a clock stepped back
  • added WakeRegistrationTests.swift: a renewal whose send fails is sent again on the next try

Evidence

  • Staging: Send Test Wake showed the alert on an iPhone.
  • CI on a5470b7 (master merged): unit, integration and E2E tests passed.
  • 6e58db5, e8201e0 (re-registration): SwiftFormat lint passes locally; tests run in CI. e8201e0 moves the max age into WakeStorage.swift, which the notification extension also compiles. 8af8e0e (failed renewal), 0a0deb6 (foreground check): SwiftFormat lint passes locally; tests run in CI.

Gaps

  • No device run yet against prod.
  • No test covers the foreground renewal check (WakeManager.sceneBecameActive); it reuses the non-forced registration the tests cover.

@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The gateway changes appear safe to merge.

Summary

Enables the deployed wake gateways:

  • Wake registration now uses the deployed gateway for mainnet and regtest.

No actionable issues found.

Acknowledged scope: coreyphillips explicitly deferred swap.claimable and paykit.sync handlers to later phases, and failed-unregister retries to #1311. coreyphillips also disclosed that production device testing remains pending.

Reviews (1) · Last reviewed commit: "feat: register with the deployed wake ga..." · Reviewed by Greptile

@talosmachina talosmachina left a comment

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.

No findings. Points Env.wakeGatewayUrl at https://wake.bitkit.to on mainnet and https://wake.staging.bitkit.to on regtest, keeps testnet and signet off, keeps the debug WAKE_GATEWAY_URL override first, and returns nil under unit tests. Twin of synonymdev/bitkit-android#1944, and the two map networks identically. Reviewed 5710a2c, light tier. Not built: iOS does not build on this reviewer's Linux host; reasoned from the code and CI.

What I checked, and 3 candidates I ruled out

Read in full: Env.swift (network and wake sections), WakeManager.swift (policy and registration), WakeReceiver.swift gateway handling, WakeDevSettingsSection.swift
Tests: WakeRegistrationTests.swift covers the per-network mapping and nil under unit tests; the author's manual unit-tests run on 5710a2c concluded success
CI: build-local failed at "Verify current PR merge checkout" (the checked-out merge did not match the PR's base and head, a check on the runner's checkout, before any build), and e2e-status failed only because the shards it gates were skipped after that; Run Tests and Integration Tests were still running

Ruled out

  • Unit tests on regtest hit the staging gateway: Env.network is .regtest under isUnitTest, and wakeGatewayUrl returns nil on isUnitTest before the mapping; WakeGatewayLiveTests reads its URL from its own environment variables.
  • E2E builds register on staging: WakeRegistrationPolicy.allowsRegistration returns false when Env.isE2E.
  • A changed gateway strands an existing registration: WakeReceiver acks through the stored registeredGatewayUrl, not the current Env value.

Merge confidence: 4/5, no findings, but no device run against the prod gateway yet (the PR's own Gaps) and build-local must rerun green.

Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to the reviewer does not carry it)

@ovitrif

ovitrif commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Triage: this PR goes in the 3.2.0 milestone under #1354, so 3.2.0 receives wakes through the deployed gateways. Twin: synonymdev/bitkit-android#1944.

@coreyphillips

Copy link
Copy Markdown
Contributor Author

@jvsena42 ready for review. Since your review of the Android twin, 6e58db5 also adds the iOS side of your LOW there: an unchanged registration is sent again once it is 30 days old, so the gateway never retires the device as idle (same as synonymdev/bitkit-android#1958).

Comment thread Bitkit/Managers/WakeManager.swift Resolved
@coreyphillips

Copy link
Copy Markdown
Contributor Author

Changed

  • @ben-kaufman on Bitkit/Managers/WakeManager.swift:223: attempt now clears record.device before every send, not only when the content changed, so a failed renewal stays pending and the retry sends it again; testARenewalWhoseSendFailsIsSentAgainOnTheNextTry covers recovery after a transient send failure.

A renewal sends the registration the gateway already holds, so the
cached device was kept before the send. When that send failed, the
advanced timestamp made the next try read as fresh and unchanged, and
the renewal waited another 30 days. The cached device is now cleared
before every send and set again once the gateway answers.
Comment thread Bitkit/Managers/WakeManager.swift Resolved
@coreyphillips

Copy link
Copy Markdown
Contributor Author

Changed

  • @ben-kaufman on Bitkit/Managers/WakeManager.swift:223: Returning to the foreground now runs a non-forced registration with the latest inputs, which does nothing unless the registration has reached its max age or something changed. Presence refreshes after a registration now only restart the presence loop, so they don't start another check. SwiftFormat lint and the 47 wake unit tests pass, though no test covers the foreground path itself.

The scene registers again only when its inputs change, so a process
that stayed in memory past the max age never sent the renewal. A
return to the foreground now runs a non-forced registration, which
stays local unless the registration is due or something changed.
Presence refreshes after a registration restart only the presence
loop, so they start no further check.
/// stayed in memory is sent from here.
private func renewRegistrationIfDue() {
guard gatewayUrl != nil, latestInputs != nil else { return }
Task { await serialized { await self.register(force: false) } }

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.

A due renewal gets one attempt here. If it fails while the phone is offline and the connection comes back with Bitkit still open, the device can stay unregistered until the next foreground return or registration input change. Could we use the existing retry policy while the app is active and registration is still allowed?

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.

A failed renewal leaves the device registered. The renewal is due at 30 days, so the gateway still holds the install for about 240 more days. sentToGatewayUrl is kept, so wakes and presence keep working (WakeStorage.swift:72). Because the device is cleared before sending (WakeManager.swift:256-258), every later register call sends again, and the next foreground return does that long before the gateway would retire the device. A retry loop here would only help an app that stays in the foreground the whole time, and it would run alongside the scene's own WakeRetry loop. Leaving this open for you.

@coreyphillips

Copy link
Copy Markdown
Contributor Author

Not changing

  • @ben-kaufman on Bitkit/Managers/WakeManager.swift:443: A failed renewal leaves the device registered. The renewal is due at 30 days, so the gateway still holds the install for about 240 more days. sentToGatewayUrl is kept, so wakes and presence keep working (WakeStorage.swift:72). Because the device is cleared before sending (WakeManager.swift:256-258), every later register call sends again, and the next foreground return does that long before the gateway would retire the device. A retry loop here would only help an app that stays in the foreground the whole time, and it would run alongside the scene's own WakeRetry loop.

@coreyphillips

Copy link
Copy Markdown
Contributor Author

@jvsena42 friendly nudge on this one. Since my last ping, ben-kaufman's review led to two fixes: a failed renewal is sent again on the next try (8af8e0e), and a return to the foreground checks whether the renewal is due (0a0deb6). CI is green on 0a0deb6, and one thread with ben-kaufman is still open. The Android side of the foreground check is synonymdev/bitkit-android#1974.

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.

feat: wakes through the deployed gateways

4 participants