@devries-cameron20 / t3code Mirror · read-only / commits / 033ae7cba0
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, 11:00 UTC

fix(server): an effect this build can't read no longer blocks its thread's later work (#32746)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 15, 2026 at 00:55 UTC 033ae7cba094ecf807ea5265e6a8acbeed4047c5
2 files changed +85 -6
apps/server/src/orchestration-v2/EffectOutbox.ts
+25 -6
@@ -25,6 +25,7 @@ import * as Effect from "effect/Effect";
25 import * as Layer from "effect/Layer";
26 import * as Option from "effect/Option";
27 import * as Queue from "effect/Queue";
28 +import * as Result from "effect/Result";
29 import * as Schedule from "effect/Schedule";
30 import * as Schema from "effect/Schema";
31 import * as SqlClient from "effect/sql/SqlClient";
@@ -575,13 +576,31 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
576 )
577 RETURNING *
578 `;
578 - const rows = yield* claimStatement.pipe(Effect.withTracerEnabled(false));
579 - const row = rows[0];
580 - if (row === undefined) return Option.none();
581 - cancellationSignals.set(row.effect_id, Deferred.makeUnsafe<void>());
582 - return Option.some(yield* rowToEffect(row));
579 + while (true) {
580 + const rows = yield* claimStatement.pipe(Effect.withTracerEnabled(false));
581 + const row = rows[0];
582 + if (row === undefined) return Option.none();
583 + const decoded = yield* Effect.result(rowToEffect(row));
584 + if (Result.isSuccess(decoded)) {
585 + cancellationSignals.set(row.effect_id, Deferred.makeUnsafe<void>());
586 + return Option.some(decoded.success);
587 + }
588 + // Left running, an unreadable row would block every later effect on its thread.
589 + yield* Effect.logWarning("Failing an orchestration effect this build cannot decode", {
590 + effectId: row.effect_id,
591 + effectType: row.effect_type,
592 + cause: decoded.failure,
593 + });
594 + yield* service.fail({
595 + effectId: row.effect_id,
596 + workerId,
597 + error: `This server build cannot decode the ${row.effect_type} effect.`,
598 + });
599 + }
600 },
584 - Effect.mapError((cause) => new EffectOutboxError({ operation: "claim", cause })),
601 + Effect.mapError((cause) =>
602 + isEffectOutboxError(cause) ? cause : new EffectOutboxError({ operation: "claim", cause }),
603 + ),
604 ),
605 nextClaimableAt: Effect.fnUntraced(
606 function* ({
apps/server/src/orchestration-v2/FoundationPersistence.test.ts
+60
@@ -2752,6 +2752,66 @@ it.layer(layerTest)("orchestration V2 foundation persistence", (it) => {
2752 }).pipe(Effect.provide(layerIsolatedOutbox)),
2753 );
2754
2755 + it.effect("fails an effect this build cannot decode and claims the thread's next effect", () =>
2756 + Effect.gen(function* () {
2757 + const outbox = yield* EffectOutbox.EffectOutboxV2;
2758 + const sql = yield* SqlClient.SqlClient;
2759 + const nowIso = DateTime.formatIso(yield* DateTime.now);
2760 + const workerId = "undecodable-worker";
2761 + const commandId = CommandId.make("command:foundation-undecodable");
2762 + const threadId = ThreadId.make("thread:foundation-undecodable");
2763 + yield* sql`
2764 + INSERT INTO orchestration_v2_effect_outbox (
2765 + effect_id, command_id, thread_id, effect_type, payload_json, status,
2766 + available_at, created_at, updated_at
2767 + )
2768 + VALUES (
2769 + 'effect:foundation-undecodable:a', ${commandId}, ${threadId}, 'future-effect.kind',
2770 + '{"type":"future-effect.kind"}', 'pending', ${nowIso}, ${nowIso}, ${nowIso}
2771 + )
2772 + `;
2773 + yield* outbox.enqueue([
2774 + {
2775 + id: "effect:foundation-undecodable:b",
2776 + commandId,
2777 + threadId,
2778 + request: { type: "provider-turn.start", runId: RunId.make("run:foundation-undecodable") },
2779 + },
2780 + ]);
2781 +
2782 + const claimed = yield* Effect.exit(outbox.claimNext({ workerId }));
2783 +
2784 + const rows = yield* sql<{
2785 + readonly effect_id: string;
2786 + readonly status: string;
2787 + readonly lease_owner: string | null;
2788 + readonly last_error: string | null;
2789 + }>`
2790 + SELECT effect_id, status, lease_owner, last_error
2791 + FROM orchestration_v2_effect_outbox
2792 + ORDER BY effect_id
2793 + `;
2794 + assert.deepEqual(rows, [
2795 + {
2796 + effect_id: "effect:foundation-undecodable:a",
2797 + status: "failed",
2798 + lease_owner: null,
2799 + last_error: "This server build cannot decode the future-effect.kind effect.",
2800 + },
2801 + {
2802 + effect_id: "effect:foundation-undecodable:b",
2803 + status: "running",
2804 + lease_owner: workerId,
2805 + last_error: null,
2806 + },
2807 + ]);
2808 + assert.equal(
2809 + Exit.isSuccess(claimed) ? Option.getOrUndefined(claimed.value)?.id : undefined,
2810 + "effect:foundation-undecodable:b",
2811 + );
2812 + }).pipe(Effect.provide(layerIsolatedOutbox)),
2813 + );
2814 +
2815 it.effect.each(["queued", "waiting"])(
2816 "keeps a %s continuation's crash budget past outbox retention",
2817 (status) =>