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, 08:30 UTC
fix(server): thread reads no longer load every run of the thread (#37915)
Julius Marminge committed
Nov 16, 2026 at 21:57 UTC
c71f98cadf66f121d5e6ae25057bfc68792bc02c
10 files changed
+149
-35
apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
+5
@@ -220,6 +220,7 @@ it("readThread preserves caller access errors and prefers activity-run status ov
220
input.threadId === parentThreadId
221
? Effect.succeed(projection)
222
: Effect.die(`unexpected thread ${input.threadId}`),
223
+ getRunCount: () => Effect.succeed(projection.runs.length),
224
} satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
225
ServerSettings.layerTest(),
226
Layer.mock(ProviderRegistry.ProviderRegistry)({
@@ -364,6 +365,7 @@ it("readThread pages cut-off text without splitting an emoji across pages", asyn
365
},
366
getThreadRecords: () => Effect.succeed(projection),
367
getProjectThreadRecords: () => Effect.succeed(projection),
368
+ getRunCount: () => Effect.succeed(projection.runs.length),
369
getThreadShell: () =>
370
Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell),
371
} satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
@@ -471,6 +473,7 @@ it("readThread returns the newest items that fit the response budget", async ()
473
},
474
getThreadRecords: () => Effect.succeed(projection),
475
getProjectThreadRecords: () => Effect.succeed(projection),
476
+ getRunCount: () => Effect.succeed(projection.runs.length),
477
getThreadShell: () =>
478
Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell),
479
} satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
@@ -577,6 +580,7 @@ it("readThread keeps an activity page within an MCP client's output limit and pa
580
},
581
getThreadRecords: () => Effect.succeed(projection),
582
getProjectThreadRecords: () => Effect.succeed(projection),
583
+ getRunCount: () => Effect.succeed(projection.runs.length),
584
getThreadShell: () =>
585
Effect.succeed(projection.thread as unknown as OrchestrationV2ThreadShell),
586
} satisfies Partial<ThreadManagementService.ThreadManagementService["Service"]>),
@@ -858,6 +862,7 @@ it("readThread and sendToThread reach threads in other projects", async () => {
862
hasMore: false,
863
hasEarlier: false,
864
}),
865
+ getRunCount: (threadId) => Effect.succeed(foreignProjection(threadId).runs.length),
866
getProjectThreadRecords: (input) =>
867
input.threadId === foreignThreadId && input.projectId === foreignProjectId
868
? Effect.succeed(foreignProjection(input.threadId))
apps/server/src/mcp/OrchestratorMcpService.ts
+43
-17
@@ -973,6 +973,7 @@ function listItemFromShell(
973
function threadDetail(
974
scope: McpInvocationScope,
975
projection: Pick<OrchestrationV2ThreadProjection, "thread" | "runs" | "runtimeRequests">,
976
+ runCount: number,
977
itemCount: number,
978
shell: OrchestrationV2ThreadShell,
979
nowMs: number,
@@ -1018,7 +1019,7 @@ function threadDetail(
1019
...(projection.thread.delegatedFrom == null
1020
? {}
1021
: { delegatedFrom: projection.thread.delegatedFrom }),
1021
- runCount: projection.runs.length,
1022
+ runCount,
1023
itemCount,
1024
pendingRequestCount: projection.runtimeRequests.filter(
1025
(request) => request.status === "pending",
@@ -1464,6 +1465,7 @@ const make = Effect.gen(function* () {
1465
const loadReadableThread = Effect.fn("OrchestratorMcpService.loadReadableThread")(function* (
1466
scope: McpInvocationScope,
1467
threadId: ThreadId,
1468
+ runLimit: number,
1469
) {
1470
const { parent } = yield* loadCaller(scope, []);
1471
const shell = yield* threadManagement
@@ -1478,20 +1480,38 @@ const make = Effect.gen(function* () {
1480
);
1481
}
1482
const input = { projectId: shell.projectId, threadId };
1481
- // Transfers are needed only to acknowledge a caller's child-task result.
1482
- const records =
1483
- parent === undefined
1484
- ? threadManagement
1485
- .getProjectThreadRecords(input, ["runs", "providerTurns", "runtimeRequests"])
1486
- .pipe(Effect.map((target) => ({ ...target, contextTransfers: [] })))
1487
- : threadManagement.getProjectThreadRecords(input, [
1488
- "runs",
1489
- "providerTurns",
1490
- "runtimeRequests",
1491
- "contextTransfers",
1492
- ]);
1493
- const target = yield* records.pipe(Effect.mapError(threadManagementFailure));
1494
- return { parent, target, shell } as const;
1483
+ // Acknowledging a caller's child-task result matches it against every run and transfer.
1484
+ if (
1485
+ parent !== undefined &&
1486
+ shell.lineage.parentThreadId === parent.thread.id &&
1487
+ shell.lineage.relationshipToParent === "subagent"
1488
+ ) {
1489
+ const target = yield* threadManagement
1490
+ .getProjectThreadRecords(input, [
1491
+ "runs",
1492
+ "providerTurns",
1493
+ "runtimeRequests",
1494
+ "contextTransfers",
1495
+ ])
1496
+ .pipe(Effect.mapError(threadManagementFailure));
1497
+ return { parent, target, shell, runCount: target.runs.length } as const;
1498
+ }
1499
+ // Long threads hold thousands of runs; the read shows only the recent and active ones.
1500
+ const [records, runCount] = yield* Effect.all([
1501
+ threadManagement.getProjectThreadRecords(input, ["runs", "runtimeRequests"], {
1502
+ latestRunLimit: runLimit,
1503
+ runStatuses: ThreadManagementService.ACTIVE_RUN_STATUSES,
1504
+ runtimeRequestStatuses: ["pending"],
1505
+ }),
1506
+ threadManagement.getRunCount(threadId),
1507
+ ]).pipe(Effect.mapError(threadManagementFailure));
1508
+ const { providerTurns } = yield* threadManagement
1509
+ .getProjectThreadRecords(input, ["providerTurns"], {
1510
+ providerTurnAttemptIds: records.runs.flatMap((run) => run.activeAttemptId ?? []),
1511
+ })
1512
+ .pipe(Effect.mapError(threadManagementFailure));
1513
+ const target = { ...records, providerTurns, contextTransfers: [] };
1514
+ return { parent, target, shell, runCount } as const;
1515
});
1516
1517
const loadProviders = providerRegistry.getProviders;
@@ -3302,7 +3322,12 @@ const make = Effect.gen(function* () {
3322
} satisfies OrchestratorMcpThreadListResult;
3323
}),
3324
readThread: Effect.fn("OrchestratorMcpService.readThread")(function* (scope, input) {
3305
- const { parent, target, shell } = yield* loadReadableThread(scope, input.threadId);
3325
+ const runLimit = input.runLimit ?? DEFAULT_THREAD_RUN_LIMIT;
3326
+ const { parent, target, shell, runCount } = yield* loadReadableThread(
3327
+ scope,
3328
+ input.threadId,
3329
+ runLimit,
3330
+ );
3331
const view = input.view ?? "messages";
3332
const limit = input.limit ?? DEFAULT_THREAD_READ_LIMIT;
3333
const maxChars = input.maxCharsPerItem ?? DEFAULT_THREAD_ITEM_MAX_CHARS;
@@ -3341,6 +3366,7 @@ const make = Effect.gen(function* () {
3366
const thread = threadDetail(
3367
scope,
3368
target,
3369
+ runCount,
3370
timeline.totalItems,
3371
shell,
3372
yield* Clock.currentTimeMillis,
@@ -3350,7 +3376,7 @@ const make = Effect.gen(function* () {
3376
);
3377
const recentRuns = target.runs
3378
.toSorted((left, right) => right.ordinal - left.ordinal)
3353
- .slice(0, input.runLimit ?? DEFAULT_THREAD_RUN_LIMIT)
3379
+ .slice(0, runLimit)
3380
.map((run) => threadRun(target, run));
3381
const { items, start } = timelineItemsWithinBudget(
3382
{ thread, recentRuns, nextPosition: null, hasMore: false, earlierPosition: null },
apps/server/src/mcp/toolkits/core.test.ts
+1
@@ -1336,6 +1336,7 @@ it.effect("discovers workflow stop targets and requires orchestration capability
1336
getThreadShell: (id) => Effect.succeed(McpToolAccessTestkit.liveThreadShell(id)),
1337
getProjectThreadRecords: () =>
1338
Effect.succeed(McpToolAccessTestkit.idleThreadProjection(shell)),
1339
+ getRunCount: () => Effect.succeed(1),
1340
getTimelinePage: () =>
1341
Effect.succeed({ items: [row], totalItems: 1, hasMore: false, hasEarlier: false }),
1342
stopWorkflow: (input) =>
apps/server/src/orchestration-v2/Orchestrator.ts
+6
@@ -436,6 +436,7 @@ export interface OrchestratorV2Shape {
436
options: ProjectionTimelinePageOptions,
437
) => Effect.Effect<ProjectionTimelinePage, OrchestratorProjectionError>;
438
readonly getMessageCount: (threadId: ThreadId) => Effect.Effect<number, OrchestratorV2Error>;
439
+ readonly getRunCount: (threadId: ThreadId) => Effect.Effect<number, OrchestratorV2Error>;
440
readonly getMessagesById: (
441
threadId: ThreadId,
442
messageIds: ReadonlyArray<MessageId>,
@@ -16229,6 +16230,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
16230
.getMessageCount(threadId)
16231
.pipe(Effect.mapError((cause) => new OrchestratorProjectionError({ threadId, cause })));
16232
}),
16233
+ getRunCount: Effect.fn("OrchestratorV2.getRunCount")(function (threadId) {
16234
+ return projectionStore
16235
+ .getRunCount(threadId)
16236
+ .pipe(Effect.mapError((cause) => new OrchestratorProjectionError({ threadId, cause })));
16237
+ }),
16238
getMessagesById: Effect.fn("OrchestratorV2.getMessagesById")(function (threadId, messageIds) {
16239
return projectionStore
16240
.getMessagesById(threadId, messageIds)
apps/server/src/orchestration-v2/ProjectionStore.test.ts
+25
@@ -729,6 +729,31 @@ it.effect("idle compaction filters keep the latest run, live work and the newest
729
.join("\n");
730
assert.notInclude(runPlan, "orchestration_v2_projection_runs_thread_ordinal_idx");
731
assert.match(runPlan, /SEARCH orchestration_v2_projection_runs USING INDEX \w*status\w*/);
732
+ // The newest runs by ordinal, whatever their status, plus older runs the statuses match.
733
+ for (const [filter, expected] of [
734
+ [{ latestRunLimit: 2 }, [4, 5]],
735
+ [{ latestRunLimit: 2, runStatuses: ["rolled_back"] as const }, [1, 4, 5]],
736
+ ] as const) {
737
+ const traced = traceSqlStatements();
738
+ const recent = yield* store
739
+ .getThreadRecords(threadId, ["runs"], filter)
740
+ .pipe(Effect.withTracer(traced.tracer));
741
+ assert.deepEqual(
742
+ recent.runs.map((run) => run.ordinal),
743
+ [...expected],
744
+ );
745
+ const recentQuery = traced.statements.find((statement) =>
746
+ statement.includes("FROM orchestration_v2_projection_runs"),
747
+ );
748
+ assert.isDefined(recentQuery);
749
+ // Fetches the chosen runs by key instead of walking every run of the thread.
750
+ assert.match(
751
+ (yield* sql.unsafe<{ readonly detail: string }>(`EXPLAIN QUERY PLAN ${recentQuery}`))
752
+ .map((row) => row.detail)
753
+ .join("\n"),
754
+ /^SEARCH orchestration_v2_projection_runs USING INDEX \w+ \(run_id=\?\)/,
755
+ );
756
+ }
757
// An id filter reads by primary key, not every row of the thread.
758
const byId = traceSqlStatements();
759
const found = yield* store
apps/server/src/orchestration-v2/ProjectionStore.ts
+59
-18
@@ -363,6 +363,8 @@ export interface ProjectionRecordFilter {
363
readonly runStatuses?: ReadonlyArray<OrchestrationV2Run["status"]>;
364
/** Keeps the thread's highest-ordinal run even when `runStatuses` excludes it. */
365
readonly includeLatestRun?: true;
366
+ /** The thread's N highest-ordinal runs, plus any run `runStatuses` matches. Ignores `includeLatestRun`. */
367
+ readonly latestRunLimit?: number;
368
readonly providerTurnThreadIds?: ReadonlyArray<ProviderThreadId>;
369
/** Only the provider turn whose token usage was updated last. */
370
readonly latestProviderTurnUsageOnly?: true;
@@ -536,6 +538,7 @@ export interface ProjectionStoreV2Shape {
538
limit: number,
539
) => Effect.Effect<number, ProjectionStoreV2Error>;
540
readonly getSubagentCount: (threadId: ThreadId) => Effect.Effect<number, ProjectionStoreV2Error>;
541
+ readonly getRunCount: (threadId: ThreadId) => Effect.Effect<number, ProjectionStoreV2Error>;
542
/** Child threads of the thread's app-owned tasks, in task order, without decoding the tasks. */
543
readonly listAppOwnedChildThreadIds: (
544
threadId: ThreadId,
@@ -3925,23 +3928,43 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
3928
(fields !== undefined && !fields.includes("runs")) ||
3929
(window === undefined &&
3930
(matchesNothing(filter?.runIds) ||
3928
- (matchesNothing(filter?.runStatuses) && filter?.includeLatestRun !== true)))
3931
+ (matchesNothing(filter?.runStatuses) &&
3932
+ filter?.includeLatestRun !== true &&
3933
+ filter?.latestRunLimit === undefined)))
3934
? Effect.succeed([])
3935
: window === undefined
3936
? sql<PayloadRow>`
3937
SELECT payload_json
3938
FROM orchestration_v2_projection_runs
3934
- WHERE ${threadColumn(filter?.runIds)} = ${threadId}
3939
+ WHERE ${threadColumn(filter?.latestRunLimit === undefined ? filter?.runIds : [])} = ${threadId}
3940
${filter?.runIds === undefined ? sql`` : sql`AND run_id IN (SELECT value FROM json_each(${encodeIdList(filter.runIds)}))`}
3941
${
3937
- filter?.runStatuses === undefined
3938
- ? sql`ORDER BY ordinal ASC`
3939
- : filter.includeLatestRun !== true
3940
- ? // `+ordinal` stops SQLite from walking every run in the (thread_id, ordinal)
3941
- // index to skip a sort; a status index reads only matching runs.
3942
- sql`AND status IN (SELECT value FROM json_each(${encodeIdList(filter.runStatuses)}))
3942
+ filter?.latestRunLimit !== undefined
3943
+ ? sql`AND run_id IN (
3944
+ SELECT run_id FROM (
3945
+ SELECT run_id FROM orchestration_v2_projection_runs
3946
+ WHERE thread_id = ${threadId}
3947
+ ORDER BY ordinal DESC
3948
+ LIMIT ${filter.latestRunLimit}
3949
+ )
3950
+ ${
3951
+ filter.runStatuses === undefined
3952
+ ? sql``
3953
+ : sql`UNION
3954
+ SELECT run_id FROM orchestration_v2_projection_runs
3955
+ WHERE thread_id = ${threadId}
3956
+ AND status IN (SELECT value FROM json_each(${encodeIdList(filter.runStatuses)}))`
3957
+ }
3958
+ )
3959
+ ORDER BY ordinal ASC`
3960
+ : filter?.runStatuses === undefined
3961
+ ? sql`ORDER BY ordinal ASC`
3962
+ : filter.includeLatestRun !== true
3963
+ ? // `+ordinal` stops SQLite from walking every run in the (thread_id, ordinal)
3964
+ // index to skip a sort; a status index reads only matching runs.
3965
+ sql`AND status IN (SELECT value FROM json_each(${encodeIdList(filter.runStatuses)}))
3966
ORDER BY +ordinal ASC`
3944
- : sql`AND (status IN (SELECT value FROM json_each(${encodeIdList(filter.runStatuses)}))
3967
+ : sql`AND (status IN (SELECT value FROM json_each(${encodeIdList(filter.runStatuses)}))
3968
OR run_id = (
3969
SELECT run_id FROM orchestration_v2_projection_runs
3970
WHERE thread_id = ${threadId}
@@ -6317,6 +6340,13 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6340
Effect.map((rows) => rows[0]?.bytes ?? 0),
6341
Effect.mapError(controlReadError(threadId)),
6342
);
6343
+ const getRunCount: ProjectionStoreV2Shape["getRunCount"] = (threadId) =>
6344
+ sql<{
6345
+ count: number;
6346
+ }>`SELECT COUNT(*) AS count FROM orchestration_v2_projection_runs WHERE thread_id = ${threadId}`.pipe(
6347
+ Effect.map((rows) => rows[0]?.count ?? 0),
6348
+ Effect.mapError(controlReadError(threadId)),
6349
+ );
6350
const getSubagentCount: ProjectionStoreV2Shape["getSubagentCount"] = (threadId) =>
6351
sql<{
6352
count: number;
@@ -6804,7 +6834,6 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6834
*/
6835
const readTimelineWindow = Effect.fn("ProjectionStore.readTimelineWindow")(function* (
6836
threadId: ThreadId,
6807
- runs: ProjectionRecords<"runs">["runs"],
6837
includePersistentOutput: boolean,
6838
where: Statement.Fragment,
6839
limit: Statement.Fragment = sql``,
@@ -6823,7 +6852,9 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6852
persistent_output: number;
6853
attempt_id: string | null;
6854
attempt_status: string | null;
6855
+ run_status: OrchestrationV2Run["status"] | null;
6856
}>`SELECT item.turn_item_id, item.run_id, item.node_id, item.parent_item_id, item.type, item.status, item.ordinal,
6857
+ run.status AS run_status,
6858
${includePersistentOutput ? sql`attempt.attempt_id` : sql`NULL`} AS attempt_id,
6859
${includePersistentOutput ? sql`attempt.status` : sql`NULL`} AS attempt_status,
6860
${includePersistentOutput ? sql`item.inline_work_output` : sql`0`} AS persistent_output,
@@ -6831,6 +6862,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6862
CASE WHEN item.type = 'user_message' THEN json_extract(item.payload_json, '$.createdBy') END AS created_by,
6863
CASE WHEN item.type IN ('user_message', 'assistant_message') THEN json_extract(item.payload_json, '$.messageId') END AS message_id
6864
FROM orchestration_v2_projection_turn_items AS item
6865
+ LEFT JOIN orchestration_v2_projection_runs AS run ON run.run_id = item.run_id
6866
${
6867
includePersistentOutput
6868
? sql`LEFT JOIN orchestration_v2_projection_nodes AS node ON node.node_id = item.node_id
@@ -6843,7 +6875,6 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6875
}
6876
WHERE item.thread_id = ${threadId} ${where}
6877
ORDER BY item.ordinal ASC, item.turn_item_id ASC ${limit}`;
6846
- const runStatuses = new Map(runs.map((run) => [String(run.id), run.status]));
6878
return rows.map((row): TimelineIndexItem => ({
6879
id: TurnItemId.make(row.turn_item_id),
6880
threadId,
@@ -6853,7 +6884,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6884
type: row.type,
6885
status: row.status,
6886
ordinal: row.ordinal,
6856
- runStatus: row.run_id === null ? undefined : runStatuses.get(row.run_id),
6887
+ runStatus: row.run_status ?? undefined,
6888
attemptId: row.attempt_id,
6889
attemptStatus: row.attempt_status,
6890
persistentOutput: row.persistent_output === 1,
@@ -6895,9 +6926,18 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6926
AND NOT (json_extract(payload_json, '$.forkedFrom.type') IS 'run'
6927
AND json_extract(payload_json, '$.lineage.sideChat') IS NOT 1)`;
6928
if (ownRowsOnly.length === 0) return null;
6898
- const records = yield* getThreadRecords(threadId, ["runs", "attempts"]);
6929
+ const records = yield* getThreadRecords(threadId, []);
6930
if (inheritedRunFork(records.thread) !== null) return null;
6900
- const superseded = records.attempts.filter((attempt) => attempt.status === "superseded");
6931
+ // Only these runs and attempts can hide rows, and their columns are all visibility reads.
6932
+ const [hidingRuns, superseded] = yield* Effect.all([
6933
+ sql<{ id: RunId; status: OrchestrationV2Run["status"] }>`
6934
+ SELECT run_id AS id, status FROM orchestration_v2_projection_runs
6935
+ WHERE thread_id = ${threadId} AND status IN ('rolled_back', 'queued', 'cancelled')`,
6936
+ sql<{ runId: RunId; rootNodeId: NodeId; status: "superseded" }>`
6937
+ SELECT run_id AS runId, root_node_id AS rootNodeId, status
6938
+ FROM orchestration_v2_projection_run_attempts
6939
+ WHERE thread_id = ${threadId} AND status = 'superseded'`,
6940
+ ]);
6941
const stopRequests =
6942
superseded.length === 0
6943
? []
@@ -6905,8 +6945,8 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6945
SELECT DISTINCT run_id FROM orchestration_v2_projection_turn_items
6946
WHERE thread_id = ${threadId} AND type = 'run_interrupt_request'`;
6947
const isVisible = createOrchestrationV2TurnItemVisibility({
6908
- runs: records.runs,
6909
- attempts: records.attempts,
6948
+ runs: hidingRuns,
6949
+ attempts: superseded,
6950
items: stopRequests.map((row) => ({
6951
type: "run_interrupt_request" as const,
6952
runId: row.run_id === null ? null : RunId.make(row.run_id),
@@ -6918,7 +6958,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6958
// are found without reading the thread.
6959
const stoppedRuns = new Set(stopRequests.map((row) => row.run_id));
6960
const runsWithStatus = (...statuses: ReadonlyArray<OrchestrationV2Run["status"]>) =>
6921
- records.runs.flatMap((run) => (statuses.includes(run.status) ? [String(run.id)] : []));
6961
+ hidingRuns.flatMap((run) => (statuses.includes(run.status) ? [String(run.id)] : []));
6962
const rolledBack = runsWithStatus("rolled_back");
6963
const heldInput = runsWithStatus("queued", "cancelled");
6964
const steered = [...new Set(superseded.map((attempt) => String(attempt.runId)))].filter(
@@ -6990,7 +7030,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
7030
hidden,
7031
visibleBefore,
7032
read: (where: Statement.Fragment, limit?: Statement.Fragment) =>
6993
- readTimelineWindow(threadId, records.runs, includePersistentOutput, where, limit),
7033
+ readTimelineWindow(threadId, includePersistentOutput, where, limit),
7034
};
7035
});
7036
type LocalTimeline = NonNullable<Effect.Success<ReturnType<typeof openLocalTimeline>>>;
@@ -9373,6 +9413,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
9413
getMessageCount: readOnReader(getMessageCount),
9414
getTranscriptByteFloor: readOnReader(getTranscriptByteFloor),
9415
getSubagentCount: readOnReader(getSubagentCount),
9416
+ getRunCount: readOnReader(getRunCount),
9417
listAppOwnedChildThreadIds: readOnReader(listAppOwnedChildThreadIds),
9418
hasPendingDelegatedCompletion: readOnReader(hasPendingDelegatedCompletion),
9419
getNextTurnItemOrdinal: readOnReader(getNextTurnItemOrdinal),
apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
+1
@@ -247,6 +247,7 @@ it.effect(
247
getTranscriptByteFloor: () => Effect.die("unused transcript byte floor"),
248
hasPendingDelegatedCompletion: () => Effect.die("unused hasPendingDelegatedCompletion"),
249
getSubagentCount: () => Effect.die("unused subagent count"),
250
+ getRunCount: () => Effect.die("unused run count"),
251
listAppOwnedChildThreadIds: () => Effect.die("unused listAppOwnedChildThreadIds"),
252
getNextTurnItemOrdinal: () => Effect.die("unused ordinal read"),
253
getTurnItem: () => Effect.die("unused turn item read"),
apps/server/src/orchestration-v2/ThreadManagementService.ts
+6
@@ -405,6 +405,7 @@ export interface ThreadManagementServiceShape {
405
readonly getThreadHistoryPage: Orchestrator.OrchestratorV2["Service"]["getThreadHistoryPage"];
406
readonly getTimelinePage: Orchestrator.OrchestratorV2["Service"]["getTimelinePage"];
407
readonly getMessageCount: Orchestrator.OrchestratorV2["Service"]["getMessageCount"];
408
+ readonly getRunCount: Orchestrator.OrchestratorV2["Service"]["getRunCount"];
409
readonly getMessagesById: Orchestrator.OrchestratorV2["Service"]["getMessagesById"];
410
readonly getTurnItem: (input: {
411
readonly threadId: ThreadId;
@@ -1720,6 +1721,11 @@ const make = Effect.gen(function* () {
1721
Effect.andThen(orchestrator.getMessageCount(threadId)),
1722
);
1723
}),
1724
+ getRunCount: Effect.fn("ThreadManagementService.getRunCount")(function (threadId) {
1725
+ return ensureProjectionTranscript(threadId).pipe(
1726
+ Effect.andThen(orchestrator.getRunCount(threadId)),
1727
+ );
1728
+ }),
1729
getMessagesById: Effect.fn("ThreadManagementService.getMessagesById")(
1730
function (threadId, messageIds) {
1731
return ensureProjectionTranscript(threadId).pipe(
apps/server/src/peer/RemoteDelegation.test.ts
+2
@@ -280,6 +280,8 @@ const boxToolkitLayer = (thread: BoxThread) => {
280
getThreadShell: shellOf,
281
getProjectThreadRecords: (input) => projectionOf(input.threadId),
282
getThreadRecords: (threadId) => projectionOf(threadId),
283
+ getRunCount: (threadId) =>
284
+ projectionOf(threadId).pipe(Effect.map((projection) => projection.runs.length)),
285
waitForThread: (input) =>
286
Effect.gen(function* () {
287
yield* Ref.update(thread.waitedFor, (seen) => [...seen, input.runId]);
apps/server/src/relay/AgentAwarenessRelay.test.ts
+1
@@ -238,6 +238,7 @@ const makeTestRelay = Effect.fnUntraced(function* (
238
getThreadHistoryPage: () => Effect.die("unused"),
239
getTimelinePage: () => Effect.die("Unused timeline read"),
240
getMessageCount: () => Effect.die("unused message count"),
241
+ getRunCount: () => Effect.die("unused run count"),
242
getMessagesById: () => Effect.die("unused messages by id"),
243
getTurnItem: () => Effect.die("unused turn item read"),
244
getThreadRecords: () => Effect.die("unused record read"),