@devries-cameron20 / t3code-1 / commits / 6d25fa10bd
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(server): skip unused parent data when forking threads (#28265)

Yuruzuu committed Nov 1, 2026 at 10:48 UTC 6d25fa10bda85402d1c564d6baa1c33fec6f155c
2 files changed +75 -3
apps/server/src/orchestration-v2/Orchestrator.ts
+1 -2
@@ -4261,11 +4261,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4261 const sourceProjection = yield* projectionStore
4262 .getThreadRecords(command.sourceThreadId, [
4263 "runs",
4264 - "checkpoints",
4264 + ...(command.sourcePoint.type === "checkpoint" ? (["checkpoints"] as const) : []),
4265 "providerThreads",
4266 "providerTurns",
4267 "attempts",
4268 - "contextTransfers",
4268 ])
4269 .pipe(
4270 Effect.mapError(
apps/server/src/orchestration-v2/ThreadFork.execution.test.ts
+74 -1
@@ -1,6 +1,8 @@
1 import { assert, it } from "@effect/vitest";
2 import {
3 CheckpointId,
4 + CheckpointRef,
5 + CheckpointScopeId,
6 CommandId,
7 EventId,
8 MessageId,
@@ -17,6 +19,7 @@ import {
19 } from "@t3tools/contracts";
20 import * as DateTime from "effect/DateTime";
21 import * as Effect from "effect/Effect";
22 +import * as Statement from "effect/sql/Statement";
23 import * as TestClock from "effect/testing/TestClock";
24
25 import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
@@ -865,6 +868,61 @@ const askSideChat = (threadId: ThreadId, commandId: string) =>
868 });
869 });
870
871 +it.effect("resolves an explicit checkpoint fork to its source run", () =>
872 + Effect.gen(function* () {
873 + const orchestrator = yield* Orchestrator.OrchestratorV2;
874 + const eventSink = yield* EventSink.EventSinkV2;
875 + const now = yield* DateTime.now;
876 + const parentId = ThreadId.make("checkpoint-fork-parent");
877 + const childId = ThreadId.make("checkpoint-fork-child");
878 + const runId = RunId.make("checkpoint-fork-run");
879 + const checkpointId = CheckpointId.make("checkpoint-fork-checkpoint");
880 + yield* createParent(parentId);
881 + yield* writeParentRun({
882 + threadId: parentId,
883 + runId,
884 + ordinal: 1,
885 + status: "completed",
886 + text: "Work",
887 + });
888 + yield* eventSink.write({
889 + events: [
890 + {
891 + id: EventId.make("checkpoint-fork-captured"),
892 + type: "checkpoint.captured",
893 + threadId: parentId,
894 + occurredAt: now,
895 + payload: {
896 + id: checkpointId,
897 + threadId: parentId,
898 + scopeId: CheckpointScopeId.make("checkpoint-fork-scope"),
899 + runId,
900 + nodeId: NodeId.make("checkpoint-fork-node"),
901 + parentCheckpointId: null,
902 + ordinalWithinScope: 1,
903 + appRunOrdinal: 1,
904 + ref: CheckpointRef.make("refs/t3/checkpoint-fork/1"),
905 + status: "ready",
906 + files: [],
907 + capturedAt: now,
908 + },
909 + },
910 + ],
911 + });
912 + yield* orchestrator.dispatch({
913 + type: "thread.fork",
914 + commandId: CommandId.make("checkpoint-fork"),
915 + sourceThreadId: parentId,
916 + targetThreadId: childId,
917 + sourcePoint: { type: "checkpoint", checkpointId },
918 + createdBy: "user",
919 + creationSource: "mcp",
920 + });
921 + const child = yield* orchestrator.getThreadShell(childId);
922 + assert.deepEqual(child?.forkedFrom, { type: "run", threadId: parentId, runId });
923 + }).pipe(Effect.provide(forkCases[0]!.layer)),
924 +);
925 +
926 it.effect("a side chat of an idle parent still starts with the framing note", () =>
927 Effect.gen(function* () {
928 const orchestrator = yield* Orchestrator.OrchestratorV2;
@@ -880,7 +938,22 @@ it.effect("a side chat of an idle parent still starts with the framing note", ()
938 stable: true,
939 });
940
883 - yield* forkSideChat("side-chat-idle-fork", parentId, sideChatId);
941 + const reads: Array<string> = [];
942 + const recordReads: Statement.Transformer = (statement) => {
943 + const [query] = statement.compile();
944 + if (/^\s*SELECT/i.test(query)) reads.push(query);
945 + return Effect.succeed(statement);
946 + };
947 + yield* forkSideChat("side-chat-idle-fork", parentId, sideChatId).pipe(
948 + Effect.provideService(Statement.CurrentTransformer, recordReads),
949 + );
950 + assert.isEmpty(
951 + reads.filter(
952 + (query) =>
953 + query.includes("FROM orchestration_v2_projection_checkpoints") ||
954 + query.includes("FROM orchestration_v2_projection_context_transfers"),
955 + ),
956 + );
957 yield* askSideChat(sideChatId, "side-chat-idle-first-message");
958
959 const started = yield* orchestrator.getThreadProjection(sideChatId);