The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
feat(cli): thread show reports why the latest run failed (#39849)
Julius Marminge committed
Nov 20, 2026 at 11:10 UTC
f0a2aa10f5165413e863db9f1502dc4bb6fa42e8
2 files changed
+44
-1
apps/server/src/cli/thread.test.ts
+27
@@ -24,6 +24,7 @@ import {
24
persistServerRuntimeState,
25
} from "../serverRuntimeState.ts";
26
import {
27
+ latestRunError,
28
launchModelSelection,
29
readLatestMessages,
30
resolveProject,
@@ -504,6 +505,32 @@ it.effect("show returns a --messages count larger than one call can spread", ()
505
}),
506
);
507
508
+it.effect("show gives the latest run's last error only when that run did not complete", () =>
509
+ Effect.gen(function* () {
510
+ const page = {
511
+ thread: {},
512
+ items: [
513
+ { itemId: "item-0", runId: RunId.make("run-0"), type: "error", text: "earlier run" },
514
+ { itemId: "item-1", runId, type: "error", text: "first try" },
515
+ { itemId: "item-2", runId, type: "error", text: "Usage limit reached" },
516
+ ],
517
+ nextPosition: null,
518
+ hasMore: false,
519
+ };
520
+ const { tools, calls } = scriptedTools({ t3_thread_read: [page] });
521
+
522
+ assert.strictEqual(
523
+ yield* latestRunError(tools, { threadId, status: "failed", latestRunId: runId }),
524
+ "Usage limit reached",
525
+ );
526
+ assert.deepInclude(calls[0]?.args, { view: "activity" });
527
+ for (const status of ["completed", "running", "queued", "idle"] as const) {
528
+ assert.isNull(yield* latestRunError(tools, { threadId, status, latestRunId: runId }), status);
529
+ }
530
+ assert.lengthOf(calls, 1);
531
+ }),
532
+);
533
+
534
it("titles from a long first line without splitting an emoji", () => {
535
const title = titleFromMessage(`${"a".repeat(78)}😀 and the rest of a long first line`);
536
assert.strictEqual(title, `${"a".repeat(78)}…`);
apps/server/src/cli/thread.ts
+17
-1
@@ -8,6 +8,7 @@ import {
8
RunId,
9
ThreadId,
10
TrimmedNonEmptyString,
11
+ type OrchestratorMcpThreadDetail,
12
type OrchestratorMcpThreadListItem,
13
type OrchestratorMcpThreadRun,
14
type OrchestratorMcpThreadStatus,
@@ -511,6 +512,17 @@ const runResultText = Effect.fn("cli.thread.runResultText")(function* (
512
return item === undefined ? null : yield* readFullText(tools, threadId, item);
513
});
514
515
+/** The latest run's last error once it ended without completing, else null. */
516
+export const latestRunError = Effect.fn("cli.thread.latestRunError")(function* (
517
+ tools: ThreadTools,
518
+ thread: Pick<OrchestratorMcpThreadDetail, "threadId" | "status" | "latestRunId">,
519
+) {
520
+ const { status, latestRunId } = thread;
521
+ if (latestRunId === null || status === "idle" || status === "completed") return null;
522
+ if (!TERMINAL_RUN_STATUSES.has(status)) return null;
523
+ return yield* runResultText(tools, thread.threadId, latestRunId, "error");
524
+});
525
+
526
type WaitOutcome =
527
| {
528
readonly type: "ended";
@@ -962,8 +974,9 @@ const threadShowCommand = Command.make("show", {
974
})),
975
),
976
);
977
+ const error = yield* latestRunError(tools, thread);
978
if (flags.json) {
966
- return yield* printJson({ thread, messages });
979
+ return yield* printJson({ thread, messages, error });
980
}
981
yield* Console.log(thread.title);
982
yield* Console.log(
@@ -977,6 +990,9 @@ const threadShowCommand = Command.make("show", {
990
if (thread.pendingRequestCount > 0) {
991
yield* Console.log(`Waiting for ${thread.pendingRequestCount} answer(s).`);
992
}
993
+ if (error !== null) {
994
+ yield* Console.log(`Error: ${error}`);
995
+ }
996
for (const entry of messages) {
997
yield* Console.log(`\n[${entry.role}]\n${entry.text}`);
998
}