Skip to content

Commit 653d807

Browse files
committed
fix(server): settle streamed reasoning without a completion detail
1 parent 8b7643f commit 653d807

3 files changed

Lines changed: 81 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,16 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
10981098
previousActivity,
10991099
event.payload.activity,
11001100
);
1101+
// A reasoning settle with no streamed row and no text of its own is an
1102+
// orphan (codex completes reasoning items without a detail string);
1103+
// inserting it would render an empty Thought entry.
1104+
if (
1105+
activity.kind === "reasoning" &&
1106+
previousActivity === undefined &&
1107+
typeof (activity.payload as { detail?: unknown } | null)?.detail !== "string"
1108+
) {
1109+
return;
1110+
}
11011111
yield* projectionThreadActivityRepository.upsert({
11021112
activityId: activity.id,
11031113
threadId: event.payload.threadId,

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,73 @@ describe("ProviderRuntimeIngestion", () => {
10701070
).toBe(false);
10711071
});
10721072

1073+
it("settles a streamed reasoning activity when the completion has no detail", async () => {
1074+
const harness = await createHarness();
1075+
1076+
// An orphan settle — no streamed row, no detail — must not create a row.
1077+
// Emitted first so the wait below proves it was processed and dropped.
1078+
harness.emit({
1079+
type: "item.completed",
1080+
eventId: asEventId("evt-reasoning-orphan-completed"),
1081+
provider: ProviderDriverKind.make("codex"),
1082+
createdAt: "2026-01-01T00:00:00.000Z",
1083+
threadId: asThreadId("thread-1"),
1084+
turnId: asTurnId("turn-reasoning"),
1085+
itemId: asItemId("item-orphan"),
1086+
payload: {
1087+
itemType: "reasoning",
1088+
status: "completed",
1089+
},
1090+
});
1091+
harness.emit({
1092+
type: "content.delta",
1093+
eventId: asEventId("evt-reasoning-nodetail-delta"),
1094+
provider: ProviderDriverKind.make("claudeAgent"),
1095+
createdAt: "2026-01-01T00:00:01.000Z",
1096+
threadId: asThreadId("thread-1"),
1097+
turnId: asTurnId("turn-reasoning"),
1098+
itemId: asItemId("item-nodetail"),
1099+
payload: {
1100+
streamKind: "reasoning_text",
1101+
delta: "Weighing options",
1102+
},
1103+
});
1104+
// Completion without a detail string (codex reasoning items usually carry
1105+
// none) must still flip the streamed activity out of its live state.
1106+
harness.emit({
1107+
type: "item.completed",
1108+
eventId: asEventId("evt-reasoning-nodetail-completed"),
1109+
provider: ProviderDriverKind.make("claudeAgent"),
1110+
createdAt: "2026-01-01T00:00:02.000Z",
1111+
threadId: asThreadId("thread-1"),
1112+
turnId: asTurnId("turn-reasoning"),
1113+
itemId: asItemId("item-nodetail"),
1114+
payload: {
1115+
itemType: "reasoning",
1116+
status: "completed",
1117+
},
1118+
});
1119+
1120+
const thread = await waitForThread(harness.readModel, (entry) =>
1121+
entry.activities.some(
1122+
(activity: ProviderRuntimeTestActivity) =>
1123+
activity.id === "reasoning:thread-1:item-nodetail" &&
1124+
(activity.payload as { streaming?: boolean }).streaming === false,
1125+
),
1126+
);
1127+
expect(
1128+
thread.activities.find(
1129+
(activity: ProviderRuntimeTestActivity) =>
1130+
activity.id === "reasoning:thread-1:item-nodetail",
1131+
)?.payload,
1132+
).toMatchObject({ detail: "Weighing options", streaming: false });
1133+
expect(
1134+
thread.activities.some(
1135+
(activity: ProviderRuntimeTestActivity) => activity.id === "reasoning:thread-1:item-orphan",
1136+
),
1137+
).toBe(false);
1138+
});
1139+
10731140
it("merges streamed reasoning into one persisted activity and settles it", async () => {
10741141
const harness = await createHarness();
10751142

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,10 @@ export function runtimeEventToActivities(
840840

841841
case "item.completed": {
842842
if (event.payload.itemType === "reasoning") {
843+
// Settle even without a detail string — a streamed activity must flip
844+
// streaming:false or it renders as live Thinking forever; the merge
845+
// keeps the accumulated delta text when the completion carries none.
843846
const detail = event.payload.detail?.trim();
844-
if (!detail) {
845-
return [];
846-
}
847847
return [
848848
{
849849
id: reasoningActivityId(event),
@@ -852,7 +852,7 @@ export function runtimeEventToActivities(
852852
kind: "reasoning",
853853
summary: event.payload.title ?? "Thought",
854854
payload: {
855-
detail,
855+
...(detail ? { detail } : {}),
856856
streaming: false,
857857
},
858858
turnId: toTurnId(event.turnId) ?? null,

0 commit comments

Comments
 (0)