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, 22:15 UTC
fix(chat): keep final replies visible after steering (#34501)
Yash Singh committed
Nov 11, 2026 at 14:52 UTC
836b86a5d6b7738193656b9c638318afe6caef35
7 files changed
+225
-74
apps/mobile/src/lib/threadActivity.test.ts
+16
@@ -1388,6 +1388,22 @@ describe("buildThreadFeed", () => {
1388
expect(rows(turn, "zen")).toEqual(["user", "final"]);
1389
const [steer, answer] = [say("steer", 2, true, true), say("answer", 3)];
1390
expect(rows([user, steer, answer, final], "zen")).toEqual(["user", "steer", "answer", "final"]);
1391
+ const commentary = { ...step, phase: "commentary" as const };
1392
+ expect(rows([user, commentary, steer, final], "zen")).toEqual(["user", "steer", "final"]);
1393
+ for (const phase of ["commentary", "partial_answer", "final_answer", undefined] as const) {
1394
+ const partial = { ...answer, ...(phase === undefined ? {} : { phase }) };
1395
+ const interrupted = buildThreadFeed(
1396
+ [user, passed, partial, steer, final].map((item, index) => projected(item, index)),
1397
+ );
1398
+ expect(
1399
+ deriveThreadFeedPresentation(interrupted, null, new Set()).some(
1400
+ (row) => row.type === "message" && row.message.id === answer.messageId,
1401
+ ),
1402
+ ).toBe(phase === "final_answer");
1403
+ expect(rows([user, partial, steer, final], "zen").includes("answer")).toBe(
1404
+ phase === "final_answer",
1405
+ );
1406
+ }
1407
expect(rows([user, steer, step, passed, final], "zen")).toEqual(["user", "steer", "final"]);
1408
expect(rows([user, steer, answer, step], "zen", running)).toEqual([
1409
"user",
apps/mobile/src/lib/threadActivity.ts
+22
-1
@@ -1073,6 +1073,25 @@ export function messageFoldRunId(
1073
return null;
1074
}
1075
1076
+function answersBeforeSteers(feed: ReadonlyArray<ThreadFeedEntry>): ReadonlySet<MessageId> {
1077
+ const ids = new Set<MessageId>();
1078
+ let previous: ThreadFeedEntry | undefined;
1079
+ for (const entry of feed) {
1080
+ if (
1081
+ entry.type === "message" &&
1082
+ isSteerMessage(entry.message) &&
1083
+ previous?.type === "message" &&
1084
+ previous.message.role === "assistant" &&
1085
+ previous.message.projectedItem?.item.type === "assistant_message" &&
1086
+ previous.message.projectedItem.item.phase === "final_answer"
1087
+ ) {
1088
+ ids.add(previous.message.id);
1089
+ }
1090
+ previous = entry;
1091
+ }
1092
+ return ids;
1093
+}
1094
+
1095
function deriveThreadFeedRunFolds(
1096
feed: ReadonlyArray<ThreadFeedEntry>,
1097
latestRun: ThreadFeedLatestRun | null,
@@ -1080,6 +1099,7 @@ function deriveThreadFeedRunFolds(
1099
feedFailedRunIds: ReadonlySet<RunId>,
1100
): ReadonlyMap<string, ThreadFeedRunFold> {
1101
const terminalAssistantMessageIdByRun = new Map<RunId, string>();
1102
+ const retainedAnswerIds = answersBeforeSteers(feed);
1103
const interruptedRunIds = new Set<RunId>();
1104
const failedRunIds = new Set(feedFailedRunIds);
1105
const promptIndexByRunId = new Map<RunId, number>();
@@ -1170,6 +1190,7 @@ function deriveThreadFeedRunFolds(
1190
.filter(
1191
(entry) =>
1192
entry.id !== terminalAssistantId &&
1193
+ !(entry.type === "message" && retainedAnswerIds.has(entry.message.id)) &&
1194
entry.type !== "html-render" &&
1195
entry.type !== "mcp-app" &&
1196
entry.id !== visibleCompactionId &&
@@ -1432,7 +1453,7 @@ function zenAnswerMessageIds(
1453
): ReadonlySet<MessageId> {
1454
const replies: Array<{ readonly message: ThreadFeedMessage; readonly index: number }> = [];
1455
const lastReplyByResponse = new Map<string, MessageId>();
1435
- const steerAnswers = new Set<MessageId>();
1456
+ const steerAnswers = new Set(answersBeforeSteers(feed));
1457
let userMessages = 0;
1458
let awaitingReply = false;
1459
let candidate: MessageId | null = null;
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+74
-4
@@ -4237,10 +4237,50 @@ describe("CodexAdapterV2 post-settle continuation", () => {
4237
Effect.scoped(
4238
Effect.gen(function* () {
4239
const transcript = finalAnswerTranscript("codex-partial-then-final", [
4240
- { id: "partial", text: "CODEX_RECOVERY_OK", phase: "partial_answer", streamed },
4241
- { id: "final", text: "CODEX_RECOVERY_OK", phase: "final_answer", streamed },
4240
+ {
4241
+ id: "status",
4242
+ text: "Checking the files",
4243
+ phase: "commentary",
4244
+ streamed,
4245
+ },
4246
+ {
4247
+ id: "partial",
4248
+ text: "CODEX_RECOVERY_OK",
4249
+ phase: "partial_answer",
4250
+ streamed,
4251
+ },
4252
+ {
4253
+ id: "final",
4254
+ text: "CODEX_RECOVERY_OK",
4255
+ phase: "final_answer",
4256
+ streamed,
4257
+ },
4258
]);
4243
- const harness = yield* makeCodexReplayHarness(transcript);
4259
+ const gates = yield* Effect.forEach(["status", "partial", "final"], (id) =>
4260
+ Effect.gen(function* () {
4261
+ return {
4262
+ id,
4263
+ ready: yield* Deferred.make<void>(),
4264
+ release: yield* Deferred.make<void>(),
4265
+ };
4266
+ }),
4267
+ );
4268
+ const harness = yield* makeCodexReplayHarness(
4269
+ transcript,
4270
+ undefined,
4271
+ undefined,
4272
+ undefined,
4273
+ (entry) => {
4274
+ const gate = streamed
4275
+ ? gates.find((gate) => entry.label === `item/completed/${gate.id}`)
4276
+ : undefined;
4277
+ return gate === undefined
4278
+ ? Effect.void
4279
+ : Deferred.succeed(gate.ready, undefined).pipe(
4280
+ Effect.andThen(Deferred.await(gate.release)),
4281
+ );
4282
+ },
4283
+ );
4284
const now = yield* DateTime.now;
4285
yield* harness.runtime.startTurn(
4286
makeCodexTestTurnInput({
@@ -4251,11 +4291,41 @@ describe("CodexAdapterV2 post-settle continuation", () => {
4291
text: "Reply with the requested recovery marker.",
4292
}),
4293
);
4294
+ if (streamed) {
4295
+ for (const gate of gates) {
4296
+ yield* Deferred.await(gate.ready);
4297
+ yield* TestClock.adjust("50 millis");
4298
+ yield* harness.until(() =>
4299
+ harness.events.some(
4300
+ (event) =>
4301
+ event.type === "turn_item.updated" &&
4302
+ event.turnItem.type === "assistant_message" &&
4303
+ event.turnItem.nativeItemRef?.nativeId === gate.id &&
4304
+ event.turnItem.streaming,
4305
+ ),
4306
+ );
4307
+ yield* Deferred.succeed(gate.release, undefined);
4308
+ }
4309
+ }
4310
yield* harness.awaitTerminal(1);
4311
assert.deepEqual(
4312
assistantMessages(harness.events).map((event) => event.message.text),
4257
- ["CODEX_RECOVERY_OK", "CODEX_RECOVERY_OK"],
4313
+ ["Checking the files", "CODEX_RECOVERY_OK", "CODEX_RECOVERY_OK"],
4314
+ );
4315
+ const updates = harness.events.flatMap((event) =>
4316
+ event.type === "turn_item.updated" && event.turnItem.type === "assistant_message"
4317
+ ? [event.turnItem]
4318
+ : [],
4319
);
4320
+ for (const [text, phase] of [
4321
+ ["Checking the files", "commentary"],
4322
+ ["CODEX_RECOVERY_OK", "partial_answer"],
4323
+ ["CODEX_RECOVERY_OK", "final_answer"],
4324
+ ]) {
4325
+ const matching = updates.filter((item) => item.text === text && item.phase === phase);
4326
+ assert.isTrue(matching.some((item) => !item.streaming));
4327
+ if (streamed) assert.isTrue(matching.some((item) => item.streaming));
4328
+ }
4329
}).pipe(
4330
Effect.provide(
4331
Layer.mergeAll(
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+11
@@ -1223,6 +1223,7 @@ interface ActiveCodexTurnContext {
1223
readonly runningCompactionItemIds: Set<string>;
1224
// Modern approval requests omit paths; keep the kinds without retaining patch bodies.
1225
readonly fileChangeKindsByItem: Map<string, CodexFileChangeKinds>;
1226
+ readonly messagePhases: Map<string, "commentary" | "partial_answer" | "final_answer">;
1227
readonly itemPositions: Map<
1228
string,
1229
{ readonly ordinal: number; readonly startedAt: DateTime.Utc }
@@ -2207,6 +2208,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
2208
startedAt: input.startedAt,
2209
itemPositions: new Map(),
2210
fileChangeKindsByItem: new Map(),
2211
+ messagePhases: new Map(),
2212
runningCompactionItemIds: new Set(),
2213
};
2214
const nativeThreadId = input.turnInput.providerThread.nativeThreadRef?.nativeId;
@@ -2813,6 +2815,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
2815
startedAt: turn.startedAt,
2816
itemPositions: new Map(),
2817
fileChangeKindsByItem: new Map(),
2818
+ messagePhases: new Map(),
2819
runningCompactionItemIds: new Set(),
2820
};
2821
beginTurnTokenUsage(activeContext);
@@ -3490,6 +3493,9 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
3493
completedAt,
3494
updatedAt,
3495
type: "assistant_message",
3496
+ ...(context.messagePhases.has(item.id)
3497
+ ? { phase: context.messagePhases.get(item.id) }
3498
+ : {}),
3499
messageId,
3500
text: item.text,
3501
streaming: !completed,
@@ -5054,6 +5060,8 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
5060
}
5061
5062
if (payload.item.type === "agentMessage") {
5063
+ if (payload.item.phase != null)
5064
+ context.messagePhases.set(payload.item.id, payload.item.phase);
5065
if (payload.item.phase == null || payload.item.phase === "final_answer") {
5066
yield* Ref.update(finalAnswerItemIdsByTurn, (current) => {
5067
const updated = new Map(current);
@@ -5442,6 +5450,8 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
5450
return;
5451
}
5452
5453
+ if (payload.item.phase != null)
5454
+ context.messagePhases.set(payload.item.id, payload.item.phase);
5455
const finalAnswer = payload.item.phase == null || payload.item.phase === "final_answer";
5456
if (finalAnswer) {
5457
yield* Ref.update(finalAnswerItemIdsByTurn, (current) => {
@@ -6913,6 +6923,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
6923
startedAt: now,
6924
itemPositions: new Map(),
6925
fileChangeKindsByItem: new Map(),
6926
+ messagePhases: new Map(),
6927
runningCompactionItemIds: new Set(),
6928
};
6929
const providerTurn = {
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+73
-54
@@ -3347,6 +3347,7 @@ describe("v2 run and attempt history", () => {
3347
id: string,
3348
attempt: typeof supersededAttempt | typeof nextAttempt,
3349
completedSecond: number,
3350
+ phase?: "commentary" | "partial_answer" | "final_answer",
3351
): TimelineEntry => ({
3352
id,
3353
kind: "message",
@@ -3364,6 +3365,7 @@ describe("v2 run and attempt history", () => {
3365
projectedItem: {
3366
item: {
3367
type: "assistant_message",
3368
+ ...(phase === undefined ? {} : { phase }),
3369
status: "completed",
3370
completedAt: DateTime.makeUnsafe(at(completedSecond)),
3371
},
@@ -3372,51 +3374,58 @@ describe("v2 run and attempt history", () => {
3374
const rowsFor = (
3375
replyCompletedSecond: number,
3376
runStatus: "running" | "completed" = "completed",
3377
+ toolCallVisibility: "showAll" | "zen" = "showAll",
3378
+ phase?: "commentary" | "partial_answer" | "final_answer",
3379
+ nativeSteer = false,
3380
) =>
3381
deriveMessagesTimelineRows({
3377
- timelineEntries: [
3378
- {
3379
- id: "initial-user-entry",
3380
- kind: "message",
3381
- createdAt: at(0),
3382
- attempt: supersededAttempt,
3383
- message: {
3384
- id: MessageId.make("initial-user"),
3385
- role: "user",
3386
- text: "Build it",
3387
- runId,
3388
- inputIntent: "turn_start",
3382
+ toolCallVisibility,
3383
+ timelineEntries: (
3384
+ [
3385
+ {
3386
+ id: "initial-user-entry",
3387
+ kind: "message",
3388
createdAt: at(0),
3390
- updatedAt: at(0),
3391
- streaming: false,
3389
+ attempt: supersededAttempt,
3390
+ message: {
3391
+ id: MessageId.make("initial-user"),
3392
+ role: "user",
3393
+ text: "Build it",
3394
+ runId,
3395
+ inputIntent: "turn_start",
3396
+ createdAt: at(0),
3397
+ updatedAt: at(0),
3398
+ streaming: false,
3399
+ },
3400
},
3393
- },
3394
- {
3395
- id: "old-work-entry",
3396
- kind: "work",
3397
- createdAt: at(1),
3398
- attempt: supersededAttempt,
3399
- entry: { id: "old-work", createdAt: at(1), runId, label: "Read", tone: "tool" },
3400
- },
3401
- assistantEntry("old-reply-entry", supersededAttempt, replyCompletedSecond),
3402
- {
3403
- id: "steer-user-entry",
3404
- kind: "message",
3405
- createdAt: at(10),
3406
- attempt: nextAttempt,
3407
- message: {
3408
- id: MessageId.make("steer-user"),
3409
- role: "user",
3410
- text: "What are you working on?",
3411
- runId,
3412
- inputIntent: "steer",
3401
+ {
3402
+ id: "old-work-entry",
3403
+ kind: "work",
3404
+ createdAt: at(1),
3405
+ attempt: supersededAttempt,
3406
+ entry: { id: "old-work", createdAt: at(1), runId, label: "Read", tone: "tool" },
3407
+ },
3408
+ assistantEntry("status-entry", supersededAttempt, 1, "commentary"),
3409
+ assistantEntry("old-reply-entry", supersededAttempt, replyCompletedSecond, phase),
3410
+ {
3411
+ id: "steer-user-entry",
3412
+ kind: "message",
3413
createdAt: at(10),
3414
- updatedAt: at(10),
3415
- streaming: false,
3414
+ attempt: nextAttempt,
3415
+ message: {
3416
+ id: MessageId.make("steer-user"),
3417
+ role: "user",
3418
+ text: "What are you working on?",
3419
+ runId,
3420
+ inputIntent: "steer",
3421
+ createdAt: at(10),
3422
+ updatedAt: at(10),
3423
+ streaming: false,
3424
+ },
3425
},
3417
- },
3418
- assistantEntry("new-reply-entry", nextAttempt, 14),
3419
- ],
3426
+ assistantEntry("new-reply-entry", nextAttempt, 14),
3427
+ ] satisfies ReadonlyArray<TimelineEntry>
3428
+ ).map((entry) => (nativeSteer ? { ...entry, attempt: nextAttempt } : entry)),
3429
latestRun: {
3430
runId,
3431
status: runStatus,
@@ -3428,23 +3437,33 @@ describe("v2 run and attempt history", () => {
3437
supportsConversationRollback: false,
3438
});
3439
3431
- it.each(["running", "completed"] as const)(
3432
- "keeps a reply that finished before the steer visible while the run is %s",
3433
- (runStatus) => {
3434
- const rows = rowsFor(4, runStatus);
3435
- expect(rows.some((row) => row.kind === "attempt-fold")).toBe(false);
3436
- expect(rows.map((row) => row.id)).toContain("old-reply-entry");
3440
+ it.each([
3441
+ ["final_answer", 4, true],
3442
+ ["final_answer", 11, true],
3443
+ ["commentary", 4, false],
3444
+ ["commentary", 11, false],
3445
+ ["partial_answer", 11, false],
3446
+ [undefined, 4, true],
3447
+ [undefined, 11, false],
3448
+ ] as const)(
3449
+ "retains phase %s ending at %s only when it is a final reply: %s",
3450
+ (phase, completedSecond, retained) => {
3451
+ for (const runStatus of ["running", "completed"] as const) {
3452
+ for (const visibility of ["showAll", "zen"] as const) {
3453
+ const rows = rowsFor(completedSecond, runStatus, visibility, phase);
3454
+ expect(rows.some((row) => row.id === "old-reply-entry")).toBe(retained);
3455
+ if (phase !== undefined && runStatus === "completed") {
3456
+ const nativeRows = rowsFor(completedSecond, runStatus, visibility, phase, true);
3457
+ expect(nativeRows.some((row) => row.id === "old-reply-entry")).toBe(retained);
3458
+ expect(nativeRows.some((row) => row.id === "status-entry")).toBe(false);
3459
+ }
3460
+ if (runStatus === "completed") {
3461
+ expect(rows.some((row) => row.id === "status-entry")).toBe(false);
3462
+ }
3463
+ }
3464
+ }
3465
},
3466
);
3439
-
3440
- it("folds a reply the steer cut off as partial output", () => {
3441
- const rows = rowsFor(11, "running");
3442
- expect(rows.find((row) => row.kind === "attempt-fold")).toMatchObject({
3443
- attemptId: supersededAttempt.id,
3444
- label: "Superseded attempt",
3445
- });
3446
- expect(rows.map((row) => row.id)).not.toContain("old-reply-entry");
3447
- });
3467
});
3468
3469
it("hides the interruption request while keeping intervening work and the result", () => {
apps/web/src/components/chat/MessagesTimeline.logic.ts
+25
-15
@@ -1,7 +1,7 @@
1
+import * as DateTime from "effect/DateTime";
2
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
3
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
4
import { isLiveSubagentTurnItem } from "@t3tools/client-runtime/state/subagentRuntime";
4
-import * as DateTime from "effect/DateTime";
5
import * as Equal from "effect/Equal";
6
import { collectAssistantCitations } from "@t3tools/shared/assistantCitations";
7
import { shallow } from "zustand/vanilla/shallow";
@@ -740,12 +740,20 @@ interface SupersededAttemptFold {
740
readonly hiddenEntryIds: ReadonlySet<string>;
741
}
742
743
-// Interrupted streams can be `completed`; only the attempt's last output proves completion.
744
-function completeSupersededReplyEntryIds(
743
+// Only an explicit final phase proves a reply cut short by steering was an answer.
744
+function retainedAssistantReplyEntryIds(
745
timelineEntries: ReadonlyArray<TimelineEntry>,
746
): ReadonlySet<string> {
747
+ const replyEntryIds = new Set<string>();
748
const lastOutputByAttemptId = new Map<RunAttemptId, TimelineEntry>();
749
for (const entry of timelineEntries) {
750
+ if (
751
+ entry.kind === "message" &&
752
+ entry.projectedItem?.item.type === "assistant_message" &&
753
+ entry.projectedItem.item.phase === "final_answer"
754
+ )
755
+ replyEntryIds.add(entry.id);
756
+
757
if (
758
entry.attempt?.status !== "superseded" ||
759
(entry.kind === "message" && entry.message.role === "user") ||
@@ -769,14 +777,14 @@ function completeSupersededReplyEntryIds(
777
if (deferredEnd !== undefined && ordinal !== undefined && deferredEnd > ordinal) continue;
778
lastOutputByAttemptId.set(entry.attempt.id, entry);
779
}
772
- const replyEntryIds = new Set<string>();
780
for (const entry of lastOutputByAttemptId.values()) {
774
- const supersededAt = entry.attempt?.completedAt ?? null;
781
const item = entry.kind === "message" ? entry.projectedItem?.item : undefined;
782
+ const supersededAt = entry.attempt?.completedAt ?? null;
783
if (
784
entry.kind === "message" &&
785
!entry.message.streaming &&
786
item?.type === "assistant_message" &&
787
+ item.phase === undefined &&
788
item.status === "completed" &&
789
item.completedAt !== null &&
790
supersededAt !== null &&
@@ -792,18 +800,18 @@ function deriveSupersededAttemptFolds(
800
timelineEntries: ReadonlyArray<TimelineEntry>,
801
unfoldedRunIds: ReadonlySet<RunId>,
802
liveSubagentEntryIds: ReadonlySet<string>,
795
- completeReplyEntryIds: ReadonlySet<string>,
803
+ retainedReplyEntryIds: ReadonlySet<string>,
804
): ReadonlyMap<string, SupersededAttemptFold> {
797
- const completeAttemptIds = new Set(
805
+ const retainedAttemptIds = new Set(
806
timelineEntries.flatMap((entry) =>
799
- entry.attempt !== undefined && completeReplyEntryIds.has(entry.id) ? [entry.attempt.id] : [],
807
+ entry.attempt !== undefined && retainedReplyEntryIds.has(entry.id) ? [entry.attempt.id] : [],
808
),
809
);
810
const entriesByAttemptId = new Map<RunAttemptId, TimelineEntry[]>();
811
for (const entry of timelineEntries) {
812
if (
813
entry.attempt?.status !== "superseded" ||
806
- completeAttemptIds.has(entry.attempt.id) ||
814
+ retainedAttemptIds.has(entry.attempt.id) ||
815
unfoldedRunIds.has(entry.attempt.runId) ||
816
(entry.kind === "message" && entry.message.role === "user") ||
817
(entry.kind === "event" && entry.projectedItem.item.type === "handoff") ||
@@ -1019,7 +1027,7 @@ function deriveTurnFolds(input: {
1027
unfoldedRunIds: ReadonlySet<RunId>;
1028
runlessWorkActive: boolean;
1029
liveSubagentEntryIds: ReadonlySet<string>;
1022
- completeSupersededReplyEntryIds: ReadonlySet<string>;
1030
+ retainedAssistantReplyEntryIds: ReadonlySet<string>;
1031
}): ReadonlyMap<string, TurnFold> {
1032
const interruptedRunIds = new Set<RunId>();
1033
const promptIndexByRunId = new Map<RunId, number>();
@@ -1152,7 +1160,7 @@ function deriveTurnFolds(input: {
1160
entry.id === visibleCompactionId ||
1161
timelineEntryIsPersistentResourceCard(entry) ||
1162
input.liveSubagentEntryIds.has(entry.id) ||
1155
- input.completeSupersededReplyEntryIds.has(entry.id)
1163
+ input.retainedAssistantReplyEntryIds.has(entry.id)
1164
) {
1165
continue;
1166
}
@@ -1457,6 +1465,7 @@ function timelineRowEntries(
1465
const answeringFrom = answering ? lastResponseBoundaryIndex(entries) + 1 : entries.length;
1466
const terminalIds = deriveTerminalAssistantMessageIds(entries);
1467
const steerAnswerIds = deriveInFlightSteerAnswerIds(entries);
1468
+ const retainedReplyIds = retainedAssistantReplyEntryIds(entries);
1469
shown = entries.filter((entry, index) => {
1470
if (entry.kind !== "message") {
1471
return workShownAsFinalAnswerOnly(entry, input.pendingApprovalRequestIds);
@@ -1466,6 +1475,7 @@ function timelineRowEntries(
1475
message.role !== "assistant" ||
1476
message.id === input.revealedMessageId ||
1477
steerAnswerIds.has(message.id) ||
1478
+ retainedReplyIds.has(entry.id) ||
1479
(terminalIds.has(message.id) &&
1480
index < answeringFrom &&
1481
(answeringRunId === null || message.runId !== answeringRunId))
@@ -1508,7 +1518,7 @@ function deriveTimelineTurnFolds(
1518
unfoldedRunIds: new Set([...activeVisualResponseRunIds, ...failedRunIds]),
1519
runlessWorkActive: input.isWorking && input.runlessWorkActive === true,
1520
liveSubagentEntryIds: liveSubagentCardEntryIds(timelineEntries),
1511
- completeSupersededReplyEntryIds: completeSupersededReplyEntryIds(timelineEntries),
1521
+ retainedAssistantReplyEntryIds: retainedAssistantReplyEntryIds(timelineEntries),
1522
});
1523
}
1524
@@ -1567,12 +1577,12 @@ export function deriveMessagesTimelineRows(input: {
1577
const failedRunIds = failedTimelineRunIds(timelineEntries, input.latestRun ?? null);
1578
const itemizedRunIds = itemizedFailedRunIds(timelineEntries, failedRunIds);
1579
const liveSubagentEntryIds = liveSubagentCardEntryIds(timelineEntries);
1570
- const completeSupersededReplyIds = completeSupersededReplyEntryIds(timelineEntries);
1580
+ const retainedAssistantReplyIds = retainedAssistantReplyEntryIds(timelineEntries);
1581
const supersededFoldsByAnchorEntryId = deriveSupersededAttemptFolds(
1582
timelineEntries,
1583
failedRunIds,
1584
liveSubagentEntryIds,
1575
- completeSupersededReplyIds,
1585
+ retainedAssistantReplyIds,
1586
);
1587
const supersededWorkItemIds = new Set(
1588
[...supersededFoldsByAnchorEntryId.values()].flatMap((fold) => fold.deferredWorkItemIds),
@@ -1593,7 +1603,7 @@ export function deriveMessagesTimelineRows(input: {
1603
unfoldedRunIds: new Set([...activeVisualResponseRunIds, ...failedRunIds]),
1604
runlessWorkActive,
1605
liveSubagentEntryIds,
1596
- completeSupersededReplyEntryIds: completeSupersededReplyIds,
1606
+ retainedAssistantReplyEntryIds: retainedAssistantReplyIds,
1607
});
1608
const timelineEntryById = new Map(timelineEntries.map((entry) => [entry.id, entry]));
1609
const collapsedEntryIds = new Set<string>();
packages/contracts/src/orchestrationV2.ts
+4
@@ -1533,6 +1533,8 @@ export const OrchestrationV2ModelSwitch = Schema.Struct({
1533
});
1534
export type OrchestrationV2ModelSwitch = typeof OrchestrationV2ModelSwitch.Type;
1535
1536
+const AssistantMessagePhase = Schema.Literals(["commentary", "partial_answer", "final_answer"]);
1537
+
1538
const OrchestrationV2TurnItemBaseFields = {
1539
/** Wire-only cursor for collapsed work; persisted items keep their complete history. */
1540
deferredWork: Schema.optionalKey(
@@ -1662,6 +1664,7 @@ export const OrchestrationV2TurnItem = Schema.Union([
1664
Schema.Struct({
1665
...OrchestrationV2TurnItemBaseFields,
1666
type: Schema.Literal("assistant_message"),
1667
+ phase: Schema.optional(AssistantMessagePhase),
1668
messageId: MessageId,
1669
text: Schema.String,
1670
textOmitted: DedupedBodyMarker,
@@ -2506,6 +2509,7 @@ export const OrchestrationV2TurnItemJson = Schema.Union([
2509
Schema.Struct({
2510
...OrchestrationV2TurnItemJsonBaseFields,
2511
type: Schema.Literal("assistant_message"),
2512
+ phase: Schema.optional(AssistantMessagePhase),
2513
messageId: MessageId,
2514
text: Schema.String,
2515
attachments: Schema.optional(Schema.Array(ChatAttachment)),