@devries-cameron20 / t3code Mirror · read-only / commits / 9f4b42e750
Fork 0

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, 19:45 UTC

fix(server): thread find skips empty replies hidden beside an HTML render (#34991)

Julius Marminge committed Nov 12, 2026 at 02:28 UTC 9f4b42e7509841d711eb893b30e77e78e9b9397f
2 files changed +77 -8
apps/server/src/orchestration-v2/ThreadFind.test.ts
+22
@@ -372,6 +372,28 @@ describe("V2 thread find", () => {
372 }).pipe(Effect.provide(layerTest)),
373 );
374
375 + it.effect("skips the empty-response fallback the timeline hides beside an HTML render", () =>
376 + Effect.gen(function* () {
377 + const projection = yield* setup;
378 + const shownRunId = RunId.make("run:shown");
379 + yield* commit([run(threadId, shownRunId, 2)]);
380 + yield* putItems([
381 + {
382 + ...item("render", 0, ""),
383 + type: "dynamic_tool",
384 + toolName: "html_render",
385 + input: {},
386 + output: { htmlRender: { attachmentId: "visual", title: "Result", height: 120 } },
387 + },
388 + item("hidden", 1, ""),
389 + { ...item("shown", 2, ""), runId: shownRunId },
390 + ]);
391 + const result = yield* projection.searchThread({ threadId, query: "empty" });
392 + assert.equal(result.totalMatches, 1);
393 + assert.equal(result.match?.entryId, "shown");
394 + }).pipe(Effect.provide(layerTest)),
395 + );
396 +
397 it.effect("searches displayed skill labels and invalidates parsed text when labels change", () =>
398 Effect.gen(function* () {
399 const projection = yield* setup;
apps/server/src/orchestration-v2/ThreadFind.ts
+55 -8
@@ -9,6 +9,7 @@ import {
9 } from "@t3tools/contracts";
10 import { searchableMessageSegments, searchablePlanSegments } from "@t3tools/shared/threadFindText";
11 import { countThreadSearchOccurrences } from "@t3tools/shared/threadSearch";
12 +import { htmlRenderFromToolItem, mcpAppFromToolItem } from "@t3tools/shared/toolOutput";
13 import * as Cache from "effect/Cache";
14 import * as Data from "effect/Data";
15 import * as Effect from "effect/Effect";
@@ -34,6 +35,7 @@ interface FindPayload extends FindRow {
35 readonly entryId: string;
36 readonly runId: OrchestrationV2TurnItem["runId"];
37 readonly type: OrchestrationV2TurnItem["type"];
38 + readonly emptyText: boolean;
39 }
40 interface FindDocument extends FindRow {
41 readonly entryId: string;
@@ -177,7 +179,7 @@ function resultForSelection(
179 export const makeThreadFind = Effect.fn("makeThreadFind")(function* (
180 readIndex: (threadId: ThreadId) => Effect.Effect<
181 readonly (Omit<FindRow, "position"> & {
180 - readonly item: Pick<OrchestrationV2TurnItem, "type">;
182 + readonly item: Pick<OrchestrationV2TurnItem, "type" | "runId">;
183 })[],
184 ProjectionStoreV2Error
185 >,
@@ -216,11 +218,13 @@ export const makeThreadFind = Effect.fn("makeThreadFind")(function* (
218 entry_id: string;
219 run_id: OrchestrationV2TurnItem["runId"];
220 item_type: OrchestrationV2TurnItem["type"];
221 + empty_text: number | null;
222 }>`
223 SELECT item.thread_id, item.turn_item_id, item.payload_json,
224 COALESCE(json_extract(item.payload_json, '$.messageId'), item.turn_item_id) AS entry_id,
225 json_extract(item.payload_json, '$.runId') AS run_id,
223 - json_extract(item.payload_json, '$.type') AS item_type
226 + json_extract(item.payload_json, '$.type') AS item_type,
227 + json_extract(item.payload_json, '$.text') = '' AS empty_text
228 FROM orchestration_v2_projection_turn_items AS item
229 JOIN json_each(${sources}) AS wanted
230 ON item.thread_id = json_extract(wanted.value, '$.threadId')
@@ -242,6 +246,7 @@ export const makeThreadFind = Effect.fn("makeThreadFind")(function* (
246 entryId: payload.entry_id,
247 runId: payload.run_id,
248 type: payload.item_type,
249 + emptyText: payload.empty_text === 1,
250 });
251 });
252 });
@@ -315,11 +320,33 @@ export const makeThreadFind = Effect.fn("makeThreadFind")(function* (
320 row.item.type,
321 ),
322 );
318 - const payloads: FindPayload[] = [];
319 - for (let start = 0; start < candidates.length; start += 128) {
320 - payloads.push(...(yield* load(threadId, candidates.slice(start, start + 128))));
321 - }
322 - return { payloads, cwd, sequence, cacheKey, sourceThreadIds };
323 + const loadAll = Effect.fnUntraced(function* (rows: readonly FindRow[]) {
324 + const loaded: FindPayload[] = [];
325 + for (let start = 0; start < rows.length; start += 128) {
326 + loaded.push(...(yield* load(threadId, rows.slice(start, start + 128))));
327 + }
328 + return loaded;
329 + });
330 + const payloads = yield* loadAll(candidates);
331 + // Only runs with an empty reply can hide its fallback, so other tool payloads stay unread.
332 + const emptyReplyRunIds = new Set(
333 + payloads.flatMap((row) =>
334 + row.type === "assistant_message" && row.emptyText && row.runId !== null
335 + ? [row.runId]
336 + : [],
337 + ),
338 + );
339 + const toolPayloads = yield* loadAll(
340 + index
341 + .map((row, position) => ({ ...row, position }))
342 + .filter(
343 + (row) =>
344 + row.item.type === "dynamic_tool" &&
345 + row.item.runId !== null &&
346 + emptyReplyRunIds.has(row.item.runId),
347 + ),
348 + );
349 + return { payloads, toolPayloads, cwd, sequence, cacheKey, sourceThreadIds };
350 },
351 (effect) => sql.withTransaction(effect).pipe(NodeSqliteClient.readOnly),
352 (effect, input) =>
@@ -338,7 +365,7 @@ export const makeThreadFind = Effect.fn("makeThreadFind")(function* (
365 // Release SQLite before decoding and parsing. Both frames describe one snapshot.
366 const data = yield* snapshot(input, scans);
367 if (data.result) return Stream.succeed(data.result);
341 - const { payloads, cwd, sequence, cacheKey, sourceThreadIds } = data;
368 + const { payloads, toolPayloads, cwd, sequence, cacheKey, sourceThreadIds } = data;
369 const decode = (row: FindPayload) =>
370 decodeItem(row.payload).pipe(
371 Effect.map((item) => ({ ...row, item })),
@@ -354,6 +381,17 @@ export const makeThreadFind = Effect.fn("makeThreadFind")(function* (
381 if (item.type === "user_input_request" && item.questionAnswer)
382 foldedAnswerRunIds.set(`async-answer:${item.questionAnswer.requestId}`, item.runId);
383 }
384 + // The timeline hides an empty reply's fallback when its run shows an HTML render or MCP app.
385 + const embeddedResultRunIds = new Set<OrchestrationV2TurnItem["runId"]>();
386 + for (const payload of toolPayloads) {
387 + const { item } = yield* decode(payload);
388 + if (
389 + item.type === "dynamic_tool" &&
390 + ((item.status === "completed" && htmlRenderFromToolItem(item)) ||
391 + mcpAppFromToolItem(item))
392 + )
393 + embeddedResultRunIds.add(item.runId);
394 + }
395 const rows = payloads.filter(
396 (row) =>
397 row.type !== "user_input_request" &&
@@ -364,6 +402,15 @@ export const makeThreadFind = Effect.fn("makeThreadFind")(function* (
402 const cached = documents.get(row.position);
403 if (cached) return cached;
404 const decoded = yield* decode(row);
405 + if (
406 + decoded.item.type === "assistant_message" &&
407 + decoded.item.text === "" &&
408 + embeddedResultRunIds.has(decoded.item.runId)
409 + ) {
410 + const document = documentFor(decoded, 0);
411 + documents.set(row.position, document);
412 + return document;
413 + }
414 const key = textKey(decoded.item, cwd, input.skills ?? []);
415 const segments = yield* Cache.get(
416 key.text.length <= 32_768 ? textCache.text : textCache.largeText,