Skip to content

Commit f899061

Browse files
feat: a running turn with no agent activity for 10 minutes is flagged
A frozen agent looks exactly like a busy one: the thread says Working for hours while nothing arrives from the provider. The session manager now records when each running turn last heard from its provider (one in-memory timestamp per event). While a client listens, it checks every 30 s and pushes the threads quiet for 10 minutes or more on the config stream. The thread shows "No activity for N" with Stop and Force stop, and the web sidebar and mobile thread list mark the row. The wording stays neutral: tools can legitimately run that long. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c2ee4be commit f899061

29 files changed

Lines changed: 1040 additions & 207 deletions

‎apps/mobile/src/connection/runtime.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const layerProvidedClientConnection = layerSnapshotLoader.pipe(
3939
Connection.layerWithOptions({
4040
usageLimitSources: true,
4141
memoryPressure: true,
42+
quietRuns: true,
4243
usageLimitsCommand: true,
4344
}),
4445
),

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ import { useAtomCommand } from "../../state/use-atom-command";
160160
import { orchestrationEnvironment } from "../../state/orchestration";
161161
import { useDelayedStatus } from "../../lib/useDelayedStatus";
162162
import type { PendingUserInputDraftAnswer } from "@t3tools/client-runtime/state/pending-user-input";
163-
import type { RunStopPresentation } from "@t3tools/client-runtime/state/thread-execution";
163+
import {
164+
quietRunId,
165+
quietRunSince,
166+
type RunStopPresentation,
167+
} from "@t3tools/client-runtime/state/thread-execution";
164168
import type {
165169
PendingApproval,
166170
PendingUserInput,
@@ -550,6 +554,12 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
550554
const canForceStop =
551555
useAtomValue(orchestrationEnvironment.forceStopThread.permissionAtom(props.environmentId)) &&
552556
props.serverConfig?.environment.capabilities.threadForceStop === true;
557+
// The run the server saw go quiet, not the latest one: a queued follow-up can be newer.
558+
const quietRunTarget = quietRunId(props.serverConfig, props.selectedThread) ?? undefined;
559+
const quietSince =
560+
props.activeWorkStartedAt === null
561+
? null
562+
: quietRunSince(props.serverConfig, props.selectedThread);
553563
const [forceStoppingKey, setForceStoppingKey] = useState<string | null>(null);
554564
// The run that ignored Stop, so a confirmation left open cannot hit a newer run.
555565
const forceStop = async (runId: RunId | undefined) => {
@@ -580,6 +590,26 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
580590
};
581591
const [statusRequest, setStatusRequest] = useState<{ threadKey: string } | null>(null);
582592
const statusPending = statusRequest?.threadKey === selectedThreadKey;
593+
const stopQuietRun = async () => {
594+
if (statusPending || !props.canOperateThread) return;
595+
const request = { threadKey: selectedThreadKey };
596+
setStatusRequest(request);
597+
const result = await interruptThreadTurn({
598+
environmentId: props.environmentId,
599+
input:
600+
quietRunTarget === undefined
601+
? { threadId: props.selectedThread.id }
602+
: { threadId: props.selectedThread.id, runId: quietRunTarget },
603+
});
604+
setStatusRequest((current) => (current === request ? null : current));
605+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
606+
const error = squashAtomCommandFailure(result);
607+
Dialog.alert(
608+
"Could not stop the turn",
609+
error instanceof Error ? error.message : "Try again.",
610+
);
611+
}
612+
};
583613
const [lifecycleNow, setLifecycleNow] = useState(() => new Date().toISOString());
584614
useFocusEffect(
585615
useCallback(() => {
@@ -723,6 +753,46 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
723753
},
724754
};
725755
}
756+
if (quietSince !== null && contentPresentationKind === "ready") {
757+
return {
758+
kind: "quiet",
759+
quietSince,
760+
action: {
761+
label:
762+
forceStoppingKey === selectedThreadKey
763+
? "Force stopping..."
764+
: statusPending
765+
? "Stopping..."
766+
: "Stop",
767+
accessibilityLabel: "Stop the quiet turn",
768+
disabled:
769+
!props.canOperateThread || statusPending || forceStoppingKey === selectedThreadKey,
770+
onPress: () =>
771+
Dialog.alert(
772+
"Stop this turn?",
773+
canForceStop
774+
? "The agent has sent nothing for a while. A long tool may still be running. Force stop ends the turn and kills the agent's processes, unless other working threads share them."
775+
: "The agent has sent nothing for a while. A long tool may still be running.",
776+
[
777+
{ text: "Cancel", style: "cancel" },
778+
{
779+
text: "Stop",
780+
onPress: () => void stopQuietRun(),
781+
},
782+
...(canForceStop
783+
? [
784+
{
785+
text: "Force stop",
786+
style: "destructive" as const,
787+
onPress: () => void forceStop(quietRunTarget),
788+
},
789+
]
790+
: []),
791+
],
792+
),
793+
},
794+
};
795+
}
726796
if (props.isCompacting && contentPresentationKind === "ready") {
727797
return { kind: "compacting" };
728798
}

