Skip to content

Commit 043ac7c

Browse files
PR Batch Testerclaude
authored andcommitted
test(server): cover transferred children and simultaneous late images
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6153fb2 commit 043ac7c

2 files changed

Lines changed: 100 additions & 40 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,27 +3325,32 @@ describe("CodexAdapterV2 post-settle continuation", () => {
33253325
);
33263326

33273327
it.effect.each(["complete", "stop"] as const)(
3328-
"retains a generating image after settlement until %s",
3328+
"retains generating images after settlement until %s",
33293329
(outcome) =>
33303330
Effect.gen(function* () {
33313331
const scenario = "codex-retained-image";
33323332
const base = finalAnswerTranscript(scenario, [{ id: "answer", text: "Done." }]);
3333-
const completion = yield* Deferred.make<void>();
3333+
const completions = {
3334+
first: yield* Deferred.make<void>(),
3335+
second: yield* Deferred.make<void>(),
3336+
};
3337+
const projected = yield* Deferred.make<void>();
33343338
const drained = yield* Deferred.make<void>();
3335-
const imageEvent = (phase: "started" | "completed") => ({
3339+
const firstText = "Done.\n\n![](</tmp/first.png>)";
3340+
const imageEvent = (image: "first" | "second", phase: "started" | "completed") => ({
33363341
type: "emit_inbound" as const,
3337-
label: `image-${phase}`,
3342+
label: `${image}-${phase}`,
33383343
frame: {
33393344
method: `item/${phase}`,
33403345
params: {
33413346
threadId: `native-${scenario}-thread`,
33423347
turnId: `native-${scenario}-turn`,
33433348
item: {
33443349
type: "imageGeneration",
3345-
id: "late-image",
3350+
id: image,
33463351
status: phase === "started" ? "inProgress" : "completed",
33473352
result: "",
3348-
...(phase === "completed" ? { savedPath: "/tmp/late.png" } : {}),
3353+
...(phase === "completed" ? { savedPath: `/tmp/${image}.png` } : {}),
33493354
},
33503355
},
33513356
},
@@ -3355,18 +3360,27 @@ describe("CodexAdapterV2 post-settle continuation", () => {
33553360
scenario,
33563361
entries: [
33573362
...base.entries.slice(0, -2),
3358-
imageEvent("started"),
3363+
imageEvent("first", "started"),
3364+
imageEvent("second", "started"),
33593365
...base.entries.slice(-2),
3360-
imageEvent("completed"),
3366+
imageEvent("first", "completed"),
3367+
imageEvent("second", "completed"),
33613368
],
33623369
}),
33633370
(event) =>
3364-
event.type === "background_work.updated" && !event.pending
3365-
? Deferred.succeed(drained, undefined)
3366-
: Effect.void,
3371+
event.type === "message.updated" && event.message.text === firstText
3372+
? Deferred.succeed(projected, undefined)
3373+
: event.type === "background_work.updated" && !event.pending
3374+
? Deferred.succeed(drained, undefined)
3375+
: Effect.void,
33673376
undefined,
33683377
undefined,
3369-
(entry) => (entry.label === "image-completed" ? Deferred.await(completion) : Effect.void),
3378+
(entry) =>
3379+
entry.label === "first-completed"
3380+
? Deferred.await(completions.first)
3381+
: entry.label === "second-completed"
3382+
? Deferred.await(completions.second)
3383+
: Effect.void,
33703384
);
33713385
yield* harness.runtime.startTurn(
33723386
makeCodexTestTurnInput({
@@ -3384,9 +3398,16 @@ describe("CodexAdapterV2 post-settle continuation", () => {
33843398
]);
33853399
assert.deepEqual(yield* pending, [true, true]);
33863400
assert.strictEqual(assistantMessages(harness.events).at(-1)?.message.text, "Done.");
3401+
const cleared = () =>
3402+
harness.events.some((e) => e.type === "background_work.updated" && !e.pending);
33873403

33883404
if (outcome === "complete") {
3389-
yield* Deferred.succeed(completion, undefined);
3405+
yield* Deferred.succeed(completions.first, undefined);
3406+
yield* Deferred.await(projected);
3407+
// The second image is still generating, so the first must not release the turn.
3408+
assert.deepEqual(yield* pending, [true, true]);
3409+
assert.isFalse(cleared());
3410+
yield* Deferred.succeed(completions.second, undefined);
33903411
} else {
33913412
yield* harness.runtime.interruptTurn({
33923413
providerThread: harness.providerThread,
@@ -3397,7 +3418,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
33973418
yield* Deferred.await(drained);
33983419
assert.deepEqual(yield* pending, [false, false]);
33993420
assert.lengthOf(harness.terminalEvents(), 1);
3400-
// Run ingestion follows these updates, so they must bracket the terminal and the image.
3421+
// Run ingestion follows these updates, so they must bracket the terminal and the images.
34013422
const indexOf = (predicate: (event: ProviderAdapter.ProviderAdapterV2Event) => boolean) =>
34023423
harness.events.findIndex(predicate);
34033424
const started = indexOf((e) => e.type === "background_work.updated" && e.pending);
@@ -3408,12 +3429,13 @@ describe("CodexAdapterV2 post-settle continuation", () => {
34083429
assert.isAbove(finished, terminal);
34093430
if (outcome === "complete") {
34103431
const messages = assistantMessages(harness.events);
3411-
const projected = indexOf(
3432+
const projectedBoth = indexOf(
34123433
(e) =>
3413-
e.type === "message.updated" && e.message.text === "Done.\n\n![](</tmp/late.png>)",
3434+
e.type === "message.updated" &&
3435+
e.message.text === `${firstText}\n\n![](</tmp/second.png>)`,
34143436
);
3415-
assert.isAbove(projected, terminal);
3416-
assert.isAbove(finished, projected);
3437+
assert.isAbove(projectedBoth, terminal);
3438+
assert.isAbove(finished, projectedBoth);
34173439
assert.strictEqual(messages.at(-1)?.message.id, messages[0]?.message.id);
34183440
assert.strictEqual(messages.at(-1)?.message.streaming, false);
34193441
}

‎apps/server/src/orchestration-v2/RunExecutionService.test.ts‎

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,30 +1783,68 @@ it.effect("ends a nested native subagent and its thread when the root run is int
17831783
it.effect("keeps ingesting until queued background work clears after the probe goes idle", () =>
17841784
Effect.gen(function* () {
17851785
// The adapter's probe runs ahead of its event queue, so only the queued update may release.
1786+
// A child transferred to another run takes its pending work with it.
17861787
const pending = yield* Ref.make(true);
1787-
const observed = yield* runBackgroundItemScenario(
1788-
"queued-background-work",
1789-
(ids) => {
1790-
const backgroundWork = {
1791-
type: "background_work.updated",
1792-
driver,
1793-
providerTurnId: ids.rootProviderTurnId,
1794-
pending: true,
1795-
} satisfies ProviderAdapter.ProviderAdapterV2Event;
1796-
return [
1797-
backgroundWork,
1798-
rootTerminalEvent(ids, "completed"),
1799-
backgroundTurnItemEvent(ids, "dynamic_tool", "completed", 1),
1800-
{ ...backgroundWork, pending: false },
1801-
];
1802-
},
1803-
{
1804-
keepEventStreamOpen: true,
1805-
hasPendingBackgroundWorkForThread: () => Ref.get(pending),
1806-
onFinalized: () => Ref.set(pending, false),
1807-
},
1788+
const consumed = yield* Deferred.make<void>();
1789+
const result = yield* Effect.raceFirst(
1790+
runBackgroundItemScenario(
1791+
"queued-background-work",
1792+
(ids) => {
1793+
const childProviderThreadId = ProviderThreadId.make(`${ids.providerThreadId}:child`);
1794+
const childProviderTurnId = ProviderTurnId.make(`${ids.rootProviderTurnId}:child`);
1795+
const running = subagentEvent(ids, "running");
1796+
if (running.type !== "subagent.updated") throw new Error("Missing subagent");
1797+
const linked = {
1798+
...running,
1799+
subagent: {
1800+
...running.subagent,
1801+
origin: "provider_native" as const,
1802+
childThreadId: ids.childThreadId,
1803+
providerThreadId: childProviderThreadId,
1804+
},
1805+
};
1806+
const backgroundWork = (providerTurnId: ProviderTurnId, pending: boolean) =>
1807+
({
1808+
type: "background_work.updated",
1809+
driver,
1810+
providerTurnId,
1811+
pending,
1812+
}) satisfies ProviderAdapter.ProviderAdapterV2Event;
1813+
return [
1814+
childThreadCreatedEvent(ids),
1815+
linked,
1816+
{
1817+
type: "provider_turn.updated",
1818+
driver,
1819+
threadId: ids.childThreadId,
1820+
providerTurn: {
1821+
id: childProviderTurnId,
1822+
providerThreadId: childProviderThreadId,
1823+
runAttemptId: null,
1824+
status: "completed",
1825+
},
1826+
} as ProviderAdapter.ProviderAdapterV2Event,
1827+
backgroundWork(childProviderTurnId, true),
1828+
backgroundWork(ids.rootProviderTurnId, true),
1829+
rootTerminalEvent(ids, "completed"),
1830+
{ ...linked, subagent: { ...linked.subagent, runId: RunId.make("run:replacement") } },
1831+
backgroundTurnItemEvent(ids, "dynamic_tool", "completed", 1),
1832+
backgroundWork(ids.rootProviderTurnId, false),
1833+
];
1834+
},
1835+
{
1836+
keepEventStreamOpen: true,
1837+
hasPendingBackgroundWorkForThread: () => Ref.get(pending),
1838+
onFinalized: () => Ref.set(pending, false),
1839+
onEventsConsumed: Deferred.succeed(consumed, undefined).pipe(Effect.asVoid),
1840+
},
1841+
).pipe(Effect.asSome),
1842+
Deferred.await(consumed).pipe(Effect.as(Option.none())),
1843+
);
1844+
assert.deepEqual(
1845+
result,
1846+
Option.some(["subagent:running", "root-finalized", "turn_item:completed"]),
18081847
);
1809-
assert.deepEqual(observed, ["root-finalized", "turn_item:completed"]);
18101848
}),
18111849
);
18121850

0 commit comments

Comments
 (0)