Skip to content

Commit fabb873

Browse files
committed
fix(agents): settle user turn persistence before reconciliation
1 parent fb9c8e7 commit fabb873

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎src/agents/embedded-agent-runner/run/attempt-session-runtime-prepare.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,25 @@ describe("prepareEmbeddedAttemptSessionRuntime", () => {
309309
fixture.trajectoryRecorder,
310310
);
311311
});
312+
313+
it("settles pending user-turn persistence before reconciling the session boundary", async () => {
314+
const fixture = createFixture();
315+
let releasePersistence: (() => void) | undefined;
316+
const pendingPersistence = new Promise<void>((resolve) => {
317+
releasePersistence = resolve;
318+
});
319+
const waitForRuntimePersistence = vi.fn(async () => await pendingPersistence);
320+
fixture.input.attempt.userTurnTranscriptRecorder = {
321+
waitForRuntimePersistence,
322+
} as unknown as PrepareInput["attempt"]["userTurnTranscriptRecorder"];
323+
324+
const preparing = prepareEmbeddedAttemptSessionRuntime(fixture.input);
325+
await vi.waitFor(() => expect(waitForRuntimePersistence).toHaveBeenCalledOnce());
326+
expect(mocks.prepareSessionBoundary).not.toHaveBeenCalled();
327+
328+
releasePersistence?.();
329+
await preparing;
330+
331+
expect(mocks.prepareSessionBoundary).toHaveBeenCalledOnce();
332+
});
312333
});

‎src/agents/embedded-agent-runner/run/attempt-session-runtime-prepare.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export async function prepareEmbeddedAttemptSessionRuntime(input: {
133133
sessionManager,
134134
});
135135
const { activeSession, setActiveSessionSystemPrompt, settingsManager } = preparedAgentSession;
136+
await attempt.userTurnTranscriptRecorder?.waitForRuntimePersistence();
136137
const boundary = prepareEmbeddedAttemptSessionBoundary({
137138
activeSession,
138139
attempt,

0 commit comments

Comments
 (0)