Skip to content

Commit 5cd4fc1

Browse files
fix(opencode): check tracked shells concurrently on reconnect
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1a7c445 commit 5cd4fc1

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

  • packages/provider-opencode/src/server/v2

‎packages/provider-opencode/src/server/v2/adapter.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,10 +2746,12 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
27462746
for (const session of sessions.toReversed()) yield* syncRoster(session);
27472747
}
27482748
// A shell's end may have been lost with the stream, and backfill may re-add an ended one.
2749-
for (const state of threads.values()) {
2750-
if (state.shells.size === 0) continue;
2751-
for (const [id, shell] of state.shells) {
2752-
const running = yield* client.shell
2749+
const tracked = [...threads.values()].filter((state) => state.shells.size > 0);
2750+
// Concurrent, so stalled checks cost one timeout, not one each, within RECONCILE_TIMEOUT.
2751+
yield* Effect.forEach(
2752+
tracked.flatMap((state) => [...state.shells].map(([id, shell]) => ({ state, id, shell }))),
2753+
({ state, id, shell }) =>
2754+
client.shell
27532755
.get({ id: Shell.ID.make(id), location: { directory: shell.directory } })
27542756
.pipe(
27552757
Effect.map(({ data }) => data.status === "running"),
@@ -2764,11 +2766,13 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
27642766
Effect.as(true),
27652767
),
27662768
),
2767-
);
2768-
if (!running) state.shells.delete(id);
2769-
}
2770-
yield* syncRosterAncestors(state);
2771-
}
2769+
Effect.map((running) => {
2770+
if (!running) state.shells.delete(id);
2771+
}),
2772+
),
2773+
{ concurrency: "unbounded", discard: true },
2774+
);
2775+
for (const state of tracked) yield* syncRosterAncestors(state);
27722776
// Stopped off the lock this reconcile holds; one still running waits for a Stop.
27732777
for (const thread of new Set([...strays.values()].map(rootOf))) {
27742778
yield* Effect.forkIn(stopStrays(thread), sessionScope);

0 commit comments

Comments
 (0)