From 57d45efe002173680d43ffe567df313df55c8327 Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Mon, 9 Nov 2026 03:02:45 +0000 Subject: [PATCH] fix(mobile): paint host labels and relay server rows from the phone's store on relaunch (#40086) * fix(mobile): paint host labels and relay server rows from the phone's store on relaunch * refactor(mobile): reuse the SSH target summary schema for stored host labels --- ...tings-repo-metadata-refuse-after-data.json | 47 +++++------------ mobile/src/host-screen/host-list-queries.ts | 52 +++++++++++++++++-- .../host-screen/host-screen-reply-schema.ts | 21 ++++---- .../src/host-screen/use-host-repo-metadata.ts | 2 +- .../host-screen/use-host-screen-controller.ts | 4 +- .../host-screen/use-host-worktree-catalog.ts | 18 ++++--- mobile/src/query/first-paint-query-keys.ts | 16 ++++++ 7 files changed, 101 insertions(+), 59 deletions(-) diff --git a/mobile/rpc-foundation/goldens/settings-repo-metadata-refuse-after-data.json b/mobile/rpc-foundation/goldens/settings-repo-metadata-refuse-after-data.json index 3b737599abd..1ccd86c7a3e 100644 --- a/mobile/rpc-foundation/goldens/settings-repo-metadata-refuse-after-data.json +++ b/mobile/rpc-foundation/goldens/settings-repo-metadata-refuse-after-data.json @@ -35,17 +35,6 @@ "ordinal": 9, "json": "{\"id\":\"frame-3\",\"deviceToken\":\"recording-device\",\"method\":\"ssh.listTargetSummaries\"}" }, - "18c2b8e092d7": { - "name": "streams-registered-at-teardown", - "ordinal": 26, - "value": [ - { - "cancelled": true, - "method": "runtime.clientEvents.subscribe", - "payload": "runtime.clientEvents.subscribe#1" - } - ] - }, "20200b8feac4": { "name": "host.platform#1", "ordinal": 6, @@ -106,6 +95,17 @@ "startedAt": 0 } }, + "44eb39507b75": { + "name": "streams-registered-at-teardown", + "ordinal": 23, + "value": [ + { + "cancelled": true, + "method": "runtime.clientEvents.subscribe", + "payload": "runtime.clientEvents.subscribe#1" + } + ] + }, "564f54c8d902": { "name": "host.platform#1", "ordinal": 6, @@ -137,11 +137,6 @@ "ordinal": 13, "value": [["ssh:ssh-1", "SSH"]] }, - "59ab92fbdbc0": { - "name": "hostPlatform", - "ordinal": 25, - "value": "linux" - }, "6770aa1912e4": { "name": "repo.list#2", "ordinal": 15, @@ -411,11 +406,6 @@ "status": "pending", "startedAt": 0 }, - "9c290301a4bc": { - "name": "hostHealthById", - "ordinal": 23, - "value": [] - }, "b2746491ac07": { "name": "repo.list#1", "ordinal": 2, @@ -642,11 +632,6 @@ "name": "hostPlatform", "ordinal": 14, "value": "linux" - }, - "fb797b9761e1": { - "name": "hostLabelById", - "ordinal": 24, - "value": [["ssh:ssh-1", "SSH"]] } }, "recording": { @@ -795,10 +780,7 @@ "8cfdd18c5fe6", "84c1dde54c62", "56ab81cb67dc", - "f9193cae5824", - "9c290301a4bc", - "fb797b9761e1", - "59ab92fbdbc0" + "f9193cae5824" ] } }, @@ -838,10 +820,7 @@ "84c1dde54c62", "56ab81cb67dc", "f9193cae5824", - "9c290301a4bc", - "fb797b9761e1", - "59ab92fbdbc0", - "18c2b8e092d7" + "44eb39507b75" ] } } diff --git a/mobile/src/host-screen/host-list-queries.ts b/mobile/src/host-screen/host-list-queries.ts index c65ded233ea..caa752201fd 100644 --- a/mobile/src/host-screen/host-list-queries.ts +++ b/mobile/src/host-screen/host-list-queries.ts @@ -1,5 +1,10 @@ import * as z from 'zod' -import { getRepoExecutionHostId, parseExecutionHostId } from '../../../src/shared/execution-host' +import { + getRepoExecutionHostId, + parseExecutionHostId, + type ExecutionHostId +} from '../../../src/shared/execution-host' +import { MOBILE_RELAY_HOST_WORKTREE_DELTAS_RUNTIME_CAPABILITY } from '../../../src/shared/mobile-desktop-relay-contract' import type { MobileRelayHost } from '../../../src/shared/remote-runtime/relay/mobile-relay-hosts-contract' import type { Query, QueryClient } from '@tanstack/react-query' import { defineHostQuery } from '../query/host-query' @@ -18,8 +23,13 @@ import { } from '../worktree/worktree-catalog-snapshot-client' import type { Worktree } from '../worktree/workspace-list-types' import { getCachedWorktrees } from '../cache/worktree-cache' -import { hostRepoCatalogRepos, type HostRepoCatalogRow } from './host-screen-reply-schema' +import { + hostRepoCatalogRepos, + hostSshTargetSummarySchema, + type HostRepoCatalogRow +} from './host-screen-reply-schema' import { hostPlatformRead, hostRepoCatalogSnapshotRead } from './host-screen-operations' +import { NODE_PLATFORM_NAMES } from '../transport/connection/mobile-runtime-host-platform' import { acceptedMetadata, readHostSshTargetLabels, @@ -119,6 +129,18 @@ const serverRowSnapshots = { full: new ServerRowSnapshots(false) } +/** + * The server rows' input. Before the host's status is read it names the key a current desktop stores them + * under, so they paint from the store: the page came from that desktop, which sends the deltas capability. + */ +export function hostServerWorkspacesInput(hostCapabilities: readonly string[] | null): { + deltas: boolean +} { + return { + deltas: hostCapabilities?.includes(MOBILE_RELAY_HOST_WORKTREE_DELTAS_RUNTIME_CAPABILITY) ?? true + } +} + // Workspaces on the servers this desktop relays to; a server whose read fails keeps its rows. export const hostServerWorkspacesQuery = defineHostQuery<{ deltas: boolean }, ServerWorkspaces>({ family: 'relayHosts.workspaces', @@ -187,10 +209,18 @@ export function catalogNeedsHostLabels(catalog: readonly HostRepoCatalogRow[]): return hostIds.size > 1 || [...hostIds].some((id) => parseExecutionHostId(id)?.kind === 'ssh') } -export type HostRepoLabels = Awaited> & { +export type HostRepoLabels = { + sshTargetSummaries: z.output[] + // Entries rather than a Map, so the record can be stored. + hostLabels: [ExecutionHostId, string][] platform: NodeJS.Platform | null } +const storedHostLabelSchema = z.tuple([ + z.custom((id) => typeof id === 'string' && parseExecutionHostId(id) !== null), + z.string() +]) + export const hostRepoLabelsQuery = defineHostQuery({ family: 'repo.hostLabels', fetch: async (client) => { @@ -198,13 +228,25 @@ export const hostRepoLabelsQuery = defineHostQuery hostPlatformRead.request(client)) ]) - return { ...labels, platform: acceptedMetadata(platform, hostPlatformRead.interpret) ?? null } + return { + sshTargetSummaries: labels.sshTargetSummaries, + hostLabels: [...labels.hostLabelById], + platform: acceptedMetadata(platform, hostPlatformRead.interpret) ?? null + } }, staleTime: 60_000, gcTime: 30 * 60_000, refetchOnWindowFocus: true, // SSH health and the host's own label overrides. - signal: { events: ['reposChanged', 'sshStateChanged'] } + signal: { events: ['reposChanged', 'sshStateChanged'] }, + persist: { + version: 1, + dataSchema: z.object({ + sshTargetSummaries: z.array(hostSshTargetSummarySchema), + hostLabels: z.array(storedHostLabelSchema), + platform: z.enum(NODE_PLATFORM_NAMES).nullable() + }) + } }) // The host list's own reads, which pull to refresh repeats; project.sections lives with its hook. diff --git a/mobile/src/host-screen/host-screen-reply-schema.ts b/mobile/src/host-screen/host-screen-reply-schema.ts index 7afeb0e3cea..171400b27eb 100644 --- a/mobile/src/host-screen/host-screen-reply-schema.ts +++ b/mobile/src/host-screen/host-screen-reply-schema.ts @@ -83,20 +83,17 @@ export const hostRepoCatalogSnapshotSchema = z.union([ ]) // Keep target parsing total: absent/malformed targets yield [] and labels degrade to host ids on older hosts. A throw here would also skip the subsequent platform write. +export const hostSshTargetSummarySchema = z.looseObject({ + id: z.string(), + label: z.string(), + // Read raw: an arm a newer desktop adds must leave the badge as it is, not read as a verdict. + connected: salvagedOptional('connected', z.boolean()), + connectionStatus: salvagedOptional('connectionStatus', z.string()) +}) + export const hostSshTargetSummariesSchema = z .looseObject({ - targets: salvagedOptional( - 'targets', - salvagingArray( - z.looseObject({ - id: z.string(), - label: z.string(), - // Read raw: an arm a newer desktop adds must leave the badge as it is, not read as a verdict. - connected: salvagedOptional('connected', z.boolean()), - connectionStatus: salvagedOptional('connectionStatus', z.string()) - }) - ) - ) + targets: salvagedOptional('targets', salvagingArray(hostSshTargetSummarySchema)) }) .transform((reply) => reply.targets ?? []) .catch(() => []) diff --git a/mobile/src/host-screen/use-host-repo-metadata.ts b/mobile/src/host-screen/use-host-repo-metadata.ts index 6a7475b1dd3..2d306455441 100644 --- a/mobile/src/host-screen/use-host-repo-metadata.ts +++ b/mobile/src/host-screen/use-host-repo-metadata.ts @@ -66,7 +66,7 @@ export function useHostRepoMetadata(args: { useEffect(() => { if (needsLabels && labels.data) { setHostHealthById(buildSshHostHealthById(labels.data.sshTargetSummaries)) - setHostLabelById(labels.data.hostLabelById) + setHostLabelById(new Map(labels.data.hostLabels)) setHostPlatform(labels.data.platform) } else if (repos.data && !needsLabels) { // Clear labels for departed hosts so stale metadata cannot badge remaining rows. diff --git a/mobile/src/host-screen/use-host-screen-controller.ts b/mobile/src/host-screen/use-host-screen-controller.ts index 8d9b449a25e..983fa99eb96 100644 --- a/mobile/src/host-screen/use-host-screen-controller.ts +++ b/mobile/src/host-screen/use-host-screen-controller.ts @@ -60,7 +60,8 @@ export function useHostScreenController({ const relayRecovery = useRelayRecoveryStatus(hostId) const forgetHostClient = useForgetHostClient() const forceReconnectHost = useForceReconnect() - const { hostCapabilities, floatingWorkspaceEnabled, hostInstallationId } = useHostProtocolGates() + const { hostCapabilities, statusReadable, floatingWorkspaceEnabled, hostInstallationId } = + useHostProtocolGates() const state = useHostScreenState(hostId, peekStoredHost(hostId)) const settings = useHostViewSettings({ client, connState, state }) const connectionVerdict = classifyConnection({ @@ -83,6 +84,7 @@ export function useHostScreenController({ connState, embedded, hostCapabilities, + hostStatusReadable: statusReadable, hostId, sidebarFeed: sidebarFeed?.triggers ?? null, state, diff --git a/mobile/src/host-screen/use-host-worktree-catalog.ts b/mobile/src/host-screen/use-host-worktree-catalog.ts index c4cd1db1da9..ca3715baef2 100644 --- a/mobile/src/host-screen/use-host-worktree-catalog.ts +++ b/mobile/src/host-screen/use-host-worktree-catalog.ts @@ -1,4 +1,3 @@ -import { MOBILE_RELAY_HOST_WORKTREE_DELTAS_RUNTIME_CAPABILITY } from '../../../src/shared/mobile-desktop-relay-contract' import { WORKTREE_ROWS_CHANGED_EVENT_RUNTIME_CAPABILITY } from '../../../src/shared/worktree-runtime-capabilities' import { readWorktreeFirstPage } from '../worktree/worktree-catalog-first-page' import type { Worktree } from '../worktree/workspace-list-types' @@ -32,6 +31,7 @@ import { HOST_LIST_BACKSTOP_POLL_MS, HOST_LIST_POLL_MS, HOST_LIST_TARGET, + hostServerWorkspacesInput, hostServerWorkspacesQuery, hostWorktreeCatalogKey, hostWorktreeCatalogQuery, @@ -54,6 +54,8 @@ export function useHostWorktreeCatalog(args: { connState: ConnectionState embedded: boolean hostCapabilities: readonly string[] + // Whether the host answered its status: capabilities are unknown, not absent, until it has. + hostStatusReadable: boolean hostId: string | undefined sidebarFeed: HostSidebarFeedTriggers | null state: HostScreenState @@ -64,6 +66,7 @@ export function useHostWorktreeCatalog(args: { connState, embedded, hostCapabilities, + hostStatusReadable, hostId, sidebarFeed, state, @@ -117,11 +120,13 @@ export function useHostWorktreeCatalog(args: { ) // An older desktop or shell lists no server rows, rather than rows that could not open. const relays = client !== null && relaysToServers(client, hostCapabilities) + // Until the host's status is read, stored server rows paint and nothing reads them. + const relaysRuledOut = hostStatusReadable && !relays const servers = useHostQuery( hostServerWorkspacesQuery, host, HOST_LIST_TARGET, - { deltas: hostCapabilities.includes(MOBILE_RELAY_HOST_WORKTREE_DELTAS_RUNTIME_CAPABILITY) }, + hostServerWorkspacesInput(hostStatusReadable ? hostCapabilities : null), // Execution hosts' notices are not relayed, so server rows keep the full poll. { enabled: !!hostId && relays, subscribed, refetchInterval: pollMs } ) @@ -210,12 +215,13 @@ export function useHostWorktreeCatalog(args: { }, [catalog.status, catalog.errorUpdatedAt]) useEffect(() => { - if (!relays) { - setServerWorkspaces(NO_SERVER_WORKSPACES) - } else if (servers.data) { + if (servers.data && !relaysRuledOut) { setServerWorkspaces(servers.data) + } else if (!relays) { + // Also drops a previous host's rows when the sidebar switches to one with none stored. + setServerWorkspaces(NO_SERVER_WORKSPACES) } - }, [relays, servers.data]) + }, [relays, relaysRuledOut, servers.data]) const fetchWorktrees = useCallback( async (options: { allowDuringModal?: boolean } = {}) => { diff --git a/mobile/src/query/first-paint-query-keys.ts b/mobile/src/query/first-paint-query-keys.ts index 609962e2284..aee6d07b4c5 100644 --- a/mobile/src/query/first-paint-query-keys.ts +++ b/mobile/src/query/first-paint-query-keys.ts @@ -2,6 +2,9 @@ import { normalizeExecutionHostId } from '../../../src/shared/execution-host' import { HOST_LIST_TARGET, hostRepoCatalogQuery, + hostRepoLabelsQuery, + hostServerWorkspacesInput, + hostServerWorkspacesQuery, hostWorktreeCatalogKey, hostWorktreeCatalogQuery, NO_HOST_LIST_INPUT @@ -42,10 +45,23 @@ export function firstPaintQueryKeys(hostId: string, route: URL): PersistedHostQu ? [ persistedHostQueryKey(hostWorktreeCatalogQuery, hostWorktreeCatalogKey(hostId)), persistedHostQueryKey(hostViewFamily, hostViewKey(hostId)), + persistedHostQueryKey( + hostServerWorkspacesQuery, + hostQueryKey( + hostId, + hostServerWorkspacesQuery.family, + HOST_LIST_TARGET, + hostServerWorkspacesInput(null) + ) + ), persistedHostQueryKey( hostRepoCatalogQuery, hostQueryKey(hostId, hostRepoCatalogQuery.family, HOST_LIST_TARGET, NO_HOST_LIST_INPUT) ), + persistedHostQueryKey( + hostRepoLabelsQuery, + hostQueryKey(hostId, hostRepoLabelsQuery.family, HOST_LIST_TARGET, NO_HOST_LIST_INPUT) + ), persistedHostQueryKey( hostProjectSectionsQuery, hostQueryKey(