Skip to content

Commit e7fc4c3

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 165f230 commit e7fc4c3

29 files changed

Lines changed: 989 additions & 209 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: 80 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,21 @@ 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 =
559+
quietRunId(
560+
props.serverConfig,
561+
props.selectedThread.id,
562+
props.selectedThread.runtime?.activeRunId,
563+
) ?? undefined;
564+
const quietSince =
565+
props.activeWorkStartedAt === null
566+
? null
567+
: quietRunSince(
568+
props.serverConfig,
569+
props.selectedThread.id,
570+
props.selectedThread.runtime?.activeRunId,
571+
);
553572
const [forceStoppingKey, setForceStoppingKey] = useState<string | null>(null);
554573
// The run that ignored Stop, so a confirmation left open cannot hit a newer run.
555574
const forceStop = async (runId: RunId | undefined) => {
@@ -580,6 +599,26 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
580599
};
581600
const [statusRequest, setStatusRequest] = useState<{ threadKey: string } | null>(null);
582601
const statusPending = statusRequest?.threadKey === selectedThreadKey;
602+
const stopQuietRun = async () => {
603+
if (statusPending || !props.canOperateThread) return;
604+
const request = { threadKey: selectedThreadKey };
605+
setStatusRequest(request);
606+
const result = await interruptThreadTurn({
607+
environmentId: props.environmentId,
608+
input:
609+
quietRunTarget === undefined
610+
? { threadId: props.selectedThread.id }
611+
: { threadId: props.selectedThread.id, runId: quietRunTarget },
612+
});
613+
setStatusRequest((current) => (current === request ? null : current));
614+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
615+
const error = squashAtomCommandFailure(result);
616+
Dialog.alert(
617+
"Could not stop the turn",
618+
error instanceof Error ? error.message : "Try again.",
619+
);
620+
}
621+
};
583622
const [lifecycleNow, setLifecycleNow] = useState(() => new Date().toISOString());
584623
useFocusEffect(
585624
useCallback(() => {
@@ -723,6 +762,46 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
723762
},
724763
};
725764
}
765+
if (quietSince !== null && contentPresentationKind === "ready") {
766+
return {
767+
kind: "quiet",
768+
quietSince,
769+
action: {
770+
label:
771+
forceStoppingKey === selectedThreadKey
772+
? "Force stopping..."
773+
: statusPending
774+
? "Stopping..."
775+
: "Stop",
776+
accessibilityLabel: "Stop the quiet turn",
777+
disabled:
778+
!props.canOperateThread || statusPending || forceStoppingKey === selectedThreadKey,
779+
onPress: () =>
780+
Dialog.alert(
781+
"Stop this turn?",
782+
canForceStop
783+
? "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."
784+
: "The agent has sent nothing for a while. A long tool may still be running.",
785+
[
786+
{ text: "Cancel", style: "cancel" },
787+
{
788+
text: "Stop",
789+
onPress: () => void stopQuietRun(),
790+
},
791+
...(canForceStop
792+
? [
793+
{
794+
text: "Force stop",
795+
style: "destructive" as const,
796+
onPress: () => void forceStop(quietRunTarget),
797+
},
798+
]
799+
: []),
800+
],
801+
),
802+
},
803+
};
804+
}
726805
if (props.isCompacting && contentPresentationKind === "ready") {
727806
return { kind: "compacting" };
728807
}

‎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: 31 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,25 @@ 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) =>
703+
status === "working" ? quietRunSince(config, thread.id, thread.runtime?.activeRunId) : null,
704+
);
705+
const workingLabel = quietSince !== null ? QUIET_STATUS_LABEL : STATUS_LABEL_BY_STATUS[status];
706+
const rowAccessibilityLabel = [
707+
thread.title,
708+
quietSince !== null ? QUIET_STATUS_LABEL.label : null,
709+
props.hasQueuedMessages ? "messages queued to send" : null,
710+
]
711+
.filter((part) => part !== null)
712+
.join(", ");
692713
const showsWoke = status === "ready" && props.wokeAt !== null;
693714
const statusLabel =
694-
(status === "working" && workingLabel !== undefined && thread.goal?.status === "active"
715+
(status === "working" &&
716+
quietSince === null &&
717+
workingLabel !== undefined &&
718+
thread.goal?.status === "active"
695719
? { ...workingLabel, label: "Goal" }
696720
: workingLabel) ?? (isUnread ? DONE_STATUS_LABEL : undefined);
697721
const recede = shouldRecedeThreadRow({ status, selected });
@@ -1145,7 +1169,9 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
11451169
>
11461170
{statusLabel.label}
11471171
{status === "working" ? (
1148-
<ThreadListV2Duration startedAt={resolveThreadWorkingStartedAt(thread)} />
1172+
<ThreadListV2Duration
1173+
startedAt={quietSince ?? resolveThreadWorkingStartedAt(thread)}
1174+
/>
11491175
) : status === "waiting" ? (
11501176
<ThreadListV2Duration startedAt={thread.latestRun?.completedAt ?? null} />
11511177
) : null}
@@ -1299,9 +1325,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
12991325
interactionOpacity={rowAppearance.interactionOpacity}
13001326
className={rowAppearance.className}
13011327
accessibilityHint={swipeAccessibilityHint}
1302-
accessibilityLabel={
1303-
props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
1304-
}
1328+
accessibilityLabel={rowAccessibilityLabel}
13051329
accessibilityRole="button"
13061330
accessibilityState={{ selected }}
13071331
accessibilityActions={rowAccessibilityActions}
@@ -1332,9 +1356,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
13321356
interactionClassName={rowAppearance.interactionClassName}
13331357
interactionOpacity={rowAppearance.interactionOpacity}
13341358
accessibilityHint={swipeAccessibilityHint}
1335-
accessibilityLabel={
1336-
props.hasQueuedMessages ? `${thread.title}, messages queued to send` : thread.title
1337-
}
1359+
accessibilityLabel={rowAccessibilityLabel}
13381360
accessibilityRole="button"
13391361
accessibilityState={{ selected }}
13401362
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)