‎apps/mobile/src/features/threads/floating-working-control.tsx‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ export function FloatingWorkingControl(props: {
8585
const action =
8686
props.status?.kind === "background" ||
8787
props.status?.kind === "lifecycle" ||
88-
props.status?.kind === "stop"
88+
props.status?.kind === "stop" ||
89+
props.status?.kind === "quiet"
8990
? props.status.action
9091
: null;
9192
const [agentsWidth, setAgentsWidth] = useState(0);
@@ -179,7 +180,9 @@ export function FloatingWorkingControl(props: {
179180
>
180181
<FloatingStatusLabel
181182
key={
182-
props.status.kind === "working" || props.status.kind === "compacting"
183+
props.status.kind === "working" ||
184+
props.status.kind === "compacting" ||
185+
props.status.kind === "quiet"
183186
? props.status.kind
184187
: `${props.status.kind}:${props.status.label}`
185188
}
@@ -473,6 +476,24 @@ function FloatingStatusLabel(props: {
473476
</StatusLabelRow>
474477
);
475478
}
479+
if (props.status.kind === "quiet") {
480+
return (
481+
<StatusLabelRow
482+
key="quiet"
483+
accessibilityLabel="No activity from the agent"
484+
className="gap-2"
485+
onLayout={props.onLayout}
486+
>
487+
<SymbolView
488+
name="timer"
489+
size={13}
490+
tintColorClassName="accent-warning-foreground"
491+
type="monochrome"
492+
/>
493+
<WorkingTimer startedAt={props.status.quietSince} prefix="No activity for" />
494+
</StatusLabelRow>
495+
);
496+
}
476497
if (props.status.kind === "stop") {
477498
return (
478499
<StatusLabelRow
@@ -588,15 +609,15 @@ function WorkingDuration(props: {
588609
);
589610
}
590611

591-
function WorkingTimer(props: { readonly startedAt: string }) {
612+
function WorkingTimer(props: { readonly startedAt: string; readonly prefix?: string }) {
592613
const nowMs = useVisibleSecondClock(true);
593614
return (
594615
<SystemText
595616
className="shrink text-xs text-foreground"
596617
numberOfLines={1}
597618
style={{ fontVariant: ["tabular-nums"], fontWeight: "500" }}
598619
>
599-
Working {formatWorkingDuration(props.startedAt, nowMs)}
620+
{props.prefix ?? "Working"} {formatWorkingDuration(props.startedAt, nowMs)}
600621
</SystemText>
601622
);
602623
}

‎apps/mobile/src/features/threads/floating-working-status.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export type FloatingWorkingStatus =
3131
readonly label: string;
3232
readonly action: FloatingStatusAction;
3333
}
34+
| {
35+
readonly kind: "quiet";
36+
/** When the provider last sent anything for the running turn. */
37+
readonly quietSince: string;
38+
readonly action: FloatingStatusAction;
39+
}
3440
| {
3541
readonly kind: "stop";
3642
readonly label: string;

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { CustomSnoozeSheet } from "./CustomSnoozeSheet";
1313
import { appAtomRegistry } from "../../state/atom-registry";
1414
import { threadArrangementOpenAtom } from "../../state/thread-order";
1515
import { threadEnvironment } from "../../state/threads";
16+
import { serverEnvironment } from "../../state/server";
17+
import { useAtomValue } from "@effect/atom-react";
18+
import { quietRunSince } from "@t3tools/client-runtime/state/thread-execution";
1619
import { useAtomCommand } from "../../state/use-atom-command";
1720
import { useVisibleSecondClock } from "./use-visible-second-clock";
1821
import type { ThreadMoveDestination } from "./threadOrder";
@@ -132,6 +135,12 @@ const STATUS_LABEL_BY_STATUS: Partial<Record<ThreadListV2Status, StatusLabel>> =
132135
iconTintClassName: "accent-warning-foreground",
133136
},
134137
};
138+
const QUIET_STATUS_LABEL: StatusLabel = {
139+
label: "No activity",
140+
icon: "timer",
141+
className: "text-warning-foreground",
142+
iconTintClassName: "accent-warning-foreground",
143+
};
135144
const DONE_STATUS_LABEL: StatusLabel = {
136145
label: "Done",
137146
icon: "checkmark.circle",
@@ -688,10 +697,24 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
688697

689698
const status = resolveThreadListV2Status(thread);
690699
const isUnread = status === "ready" && threadHasUnseenCompletion(thread);
691-
const workingLabel = STATUS_LABEL_BY_STATUS[status];
700+
const quietSince = useAtomValue(
701+
serverEnvironment.configValueAtom(thread.environmentId),
702+
(config) => (status === "working" ? quietRunSince(config, thread) : null),
703+
);
704+
const workingLabel = quietSince !== null ? QUIET_STATUS_LABEL : STATUS_LABEL_BY_STATUS[status];
705+
const rowAccessibilityLabel = [
706+
thread.title,
707+
quietSince !== null ? QUIET_STATUS_LABEL.label : null,
708+
props.hasQueuedMessages ? "messages queued to send" : null,
709+
]
710+
.filter((part) => part !== null)
711+
.join(", ");
692712
const showsWoke = status === "ready" && props.wokeAt !== null;
693713
const statusLabel =
694-
(status === "working" && workingLabel !== undefined && thread.goal?.status === "active"
714+
(status === "working" &&
715+
quietSince === null &&
716+
workingLabel !== undefined &&
717+
thread.goal?.status === "active"
695718
? { ...workingLabel, label: "Goal" }
696719
: workingLabel) ?? (isUnread ? DONE_STATUS_LABEL : undefined);
697720
const recede = shouldRecedeThreadRow({ status, selected });
@@ -1145,7 +1168,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11451168
>
11461169
{statusLabel.label}
11471170
{status === "working" ? (
1148-
<ThreadListV2Duration startedAt={resolveThreadWorkingStartedAt(thread)} />
1171+
<ThreadListV2Duration
1172+
startedAt={quietSince ?? resolveThreadWorkingStartedAt(thread)}
1173+
/>
11491174
) : status === "waiting" ? (
11501175
<ThreadListV2Duration startedAt={thread.latestRun?.completedAt ?? null} />
11511176
) : null}
@@ -1299,9 +1324,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
12991324
interactionOpacity={rowAppearance.interactionOpacity}
13001325
className={rowAppearance.className}
13011326
accessibilityHint={swipeAccessibilityHint}
1302-
accessibilityLabel={
1303-
props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
1304-
}
1327+
accessibilityLabel={rowAccessibilityLabel}
13051328
accessibilityRole="button"
13061329
accessibilityState={{ selected }}
13071330
accessibilityActions={rowAccessibilityActions}
@@ -1332,9 +1355,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
13321355
interactionClassName={rowAppearance.interactionClassName}
13331356
interactionOpacity={rowAppearance.interactionOpacity}
13341357
accessibilityHint={swipeAccessibilityHint}
1335-
accessibilityLabel={
1336-
props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
1337-
}
1358+
accessibilityLabel={rowAccessibilityLabel}
13381359
accessibilityRole="button"
13391360
accessibilityState={{ selected }}
13401361
className={rowAppearance.className}

‎apps/mobile/src/state/server.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const serverEnvironment = createServerEnvironmentAtoms(connectionAtomRunt
1414
initialConfigValueAtom: environmentSession.initialConfigValueAtom,
1515
usageLimitSources: true,
1616
memoryPressure: true,
17+
quietRuns: true,
1718
usageLimitsCommand: true,
1819
});
1920
export const describeOutdatedServer = createOutdatedServerDescriptionCommand(connectionAtomRuntime);

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export const make = Effect.gen(function* () {
242242
threadSnooze: true,
243243
threadForceStop: true,
244244
memoryPressure: true,
245+
quietRuns: true,
245246
environmentThemes: true,
246247
usageLimitSources: true,
247248
providerWorkspaceSnapshotsOnDemand: true,

‎apps/server/src/orchestration-v2/EffectWorker.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as Exit from "effect/Exit";
2121
import * as Layer from "effect/Layer";
2222
import * as Option from "effect/Option";
2323
import * as Ref from "effect/Ref";
24+
import * as Stream from "effect/Stream";
2425

2526
import * as CheckpointRollbackService from "./CheckpointRollbackService.ts";
2627
import * as CheckpointService from "./CheckpointService.ts";
@@ -113,6 +114,7 @@ function layerExecutorFor(input: {
113114
detach: () => record("detach"),
114115
otherWorkingThreads: () => Effect.succeed([]),
115116
releaseUnlessBusy: () => Effect.succeed(true),
117+
quietRuns: Stream.empty,
116118
}),
117119
),
118120
Layer.succeed(

0 commit comments

Comments
 (0)