Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): cancellation - avoid auth teardown stalls (#816)

Andrew Barbad5db8769a83d
diff --git a/.changeset/dispose-auth-hook-teardown.md b/.changeset/dispose-auth-hook-teardown.md
new file mode 100644
index 000000000..8a6a4d964
--- /dev/null
+++ b/.changeset/dispose-auth-hook-teardown.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Session teardown now disposes authorization hooks without waiting on pending durable iterator reads, preventing cancelled sessions from hanging during cleanup.
diff --git a/packages/eve/src/execution/settle-cancelled-turn-step.ts b/packages/eve/src/execution/settle-cancelled-turn-step.ts
index c19aad09a..eb6544458 100644
--- a/packages/eve/src/execution/settle-cancelled-turn-step.ts
+++ b/packages/eve/src/execution/settle-cancelled-turn-step.ts
@@ -12,7 +12,11 @@ import {
import { hydrateDurableSession } from "#execution/session.js";
import { reconcileSessionContinuationToken } from "#execution/reconcile-session-continuation-token.js";
import { emitCancelledTurn } from "#harness/cancelled-turn-emission.js";
-import { getHarnessEmissionState, setHarnessEmissionState } from "#harness/emission.js";
+import {
+ getHarnessEmissionState,
+ isHarnessBetweenTurns,
+ setHarnessEmissionState,
+} from "#harness/emission.js";
import {
clearAllProxyInputRequests,
hasProxyInputRequests,
@@ -63,7 +67,7 @@ export async function settleCancelledTurnStep(input: {
// (the proxy epilogue clears the turn id); re-emitting would fabricate
// a turn id and duplicate the boundary.
const alreadyEpilogued =
- emissionState.turnId === "" && hasProxyInputRequests(durableSession.state);
+ isHarnessBetweenTurns(session) && hasProxyInputRequests(durableSession.state);
if (!alreadyEpilogued) {
const writer = input.parentWritable.getWriter();
diff --git a/packages/eve/src/execution/workflow-entry.test.ts b/packages/eve/src/execution/workflow-entry.test.ts
index b1dd420af..0170f6b71 100644
--- a/packages/eve/src/execution/workflow-entry.test.ts
+++ b/packages/eve/src/execution/workflow-entry.test.ts
@@ -96,6 +96,11 @@ interface DeliveryHookConfig {
readonly values?: readonly HookPayload[];
}
+interface AuthHookConfig {
+ readonly dispose?: () => void;
+ readonly return?: () => Promise<IteratorResult<HookPayload>>;
+}
+
describe("workflowEntry", () => {
beforeEach(() => {
vi.stubEnv("VERCEL_PROJECT_PRODUCTION_URL", "");
@@ -764,6 +769,28 @@ describe("workflowEntry", () => {
expect(dispose).toHaveBeenCalledTimes(1);
expect(symbolDispose).not.toHaveBeenCalled();
});
+
+ it("disposes the auth hook without closing its iterator", async () => {
+ const sessionState = createBaseSessionState();
+ vi.mocked(createSessionStep).mockResolvedValue(createSessionStepResultForMock(sessionState));
+
+ const authDispose = vi.fn();
+ const authReturn = createIteratorReturn();
+ installHookMocks({
+ authHook: { dispose: authDispose, return: authReturn },
+ turnControls: [turnResult({ action: "done", output: "ok", sessionState })],
+ });
+
+ await expect(
+ workflowEntry({
+ input: { message: "hello" },
+ serializedContext: createSerializedContext(),
+ }),
+ ).resolves.toEqual({ output: "ok" });
+
+ expect(authDispose).toHaveBeenCalledOnce();
+ expect(authReturn).not.toHaveBeenCalled();
+ });
});
function createSerializedContext(overrides: Record<string, unknown> = {}): Record<string, unknown> {
@@ -817,6 +844,7 @@ function turnResult(input: {
}
function installHookMocks(input: {
+ readonly authHook?: AuthHookConfig;
readonly deliveryHooks?: readonly DeliveryHookConfig[];
readonly symbolDispose?: () => void;
readonly turnControls: readonly TurnControlPayload[];
@@ -836,7 +864,12 @@ function installHookMocks(input: {
}
if (token.endsWith(":auth")) {
- return createMockHook({ token, values: [] }) as never;
+ return createMockHook({
+ dispose: input.authHook?.dispose,
+ return: input.authHook?.return,
+ token,
+ values: [],
+ }) as never;
}
const config = deliveryHooks.shift() ?? { token, values: [] };
diff --git a/packages/eve/src/execution/workflow-entry.ts b/packages/eve/src/execution/workflow-entry.ts
index 4f0147dce..ab3c2489b 100644
--- a/packages/eve/src/execution/workflow-entry.ts
+++ b/packages/eve/src/execution/workflow-entry.ts
@@ -25,7 +25,7 @@ import { createSessionStep } from "#execution/create-session-step.js";
import { settleCancelledTurnStep } from "#execution/settle-cancelled-turn-step.js";
import { emitTerminalSessionFailureStep } from "#execution/terminal-session-failure-step.js";
import { fireSessionCallbackStep } from "#execution/session-callback-step.js";
-import { closeHookIterator, disposeHook } from "#execution/hook-ownership.js";
+import { disposeHook } from "#execution/hook-ownership.js";
import {
createSessionDeliveryHook,
type SessionDeliveryHook,
@@ -301,7 +301,9 @@ async function runDriverLoop(input: {
} finally {
await disposeSettledTurnControl?.();
await deliveryHook.dispose();
- await closeHookIterator(authIterator);
+ // Dispose without closing the iterator: a session cancelled while
+ // awaiting authorization can leave a durable read in flight, and an
+ // async iterator only honors `return()` after that read settles.
await disposeHook(authHook);
}
}