fix(runner): bind fast terminal turns deterministically

This commit is contained in:
Dotta 2026-09-03 07:07:20 -05:00
parent 5f3b5bd690
commit 981fb0fe86
2 changed files with 26 additions and 12 deletions

View File

@ -282,9 +282,7 @@ describe("ACPX runtime host", () => {
expect(lifetimeFenceCandidates).toHaveLength(3);
expect(new Set(lifetimeFenceCandidates).size).toBe(3);
expect(
lifetimeFenceCandidates.every(
(port) => port >= 49_152 && port <= 65_535,
),
lifetimeFenceCandidates.every((port) => port >= 49_152 && port <= 65_535),
).toBe(true);
expect(capturedEnvironment.OPENAI_API_KEY).toBe("launch-secret");
expect(host.persistedEnvironment().OPENAI_API_KEY).toBeUndefined();
@ -1255,13 +1253,15 @@ describe("ACPX runtime host", () => {
});
// File removal precedes kernel lease release. Wait for the lease itself so
// this assertion cannot race between those two ordered cleanup steps.
const contender = await vi.waitFor(() =>
stageManagedCodexCredential({
agentHomeDirectory: credentialHome,
environment: {
PAPERCLIP_ACPX_CODEX_AUTH_JSON_SECRET: '{"owner":"contender"}',
},
}),
const contender = await vi.waitFor(
() =>
stageManagedCodexCredential({
agentHomeDirectory: credentialHome,
environment: {
PAPERCLIP_ACPX_CODEX_AUTH_JSON_SECRET: '{"owner":"contender"}',
},
}),
{ timeout: 5_000 },
);
await contender.close();
});

View File

@ -3013,7 +3013,22 @@ class DurablePrpCodexTransport implements CodexAppServerTransport {
this.#flushPendingTraceRehydrations();
const events = this.#core?.store.state.committedEvents ?? [];
while (this.#eventIndex < events.length) {
const event = events[this.#eventIndex++];
const event = events[this.#eventIndex]!;
const eventPayload = record(event.envelope.payload).payload;
const terminalWhileTurnStartPending =
this.#turnStartResponsePending &&
([
"turn.completed",
"turn.failed",
"turn.interrupted",
"turn.cancelled",
].includes(event.eventType) ||
(event.eventType === "provider.event" &&
unwrapRunnerdProviderNotifications(eventPayload).some(
(notification) => notification.method === "turn/completed",
)));
if (terminalWhileTurnStartPending) return;
this.#eventIndex += 1;
if (
event.eventType === "harness.ready" ||
event.eventType === "session.started" ||
@ -3141,7 +3156,6 @@ class DurablePrpCodexTransport implements CodexAppServerTransport {
this.#bridgedRuntimeInputs.delete(requestId);
continue;
}
const eventPayload = record(event.envelope.payload).payload;
const sessionUpdatePayload = record(eventPayload);
const canonicalMethod = (
{