Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 8e3467f

Browse files
Synchronize mobile threads with authoritative shell snapshots (pingdotgg#4163)
Co-authored-by: codex <[email protected]>
1 parent 2fae0d0 commit 8e3467f

17 files changed

Lines changed: 779 additions & 233 deletions

‎apps/mobile/src/Stack.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { DynamicColorIOS, Platform, Pressable, ScrollView, StyleSheet } from "re
1515
import { useResolveClassNames } from "uniwind";
1616

1717
import { AppText as Text } from "./components/AppText";
18-
import { renderCompactBrandTitle } from "./components/CompactBrandTitle";
1918
import { ArchivedThreadsRouteScreen } from "./features/archive/ArchivedThreadsRouteScreen";
2019
import { useAgentNotificationNavigation } from "./features/agent-awareness/notificationNavigation";
2120
import { ClerkSettingsSheetDetentProvider } from "./features/cloud/ClerkSettingsSheetDetent";
@@ -378,8 +377,7 @@ export const RootStack = createNativeStackNavigator({
378377
...GLASS_HEADER_OPTIONS,
379378
contentStyle: { backgroundColor: "transparent" },
380379
headerBackVisible: false,
381-
headerTitle: renderCompactBrandTitle,
382-
title: "T3 Code",
380+
title: "Threads",
383381
},
384382
}),
385383
Thread: createNativeStackScreen({

‎apps/mobile/src/components/CompactBrandTitle.tsx‎

Lines changed: 0 additions & 60 deletions
This file was deleted.

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useNavigation } from "@react-navigation/native";
44
import { useMemo, useState } from "react";
55

66
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
7-
import { renderCompactBrandTitle } from "../../components/CompactBrandTitle";
87
import { useProjects, useThreadShells } from "../../state/entities";
98
import { usePendingNewTasks } from "../../state/use-pending-new-tasks";
109
import { useWorkspaceState } from "../../state/workspace";
@@ -87,9 +86,7 @@ export function HomeRouteScreen() {
8786
>
8887
<>
8988
{/* Restore the compact title in case the split branch blanked it. */}
90-
<NativeStackScreenOptions
91-
options={{ title: "T3 Code", headerTitle: renderCompactBrandTitle }}
92-
/>
89+
<NativeStackScreenOptions options={{ title: "Threads", headerTitle: "Threads" }} />
9390
<HomeHeader
9491
environments={environments}
9592
searchQuery={searchQuery}

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,20 @@ export function HomeScreen(props: HomeScreenProps) {
399399
onAction={!props.catalogState.hasReadyEnvironment ? props.onAddConnection : undefined}
400400
variant="plain"
401401
/>
402-
{emptyState.loading ? (
402+
{emptyState.loading && !shouldShowConnectionStatus ? (
403403
<View className="mt-4 items-center">
404404
<ActivityIndicator color={accentColor} />
405405
</View>
406406
) : null}
407+
{shouldShowConnectionStatus && Platform.OS === "ios" ? (
408+
<View className="mt-4">
409+
<WorkspaceConnectionStatus
410+
state={props.catalogState}
411+
onPress={props.onOpenEnvironments}
412+
variant="sidebar"
413+
/>
414+
</View>
415+
) : null}
407416
</View>
408417
{connectionStatus}
409418
</View>

‎apps/mobile/src/features/home/WorkspaceConnectionStatus.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,21 @@ describe("workspace connection status", () => {
6767
expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
6868
expect(workspaceConnectionStatusLabel(state)).toBe("Could not reach Julius’s Mac mini");
6969
});
70+
71+
it("shows shell catch-up while cached threads remain visible", () => {
72+
const state = workspaceState({ hasPendingShellSnapshot: true });
73+
74+
expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
75+
expect(workspaceConnectionStatusLabel(state)).toBe("Syncing threads...");
76+
});
77+
78+
it("distinguishes initial shell loading from cached catch-up", () => {
79+
const state = workspaceState({
80+
hasLoadedShellSnapshot: false,
81+
hasPendingShellSnapshot: true,
82+
});
83+
84+
expect(shouldShowWorkspaceConnectionStatus(state)).toBe(true);
85+
expect(workspaceConnectionStatusLabel(state)).toBe("Loading threads...");
86+
});
7087
});

‎apps/mobile/src/features/home/WorkspaceConnectionStatus.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export function WorkspaceConnectionStatus(props: {
1212
readonly variant?: "floating" | "sidebar";
1313
}) {
1414
const iconColor = useThemeColor("--color-icon-muted");
15-
const isReconnecting = props.state.connectingEnvironments.length > 0;
15+
const isSynchronizing =
16+
props.state.networkStatus !== "offline" &&
17+
props.state.connectionError === null &&
18+
(props.state.connectingEnvironments.length > 0 || props.state.hasPendingShellSnapshot);
1619
const variant = props.variant ?? "floating";
1720

1821
return (
@@ -37,7 +40,7 @@ export function WorkspaceConnectionStatus(props: {
3740
: undefined
3841
}
3942
>
40-
{isReconnecting ? (
43+
{isSynchronizing ? (
4144
<ActivityIndicator color={iconColor} size="small" />
4245
) : (
4346
<SymbolView name="wifi.slash" size={15} tintColor={iconColor} type="monochrome" />

‎apps/mobile/src/features/home/workspace-connection-status.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export function shouldShowWorkspaceConnectionStatus(state: WorkspaceState): bool
55
state.networkStatus === "offline" ||
66
state.connectionError !== null ||
77
state.hasConnectingEnvironment ||
8+
state.hasPendingShellSnapshot ||
89
(state.hasLoadedShellSnapshot && !state.hasReadyEnvironment)
910
);
1011
}
@@ -18,5 +19,8 @@ export function workspaceConnectionStatusLabel(state: WorkspaceState): string {
1819
return `Reconnecting ${state.connectingEnvironments.length} environments`;
1920
}
2021
if (state.connectionError !== null) return state.connectionError;
22+
if (state.hasPendingShellSnapshot) {
23+
return state.hasLoadedShellSnapshot ? "Syncing threads..." : "Loading threads...";
24+
}
2125
return "Not connected";
2226
}

‎apps/mobile/src/features/threads/sidebar-navigation-shell.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import type { ReactNode } from "react";
1212
import { Platform, useColorScheme } from "react-native";
1313

14-
import { renderCompactBrandTitle } from "../../components/CompactBrandTitle";
1514
import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
1615

1716
const SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
@@ -35,11 +34,10 @@ const SIDEBAR_SCREEN_OPTIONS: SidebarScreenOptions = {
3534
headerShadowVisible: false,
3635
headerShown: true,
3736
headerStyle: { backgroundColor: "transparent" },
38-
headerTitle: renderCompactBrandTitle,
3937
headerTitleStyle: { fontSize: 18, fontWeight: "800" },
4038
headerTransparent: true,
4139
scrollEdgeEffects: SCROLL_EDGE_EFFECTS,
42-
title: "T3 Code",
40+
title: "Threads",
4341
unstable_navigationItemStyle: "editor",
4442
};
4543

‎apps/server/src/server.test.ts‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,6 +3717,8 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
37173717

37183718
assert.equal(response.environment.environmentId, testEnvironmentDescriptor.environmentId);
37193719
assert.equal(response.auth.policy, "desktop-managed-local");
3720+
assert.equal(response.shellResumeCompletionMarker, true);
3721+
assert.equal(response.threadResumeCompletionMarker, true);
37203722
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
37213723
);
37223724

@@ -5607,6 +5609,113 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
56075609
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
56085610
);
56095611

5612+
it.effect("marks an empty shell catch-up replay as synchronized when requested", () =>
5613+
Effect.gen(function* () {
5614+
yield* buildAppUnderTest({
5615+
layers: {
5616+
orchestrationEngine: {
5617+
readEvents: () => Stream.empty,
5618+
},
5619+
},
5620+
});
5621+
5622+
const wsUrl = yield* getWsServerUrl("/ws");
5623+
const firstItem = yield* Effect.scoped(
5624+
withWsRpcClient(wsUrl, (client) =>
5625+
client[ORCHESTRATION_WS_METHODS.subscribeShell]({
5626+
afterSequence: 0,
5627+
requestCompletionMarker: true,
5628+
}).pipe(Stream.runHead),
5629+
),
5630+
);
5631+
5632+
assert.deepEqual(Option.getOrThrow(firstItem), { kind: "synchronized" });
5633+
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
5634+
);
5635+
5636+
it.effect("marks a socket thread snapshot as synchronized when requested", () =>
5637+
Effect.gen(function* () {
5638+
const thread = makeDefaultOrchestrationReadModel().threads[0]!;
5639+
yield* buildAppUnderTest({
5640+
layers: {
5641+
projectionSnapshotQuery: {
5642+
getThreadDetailSnapshot: () =>
5643+
Effect.succeed(Option.some({ snapshotSequence: 1, thread })),
5644+
},
5645+
},
5646+
});
5647+
5648+
const wsUrl = yield* getWsServerUrl("/ws");
5649+
const items = yield* Effect.scoped(
5650+
withWsRpcClient(wsUrl, (client) =>
5651+
client[ORCHESTRATION_WS_METHODS.subscribeThread]({
5652+
threadId: defaultThreadId,
5653+
requestCompletionMarker: true,
5654+
}).pipe(Stream.take(2), Stream.runCollect),
5655+
),
5656+
);
5657+
5658+
assert.equal(items[0]?.kind, "snapshot");
5659+
assert.deepEqual(items[1], { kind: "synchronized" });
5660+
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
5661+
);
5662+
5663+
it.effect("buffers shell events published while the fallback snapshot loads", () =>
5664+
Effect.gen(function* () {
5665+
const liveEvents = yield* PubSub.unbounded<OrchestrationEvent>();
5666+
const deletedEvent = {
5667+
sequence: 2,
5668+
eventId: EventId.make("event-shell-thread-deleted"),
5669+
aggregateKind: "thread",
5670+
aggregateId: defaultThreadId,
5671+
occurredAt: "2026-01-01T00:00:01.000Z",
5672+
commandId: null,
5673+
causationEventId: null,
5674+
correlationId: null,
5675+
metadata: {},
5676+
type: "thread.deleted",
5677+
payload: {
5678+
threadId: defaultThreadId,
5679+
deletedAt: "2026-01-01T00:00:01.000Z",
5680+
},
5681+
} satisfies Extract<OrchestrationEvent, { type: "thread.deleted" }>;
5682+
5683+
yield* buildAppUnderTest({
5684+
layers: {
5685+
orchestrationEngine: {
5686+
streamDomainEvents: Stream.fromPubSub(liveEvents),
5687+
},
5688+
projectionSnapshotQuery: {
5689+
getShellSnapshot: () =>
5690+
Effect.gen(function* () {
5691+
yield* Effect.sleep("25 millis");
5692+
yield* PubSub.publish(liveEvents, deletedEvent);
5693+
return {
5694+
snapshotSequence: 1,
5695+
projects: [],
5696+
threads: [makeDefaultOrchestrationThreadShell()],
5697+
updatedAt: "2026-01-01T00:00:00.000Z",
5698+
};
5699+
}),
5700+
},
5701+
},
5702+
});
5703+
5704+
const wsUrl = yield* getWsServerUrl("/ws");
5705+
const items = yield* Effect.scoped(
5706+
withWsRpcClient(wsUrl, (client) =>
5707+
client[ORCHESTRATION_WS_METHODS.subscribeShell]({
5708+
requestCompletionMarker: true,
5709+
}).pipe(Stream.take(3), Stream.runCollect),
5710+
),
5711+
).pipe(Effect.timeout("2 seconds"));
5712+
5713+
assert.equal(items[0]?.kind, "snapshot");
5714+
assert.equal(items[1]?.kind, "thread-removed");
5715+
assert.deepEqual(items[2], { kind: "synchronized" });
5716+
}).pipe(Effect.provide(NodeHttpServer.layerTest), TestClock.withLive),
5717+
);
5718+
56105719
it.effect("buffers thread events published while the initial snapshot loads", () =>
56115720
Effect.gen(function* () {
56125721
const thread = makeDefaultOrchestrationReadModel().threads[0]!;

0 commit comments

Comments
 (0)