mirror of
https://github.com/Monkopedia/rouse-context.git
synced 2026-12-01 05:40:19 +00:00
Three sibling instances of the cold-start async-state-not-loaded-yet race that #416 fixed for ProviderRegistry (issue #414). Each used the same shape: async state seeded into a StateFlow with a default value, read synchronously by callers that fire during the cold-start window between process spawn and the first DataStore emission. Finding #1 (HIGH) - securityAlertCheck The McpSession `securityAlertCheck` lambda was `() -> Boolean` reading `alertFlag.value` from a `combine().stateIn(..., initialValue = false)` flow. On cold-start FCM wake the very first request arrived before the flow had emitted, so a device whose security check reported `alert` answered the request anyway. Subsequent requests refused correctly. Fix: introduce SecurityAlertGate (mirrors ProviderRegistry's awaitReady shape) that suspends until the underlying combined flow has emitted once, then exposes `suspend fun isAlerting()`. McpRouting's `securityAlertCheck` lambda type changes to `suspend () -> Boolean`; existing test lambdas (`{ true }` / `{ false }`) auto-cast. Finding #2 (MEDIUM) - OutreachIntegration._directLaunchEnabled `canLaunchDirectly` was a `() -> Boolean` reading `_directLaunchEnabled.value` from a MutableStateFlow seeded by an `appScope.launch{}` collector. First tool call after cold-start could mis-route through the notification fallback even when the user had opted into direct launch. Fix: convert `canLaunchDirectly` to `suspend () -> Boolean` through the chain (LaunchAppTool, OpenLinkTool, launchActivitySafely). Add `awaitReady` / `awaitReadyBlocking` to OutreachIntegration; the lambda becomes `{ isDirectLaunchAllowed() }` which suspends on awaitReady before reading the flow value. Finding #3 (MEDIUM, latent) - DeviceRegistrationStatus Constructed with `initiallyRegistered = false` and an `appScope.launch{ if (certStore.getSubdomain() != null) markComplete() }`. Currently safe only because IntegrationSetupViewModel.awaitRegistrationIfNeeded (issue #242) consults the cert store directly; future readers that add `.complete.value` without copying the workaround re-introduce the bug. Fix: add `DeviceRegistrationStatus.create(scope, suspend isRegistered)` factory that runs the check in `scope` and signals `awaitReady` once it resolves. AppModule's Koin binding switches to `create()`. The synchronous constructor is preserved for tests; both code paths signal readiness eagerly when the answer is known up front. Per #419 hard rules: - Workaround in IntegrationSetupViewModel.awaitRegistrationIfNeeded left in place; no UX-flow files touched. - No runBlocking added to production code. Tests: - SecurityAlertGateTest (new): slow-flow regression + idempotent awaitReady + empty-first-emission ready signal. - DeviceRegistrationStatusTest (extended): create() defers awaitReady until check resolves; both true/false verdicts unblock. - OutreachIntegrationTest (extended): mockk-based slow settings store proves awaitReady waits for first emission. - HttpRoutingTest (extended): suspend-awaiting securityAlertCheck still rejects with 503. Verification: - `./gradlew :app:testDebugUnitTest :work:testDebugUnitTest :core:mcp:jvmTest :integrations:testDebugUnitTest` all green. - `./gradlew ktlintCheck detekt` clean. Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| screenshots | ||
| src | ||
| build.gradle.kts | ||
| google-services.json | ||
| proguard-rules.pro | ||