Skip to content

Commit 377bdad

Browse files
committed
fix: emit error/exit events before closing session scope and remove dead code
- Move emit calls for runtime.error and session.exited before stopOpenCodeContext in emitUnexpectedExit. The scope close interrupts the event-pump fiber that is executing the function, so events emitted after the close are silently dropped. - Remove unused isProviderAdapterProcessError variable (dead code from the Schema.is refactor).
1 parent f7b7928 commit 377bdad

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

apps/server/src/provider/Layers/OpenCodeAdapter.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ function nowIso(): string {
9595
}
9696

9797
const isProviderAdapterRequestError = Schema.is(ProviderAdapterRequestError);
98-
const isProviderAdapterProcessError = Schema.is(ProviderAdapterProcessError);
9998

10099
function buildEventBase(input: {
101100
readonly threadId: ThreadId;
@@ -473,7 +472,12 @@ export function makeOpenCodeAdapterLive(options?: OpenCodeAdapterLiveOptions) {
473472
}
474473
const turnId = context.activeTurnId;
475474
sessions.delete(context.session.threadId);
476-
yield* stopOpenCodeContext(context);
475+
// Emit error and exit events *before* closing the session scope.
476+
// `stopOpenCodeContext` closes `context.sessionScope`, which
477+
// interrupts every fiber forked into it — including the event-pump
478+
// fiber that may be running this function. Emitting after the close
479+
// would silently drop these events because the fiber observes the
480+
// pending interruption at the next yield point.
477481
yield* emit({
478482
...buildEventBase({ threadId: context.session.threadId, turnId }),
479483
type: "runtime.error",
@@ -491,6 +495,7 @@ export function makeOpenCodeAdapterLive(options?: OpenCodeAdapterLiveOptions) {
491495
exitKind: "error",
492496
},
493497
}).pipe(Effect.ignore);
498+
yield* stopOpenCodeContext(context);
494499
});
495500

496501
/** Emit content.delta and item.completed events for an assistant text part. */

0 commit comments

Comments
 (0)