Skip to content

Commit 7aef9f9

Browse files
committed
fix(providers): keep rollback blocked by running Codex descendants
1 parent c88e52c commit 7aef9f9

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,6 +5410,37 @@ describe("CodexAdapterV2 post-settle continuation", () => {
54105410
assert.equal(harness.terminalEvents()[0]?.status, "completed");
54115411
assert.lengthOf(harness.continuationRequests, 0);
54125412

5413+
assert.isTrue(
5414+
yield* harness.runtime.hasPendingBackgroundWorkForThread!(harness.providerThread),
5415+
);
5416+
const rollbackInput = {
5417+
providerThread: harness.providerThread,
5418+
target: {
5419+
type: "thread_start" as const,
5420+
checkpointId: CheckpointId.make("late-child-admission"),
5421+
appRunOrdinal: 0 as const,
5422+
},
5423+
providerThreadTurns: [],
5424+
};
5425+
const admissionError = yield* harness.runtime.withRollbackAdmission!(rollbackInput, () =>
5426+
Effect.die("a running descendant must exclude restoration"),
5427+
).pipe(Effect.flip);
5428+
assert.equal(admissionError._tag, "ProviderAdapterProtocolError");
5429+
const unrelated = {
5430+
...rollbackInput,
5431+
providerThread: {
5432+
...harness.providerThread,
5433+
id: ProviderThreadId.make("unrelated-admission-thread"),
5434+
nativeThreadRef: null,
5435+
},
5436+
};
5437+
assert.isFalse(
5438+
yield* harness.runtime.hasPendingBackgroundWorkForThread!(unrelated.providerThread),
5439+
);
5440+
assert.isTrue(
5441+
yield* harness.runtime.withRollbackAdmission!(unrelated, () => Effect.succeed(true)),
5442+
);
5443+
54135444
yield* TestClock.adjust("60 seconds");
54145445
yield* harness.until(
54155446
() => harness.subagentUpdates().at(-1)?.subagent.result === "NATIVE_CHILD_16900_DONE",

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6760,12 +6760,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
67606760
...(yield* Ref.get(activeTurns)).values(),
67616761
...(yield* Ref.get(settledTurns)).values(),
67626762
];
6763-
const roots = contexts.filter(
6764-
(context) => context.providerThread.id === providerThread.id,
6765-
);
67666763
for (const context of contexts) {
6767-
if (!roots.some((root) => context === root || isDescendantCodexTurn(context, root)))
6768-
continue;
6764+
// Descendants retain their ancestry after the root leaves the runtime maps.
6765+
let ancestor: ActiveCodexTurnContext | undefined = context;
6766+
while (ancestor !== undefined && ancestor.providerThread.id !== providerThread.id) {
6767+
ancestor = ancestor.subagent?.parentContext;
6768+
}
6769+
if (ancestor === undefined) continue;
67696770
if (yield* turnHasRetainedBackgroundWork(context.nativeTurnId)) return true;
67706771
if (
67716772
context.subagent !== null &&

0 commit comments

Comments
 (0)