Skip to content

Commit 375243d

Browse files
shivamhwpsaphid
andcommitted
fix(codex): keep pending descendants out of archive cleanup
Count native descendants between spawn and their first turn, and extend the existing regression through pending, running and completed states. Document cleanup of older completed sessions and provide the crypto service needed by the imported archived-fork regression on current Effect. Co-authored-by: Alex Southwell <[email protected]>
1 parent 32d01de commit 375243d

3 files changed

Lines changed: 34 additions & 12 deletions

File tree

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7180,7 +7180,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
71807180
),
71817181
);
71827182

7183-
it.effect("counts a running grandchild after its root and direct child settled", () =>
7183+
it.effect("counts a pending or running grandchild after its root and direct child settled", () =>
71847184
Effect.scoped(
71857185
Effect.gen(function* () {
71867186
const grandchildThread = "native-codex-resume-grandchild-thread";
@@ -7230,16 +7230,6 @@ describe("CodexAdapterV2 post-settle continuation", () => {
72307230
},
72317231
},
72327232
},
7233-
{
7234-
type: "emit_inbound",
7235-
frame: {
7236-
method: "turn/started",
7237-
params: {
7238-
threadId: grandchildThread,
7239-
turn: makeCodexReplayTurn({ id: grandchildTurn, status: "inProgress" }),
7240-
},
7241-
},
7242-
},
72437233
...rootFinished,
72447234
childAgentMessage({
72457235
id: "child-answer",
@@ -7250,6 +7240,18 @@ describe("CodexAdapterV2 post-settle continuation", () => {
72507240
}),
72517241
childTurnCompleted(RESUME_CHILD_TURN_1),
72527242
fence("gpt-fence-child-settled"),
7243+
{
7244+
type: "emit_inbound",
7245+
afterMs: 30_000,
7246+
frame: {
7247+
method: "turn/started",
7248+
params: {
7249+
threadId: grandchildThread,
7250+
turn: makeCodexReplayTurn({ id: grandchildTurn, status: "inProgress" }),
7251+
},
7252+
},
7253+
},
7254+
fence("gpt-fence-grandchild-running"),
72537255
{
72547256
type: "emit_inbound",
72557257
afterMs: 30_000,
@@ -7290,6 +7292,10 @@ describe("CodexAdapterV2 post-settle continuation", () => {
72907292
assert.include(harness.continuationRequests[0]?.detail, "CHILD_DONE");
72917293
assert.isTrue(yield* ownsRunningWork);
72927294

7295+
yield* TestClock.adjust("30 seconds");
7296+
yield* fenced("gpt-fence-grandchild-running");
7297+
assert.isTrue(yield* ownsRunningWork);
7298+
72937299
yield* TestClock.adjust("30 seconds");
72947300
yield* fenced("gpt-fence-grandchild-settled");
72957301
assert.isFalse(yield* ownsRunningWork);
@@ -8305,7 +8311,12 @@ describe("CodexAdapterV2 post-settle continuation", () => {
83058311
}).pipe(
83068312
Effect.scoped,
83078313
Effect.provide(
8308-
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
8314+
Layer.mergeAll(
8315+
IdAllocator.layer,
8316+
McpProviderSessions.layer,
8317+
NodeServices.layer,
8318+
NodeCrypto.layer,
8319+
),
83098320
),
83108321
),
83118322
);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7060,6 +7060,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
70607060
}
70617061
return false;
70627062
};
7063+
if (options?.includeSubagents === true) {
7064+
for (const subagent of (yield* Ref.get(subagentThreads)).values()) {
7065+
if (subagent.task.status === "running" && owned(subagent.parentContext)) {
7066+
return true;
7067+
}
7068+
}
7069+
}
70637070
for (const context of contexts) {
70647071
if (!owned(context)) continue;
70657072
if (yield* turnHasRetainedBackgroundWork(context.nativeTurnId)) return true;

‎docs/user/thread-sidebar.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ task has completed, the parent agent has its result, and the thread has sat idle
269269
This keeps those threads out of other Codex apps' thread lists. T3 Code keeps the
270270
full history, and a follow-up to the task continues the same Codex conversation.
271271

272+
To clean up older entries, wait for the task and its subagents to finish and for
273+
the parent to receive the result. Then run `codex archive <session-id>` on the
274+
machine hosting that Codex session. Keep the T3 thread to continue it later.
275+
272276
Subagent threads started by the agent can't take messages; message the parent
273277
thread instead. When such a subagent needs an approval or an answer, the parent
274278
thread asks for it.

0 commit comments

Comments
 (0)