The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): keep turn and connection status from shifting the composer area (#37508)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 16, 2026 at 12:16 UTC
8bbe7fdd1a2ab217a77aeef561e19beb7bb632eb
14 files changed
+525
-333
apps/mobile/src/components/ui/AppSymbol.android.tsx
+2
@@ -1,6 +1,7 @@
1
import type { Icon } from "@tabler/icons-react-native/types";
2
/* Package-root imports eagerly register the entire Tabler icon set in Metro. */
3
import IconAdjustmentsHorizontal from "@tabler/icons-react-native/IconAdjustmentsHorizontal";
4
+import IconAlarm from "@tabler/icons-react-native/IconAlarm";
5
import IconAlignLeft from "@tabler/icons-react-native/IconAlignLeft";
6
import IconAlertCircle from "@tabler/icons-react-native/IconAlertCircle";
7
import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
@@ -189,6 +190,7 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
190
"circle.inset.filled": IconCircleDot,
191
"circle.dashed.inset.filled": IconCircleDot,
192
"calendar.badge.clock": IconCalendarClock,
193
+ alarm: IconAlarm,
194
clock: IconClock,
195
timer: IconClock,
196
"face.smiling": IconMoodPlus,
apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+36
-70
@@ -168,7 +168,6 @@ import { appAtomRegistry } from "../../state/atom-registry";
168
import { threadStreamHaptics } from "./threadStreamHaptics";
169
import { useAtomCommand } from "../../state/use-atom-command";
170
import { orchestrationEnvironment } from "../../state/orchestration";
171
-import { useDelayedStatus } from "../../lib/useDelayedStatus";
171
import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input";
172
import type { RunStopPresentation } from "@t3tools/client-runtime/state/thread-execution";
173
import type {
@@ -191,6 +190,7 @@ import {
190
FloatingWorkingControl,
191
} from "./floating-working-control";
192
import { connectionFloatingStatus, type FloatingWorkingStatus } from "./floating-working-status";
193
+import type { ThreadLifecycleEvent } from "./thread-context-divider";
194
import {
195
derivePendingUserInputMaxHeight,
196
ESTIMATED_KEYBOARD_HEIGHT,
@@ -268,7 +268,6 @@ export interface ThreadDetailScreenProps {
268
readonly activePendingUserInputAnswers: Record<string, string | ReadonlyArray<string>> | null;
269
readonly respondingUserInputId: RuntimeRequestId | null;
270
readonly connectionStateLabel: EnvironmentConnectionPhase;
271
- readonly connectionAwaitingApproval?: boolean;
271
readonly historyControls?: ThreadFeedHistoryControls;
272
readonly activeThreadBusy: boolean;
273
readonly canStopThread: boolean;
@@ -383,9 +382,6 @@ const NO_RUN_STOP_ATOM = Atom.make<RunStopPresentation | null>(null).pipe(
382
Atom.withLabel("mobile-thread-run-stop:empty"),
383
);
384
386
-// Connection failures survive retries and app suspension.
387
-const RECONNECT_ERROR_DELAY_MS = 5_000;
388
-
385
// Anchors, the submitted message, follow state and pending scrolls belong to
386
// one thread, so the body remounts when the thread changes.
387
export function ThreadDetailScreen(props: ThreadDetailScreenProps) {
@@ -569,14 +565,6 @@ function ThreadDetailBody(
565
);
566
const composerKeyboardOffset = composerBottomInset;
567
const contentPresentationKind = props.contentPresentation.kind;
572
- const connectionRetrying =
573
- props.connectionStateLabel === "connecting" || props.connectionStateLabel === "reconnecting";
574
- const retryError = connectionRetrying ? props.connectionError : null;
575
- const retryConnectionError = useDelayedStatus(
576
- `${props.environmentId}:${retryError !== null}`,
577
- retryError,
578
- RECONNECT_ERROR_DELAY_MS,
579
- );
568
const interruptThreadTurn = useAtomCommand(threadEnvironment.interruptTurn, {
569
reportFailure: false,
570
});
@@ -750,11 +738,41 @@ function ThreadDetailBody(
738
Dialog.alert("Pi", props.extensionStatuses?.map((status) => status.text).join("\n\n")),
739
}
740
: null;
741
+ const lifecycleEvent = ((): ThreadLifecycleEvent | null => {
742
+ if (contentPresentationKind !== "ready" || !(lifecycleSnoozed || settled || woke)) return null;
743
+ const actionLabel = lifecycleSnoozed ? "Wake now" : settled ? "Un-settle" : "Dismiss";
744
+ const wake =
745
+ lifecycleSnoozed && snoozedUntil !== null
746
+ ? snoozeWakeLabel(snoozedUntil, { now: lifecycleNow })
747
+ : "now";
748
+ return {
749
+ state: lifecycleSnoozed ? "snoozed" : settled ? "settled" : "woke",
750
+ label: lifecycleSnoozed
751
+ ? wake === "now"
752
+ ? "Snoozed"
753
+ : `Snoozed, ${wake} left`
754
+ : settled
755
+ ? "Settled"
756
+ : "Woke from snooze",
757
+ action: {
758
+ label: statusPending
759
+ ? lifecycleSnoozed
760
+ ? "Waking..."
761
+ : settled
762
+ ? "Un-settling..."
763
+ : "Dismissing..."
764
+ : actionLabel,
765
+ accessibilityLabel: actionLabel,
766
+ disabled: !props.canOperateThread || statusPending,
767
+ onPress: () =>
768
+ void runStatusAction(lifecycleSnoozed ? "wake" : settled ? "unsettle" : "dismiss"),
769
+ },
770
+ };
771
+ })();
772
const floatingStatus = ((): FloatingWorkingStatus | null => {
773
const connectionStatus = connectionFloatingStatus({
755
- connectionError: connectionRetrying ? retryConnectionError : props.connectionError,
774
+ connectionError: props.connectionError,
775
connectionState: props.connectionStateLabel,
757
- connectionAwaitingApproval: props.connectionAwaitingApproval === true,
776
environmentLabel: props.environmentLabel,
777
onReconnect: props.onReconnectEnvironment,
778
});
@@ -810,16 +828,6 @@ function ThreadDetailBody(
828
},
829
};
830
}
813
- if (props.isCompacting && contentPresentationKind === "ready") {
814
- return { kind: "compacting" };
815
- }
816
- if (props.activeWorkStartedAt !== null && contentPresentationKind === "ready") {
817
- return {
818
- kind: "working",
819
- environmentId: props.environmentId,
820
- startedAt: props.activeWorkStartedAt,
821
- };
822
- }
831
if (pendingBackgroundWork !== null && contentPresentationKind === "ready") {
832
return {
833
kind: "background",
@@ -843,34 +851,6 @@ function ThreadDetailBody(
851
},
852
};
853
}
846
- if (contentPresentationKind === "ready" && (lifecycleSnoozed || settled || woke)) {
847
- const state = lifecycleSnoozed ? "snoozed" : settled ? "settled" : "woke";
848
- const label =
849
- lifecycleSnoozed && snoozedUntil !== null
850
- ? `Snoozed, wakes in ${snoozeWakeLabel(snoozedUntil, { now: lifecycleNow })}`
851
- : settled
852
- ? "Settled"
853
- : "Woke from snooze";
854
- const actionLabel = lifecycleSnoozed ? "Wake now" : settled ? "Un-settle" : "Dismiss";
855
- return {
856
- kind: "lifecycle",
857
- state,
858
- label,
859
- action: {
860
- label: statusPending
861
- ? lifecycleSnoozed
862
- ? "Waking..."
863
- : settled
864
- ? "Un-settling..."
865
- : "Dismissing..."
866
- : actionLabel,
867
- accessibilityLabel: actionLabel,
868
- disabled: !props.canOperateThread || statusPending,
869
- onPress: () =>
870
- void runStatusAction(lifecycleSnoozed ? "wake" : settled ? "unsettle" : "dismiss"),
871
- },
872
- };
873
- }
854
if (props.selectedThread.goal !== null && contentPresentationKind === "ready") {
855
const goal = presentProviderGoal(props.selectedThread.goal, false);
856
return {
@@ -885,23 +865,12 @@ function ThreadDetailBody(
865
return null;
866
})();
867
const showWorkingControl = floatingStatus !== null;
888
- // A pending message holds the pill's row for its Starting/Working pill. Worktree setup reports
889
- // progress in the feed instead, so holding the row there only leaves a gap that later closes.
890
- const worktreeSetupInFeed =
891
- props.worktreeSetup?.snapshot.phase === "running" ||
892
- (props.creationState?.kind === "preparing" && props.creationState.preparingWorktree);
868
const showFloatingStatus =
869
showWorkingControl ||
870
queuedCount > 0 ||
871
agentsSegment !== null ||
872
devicePreviews.length > 0 ||
898
- browserTabs.tabs.length > 0 ||
899
- props.connectionStateLabel !== "connected" ||
900
- (!worktreeSetupInFeed &&
901
- (props.queuedMessages.length > 0 ||
902
- props.selectedThreadFeed.some(
903
- (entry) => "acknowledged" in entry && entry.acknowledged === true,
904
- )));
873
+ browserTabs.tabs.length > 0;
874
const selectedThreadFeed = props.selectedThreadFeed;
875
// A palette message result opens the thread at that message: earlier
876
// history loads until the message is in the feed, which then scrolls to it.
@@ -1479,6 +1448,7 @@ function ThreadDetailBody(
1448
workspaceRoot={props.threadCwd}
1449
feed={props.selectedThreadFeed}
1450
pendingHandoff={props.pendingHandoff}
1451
+ lifecycleEvent={lifecycleEvent}
1452
worktreeSetup={props.worktreeSetup}
1453
setupWorkingStartedAt={props.setupWorkingStartedAt}
1454
preparingWorktree={
@@ -1606,11 +1576,7 @@ function ThreadDetailBody(
1576
status={floatingStatus}
1577
extensionStatus={
1578
floatingStatus !== null &&
1609
- (floatingStatus.kind === "working" ||
1610
- floatingStatus.kind === "compacting" ||
1611
- floatingStatus.kind === "background" ||
1612
- floatingStatus.kind === "goal" ||
1613
- floatingStatus.kind === "lifecycle")
1579
+ (floatingStatus.kind === "background" || floatingStatus.kind === "goal")
1580
? extensionStatus
1581
: null
1582
}
apps/mobile/src/features/threads/ThreadFeed.tsx
+113
-23
@@ -1,7 +1,10 @@
1
+import { toServerClock } from "@t3tools/client-runtime/clock";
2
+import { formatDuration } from "@t3tools/shared/orchestrationTiming";
3
import { Button } from "../../components/ui/Button";
4
import * as Dialog from "../../components/ui/Dialog";
5
import { useOpenPullRequest } from "../../native/useOpenPullRequest";
6
import { useWorkspaceSettledContentWidth } from "../layout/workspace-content-width";
7
+import { useVisibleSecondClock } from "./use-visible-second-clock";
8
import {
9
ThreadMarkdownVideo,
10
ThreadMediaRetainContext,
@@ -18,7 +21,11 @@ import {
21
enrichedSkillReference,
22
} from "../../lib/enrichedLinkPresentation";
23
import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
21
-import { ThreadContextDivider } from "./thread-context-divider";
24
+import {
25
+ ThreadContextDivider,
26
+ ThreadLifecycleLine,
27
+ type ThreadLifecycleEvent,
28
+} from "./thread-context-divider";
29
import {
30
ThreadHandoffDivider,
31
ThreadHandoffRow,
@@ -243,6 +250,7 @@ import {
250
import {
251
appendGuestPendingMessages,
252
appendPendingThreadMessages,
253
+ createPendingTurnAppender,
254
createThreadFeedGrouping,
255
isCompactionCommandFeedEntry,
256
type GroupedThreadFeedRow,
@@ -354,6 +362,7 @@ export interface ThreadFeedProps {
362
readonly workspaceRoot?: string | null;
363
readonly feed: ReadonlyArray<ThreadFeedEntry>;
364
readonly pendingHandoff?: HandoffEndpoints | null;
365
+ readonly lifecycleEvent?: ThreadLifecycleEvent | null;
366
readonly contentPresentation: ThreadContentPresentation;
367
readonly latestRun: ThreadFeedLatestRun | null;
368
readonly activeWorkStartedAt: string | null;
@@ -1682,9 +1691,35 @@ function ThreadAutomationMessageRow(props: {
1691
1692
/** Leads with why T3 Code compacted, when it did so without being asked. */
1693
function compactionLabel(label: string, title: string | undefined) {
1685
- return title !== undefined && label.startsWith("Context compacted")
1686
- ? title + label.slice("Context compacted".length)
1687
- : label;
1694
+ const text =
1695
+ title !== undefined && label.startsWith("Context compacted")
1696
+ ? title + label.slice("Context compacted".length)
1697
+ : label;
1698
+ // Non-breaking spaces keep "549K → 16.8K tokens" on one line when the label wraps.
1699
+ return text.replace(/ (→|tokens)/g, "\u00A0$1").replace(/→ /g, "→\u00A0");
1700
+}
1701
+
1702
+function RunFoldWorking(props: {
1703
+ environmentId: EnvironmentId;
1704
+ startedAt: string;
1705
+ rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
1706
+}) {
1707
+ const nowMs = toServerClock(props.environmentId, useVisibleSecondClock(true));
1708
+ const seconds = Math.floor((nowMs - Date.parse(props.startedAt)) / 1_000);
1709
+ return (
1710
+ <View
1711
+ className="min-h-11 min-w-0 flex-1 flex-row items-center"
1712
+ style={{ minHeight: Math.max(TURN_FOLD_HEIGHT - 3.5, props.rowSizing.estimatedRowHeight) }}
1713
+ >
1714
+ <Text
1715
+ key={props.rowSizing.textSizeKey}
1716
+ numberOfLines={1}
1717
+ className="shrink font-t3-medium text-sm tabular-nums text-foreground-muted"
1718
+ >
1719
+ Working for {seconds > 0 ? formatDuration(seconds * 1_000) : "0s"}
1720
+ </Text>
1721
+ </View>
1722
+ );
1723
}
1724
1725
function RunFoldButton({
@@ -1785,6 +1820,7 @@ function renderFeedEntry(
1820
| "threadId"
1821
| "workspaceRoot"
1822
> & {
1823
+ readonly pendingFoldMessageId: string | null;
1824
readonly formatMessageTime: (input: string) => string;
1825
readonly copiedRowId: string | null;
1826
readonly expandedWorkRows: Record<string, boolean>;
@@ -1844,18 +1880,47 @@ function renderFeedEntry(
1880
);
1881
}
1882
1883
+ if (entry.type === "pending-fold") {
1884
+ return (
1885
+ <View className="mb-1 flex-row items-center border-b border-border-subtle px-2">
1886
+ <View
1887
+ className="min-h-11 min-w-0 flex-1 flex-row items-center"
1888
+ style={{
1889
+ minHeight: Math.max(TURN_FOLD_HEIGHT - 3.5, props.workRowSizing.estimatedRowHeight),
1890
+ }}
1891
+ >
1892
+ <Text
1893
+ key={props.workRowSizing.textSizeKey}
1894
+ numberOfLines={1}
1895
+ className="shrink font-t3-medium text-sm text-foreground-muted"
1896
+ >
1897
+ Pending
1898
+ </Text>
1899
+ </View>
1900
+ </View>
1901
+ );
1902
+ }
1903
+
1904
if (entry.type === "run-fold") {
1905
return (
1906
<View className="mb-1 flex-row items-center border-b border-border-subtle px-2">
1850
- <RunFoldButton
1851
- key={entry.id}
1852
- entry={entry}
1853
- environmentId={props.environmentId}
1854
- threadId={props.threadId}
1855
- onToggle={props.onToggleTurnFold}
1856
- rowSizing={props.workRowSizing}
1857
- iconColor={iconSubtleColor}
1858
- />
1907
+ {entry.workingSince ? (
1908
+ <RunFoldWorking
1909
+ environmentId={props.environmentId}
1910
+ startedAt={entry.workingSince}
1911
+ rowSizing={props.workRowSizing}
1912
+ />
1913
+ ) : (
1914
+ <RunFoldButton
1915
+ key={entry.id}
1916
+ entry={entry}
1917
+ environmentId={props.environmentId}
1918
+ threadId={props.threadId}
1919
+ onToggle={props.onToggleTurnFold}
1920
+ rowSizing={props.workRowSizing}
1921
+ iconColor={iconSubtleColor}
1922
+ />
1923
+ )}
1924
{entry.checkpointSummary ? (
1925
<TurnDiffStat
1926
checkpoint={entry.checkpointSummary}
@@ -2366,7 +2431,11 @@ function renderFeedEntry(
2431
</Text>
2432
) : null}
2433
<Text className="font-t3-medium text-xs tabular-nums text-foreground-secondary">
2369
- {entry.pendingMessage && !entry.acknowledged ? "Pending" : timestampLabel}
2434
+ {entry.pendingMessage &&
2435
+ !entry.acknowledged &&
2436
+ entry.id !== props.pendingFoldMessageId
2437
+ ? "Pending"
2438
+ : timestampLabel}
2439
</Text>
2440
{props.onEditPendingMessage !== null &&
2441
entry.pendingMessage &&
@@ -3572,10 +3641,16 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3641
if (jumpReady && revealedMessageId !== jumpToMessageId) {
3642
setInteractionState((current) => ({ ...current, revealedMessageId: jumpToMessageId }));
3643
}
3644
+ const [appendPendingTurn] = useState(createPendingTurnAppender);
3645
const presentedFeed = appendGuestPendingMessages(
3576
- useThreadFeedPresentation(props, expandedTurnIds, expandedWorkGroups, revealedMessageId),
3646
+ appendPendingTurn(
3647
+ useThreadFeedPresentation(props, expandedTurnIds, expandedWorkGroups, revealedMessageId),
3648
+ { zen: props.toolCallVisibility === "zen" },
3649
+ ),
3650
guestShare,
3651
);
3652
+ const pendingFoldMessageId =
3653
+ presentedFeed.findLast((entry) => entry.type === "pending-fold")?.messageId ?? null;
3654
const jumpRunId =
3655
jumpReady &&
3656
!presentedFeed.some((entry) => entry.type === "message" && entry.id === jumpToMessageId)
@@ -3834,6 +3909,11 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3909
// corrects each row's height as it mounts — the feed visibly jumps.
3910
const getFixedItemSize = (entry: ThreadFeedRow) => {
3911
if (entry.type === "guest-pending") return undefined;
3912
+ if (entry.type === "pending-fold") {
3913
+ return workRowSizing.fixedRowHeight === undefined
3914
+ ? undefined
3915
+ : resolveThreadFeedFixedItemSize("run-fold");
3916
+ }
3917
if (entry.type === "html-render") {
3918
return htmlRenderRowHeight(htmlRenderFrameHeight(entry.render, contentWidth));
3919
}
@@ -3924,6 +4004,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4004
formatMessageTime,
4005
environmentId: props.environmentId,
4006
dispatchingMessageId: props.dispatchingMessageId,
4007
+ pendingFoldMessageId,
4008
onEditPendingMessage: props.onEditPendingMessage,
4009
onUseArtifactTemplate: props.onUseArtifactTemplate,
4010
threadId: props.threadId,
@@ -4023,6 +4104,8 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4104
viewabilityConfig={THREAD_MEDIA_VIEWABILITY_CONFIG}
4105
keyExtractor={(entry) => entry.id}
4106
getItemType={(entry) => {
4107
+ // Same container as the live fold that replaces it.
4108
+ if (entry.type === "pending-fold") return "run-fold";
4109
if (entry.type !== "message") return entry.type;
4110
if (isCompactionCommandFeedEntry(entry)) return "message:compaction";
4111
if (
@@ -4077,14 +4160,21 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4160
</>
4161
}
4162
ListFooterComponent={
4080
- props.pendingHandoff ? (
4081
- <ThreadHandoffDivider
4082
- environmentId={props.environmentId}
4083
- endpoints={props.pendingHandoff}
4084
- iconColor={iconSubtleColor}
4085
- surfaceColor={screenColor}
4086
- label="Context handoff pending"
4087
- />
4163
+ props.pendingHandoff || props.lifecycleEvent ? (
4164
+ <>
4165
+ {props.pendingHandoff ? (
4166
+ <ThreadHandoffDivider
4167
+ environmentId={props.environmentId}
4168
+ endpoints={props.pendingHandoff}
4169
+ iconColor={iconSubtleColor}
4170
+ surfaceColor={screenColor}
4171
+ label="Context handoff pending"
4172
+ />
4173
+ ) : null}
4174
+ {props.lifecycleEvent ? (
4175
+ <ThreadLifecycleLine event={props.lifecycleEvent} iconColor={iconSubtleColor} />
4176
+ ) : null}
4177
+ </>
4178
) : null
4179
}
4180
contentContainerStyle={{
apps/mobile/src/features/threads/ThreadRouteScreen.tsx
+25
-8
@@ -52,6 +52,7 @@ import { EmptyState } from "../../components/ui/EmptyState";
52
import { LoadingScreen } from "../../components/LoadingScreen";
53
import { scopedThreadKey } from "../../lib/scopedEntities";
54
import { useDelayedStatus } from "../../lib/useDelayedStatus";
55
+import { connectionRetryLabel } from "./floating-working-status";
56
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
57
import { useThreadShell } from "../../state/entities";
58
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
@@ -136,6 +137,8 @@ function firstRouteParam(value: string | string[] | undefined): string | null {
137
return first === undefined || first.trim().length === 0 ? null : first;
138
}
139
140
+const RECONNECT_ERROR_DELAY_MS = 5_000;
141
+
142
// The inspector pane's bar belongs to ThreadInspectorHeader; the fallback must not draw its own.
143
const InspectorHeaderShownContext = createContext(false);
144
@@ -961,18 +964,33 @@ function ThreadRouteContent(
964
detailDeleted: selectedThreadDetailState.status === "deleted",
965
connectionState: routeConnectionState,
966
});
964
- // Shown in the header subtitle so the composer's status slot doesn't jump while history syncs.
965
- const threadSyncLabel = useDelayedStatus(
966
- selectedThread === null ? "" : scopedThreadKey(selectedThread.environmentId, selectedThread.id),
967
- // A thread this client is creating has nothing older to sync.
967
+ const connectionRetrying =
968
+ routeConnectionState === "connecting" || routeConnectionState === "reconnecting";
969
+ // Connection failures survive retries and app suspension.
970
+ const retryConnectionError = useDelayedStatus(
971
+ `${environmentId}:${connectionRetrying && routeConnectionError !== null}`,
972
+ connectionRetrying ? routeConnectionError : null,
973
+ RECONNECT_ERROR_DELAY_MS,
974
+ );
975
+ const connectionStatusLabel = connectionRetryLabel({
976
+ connectionError: retryConnectionError,
977
+ connectionState: routeConnectionState,
978
+ connectionAwaitingApproval: routeEnvironmentRuntime?.connectionAwaitingApproval === true,
979
+ });
980
+ // A thread this client is creating has nothing older to sync.
981
+ const threadSyncLabel =
982
creationState === null
983
? threadSyncStatusLabel(selectedThreadDetailState.status, contentPresentation.kind)
970
- : null,
984
+ : null;
985
+ // Transient states go in the header subtitle so the composer's status slot doesn't jump.
986
+ const threadStatusLabel = useDelayedStatus(
987
+ selectedThread === null ? "" : scopedThreadKey(selectedThread.environmentId, selectedThread.id),
988
+ connectionStatusLabel !== null ? connectionStatusLabel : threadSyncLabel,
989
);
990
const inspectorHeader = props.inspectorPresentation ? (
991
<ThreadInspectorHeader
992
title={selectedThread?.title ?? "Thread"}
975
- subtitle={threadSyncLabel ?? undefined}
993
+ subtitle={threadStatusLabel ?? undefined}
994
{...props.inspectorPresentation}
995
/>
996
) : null;
@@ -1000,7 +1018,7 @@ function ThreadRouteContent(
1018
props.inspectorPresentation ? null : (
1019
<ThreadHeader
1020
title={selectedThread.title}
1003
- subtitle={threadSyncLabel ?? headerSubtitle}
1021
+ subtitle={threadStatusLabel ?? headerSubtitle}
1022
gitControls={threadGitControlProps}
1023
hasThreadCwd={selectedThreadCwd !== null}
1024
inspectorMode={inspectorMode}
@@ -1065,7 +1083,6 @@ function ThreadRouteContent(
1083
activePendingUserInputAnswers={requests.activePendingUserInputAnswers}
1084
respondingUserInputId={requests.respondingUserInputId}
1085
connectionStateLabel={routeConnectionState}
1068
- connectionAwaitingApproval={routeEnvironmentRuntime?.connectionAwaitingApproval === true}
1086
historyControls={historyControls}
1087
activeThreadBusy={composer.activeThreadBusy}
1088
canStopThread={awaitingBootstrapTurn || composer.interruptibleRunId !== null}
apps/mobile/src/features/threads/floating-working-control.tsx
+24
-136
@@ -1,16 +1,7 @@
1
-import { toServerClock } from "@t3tools/client-runtime/clock";
1
import type { SubagentPillSegment } from "@t3tools/client-runtime/state/thread-subagents";
3
-import type { EnvironmentId } from "@t3tools/contracts";
4
-import { formatDuration } from "@t3tools/shared/orchestrationTiming";
2
import { GlassContainer, GlassView } from "expo-glass-effect";
3
import { type ReactNode, useEffect, useRef, useState } from "react";
7
-import {
8
- type LayoutChangeEvent,
9
- Pressable,
10
- Text as SystemText,
11
- useWindowDimensions,
12
- View,
13
-} from "react-native";
4
+import { type LayoutChangeEvent, Pressable, useWindowDimensions, View } from "react-native";
5
import Animated, {
6
Easing,
7
FadeIn,
@@ -33,7 +24,6 @@ import { BrowserPreviewButton } from "../browser/browser-preview-button";
24
import { DevicePreviewButton } from "../devices/device-preview-button";
25
import type { FloatingWorkingStatus } from "./floating-working-status";
26
import { ShimmeringWorkContent } from "./thread-work-log";
36
-import { useVisibleSecondClock } from "./use-visible-second-clock";
27
28
const CONTROL_HEIGHT = 38.5;
29
const CONTROL_GAP = 8;
@@ -92,9 +82,7 @@ export function FloatingWorkingControl(props: {
82
const extensionOnly = props.status?.kind === "extension";
83
const useGlass = NATIVE_LIQUID_GLASS_SUPPORTED && !extensionOnly;
84
const action =
95
- props.status?.kind === "background" ||
96
- props.status?.kind === "lifecycle" ||
97
- props.status?.kind === "stop"
85
+ props.status?.kind === "background" || props.status?.kind === "stop"
86
? props.status.action
87
: null;
88
const [agentsWidth, setAgentsWidth] = useState(0);
@@ -199,8 +187,6 @@ export function FloatingWorkingControl(props: {
187
>
188
<FloatingStatusLabel
189
key={
202
- props.status.kind === "working" ||
203
- props.status.kind === "compacting" ||
190
props.status.kind === "extension"
191
? props.status.kind
192
: `${props.status.kind}:${props.status.label}`
@@ -392,20 +378,6 @@ export function FloatingWorkingControl(props: {
378
);
379
}
380
395
-function CompactingLabel(props: { readonly onLayout: (event: LayoutChangeEvent) => void }) {
396
- return (
397
- <StatusLabelRow accessibilityLabel="Compacting" className="gap-1.5" onLayout={props.onLayout}>
398
- <SymbolView
399
- name="arrow.down.right.and.arrow.up.left"
400
- size={13}
401
- tintColorClassName="accent-foreground"
402
- type="monochrome"
403
- />
404
- <Text className="font-t3-medium text-xs text-foreground">Compacting…</Text>
405
- </StatusLabelRow>
406
- );
407
-}
408
-
381
function FloatingStatusLabel(props: {
382
readonly status: FloatingWorkingStatus;
383
readonly onLayout: (event: LayoutChangeEvent) => void;
@@ -427,9 +399,6 @@ function FloatingStatusLabel(props: {
399
</StatusLabelRow>
400
);
401
}
430
- if (props.status.kind === "compacting") {
431
- return <CompactingLabel key="compacting" onLayout={props.onLayout} />;
432
- }
402
if (props.status.kind === "child-input") {
403
return (
404
<StatusLabelRow
@@ -457,11 +426,7 @@ function FloatingStatusLabel(props: {
426
onLayout={props.onLayout}
427
onPress={props.status.onPress}
428
>
460
- {props.status.tone === "reconnecting" ? (
461
- <AppActivityIndicator size="small" colorClassName="accent-icon-muted" />
462
- ) : (
463
- <View className="h-2 w-2 rounded-full bg-red-500" />
464
- )}
429
+ <View className="h-2 w-2 rounded-full bg-red-500" />
430
<Text
431
className="max-w-[260px] shrink font-t3-medium text-xs text-foreground"
432
numberOfLines={1}
@@ -471,26 +436,6 @@ function FloatingStatusLabel(props: {
436
</StatusLabelRow>
437
);
438
}
474
- if (props.status.kind === "lifecycle") {
475
- return (
476
- <StatusLabelRow
477
- key="lifecycle"
478
- accessibilityLabel={props.status.label}
479
- className="gap-2"
480
- onLayout={props.onLayout}
481
- >
482
- <SymbolView
483
- name={props.status.state === "settled" ? "checkmark.circle" : "clock"}
484
- size={13}
485
- tintColorClassName="accent-foreground"
486
- type="monochrome"
487
- />
488
- <Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
489
- {props.status.label}
490
- </Text>
491
- </StatusLabelRow>
492
- );
493
- }
439
if (props.status.kind === "background") {
440
return (
441
<StatusLabelRow
@@ -557,39 +502,29 @@ function FloatingStatusLabel(props: {
502
</StatusLabelRow>
503
);
504
}
560
- if (props.status.kind === "preparing") {
561
- return (
562
- <StatusLabelRow
563
- key="preparing"
564
- accessibilityLabel={props.status.label}
565
- className="gap-1.5"
566
- onLayout={props.onLayout}
567
- >
568
- <SymbolView
569
- name="arrow.triangle.branch"
570
- size={13}
571
- tintColorClassName="accent-foreground"
572
- type="monochrome"
573
- />
574
- <ShimmeringWorkContent
575
- className="flex-none"
576
- textClassName="font-t3-medium"
577
- compact
578
- icon="arrow.triangle.branch"
579
- iconSubtleColor="transparent"
580
- label={props.status.label}
581
- showIcon={false}
582
- />
583
- </StatusLabelRow>
584
- );
585
- }
505
return (
587
- <WorkingDuration
588
- key="working"
589
- environmentId={props.status.environmentId}
590
- startedAt={props.status.startedAt}
506
+ <StatusLabelRow
507
+ key="preparing"
508
+ accessibilityLabel={props.status.label}
509
+ className="gap-1.5"
510
onLayout={props.onLayout}
592
- />
511
+ >
512
+ <SymbolView
513
+ name="arrow.triangle.branch"
514
+ size={13}
515
+ tintColorClassName="accent-foreground"
516
+ type="monochrome"
517
+ />
518
+ <ShimmeringWorkContent
519
+ className="flex-none"
520
+ textClassName="font-t3-medium"
521
+ compact
522
+ icon="arrow.triangle.branch"
523
+ iconSubtleColor="transparent"
524
+ label={props.status.label}
525
+ showIcon={false}
526
+ />
527
+ </StatusLabelRow>
528
);
529
}
530
@@ -629,53 +564,6 @@ function StatusLabelRow(props: {
564
);
565
}
566
632
-function WorkingDuration(props: {
633
- readonly environmentId: EnvironmentId;
634
- readonly startedAt: string;
635
- readonly onLayout: (event: LayoutChangeEvent) => void;
636
-}) {
637
- return (
638
- <StatusLabelRow onLayout={props.onLayout}>
639
- <WorkingTimer environmentId={props.environmentId} startedAt={props.startedAt} />
640
- </StatusLabelRow>
641
- );
642
-}
643
-
644
-function WorkingTimer(props: {
645
- readonly environmentId: EnvironmentId;
646
- readonly startedAt: string;
647
-}) {
648
- const nowMs = useVisibleSecondClock(true);
649
- return (
650
- <SystemText
651
- className="shrink text-xs text-foreground"
652
- numberOfLines={1}
653
- style={{ fontVariant: ["tabular-nums"], fontWeight: "500" }}
654
- >
655
- Working {formatWorkingDuration(props.startedAt, toServerClock(props.environmentId, nowMs))}
656
- </SystemText>
657
- );
658
-}
659
-
660
-function formatWorkingDuration(startedAt: string, nowMs: number): string {
661
- const startedAtMs = Date.parse(startedAt);
662
- if (!Number.isFinite(startedAtMs) || nowMs <= startedAtMs) {
663
- return "0s";
664
- }
665
-
666
- const totalSeconds = Math.floor((nowMs - startedAtMs) / 1_000);
667
- if (totalSeconds < 60) {
668
- return `${totalSeconds}s`;
669
- }
670
- if (totalSeconds >= 3_600) {
671
- return formatDuration(totalSeconds * 1_000);
672
- }
673
-
674
- const minutes = Math.floor(totalSeconds / 60);
675
- const seconds = String(totalSeconds % 60).padStart(2, "0");
676
- return `${minutes}m ${seconds}s`;
677
-}
678
-
567
function ScrollToEndButton(props: { readonly disabled?: boolean; readonly onPress: () => void }) {
568
return (
569
<ControlPill
apps/mobile/src/features/threads/floating-working-status.ts
+17
-31
@@ -1,5 +1,4 @@
1
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2
-import type { EnvironmentId } from "@t3tools/contracts";
2
3
export interface FloatingStatusAction {
4
readonly label: string;
@@ -9,8 +8,6 @@ export interface FloatingStatusAction {
8
}
9
10
export type FloatingWorkingStatus =
12
- | { readonly kind: "working"; readonly environmentId: EnvironmentId; readonly startedAt: string }
13
- | { readonly kind: "compacting" }
11
| {
12
readonly kind: "child-input";
13
readonly label: string;
@@ -25,12 +22,6 @@ export type FloatingWorkingStatus =
22
readonly onPress: () => void;
23
readonly action: FloatingStatusAction;
24
}
28
- | {
29
- readonly kind: "lifecycle";
30
- readonly state: "snoozed" | "settled" | "woke";
31
- readonly label: string;
32
- readonly action: FloatingStatusAction;
33
- }
25
| {
26
readonly kind: "stop";
27
readonly label: string;
@@ -42,46 +33,39 @@ export type FloatingWorkingStatus =
33
| { readonly kind: "preparing"; readonly label: string }
34
| {
35
readonly kind: "connection";
45
- readonly tone: "reconnecting" | "unavailable";
36
readonly label: string;
37
readonly onPress: () => void;
38
};
39
50
-export function connectionFloatingStatus(input: {
40
+/** A connection still retrying on its own; short enough for the thread header subtitle. */
41
+export function connectionRetryLabel(input: {
42
readonly connectionError: string | null;
43
readonly connectionState: EnvironmentConnectionPhase;
44
readonly connectionAwaitingApproval?: boolean;
45
+}): string | null {
46
+ if (input.connectionState === "reconnecting" && input.connectionAwaitingApproval) {
47
+ return "Awaiting device approval";
48
+ }
49
+ if (input.connectionState !== "connecting" && input.connectionState !== "reconnecting") {
50
+ return null;
51
+ }
52
+ return input.connectionError === null ? "Reconnecting…" : "Retrying connection…";
53
+}
54
+
55
+export function connectionFloatingStatus(input: {
56
+ readonly connectionError: string | null;
57
+ readonly connectionState: EnvironmentConnectionPhase;
58
readonly environmentLabel: string | null;
59
readonly onReconnect: () => void;
60
}): FloatingWorkingStatus | null {
61
const environmentLabel = input.environmentLabel ?? "Environment";
62
const unavailable = (label: string): FloatingWorkingStatus => ({
63
kind: "connection",
60
- tone: "unavailable",
64
label,
65
onPress: input.onReconnect,
66
});
67
65
- if (input.connectionState === "reconnecting" && input.connectionAwaitingApproval) {
66
- return {
67
- kind: "connection",
68
- tone: "reconnecting",
69
- label: `Waiting for ${environmentLabel} to approve this device`,
70
- onPress: input.onReconnect,
71
- };
72
- }
68
switch (input.connectionState) {
74
- case "connecting":
75
- case "reconnecting":
76
- return {
77
- kind: "connection",
78
- tone: "reconnecting",
79
- label:
80
- input.connectionError === null
81
- ? `Reconnecting to ${environmentLabel}...`
82
- : `Failed to connect. Retrying ${environmentLabel}...`,
83
- onPress: input.onReconnect,
84
- };
69
case "offline":
70
return unavailable("You are offline");
71
case "unsupported":
@@ -94,6 +78,8 @@ export function connectionFloatingStatus(input: {
78
);
79
case "available":
80
return unavailable(`${environmentLabel} is not connected`);
81
+ case "connecting":
82
+ case "reconnecting":
83
case "connected":
84
return null;
85
}
apps/mobile/src/features/threads/pending-thread-feed.test.ts
+27
@@ -11,6 +11,7 @@ import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
11
import {
12
appendAcceptedThreadMessages,
13
appendPendingThreadMessages,
14
+ createPendingTurnAppender,
15
createThreadFeedGrouping,
16
isCompactionCommandFeedEntry,
17
selectPendingAcknowledgedMessages,
@@ -229,4 +230,30 @@ describe("pending timeline messages", () => {
230
"waiting",
231
]);
232
});
233
+
234
+ it("holds the run's rows after a sent message until the run shows", () => {
235
+ const appendTurn = createPendingTurnAppender();
236
+ const sent = appendPendingThreadMessages([], [], [pending("sent")]);
237
+ const held = appendTurn(sent, { zen: false });
238
+ expect(held.map((entry) => [entry.id, "label" in entry ? entry.label : null])).toEqual([
239
+ ["sent", null],
240
+ ["pending-fold:sent", null],
241
+ ["live-activity-row", "Sending…"],
242
+ ]);
243
+ expect(appendTurn(sent, { zen: false })[1]).toBe(held[1]);
244
+ const delivered = sent.map((entry) => ({ ...entry, acknowledged: true }));
245
+ expect(appendTurn(delivered, { zen: true }).map((entry) => entry.id)).toEqual([
246
+ "sent",
247
+ "live-activity-row",
248
+ ]);
249
+ // A working run already shows its own rows.
250
+ const thinking = {
251
+ type: "thinking",
252
+ runId: null,
253
+ id: "thinking",
254
+ createdAt: "2026-09-06T11:00:00.000Z",
255
+ } as const;
256
+ const working = appendPendingThreadMessages([thinking], [], [pending("queued")]);
257
+ expect(appendTurn(working, { zen: false })).toBe(working);
258
+ });
259
});
apps/mobile/src/features/threads/pending-thread-feed.ts
+64
-3
@@ -3,7 +3,7 @@ import {
3
type ThreadGuestMessage,
4
type ThreadGuestShare,
5
} from "@t3tools/contracts";
6
-import type { ThreadFeedEntry } from "../../lib/threadActivity";
6
+import { LIVE_ACTIVITY_ROW_ID, type ThreadFeedEntry } from "../../lib/threadActivity";
7
import { scopedThreadKey } from "../../lib/scopedEntities";
8
import { threadHasCaughtUpTo } from "@t3tools/client-runtime/state/threads";
9
import { resolveUserMessageGrouping } from "@t3tools/client-runtime/user-message";
@@ -51,8 +51,19 @@ export function selectPendingAcknowledgedMessages(
51
);
52
}
53
54
+/**
55
+ * Holds the turn's fold slot while a sent message waits for its run, so the live "Working for"
56
+ * row replaces it in place instead of being inserted.
57
+ */
58
+export interface PendingFoldFeedEntry {
59
+ readonly type: "pending-fold";
60
+ readonly id: string;
61
+ readonly createdAt: string;
62
+ readonly messageId: string;
63
+}
64
+
65
/** A row of the thread feed's list. */
55
-export type ThreadFeedRow = PendingThreadFeedEntry | GuestPendingFeedEntry;
66
+export type ThreadFeedRow = PendingThreadFeedEntry | GuestPendingFeedEntry | PendingFoldFeedEntry;
67
68
export type GroupedThreadFeedRow = ThreadFeedRow & {
69
readonly userMessageGrouping: ReturnType<typeof resolveUserMessageGrouping>;
@@ -100,7 +111,7 @@ export function createThreadFeedGrouping() {
111
112
/** Waiting guest messages go after the transcript, oldest first. */
113
export function appendGuestPendingMessages(
103
- presentedFeed: ReadonlyArray<PendingThreadFeedEntry>,
114
+ presentedFeed: ReadonlyArray<PendingThreadFeedEntry | PendingFoldFeedEntry>,
115
share: ThreadGuestShare | null,
116
): ReadonlyArray<ThreadFeedRow> {
117
const pending = share?.messages.filter((message) => message.status === "pending") ?? [];
@@ -175,6 +186,56 @@ export function appendAcceptedThreadMessages(
186
);
187
}
188
189
+/**
190
+ * Ends the feed with the rows a starting run will fill, while its last row is a sent message no
191
+ * run has picked up: the fold slot and the live activity row, under the activity row's own key.
192
+ * The run's rows then replace them in place instead of being inserted.
193
+ */
194
+export function createPendingTurnAppender() {
195
+ let fold: PendingFoldFeedEntry | null = null;
196
+ let activity: Extract<ThreadFeedEntry, { readonly type: "thinking" }> | null = null;
197
+ return (
198
+ feed: ReadonlyArray<PendingThreadFeedEntry>,
199
+ options: { readonly zen: boolean },
200
+ ): ReadonlyArray<PendingThreadFeedEntry | PendingFoldFeedEntry> => {
201
+ const last = feed.at(-1);
202
+ if (
203
+ last?.type !== "message" ||
204
+ last.message.role !== "user" ||
205
+ last.pendingMessage === undefined ||
206
+ last.pendingMessage.creation !== undefined ||
207
+ isCompactionCommandMessage(last.message) ||
208
+ feed.some(
209
+ (entry) =>
210
+ (entry.type === "run-fold" && entry.workingSince !== undefined) ||
211
+ entry.type === "thinking",
212
+ )
213
+ ) {
214
+ return feed;
215
+ }
216
+ const label = last.acknowledged ? "Starting…" : "Sending…";
217
+ if (activity?.createdAt !== last.createdAt || activity.label !== label) {
218
+ activity = {
219
+ type: "thinking",
220
+ id: LIVE_ACTIVITY_ROW_ID,
221
+ createdAt: last.createdAt,
222
+ runId: null,
223
+ label,
224
+ };
225
+ }
226
+ if (options.zen) return [...feed, activity];
227
+ if (fold?.messageId !== last.id) {
228
+ fold = {
229
+ type: "pending-fold",
230
+ id: `pending-fold:${last.id}`,
231
+ createdAt: last.createdAt,
232
+ messageId: last.id,
233
+ };
234
+ }
235
+ return [...feed, fold, activity];
236
+ };
237
+}
238
+
239
export function isCompactionCommandFeedEntry(entry: PendingThreadFeedEntry): boolean {
240
return (
241
entry.type === "message" &&
apps/mobile/src/features/threads/thread-context-divider.tsx
+74
-27
@@ -1,5 +1,5 @@
1
import type { ReactNode } from "react";
2
-import { View, type ColorValue } from "react-native";
2
+import { Pressable, View, type ColorValue } from "react-native";
3
import { AppText as Text } from "../../components/ui/AppText";
4
import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
5
import { ShimmeringWorkContent } from "./thread-work-log";
@@ -14,35 +14,82 @@ export function ThreadContextDivider(props: {
14
}) {
15
return (
16
<View className="mb-3 flex-row items-center gap-3 px-1 py-1">
17
- <View className="h-px min-w-2 flex-1 bg-separator" />
17
+ <View className="h-px min-w-4 flex-1 bg-separator" />
18
<View className="shrink flex-row flex-wrap items-center justify-center gap-1.5">
19
- {props.icon ? (
20
- <SymbolView name={props.icon} size={12} tintColor={props.iconColor} type="monochrome" />
21
- ) : null}
22
- {props.active ? (
23
- <ShimmeringWorkContent
24
- className="flex-none"
25
- textClassName="font-t3-medium"
26
- compact
27
- icon="brain"
28
- iconSubtleColor={props.iconColor}
29
- label={props.label}
30
- showIcon={false}
31
- />
32
- ) : (
33
- <Text
34
- className={
35
- props.failed
36
- ? "font-t3-medium text-xs text-danger-foreground"
37
- : "font-t3-medium text-xs text-foreground-muted"
38
- }
39
- >
40
- {props.label}
41
- </Text>
42
- )}
19
+ {/* One row, so a long label wraps beside its icon instead of under it. */}
20
+ <View className="shrink flex-row items-center gap-1.5">
21
+ {props.icon ? (
22
+ <SymbolView name={props.icon} size={12} tintColor={props.iconColor} type="monochrome" />
23
+ ) : null}
24
+ {props.active ? (
25
+ <ShimmeringWorkContent
26
+ className="flex-none"
27
+ textClassName="font-t3-medium"
28
+ compact
29
+ icon="brain"
30
+ iconSubtleColor={props.iconColor}
31
+ label={props.label}
32
+ showIcon={false}
33
+ />
34
+ ) : (
35
+ <Text
36
+ className={
37
+ props.failed
38
+ ? "shrink font-t3-medium text-xs text-danger-foreground"
39
+ : "shrink font-t3-medium text-xs text-foreground-muted"
40
+ }
41
+ >
42
+ {props.label}
43
+ </Text>
44
+ )}
45
+ </View>
46
{props.children}
47
</View>
45
- <View className="h-px min-w-2 flex-1 bg-separator" />
48
+ <View className="h-px min-w-4 flex-1 bg-separator" />
49
+ </View>
50
+ );
51
+}
52
+
53
+export interface ThreadLifecycleEvent {
54
+ readonly state: "snoozed" | "settled" | "woke";
55
+ readonly label: string;
56
+ readonly action: {
57
+ readonly label: string;
58
+ readonly accessibilityLabel: string;
59
+ readonly disabled: boolean;
60
+ readonly onPress: () => void;
61
+ };
62
+}
63
+
64
+/** Closes the feed while the thread is snoozed, settled, or just woke. Left-aligned, as on web. */
65
+export function ThreadLifecycleLine(props: {
66
+ readonly event: ThreadLifecycleEvent;
67
+ readonly iconColor: ColorValue;
68
+}) {
69
+ const { action } = props.event;
70
+ return (
71
+ <View className="mb-3 flex-row items-center gap-1.5 px-1 py-1">
72
+ <SymbolView
73
+ name={props.event.state === "settled" ? "checkmark.circle" : "alarm"}
74
+ size={13}
75
+ tintColor={props.iconColor}
76
+ type="monochrome"
77
+ />
78
+ <Text className="shrink font-t3-medium text-xs text-foreground-muted" numberOfLines={1}>
79
+ {props.event.label}
80
+ </Text>
81
+ <Text className="text-xs text-foreground-muted">·</Text>
82
+ <Pressable
83
+ accessibilityRole="button"
84
+ accessibilityLabel={action.accessibilityLabel}
85
+ accessibilityState={{ disabled: action.disabled }}
86
+ disabled={action.disabled}
87
+ onPress={action.onPress}
88
+ hitSlop={8}
89
+ className={`active:opacity-70 ${action.disabled ? "opacity-50" : ""}`}
90
+ >
91
+ <Text className="font-t3-medium text-xs text-foreground">{action.label}</Text>
92
+ </Pressable>
93
</View>
94
);
95
}
apps/mobile/src/lib/threadActivity.test.ts
+63
-15
@@ -1328,24 +1328,24 @@ describe("buildThreadFeed", () => {
1328
"assistant:resume-answer",
1329
]);
1330
1331
- expect(
1332
- shape(
1333
- deriveThreadFeedPresentation(
1334
- feed(true),
1335
- null,
1336
- new Set(),
1337
- new Set(),
1338
- "2026-06-20T00:01:12.000Z",
1339
- true,
1340
- ),
1341
- ),
1342
- ).toEqual([
1331
+ const working = deriveThreadFeedPresentation(
1332
+ feed(true),
1333
+ null,
1334
+ new Set(),
1335
+ new Set(),
1336
+ "2026-06-20T00:01:12.000Z",
1337
+ true,
1338
+ );
1339
+ expect(shape(working)).toEqual([
1340
"user:launch",
1341
"fold:Worked for 8s",
1342
"assistant:launch-answer",
1343
"user:resume",
1344
+ "fold:Working",
1345
"activity-group",
1346
]);
1347
+ // The live timer row becomes the settled fold in place.
1348
+ expect(working[4]?.id).toBe(settled[4]?.id);
1349
});
1350
1351
it("keeps imported V1 turns folded once the thread's first V2 run starts", () => {
@@ -1443,8 +1443,8 @@ describe("buildThreadFeed", () => {
1443
new Set(),
1444
new Set(),
1445
startedAt,
1446
- ),
1447
- ).toEqual([]);
1446
+ ).map((row) => row.type),
1447
+ ).toEqual(["run-fold"]);
1448
});
1449
it("hides tool calls or everything but the final answer", () => {
1450
const at = (second: number) => `2026-06-20T00:00:${String(second).padStart(2, "0")}.000Z`;
@@ -1794,8 +1794,9 @@ describe("subagent continued by a later turn", () => {
1794
];
1795
1796
it("keeps each turn's fold between its own prompt and answer", () => {
1797
+ const feed = buildThreadFeed(items.map((entry, index) => projected(entry, index)));
1798
const presented = deriveThreadFeedPresentation(
1798
- buildThreadFeed(items.map((entry, index) => projected(entry, index))),
1799
+ feed,
1800
{ runId: run2, status: "completed", startedAt: at(30), completedAt: at(41) },
1801
new Set(),
1802
);
@@ -1807,6 +1808,53 @@ describe("subagent continued by a later turn", () => {
1808
`run-fold:${run2}`,
1809
"closing-2",
1810
]);
1811
+
1812
+ // While the run works, its fold row already holds that slot with a live timer.
1813
+ const live = deriveThreadFeedPresentation(
1814
+ feed,
1815
+ { runId: run2, status: "running", startedAt: at(30), completedAt: null },
1816
+ new Set(),
1817
+ new Set(),
1818
+ at(30),
1819
+ );
1820
+ expect(live.slice(3, 6).map((entry) => entry.id)).toEqual([
1821
+ "prompt-2",
1822
+ `run-fold:${run2}`,
1823
+ expect.not.stringMatching(/^run-fold:/),
1824
+ ]);
1825
+ expect(live[4]).toMatchObject({ workingSince: at(30) });
1826
+ expect(live.filter((entry) => entry.type === "run-fold")).toHaveLength(2);
1827
+ });
1828
+
1829
+ it("puts the live fold after a plan the settled fold leaves in view", () => {
1830
+ const planned = buildThreadFeed(
1831
+ [
1832
+ user("prompt", run2, 1, 0),
1833
+ {
1834
+ ...item("plan", run2, 2, 1),
1835
+ type: "proposed_plan",
1836
+ planId: "plan",
1837
+ markdown: "The plan",
1838
+ streaming: false,
1839
+ } as OrchestrationV2TurnItem,
1840
+ reasoning("reasoning", run2, 3, 2),
1841
+ assistant("closing", run2, 4, 9),
1842
+ ].map((entry, index) => projected(entry, index)),
1843
+ );
1844
+ const ids = (running: boolean) =>
1845
+ deriveThreadFeedPresentation(
1846
+ planned,
1847
+ running
1848
+ ? { runId: run2, status: "running", startedAt: at(0), completedAt: null }
1849
+ : { runId: run2, status: "completed", startedAt: at(0), completedAt: at(9) },
1850
+ new Set(),
1851
+ new Set(),
1852
+ running ? at(0) : null,
1853
+ ).map((entry) => entry.id);
1854
+ const settledIds = ids(false);
1855
+ const foldIndex = settledIds.indexOf(`run-fold:${run2}`);
1856
+ expect(foldIndex).toBeGreaterThan(1);
1857
+ expect(ids(true).indexOf(`run-fold:${run2}`)).toBe(foldIndex);
1858
});
1859
});
1860
apps/mobile/src/lib/threadActivity.ts
+77
-17
@@ -248,6 +248,8 @@ type ThreadFeedEntryContent =
248
| {
249
readonly type: "run-fold";
250
readonly deferredWorkItemIds?: ReadonlyArray<string>;
251
+ /** Set while the run works: the row shows a live timer and does not toggle. */
252
+ readonly workingSince?: string;
253
readonly id: string;
254
readonly createdAt: string;
255
readonly runId: RunId;
@@ -1242,23 +1244,8 @@ function deriveThreadFeedRunFolds(
1244
(entry) =>
1245
entry.id !== terminalAssistantId &&
1246
!(entry.type === "message" && retainedAnswerIds.has(entry.message.id)) &&
1245
- entry.type !== "html-render" &&
1246
- entry.type !== "sent-message" &&
1247
- entry.type !== "mcp-app" &&
1247
entry.id !== visibleCompactionId &&
1249
- !(
1250
- entry.type === "activity-group" &&
1251
- entry.activities.some(
1252
- (activity) =>
1253
- activity.prominent ||
1254
- activity.workEntry.questionAnswer !== undefined ||
1255
- activity.projectedItem.item.type === "notification" ||
1256
- activity.projectedItem.item.type === "handoff" ||
1257
- // A child still working outlives its settled launching run;
1258
- // its group stays visible while any member is live.
1259
- isLiveSubagentTurnItem(activity.projectedItem.item),
1260
- )
1261
- ),
1248
+ !staysOutOfFold(entry),
1249
)
1250
.map((entry) => entry.id),
1251
);
@@ -1426,6 +1413,26 @@ function latestRunsEqual(left: ThreadFeedLatestRun | null, right: ThreadFeedLate
1413
);
1414
}
1415
1416
+/** Rows a fold leaves in view; the live fold skips them too, so settling keeps its place. */
1417
+function staysOutOfFold(entry: ThreadFeedEntry): boolean {
1418
+ return (
1419
+ entry.type === "html-render" ||
1420
+ entry.type === "sent-message" ||
1421
+ entry.type === "mcp-app" ||
1422
+ (entry.type === "activity-group" &&
1423
+ entry.activities.some(
1424
+ (activity) =>
1425
+ activity.prominent ||
1426
+ activity.workEntry.questionAnswer !== undefined ||
1427
+ activity.projectedItem.item.type === "notification" ||
1428
+ activity.projectedItem.item.type === "handoff" ||
1429
+ // A child still working outlives its settled launching run;
1430
+ // its group stays visible while any member is live.
1431
+ isLiveSubagentTurnItem(activity.projectedItem.item),
1432
+ ))
1433
+ );
1434
+}
1435
+
1436
function feedEntryRunId(entry: ThreadFeedEntry): RunId | null {
1437
return entry.type === "message" ? (entry.message.runId ?? null) : entry.runId;
1438
}
@@ -1725,9 +1732,44 @@ export function deriveThreadFeedPresentation(
1732
for (const entryId of fold.hiddenEntryIds) collapsedEntryIds.add(entryId);
1733
}
1734
}
1735
+ // The working run's fold row shows its live timer where "Worked for" lands once it settles.
1736
+ // Zen never folds, so it keeps only the Thinking row.
1737
+ // Runless work folds under its prompt's key once it settles, so the live row takes that key.
1738
+ const runlessPrompt =
1739
+ activeRunId === null && runlessWorkActive
1740
+ ? sourceFeed.findLast((entry) => isUserMessageEntry(entry) && feedEntryRunId(entry) === null)
1741
+ : undefined;
1742
+ const liveRunId =
1743
+ activeRunId ?? (runlessPrompt ? RunId.make(`runless:${runlessPrompt.id}`) : null);
1744
+ const liveFold =
1745
+ !zen &&
1746
+ isWorking &&
1747
+ activeWorkStartedAt !== null &&
1748
+ liveRunId !== null &&
1749
+ !compactionCommandRunIds.has(liveRunId)
1750
+ ? liveRunFoldRow(liveRunId, activeWorkStartedAt)
1751
+ : null;
1752
+ let liveFoldPlaced = false;
1753
+ // Earlier turns can hold the run's own items (a subagent it continued), so wait for its prompt.
1754
+ let liveFoldReady =
1755
+ liveFold !== null &&
1756
+ activeRunId !== null &&
1757
+ !sourceFeed.some((entry) => isUserMessageEntry(entry) && feedEntryRunId(entry) === activeRunId);
1758
for (let sourceIndex = 0; sourceIndex < sourceFeed.length; sourceIndex += 1) {
1759
const entry = sourceFeed[sourceIndex]!;
1760
const feedIndex = retainedFeedIndices[sourceIndex]!;
1761
+ if (liveFold !== null && !liveFoldPlaced && feedEntryRunId(entry) === activeRunId) {
1762
+ if (isUserMessageEntry(entry)) {
1763
+ liveFoldReady = activeRunId !== null || entry === runlessPrompt;
1764
+ } else if (
1765
+ liveFoldReady &&
1766
+ !staysOutOfFold(entry) &&
1767
+ !(entry.type === "activity-group" && isContextCompactionActivityGroup(entry))
1768
+ ) {
1769
+ result.push(liveFold);
1770
+ liveFoldPlaced = true;
1771
+ }
1772
+ }
1773
if (isUserMessageEntry(entry)) {
1774
restarts.push({ entry: feedIndex, rowsLength: result.length });
1775
}
@@ -1808,6 +1850,7 @@ export function deriveThreadFeedPresentation(
1850
);
1851
}
1852
}
1853
+ if (liveFold !== null && !liveFoldPlaced) result.push(liveFold);
1854
if (
1855
isWorking &&
1856
activeWorkStartedAt !== null &&
@@ -1932,7 +1975,7 @@ function isWorkLogFeedRow(row: ThreadFeedEntry | undefined): boolean {
1975
);
1976
}
1977
1935
-const LIVE_ACTIVITY_ROW_ID = "live-activity-row";
1978
+export const LIVE_ACTIVITY_ROW_ID = "live-activity-row";
1979
1980
/** Reads the feed before tool visibility filters it, so hidden newer parent work still counts. */
1981
function runningSubagentsAtRunTail(feed: ReadonlyArray<ThreadFeedEntry>, runId: RunId): number {
@@ -1947,6 +1990,23 @@ function runningSubagentsAtRunTail(feed: ReadonlyArray<ThreadFeedEntry>, runId:
1990
return running;
1991
}
1992
1993
+let cachedLiveRunFoldRow: Extract<ThreadFeedEntry, { readonly type: "run-fold" }> | null = null;
1994
+
1995
+function liveRunFoldRow(runId: RunId, startedAt: string) {
1996
+ if (cachedLiveRunFoldRow?.runId !== runId || cachedLiveRunFoldRow.workingSince !== startedAt) {
1997
+ cachedLiveRunFoldRow = {
1998
+ type: "run-fold",
1999
+ id: `run-fold:${runId}`,
2000
+ createdAt: startedAt,
2001
+ runId,
2002
+ label: "Working",
2003
+ expanded: false,
2004
+ workingSince: startedAt,
2005
+ };
2006
+ }
2007
+ return cachedLiveRunFoldRow;
2008
+}
2009
+
2010
function thinkingRow(
2011
createdAt: string,
2012
runId: RunId | null,
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+1
-1
@@ -2083,7 +2083,7 @@ it("renders automatic compaction as one live divider that finishes with its reas
2083
await expect
2084
.element(
2085
screen.getByRole("separator", {
2086
- name: "Context automatically compacted before cache expiry 899K → 19K tokens",
2086
+ name: "Auto-compacted before cache expiry 899K → 19K tokens",
2087
}),
2088
)
2089
.toBeVisible();
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+1
-1
@@ -686,7 +686,7 @@ describe("deriveMessagesTimelineRows", () => {
686
active: true,
687
label: "Compacting before the cache expires…",
688
},
689
- "Context automatically compacted before cache expiry",
689
+ "Auto-compacted before cache expiry",
690
],
691
["onReturn", { kind: "working", compacting: true }, "Context compacted before sending"],
692
[undefined, { kind: "context-compaction", active: true }, undefined],
packages/client-runtime/src/userMessage.ts
+1
-1
@@ -25,7 +25,7 @@ export const IDLE_COMPACTING_LABELS = {
25
26
/** Leads the finished compaction's token counts, in place of "Context compacted". */
27
export const IDLE_COMPACTION_TITLES = {
28
- beforeCacheExpires: "Context automatically compacted before cache expiry",
28
+ beforeCacheExpires: "Auto-compacted before cache expiry",
29
onReturn: "Context compacted before sending",
30
} satisfies Record<OrchestrationV2IdleCompaction, string>;
31