mirror of
https://github.com/Monkopedia/rouse-context.git
synced 2026-11-29 11:13:05 +00:00
On a cold-start FCM wake, FcmReceiver and TunnelForegroundService both read ProviderRegistry.enabledPaths() synchronously to decide whether to honor the wake. The app-side IntegrationProviderRegistry is DataStore-backed: its _enabledIds StateFlow starts at emptySet() and only populates after the first async combine() emission lands. In a freshly-spawned process the FCM message arrives before that emission, the synchronous read returns emptySet(), and the wake is silently dropped — every subsequent AI-client request EOFs after the relay's 20s wakeup timeout. This fix introduces ProviderRegistry.awaitReady()/awaitReadyBlocking() and routes the three production callers through it before checking enabledPaths(): - FcmReceiver.onMessageReceived blocks the FCM worker thread (NOT main) on a CountDownLatch with a 2s timeout, then runs the empty-check and dispatches. - TunnelForegroundService.onStartCommand defers the empty-check into a lifecycleScope coroutine that suspends on awaitReady() first. - The state-store collector signals readiness on its first emission (which is emptySet() if nothing is enabled on disk — still a valid loaded state). Empty integrations list → registry is trivially ready (no flow to wait on). On timeout, drop the wake rather than spin up the tunnel against unknown state. Reproduced via /tmp/probe-fresh and /tmp/probe-warm1: relay sends FCM, device logs "Ignoring wake: no integrations enabled" and returns, relay's 20s timer fires, client gets TLS EOF. The new FcmReceiverTest.`wake dispatches to startService once registry becomes ready with enabled state` regression test fails on the pre-fix code (verified) and passes here. Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| src | ||
| build.gradle.kts | ||