@devries-cameron20 / t3code Mirror · read-only / commits / 9c8942480e
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 22, 05:45 UTC

fix(server): forking a Codex thread archived outside T3 Code no longer fails (#29618)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>

Alex Southwell committed Nov 3, 2026 at 23:10 UTC 9c8942480e84cf07edae0ea8eb554e44c9503f6d
2 files changed +101 -15
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+78
@@ -8244,6 +8244,84 @@ describe("CodexAdapterV2 post-settle continuation", () => {
8244 ),
8245 );
8246
8247 + it.effect("unarchives an archived Codex source thread before forking it", () =>
8248 + Effect.gen(function* () {
8249 + const nativeThreadId = "archived-fork-source";
8250 + const forkThreadId = "archived-fork-target";
8251 + const forkParams = {
8252 + threadId: nativeThreadId,
8253 + lastTurnId: "native-turn-first",
8254 + config: CodexAdapterV2.CODEX_THREAD_CONFIG,
8255 + };
8256 + const exchange = (
8257 + id: number,
8258 + method: string,
8259 + params: unknown,
8260 + reply: { readonly result: unknown } | { readonly error: unknown },
8261 + ): Array<CodexReplay.CodexAppServerReplayEntry> => [
8262 + { type: "expect_outbound", label: method, frame: { id, method, params } },
8263 + { type: "emit_inbound", label: method, frame: { id, ...reply } },
8264 + ];
8265 + const transcript = makeCodexReplayTranscript({
8266 + scenario: "codex-archived-fork",
8267 + entries: [
8268 + ...codexReplayPreamble({
8269 + nativeThreadId,
8270 + nativeTurnId: "archived-fork-turn",
8271 + prompt: "unused",
8272 + }).slice(0, 5),
8273 + ...exchange(3, "thread/fork", forkParams, {
8274 + error: {
8275 + code: -32600,
8276 + message: `session ${nativeThreadId} is archived. Run \`codex unarchive ${nativeThreadId}\` to unarchive it first.`,
8277 + },
8278 + }),
8279 + ...exchange(
8280 + 4,
8281 + "thread/unarchive",
8282 + { threadId: nativeThreadId },
8283 + { result: codexReplayThreadResult({ nativeThreadId, forkedFromId: null }) },
8284 + ),
8285 + ...exchange(5, "thread/fork", forkParams, {
8286 + result: codexReplayThreadResult({
8287 + nativeThreadId: forkThreadId,
8288 + forkedFromId: nativeThreadId,
8289 + }),
8290 + }),
8291 + ],
8292 + });
8293 + const harness = yield* makeCodexReplayHarness(transcript);
8294 + const now = yield* DateTime.now;
8295 + const firstTurn = codexReplaySourceTurn({
8296 + id: "provider-turn-first",
8297 + ordinal: 1,
8298 + nativeId: "native-turn-first",
8299 + providerThreadId: harness.providerThread.id,
8300 + now,
8301 + });
8302 +
8303 + const forkedProviderThread = yield* harness.runtime.forkThread({
8304 + sourceProviderThread: harness.providerThread,
8305 + sourceProviderTurns: [firstTurn],
8306 + providerTurnId: firstTurn.id,
8307 + targetThreadId: ThreadId.make("thread-archived-fork-target"),
8308 + });
8309 +
8310 + assert.equal(forkedProviderThread.nativeThreadRef?.nativeId, forkThreadId);
8311 + assert.equal(forkedProviderThread.forkedFrom?.providerTurnId, firstTurn.id);
8312 + }).pipe(
8313 + Effect.scoped,
8314 + Effect.provide(
8315 + Layer.mergeAll(
8316 + IdAllocator.layer,
8317 + McpProviderSessions.layer,
8318 + NodeServices.layer,
8319 + NodeCrypto.layer,
8320 + ),
8321 + ),
8322 + ),
8323 + );
8324 +
8325 describe("native goals", () => {
8326 const nativeThreadId = "goal-thread";
8327 const objective = "Ship the feature";
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+23 -15
@@ -7937,24 +7937,32 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
7937 function* (threadInput) {
7938 const threadId = yield* getNativeThreadId(threadInput.sourceProviderThread);
7939 const boundary = yield* resolveCodexForkBoundary(threadInput);
7940 + const fork = client.request("thread/fork", {
7941 + threadId,
7942 + ...(boundary.lastTurnId === undefined ? {} : { lastTurnId: boundary.lastTurnId }),
7943 + ...codexThreadRuntimeParams({
7944 + threadId: threadInput.targetThreadId,
7945 + mcpSession: yield* mcpSessions.read(threadInput.targetThreadId),
7946 + ...(threadInput.modelSelection === undefined
7947 + ? {}
7948 + : { modelSelection: threadInput.modelSelection }),
7949 + ...(threadInput.runtimePolicy === undefined
7950 + ? {}
7951 + : { runtimePolicy: threadInput.runtimePolicy }),
7952 + }),
7953 + });
7954 const response = yield* ensureInitialized.pipe(
7955 Effect.andThen(
7942 - client.request("thread/fork", {
7943 - threadId,
7944 - ...(boundary.lastTurnId === undefined
7945 - ? {}
7946 - : { lastTurnId: boundary.lastTurnId }),
7947 - ...codexThreadRuntimeParams({
7948 - threadId: threadInput.targetThreadId,
7949 - mcpSession: yield* mcpSessions.read(threadInput.targetThreadId),
7950 - ...(threadInput.modelSelection === undefined
7951 - ? {}
7952 - : { modelSelection: threadInput.modelSelection }),
7953 - ...(threadInput.runtimePolicy === undefined
7954 - ? {}
7955 - : { runtimePolicy: threadInput.runtimePolicy }),
7956 + fork.pipe(
7957 + Effect.catchTags({
7958 + CodexAppServerRequestError: (cause) =>
7959 + /\bsession \S+ is archived\b|\bcodex unarchive\b/i.test(cause.errorMessage)
7960 + ? client.raw
7961 + .request("thread/unarchive", { threadId })
7962 + .pipe(Effect.andThen(fork))
7963 + : Effect.fail(cause),
7964 }),
7957 - }),
7965 + ),
7966 ),
7967 Effect.mapError(
7968 (cause) =>