Repository navigation
fix(profiles): recover from access changes without failed loads #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Quick104
merged 26 commits into
Silo-Server:main
from
Rhainland:fix/profile-verification-recovery
Oct 10, 2026
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
78e150e
feat(profiles): send stale PIN profiles back to profile selection
Rhainland dcd7805
fix(notifications): resume realtime after the profile is re-verified
Rhainland e910c0d
feat(realtime): refresh access-dependent screens when access changes
Rhainland d737d4e
test(auth): cover the quiet refresh on token_refresh_required
Rhainland e02c0e0
fix(realtime): refresh once when both events sockets report one acces…
Rhainland 02ad28a
fix(profiles): log only the exception class when recovery init fails
Rhainland 348998c
fix(detail): show the unavailable state when an access change hides t…
Rhainland 2fd8178
fix(profiles): re-check a deferred profile prompt when remote playbac…
Rhainland b92fb7e
fix(tv): refresh library pages when the viewer's access changes
Rhainland a356013
fix(tv): re-probe library collections after an access change
Rhainland df797b6
fix(detail): reload a refused title when access changes again
Rhainland 0716126
fix(detail): keep a refused title hidden when the full load runs again
Rhainland f23df3a
fix(realtime): apply access changes a screen missed while away
Rhainland 1afcbfd
fix(detail): reload past a pre-change warm-up after an access change
Rhainland 094daf9
fix(tv): skip a pre-change warm-up when an access change reruns the f…
Rhainland 0cb7b76
fix(realtime): check the library list for an access change after the …
Rhainland b7498ff
fix(realtime): refresh for a change reported by a socket opened after…
Rhainland e61a69b
fix(detail): keep an older quiet refresh from overwriting a newer one
Rhainland 159dd68
fix(tv): let only the newest library-list, filters, and collections l…
Rhainland bb10943
fix(tv): keep a watched change from restoring an older resume position
Rhainland 9025078
Merge branch 'main' into fix/profile-verification-recovery
Quick104 5d34946
fix(profiles): return to the server list from a picker opened while a…
Quick104 9181a20
fix(search): keep an older search from overwriting the access-change …
Quick104 f2e3aa8
fix(collections): let only the newest collections load publish
Quick104 5805bc6
fix(libraries): keep a pending facet load from refilling facets after…
Quick104 32e759c
fix(tv): declare the library page's load jobs before init
Quick104 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/ui/ViewerAccessEffects.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package org.siloserver.silo.common.ui | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableIntStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.rememberUpdatedState | ||
| import androidx.compose.runtime.setValue | ||
| import org.siloserver.silo.network.AccessChangeCursor | ||
| import org.siloserver.silo.network.AccessChangeSignals | ||
|
|
||
| /** | ||
| * Runs [onChanged] each time the server reports that the viewer's access | ||
| * changed (access group, permissions, or playback-quality override) while this | ||
| * composable is on screen, or, with a [AccessChangeCursor], since it was last | ||
| * on screen. Screens use it to refetch libraries, search results, | ||
| * details, and collections the new policy may have added or removed. | ||
| * | ||
| * Inert against a server that never reports access changes. | ||
| */ | ||
| @Composable | ||
| fun OnViewerAccessChanged( | ||
| signals: AccessChangeSignals, | ||
| /** | ||
| * The retained ViewModel's cursor. With it, a change reported while this | ||
| * screen was out of composition (another destination in front, another | ||
| * tab showing) runs [onChanged] as soon as the screen returns. | ||
| */ | ||
| cursor: AccessChangeCursor? = null, | ||
| onChanged: () -> Unit, | ||
| ) { | ||
| val latest by rememberUpdatedState(onChanged) | ||
| LaunchedEffect(signals, cursor) { | ||
| val changes = if (cursor != null) signals.changes(cursor) else signals.changes | ||
| changes.collect { latest() } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A key that moves on each reported access change, for `produceState` and | ||
| * `LaunchedEffect` loaders that should re-run under the new policy. | ||
| */ | ||
| @Composable | ||
| fun rememberViewerAccessKey(signals: AccessChangeSignals): Int { | ||
| var key by remember(signals) { mutableIntStateOf(0) } | ||
| OnViewerAccessChanged(signals) { key++ } | ||
| return key | ||
| } |
123 changes: 123 additions & 0 deletions
123
...androidUnitTest/kotlin/org/siloserver/silo/common/network/EventsSocketAccessChangeTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package org.siloserver.silo.common.network | ||
|
|
||
| import kotlinx.coroutines.flow.toList | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlinx.coroutines.withTimeout | ||
| import okhttp3.WebSocket | ||
| import okhttp3.WebSocketListener | ||
| import okhttp3.mockwebserver.MockResponse | ||
| import okhttp3.mockwebserver.MockWebServer | ||
| import org.siloserver.silo.network.AccessChangeSignals | ||
| import org.siloserver.silo.network.AuthScopeSnapshot | ||
| import org.siloserver.silo.network.CleartextOriginConsent | ||
| import org.siloserver.silo.network.TokenManager | ||
| import org.siloserver.silo.network.TokenManagerImpl | ||
| import org.siloserver.silo.network.apiv2.ApiV2Gate | ||
| import org.siloserver.silo.network.apiv2.EventsSocketV2Api | ||
| import org.siloserver.silo.network.canonicalHttpOrigin | ||
| import org.siloserver.silo.network.createSiloClient | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertTrue | ||
|
|
||
| /** | ||
| * The events socket's access-change notice (a frame, then close code 4001) | ||
| * reaches [AccessChangeSignals] once per connection, and a server that never | ||
| * sends it leaves the signals untouched. | ||
| */ | ||
| class EventsSocketAccessChangeTest { | ||
|
|
||
| @Test | ||
| fun `access_changed frame and 4001 close report one access change`() = runBlocking { | ||
| val frames = connectOnce { socket -> | ||
| socket.send("""{"type":"access_changed"}""") | ||
| socket.close(4001, "access_changed") | ||
| } | ||
|
|
||
| assertEquals(1L, frames.signals.revision.value) | ||
| assertTrue(frames.received.any { it.contains("access_changed") }) | ||
| } | ||
|
|
||
| @Test | ||
| fun `a 4001 close alone reports the access change`() = runBlocking { | ||
| val frames = connectOnce { socket -> socket.close(4001, "access_changed") } | ||
|
|
||
| assertEquals(1L, frames.signals.revision.value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `an ordinary close reports nothing`() = runBlocking { | ||
| val frames = connectOnce { socket -> | ||
| socket.send("""{"type":"subscribed","channel":"catalog"}""") | ||
| socket.close(1000, "bye") | ||
| } | ||
|
|
||
| assertEquals(0L, frames.signals.revision.value) | ||
| } | ||
|
|
||
| private class Outcome(val signals: AccessChangeSignals, val received: List<String>) | ||
|
|
||
| /** [afterSubscribe] runs once the client's subscribe frame arrives, as the server's recheck would. */ | ||
| private suspend fun connectOnce(afterSubscribe: (WebSocket) -> Unit): Outcome { | ||
| val server = MockWebServer() | ||
| server.enqueue( | ||
| MockResponse() | ||
| .setResponseCode(200) | ||
| .addHeader("Content-Type", "application/json") | ||
| .setBody("""{"ticket":"opaque-proof","expires_in":20,"max_connection_seconds":300,"protocol":"silo.events.v2"}"""), | ||
| ) | ||
| server.enqueue( | ||
| MockResponse() | ||
| .withWebSocketUpgrade( | ||
| object : WebSocketListener() { | ||
| override fun onMessage(webSocket: WebSocket, text: String) = afterSubscribe(webSocket) | ||
| override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { | ||
| webSocket.close(code, reason) | ||
| } | ||
| }, | ||
| ) | ||
| .addHeader("Sec-WebSocket-Protocol", "silo.events.v2"), | ||
| ) | ||
| server.start() | ||
| val signals = AccessChangeSignals() | ||
| val tokens = scopedTokens(server.url("/").toString()) | ||
| val approvedOrigin = canonicalHttpOrigin(server.url("/").toString()) | ||
| val httpClient = createSiloClient( | ||
| tokenManager = tokens, | ||
| cleartextOriginConsent = object : CleartextOriginConsent { | ||
| override suspend fun isApproved(origin: String): Boolean = origin == approvedOrigin | ||
| }, | ||
| accessChangeSignals = signals, | ||
| ) | ||
| try { | ||
| val received = withTimeout(10_000) { | ||
| EventsSocketV2Api(httpClient, tokens, ApiV2Gate.Unrestricted, signals) | ||
| .frames(listOf("catalog")) | ||
| .toList() | ||
| } | ||
| return Outcome(signals, received) | ||
| } finally { | ||
| httpClient.close() | ||
| server.shutdown() | ||
| } | ||
| } | ||
|
|
||
| private suspend fun scopedTokens(serverUrl: String): TokenManager { | ||
| val delegate = TokenManagerImpl().apply { | ||
| setServerUrl(serverUrl) | ||
| saveTokens("ACCESS", "refresh", 3_600) | ||
| setProfileIdentity("profile-1", "PROFILE_TOKEN") | ||
| } | ||
| val active = AuthScopeSnapshot( | ||
| serverId = "server-1", | ||
| profileId = "profile-1", | ||
| serverUrl = serverUrl, | ||
| profileToken = "PROFILE_TOKEN", | ||
| ) | ||
| return object : TokenManager by delegate { | ||
| override suspend fun snapshotCurrentScope(): AuthScopeSnapshot = active | ||
| override suspend fun getAccessTokenForScope(scope: AuthScopeSnapshot): String? = | ||
| "ACCESS".takeIf { scope == active } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.