Skip to content

Commit ba49da6

Browse files
committed
feat(opencode): show actual model per turn
1 parent bad1143 commit ba49da6

20 files changed

Lines changed: 377 additions & 16 deletions

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,15 @@ function renderFeedEntry(
10051005
})}
10061006
{showAssistantMeta ? (
10071007
<View className="mt-1 flex-row items-center gap-1">
1008+
{message.actualModel ? (
1009+
<Text
1010+
accessibilityLabel={`Actual model: ${message.actualModel}`}
1011+
className="mr-1 max-w-[70%] font-t3-medium text-xs text-neutral-600 dark:text-neutral-400"
1012+
numberOfLines={1}
1013+
>
1014+
Model: {message.actualModel}
1015+
</Text>
1016+
) : null}
10081017
<CopyTextButton
10091018
accessibilityLabel="Copy message"
10101019
text={message.text}

‎apps/server/src/orchestration/Layers/ProjectionPipeline.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,11 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
978978
turnId: event.payload.turnId,
979979
role: event.payload.role,
980980
text: nextText,
981+
...(event.payload.actualModel !== undefined
982+
? { actualModel: event.payload.actualModel }
983+
: previousMessage?.actualModel !== undefined
984+
? { actualModel: previousMessage.actualModel }
985+
: {}),
981986
...(nextAttachments !== undefined ? { attachments: [...nextAttachments] } : {}),
982987
isStreaming: event.payload.streaming,
983988
createdAt: previousMessage?.createdAt ?? event.payload.createdAt,

‎apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
ModelSelection,
2626
ProjectId,
2727
ThreadId,
28+
TrimmedNonEmptyString,
2829
} from "@t3tools/contracts";
2930
import * as Arr from "effect/Array";
3031
import * as Effect from "effect/Effect";
@@ -78,6 +79,7 @@ const ProjectionProjectDbRowSchema = ProjectionProject.mapFields(
7879
const ProjectionThreadMessageDbRowSchema = ProjectionThreadMessage.mapFields(
7980
Struct.assign({
8081
isStreaming: Schema.Number,
82+
actualModel: Schema.NullOr(TrimmedNonEmptyString),
8183
attachments: Schema.NullOr(Schema.fromJsonString(Schema.Array(ChatAttachment))),
8284
}),
8385
);
@@ -527,6 +529,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
527529
turn_id AS "turnId",
528530
role,
529531
text,
532+
actual_model AS "actualModel",
530533
attachments_json AS "attachments",
531534
is_streaming AS "isStreaming",
532535
created_at AS "createdAt",
@@ -970,6 +973,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
970973
turn_id AS "turnId",
971974
role,
972975
text,
976+
actual_model AS "actualModel",
973977
attachments_json AS "attachments",
974978
is_streaming AS "isStreaming",
975979
created_at AS "createdAt",
@@ -1196,6 +1200,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
11961200
turn_id AS "turnId",
11971201
role,
11981202
text,
1203+
actual_model AS "actualModel",
11991204
attachments_json AS "attachments",
12001205
is_streaming AS "isStreaming",
12011206
created_at AS "createdAt",
@@ -1432,6 +1437,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
14321437
id: row.messageId,
14331438
role: row.role,
14341439
text: row.text,
1440+
...(row.actualModel !== null ? { actualModel: row.actualModel } : {}),
14351441
...(row.attachments !== null ? { attachments: row.attachments } : {}),
14361442
turnId: row.turnId,
14371443
streaming: row.isStreaming === 1,
@@ -2472,6 +2478,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
24722478
id: row.messageId,
24732479
role: row.role,
24742480
text: row.text,
2481+
...(row.actualModel !== null ? { actualModel: row.actualModel } : {}),
24752482
turnId: row.turnId,
24762483
streaming: row.isStreaming === 1,
24772484
createdAt: row.createdAt,

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,6 +2617,72 @@ describe("ProviderRuntimeIngestion", () => {
26172617
expect(completionEvents).toHaveLength(1);
26182618
});
26192619

2620+
it("enriches an already completed assistant message with the actual turn model", async () => {
2621+
const harness = await createHarness();
2622+
const now = "2026-08-14T00:00:00.000Z";
2623+
const threadId = asThreadId("thread-1");
2624+
const turnId = asTurnId("turn-actual-model");
2625+
const itemId = asItemId("item-actual-model");
2626+
2627+
harness.emit({
2628+
type: "turn.started",
2629+
eventId: asEventId("evt-turn-started-actual-model"),
2630+
provider: ProviderDriverKind.make("opencode"),
2631+
createdAt: now,
2632+
threadId,
2633+
turnId,
2634+
});
2635+
await waitForThread(harness.readModel, (thread) => thread.session?.activeTurnId === turnId);
2636+
2637+
harness.emit({
2638+
type: "content.delta",
2639+
eventId: asEventId("evt-message-delta-actual-model"),
2640+
provider: ProviderDriverKind.make("opencode"),
2641+
createdAt: now,
2642+
threadId,
2643+
turnId,
2644+
itemId,
2645+
payload: { streamKind: "assistant_text", delta: "done" },
2646+
});
2647+
harness.emit({
2648+
type: "item.completed",
2649+
eventId: asEventId("evt-message-completed-actual-model"),
2650+
provider: ProviderDriverKind.make("opencode"),
2651+
createdAt: now,
2652+
threadId,
2653+
turnId,
2654+
itemId,
2655+
payload: { itemType: "assistant_message", status: "completed" },
2656+
});
2657+
await waitForThread(harness.readModel, (thread) =>
2658+
thread.messages.some(
2659+
(message) => message.id === "assistant:item-actual-model" && !message.streaming,
2660+
),
2661+
);
2662+
2663+
harness.emit({
2664+
type: "turn.completed",
2665+
eventId: asEventId("evt-turn-completed-actual-model"),
2666+
provider: ProviderDriverKind.make("opencode"),
2667+
createdAt: now,
2668+
threadId,
2669+
turnId,
2670+
payload: { state: "completed", actualModel: "gpt-5.6-luna" },
2671+
});
2672+
2673+
const thread = await waitForThread(harness.readModel, (entry) =>
2674+
entry.messages.some(
2675+
(message) =>
2676+
message.id === "assistant:item-actual-model" && message.actualModel === "gpt-5.6-luna",
2677+
),
2678+
);
2679+
const messages = thread.messages.filter(
2680+
(message) => message.id === "assistant:item-actual-model",
2681+
);
2682+
expect(messages).toHaveLength(1);
2683+
expect(messages[0]?.actualModel).toBe("gpt-5.6-luna");
2684+
});
2685+
26202686
it("maps canonical request events into approval activities with requestKind", async () => {
26212687
const harness = await createHarness();
26222688
const now = "2026-01-01T00:00:00.000Z";

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@ const make = Effect.gen(function* () {
11891189
finalDeltaCommandTag: string;
11901190
fallbackText?: string;
11911191
hasProjectedMessage?: boolean;
1192+
actualModel?: string;
11921193
}) =>
11931194
Effect.gen(function* () {
11941195
const bufferedText = yield* takeBufferedAssistantText(input.messageId);
@@ -1219,6 +1220,7 @@ const make = Effect.gen(function* () {
12191220
threadId: input.threadId,
12201221
messageId: input.messageId,
12211222
...(input.turnId ? { turnId: input.turnId } : {}),
1223+
...(input.actualModel ? { actualModel: input.actualModel } : {}),
12221224
createdAt: input.createdAt,
12231225
});
12241226
}
@@ -1828,7 +1830,20 @@ const make = Effect.gen(function* () {
18281830
const proposedPlans = detailedThread?.proposedPlans ?? [];
18291831
const turnId = toTurnId(event.turnId);
18301832
if (turnId) {
1831-
const assistantMessageIds = yield* getAssistantMessageIdsForTurn(thread.id, turnId);
1833+
const trackedAssistantMessageIds = yield* getAssistantMessageIdsForTurn(
1834+
thread.id,
1835+
turnId,
1836+
);
1837+
const completedAssistantMessageId = messages.findLast(
1838+
(message) => message.role === "assistant" && message.turnId === turnId,
1839+
)?.id;
1840+
const assistantMessageIds =
1841+
trackedAssistantMessageIds.size > 0
1842+
? Array.from(trackedAssistantMessageIds)
1843+
: event.payload.actualModel && completedAssistantMessageId
1844+
? [completedAssistantMessageId]
1845+
: [];
1846+
const terminalAssistantMessageId = assistantMessageIds.at(-1);
18321847
yield* Effect.forEach(
18331848
assistantMessageIds,
18341849
(assistantMessageId) =>
@@ -1841,6 +1856,9 @@ const make = Effect.gen(function* () {
18411856
commandTag: "assistant-complete-finalize",
18421857
finalDeltaCommandTag: "assistant-delta-finalize-fallback",
18431858
hasProjectedMessage: findMessageById(messages, assistantMessageId) !== undefined,
1859+
...(event.payload.actualModel && assistantMessageId === terminalAssistantMessageId
1860+
? { actualModel: event.payload.actualModel }
1861+
: {}),
18441862
}),
18451863
{ concurrency: 1 },
18461864
).pipe(Effect.asVoid);

‎apps/server/src/orchestration/decider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
12591259
messageId: command.messageId,
12601260
role: "assistant",
12611261
text: "",
1262+
...(command.actualModel ? { actualModel: command.actualModel } : {}),
12621263
turnId: command.turnId ?? null,
12631264
streaming: false,
12641265
createdAt: command.createdAt,

‎apps/server/src/orchestration/projector.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ export function projectEvent(
507507
id: payload.messageId,
508508
role: payload.role,
509509
text: payload.text,
510+
...(payload.actualModel !== undefined ? { actualModel: payload.actualModel } : {}),
510511
...(payload.attachments !== undefined ? { attachments: payload.attachments } : {}),
511512
turnId: payload.turnId,
512513
streaming: payload.streaming,
@@ -531,6 +532,9 @@ export function projectEvent(
531532
streaming: message.streaming,
532533
updatedAt: message.updatedAt,
533534
turnId: message.turnId,
535+
...(message.actualModel !== undefined
536+
? { actualModel: message.actualModel }
537+
: {}),
534538
...(message.attachments !== undefined
535539
? { attachments: message.attachments }
536540
: {}),

‎apps/server/src/persistence/Layers/ProjectionThreadMessages.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,43 @@ const layer = it.layer(
1212
);
1313

1414
layer("ProjectionThreadMessageRepository", (it) => {
15+
it.effect("persists actual model metadata across later partial upserts", () =>
16+
Effect.gen(function* () {
17+
const repository = yield* ProjectionThreadMessageRepository;
18+
const threadId = ThreadId.make("thread-actual-model");
19+
const messageId = MessageId.make("message-actual-model");
20+
const createdAt = "2026-08-14T00:00:00.000Z";
21+
22+
yield* repository.upsert({
23+
messageId,
24+
threadId,
25+
turnId: null,
26+
role: "assistant",
27+
text: "complete",
28+
actualModel: "gpt-5.6-luna",
29+
isStreaming: false,
30+
createdAt,
31+
updatedAt: createdAt,
32+
});
33+
yield* repository.upsert({
34+
messageId,
35+
threadId,
36+
turnId: null,
37+
role: "assistant",
38+
text: "complete",
39+
isStreaming: false,
40+
createdAt,
41+
updatedAt: "2026-08-14T00:00:01.000Z",
42+
});
43+
44+
const row = yield* repository.getByMessageId({ messageId });
45+
assert.equal(row._tag, "Some");
46+
if (row._tag === "Some") {
47+
assert.equal(row.value.actualModel, "gpt-5.6-luna");
48+
}
49+
}),
50+
);
51+
1552
it.effect("preserves existing attachments when upsert omits attachments", () =>
1653
Effect.gen(function* () {
1754
const repository = yield* ProjectionThreadMessageRepository;

‎apps/server/src/persistence/Layers/ProjectionThreadMessages.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Layer from "effect/Layer";
55
import * as Option from "effect/Option";
66
import * as Schema from "effect/Schema";
77
import * as Struct from "effect/Struct";
8-
import { ChatAttachment } from "@t3tools/contracts";
8+
import { ChatAttachment, TrimmedNonEmptyString } from "@t3tools/contracts";
99

1010
import { toPersistenceSqlError } from "../Errors.ts";
1111
import {
@@ -20,6 +20,7 @@ import {
2020
const ProjectionThreadMessageDbRowSchema = ProjectionThreadMessage.mapFields(
2121
Struct.assign({
2222
isStreaming: Schema.Number,
23+
actualModel: Schema.NullOr(TrimmedNonEmptyString),
2324
attachments: Schema.NullOr(Schema.fromJsonString(Schema.Array(ChatAttachment))),
2425
}),
2526
);
@@ -33,6 +34,7 @@ function toProjectionThreadMessage(
3334
turnId: row.turnId,
3435
role: row.role,
3536
text: row.text,
37+
...(row.actualModel !== null ? { actualModel: row.actualModel } : {}),
3638
isStreaming: row.isStreaming === 1,
3739
createdAt: row.createdAt,
3840
updatedAt: row.updatedAt,
@@ -55,6 +57,7 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
5557
turn_id,
5658
role,
5759
text,
60+
actual_model,
5861
attachments_json,
5962
is_streaming,
6063
created_at,
@@ -66,6 +69,14 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
6669
${row.turnId},
6770
${row.role},
6871
${row.text},
72+
COALESCE(
73+
${row.actualModel ?? null},
74+
(
75+
SELECT actual_model
76+
FROM projection_thread_messages
77+
WHERE message_id = ${row.messageId}
78+
)
79+
),
6980
COALESCE(
7081
${nextAttachmentsJson},
7182
(
@@ -84,6 +95,10 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
8495
turn_id = excluded.turn_id,
8596
role = excluded.role,
8697
text = excluded.text,
98+
actual_model = COALESCE(
99+
excluded.actual_model,
100+
projection_thread_messages.actual_model
101+
),
87102
attachments_json = COALESCE(
88103
excluded.attachments_json,
89104
projection_thread_messages.attachments_json
@@ -106,6 +121,7 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
106121
turn_id AS "turnId",
107122
role,
108123
text,
124+
actual_model AS "actualModel",
109125
attachments_json AS "attachments",
110126
is_streaming AS "isStreaming",
111127
created_at AS "createdAt",
@@ -127,6 +143,7 @@ const makeProjectionThreadMessageRepository = Effect.gen(function* () {
127143
turn_id AS "turnId",
128144
role,
129145
text,
146+
actual_model AS "actualModel",
130147
attachments_json AS "attachments",
131148
is_streaming AS "isStreaming",
132149
created_at AS "createdAt",

‎apps/server/src/persistence/Migrations.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import Migration0037 from "./Migrations/037_ProjectionTurnsKeysetIndex.ts";
5353
import Migration0038 from "./Migrations/038_ProjectionThreadsPinOrderKey.ts";
5454
import Migration0039 from "./Migrations/039_ProjectionProjectsDefaultThreadEnvMode.ts";
5555
import Migration0040 from "./Migrations/040_ProjectionProjectFaviconPath.ts";
56+
import Migration0041 from "./Migrations/041_ProjectionThreadMessageActualModel.ts";
5657

5758
/**
5859
* Migration loader with all migrations defined inline.
@@ -105,6 +106,7 @@ export const migrationEntries = [
105106
[38, "ProjectionThreadsPinOrderKey", Migration0038],
106107
[39, "ProjectionProjectsDefaultThreadEnvMode", Migration0039],
107108
[40, "ProjectionProjectFaviconPath", Migration0040],
109+
[41, "ProjectionThreadMessageActualModel", Migration0041],
108110
] as const;
109111

110112
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);

0 commit comments

Comments
 (0)