Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions apps/server/src/orchestration-v2/EffectOutbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Queue from "effect/Queue";
import * as Result from "effect/Result";
import * as Schedule from "effect/Schedule";
import * as Schema from "effect/Schema";
import * as SqlClient from "effect/sql/SqlClient";
Expand Down Expand Up @@ -575,13 +576,31 @@ export const layer: Layer.Layer<EffectOutboxV2, never, SqlClient.SqlClient> = La
)
RETURNING *
`;
const rows = yield* claimStatement.pipe(Effect.withTracerEnabled(false));
const row = rows[0];
if (row === undefined) return Option.none();
cancellationSignals.set(row.effect_id, Deferred.makeUnsafe<void>());
return Option.some(yield* rowToEffect(row));
while (true) {
const rows = yield* claimStatement.pipe(Effect.withTracerEnabled(false));
const row = rows[0];
if (row === undefined) return Option.none();
const decoded = yield* Effect.result(rowToEffect(row));
if (Result.isSuccess(decoded)) {
cancellationSignals.set(row.effect_id, Deferred.makeUnsafe<void>());
return Option.some(decoded.success);
}
// Left running, an unreadable row would block every later effect on its thread.
yield* Effect.logWarning("Failing an orchestration effect this build cannot decode", {
effectId: row.effect_id,
effectType: row.effect_type,
cause: decoded.failure,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
});
yield* service.fail({
effectId: row.effect_id,
workerId,
error: `This server build cannot decode the ${row.effect_type} effect.`,
});
}
},
Effect.mapError((cause) => new EffectOutboxError({ operation: "claim", cause })),
Effect.mapError((cause) =>
isEffectOutboxError(cause) ? cause : new EffectOutboxError({ operation: "claim", cause }),
),
),
nextClaimableAt: Effect.fnUntraced(
function* ({
Expand Down
60 changes: 60 additions & 0 deletions apps/server/src/orchestration-v2/FoundationPersistence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,66 @@ it.layer(layerTest)("orchestration V2 foundation persistence", (it) => {
}).pipe(Effect.provide(layerIsolatedOutbox)),
);

it.effect("fails an effect this build cannot decode and claims the thread's next effect", () =>
Effect.gen(function* () {
const outbox = yield* EffectOutbox.EffectOutboxV2;
const sql = yield* SqlClient.SqlClient;
const nowIso = DateTime.formatIso(yield* DateTime.now);
const workerId = "undecodable-worker";
const commandId = CommandId.make("command:foundation-undecodable");
const threadId = ThreadId.make("thread:foundation-undecodable");
yield* sql`
INSERT INTO orchestration_v2_effect_outbox (
effect_id, command_id, thread_id, effect_type, payload_json, status,
available_at, created_at, updated_at
)
VALUES (
'effect:foundation-undecodable:a', ${commandId}, ${threadId}, 'future-effect.kind',
'{"type":"future-effect.kind"}', 'pending', ${nowIso}, ${nowIso}, ${nowIso}
)
`;
yield* outbox.enqueue([
{
id: "effect:foundation-undecodable:b",
commandId,
threadId,
request: { type: "provider-turn.start", runId: RunId.make("run:foundation-undecodable") },
},
]);

const claimed = yield* Effect.exit(outbox.claimNext({ workerId }));

const rows = yield* sql<{
readonly effect_id: string;
readonly status: string;
readonly lease_owner: string | null;
readonly last_error: string | null;
}>`
SELECT effect_id, status, lease_owner, last_error
FROM orchestration_v2_effect_outbox
ORDER BY effect_id
`;
assert.deepEqual(rows, [
{
effect_id: "effect:foundation-undecodable:a",
status: "failed",
lease_owner: null,
last_error: "This server build cannot decode the future-effect.kind effect.",
},
{
effect_id: "effect:foundation-undecodable:b",
status: "running",
lease_owner: workerId,
last_error: null,
},
]);
assert.equal(
Exit.isSuccess(claimed) ? Option.getOrUndefined(claimed.value)?.id : undefined,
"effect:foundation-undecodable:b",
);
}).pipe(Effect.provide(layerIsolatedOutbox)),
);

it.effect.each(["queued", "waiting"])(
"keeps a %s continuation's crash budget past outbox retention",
(status) =>
Expand Down
Loading