Skip to content

Commit 48b0235

Browse files
committed
fix(codex): preserve stop tracking for memory turns
1 parent 78cec14 commit 48b0235

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

‎apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { makeCodexSessionRuntime } from "./CodexSessionRuntime.ts";
2424

2525
const ROOT = wireFixture.rootThreadId;
2626
const [CHILD_A, CHILD_B] = wireFixture.childThreadIds as [string, string];
27+
const MEMORY = "memory-consolidation-thread";
2728

2829
/**
2930
* The captured sequence, extended with the shapes the live capture didn't
@@ -174,15 +175,44 @@ describe("CodexSessionRuntime collab integration", () => {
174175
const turnStartedB = byIndex.find((entry) => isTurnStarted(entry, CHILD_B));
175176
const registrationA = byIndex.find((entry) => isRegistration(entry, CHILD_A));
176177
const registrationB = byIndex.find((entry) => isRegistration(entry, CHILD_B));
178+
const rootThreadStarted = byIndex.find((entry) => entry.method === "thread/started");
177179
assert.isDefined(turnStartedA);
178180
assert.isDefined(turnStartedB);
179181
assert.isDefined(registrationA);
180182
assert.isDefined(registrationB);
183+
assert.isDefined(rootThreadStarted);
184+
const memoryThreadStarted = {
185+
...rootThreadStarted,
186+
params: {
187+
thread: {
188+
...rootThreadStarted.params.thread,
189+
id: MEMORY,
190+
sessionId: MEMORY,
191+
source: "unknown",
192+
threadSource: "memory_consolidation",
193+
},
194+
},
195+
};
196+
const memoryTurnStarted = {
197+
...turnStartedA,
198+
params: {
199+
...turnStartedA.params,
200+
threadId: MEMORY,
201+
turn: { ...turnStartedA.params.turn, id: "memory-consolidation-turn" },
202+
},
203+
};
181204
const script = {
182205
rootThreadId: ROOT,
183206
holdTurnOpen: true,
184207
hangInterruptFor: CHILD_A,
185-
notifications: [turnStartedA, registrationA, registrationB, turnStartedB],
208+
notifications: [
209+
turnStartedA,
210+
registrationA,
211+
memoryThreadStarted,
212+
memoryTurnStarted,
213+
registrationB,
214+
turnStartedB,
215+
],
186216
};
187217
// @effect-diagnostics-next-line preferSchemaOverJson:off
188218
NodeFS.writeFileSync(scriptPath, JSON.stringify(script), "utf8");
@@ -240,6 +270,10 @@ describe("CodexSessionRuntime collab integration", () => {
240270
"pre-registration child A must still receive the interrupt RPC",
241271
);
242272
assert.isTrue(interruptedThreads.has(CHILD_B), "registered child B must be interrupted");
273+
assert.isTrue(
274+
interruptedThreads.has(MEMORY),
275+
"memory consolidation must be interrupted without appearing in chat",
276+
);
243277
assert.isTrue(interruptedThreads.has(ROOT), "parent turn must be interrupted last");
244278

245279
yield* runtime.close;

‎apps/server/src/provider/Layers/CodexSessionRuntime.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,8 @@ export const makeCodexSessionRuntime = (
12891289

12901290
const handleRawNotification = (notification: CodexServerNotification) =>
12911291
Effect.gen(function* () {
1292-
if (suppressMemoryConsolidationNotification(notification)) {
1293-
return;
1294-
}
1292+
const isMemoryConsolidationNotification =
1293+
suppressMemoryConsolidationNotification(notification);
12951294

12961295
const payload = notification.params;
12971296
const route = readRouteFields(notification);
@@ -1370,6 +1369,10 @@ export const makeCodexSessionRuntime = (
13701369
return;
13711370
}
13721371

1372+
if (isMemoryConsolidationNotification) {
1373+
return;
1374+
}
1375+
13731376
let requestId: ApprovalRequestId | undefined;
13741377
let requestKind: ProviderRequestKind | undefined;
13751378
let turnId = childParentTurnId ?? route.turnId;

0 commit comments

Comments
 (0)