@devries-cameron20 / t3code Mirror · read-only / commits / 73e5d5bd76
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

perf(server): OpenCode 2 stops writing unchanged session status updates (#16775)

Abdullah committed Oct 18, 2026 at 23:32 UTC 73e5d5bd764b007a7e7cbc1bd841265213e97db9
2 files changed +67
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
+64
@@ -3710,6 +3710,70 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
3710 }).pipe(Effect.scoped, Effect.provide(IdAllocator.layer)),
3711 );
3712
3713 + it.effect("reports the shared session's status only when it changes", () =>
3714 + Effect.gen(function* () {
3715 + const OTHER = "ses_f148ca2deffeOtherSession000";
3716 + const promptInto = (
3717 + session: string,
3718 + recorded: string,
3719 + ): ReadonlyArray<ProviderReplayEntry> => [
3720 + out("session.prompt", { sessionID: session, id: recorded, text: "<any>" }),
3721 + replyData("session.prompt", {
3722 + id: recorded,
3723 + sessionID: session,
3724 + time: { created: 1790656601410 },
3725 + type: "user",
3726 + payload: { text: "hi" },
3727 + delivery: "steer",
3728 + }),
3729 + ];
3730 + const { runtime, thread } = yield* resumed([
3731 + out("session.get", { sessionID: OTHER }),
3732 + replyData("session.get", sessionInfo({ id: OTHER })),
3733 + out("permission.list", { sessionID: OTHER }),
3734 + replyData("permission.list", []),
3735 + out("session.form.list", { sessionID: OTHER }),
3736 + replyData("session.form.list", []),
3737 + ...promptInto(SESSION, "msg_recorded_turn_a"),
3738 + out("session.instructions.entry.put", { sessionID: OTHER, key: "t3-code", value: "<any>" }),
3739 + reply("session.instructions.entry.put", null),
3740 + ...promptInto(OTHER, "msg_recorded_turn_b"),
3741 + event("session.execution.succeeded", { sessionID: SESSION }),
3742 + event("session.execution.succeeded", { sessionID: OTHER }),
3743 + ]);
3744 + const other = {
3745 + ...thread,
3746 + id: ProviderThreadId.make("provider-thread:opencode2-adapter:other"),
3747 + nativeThreadRef: {
3748 + driver: OPENCODE_PROVIDER,
3749 + nativeId: OTHER,
3750 + strength: "strong" as const,
3751 + },
3752 + };
3753 + yield* runtime.resumeThread({
3754 + providerThread: other,
3755 + threadId,
3756 + modelSelection: bigPickle,
3757 + runtimePolicy: policy(),
3758 + });
3759 + let ended = 0;
3760 + const collected = yield* runtime.events.pipe(
3761 + Stream.takeUntil((event) => event.type === "turn.terminal" && ++ended === 2),
3762 + Stream.runCollect,
3763 + Effect.forkScoped,
3764 + );
3765 + yield* runtime.startTurn(turnInput(thread));
3766 + yield* runtime.startTurn(turnInput(other));
3767 + // The second turn starts and the first ends while the session stays running.
3768 + assert.deepEqual(
3769 + [...(yield* Fiber.join(collected))].flatMap((event) =>
3770 + event.type === "provider_session.updated" ? [event.providerSession.status] : [],
3771 + ),
3772 + ["running", "ready"],
3773 + );
3774 + }).pipe(Effect.scoped),
3775 + );
3776 +
3777 it.effect.each([
3778 ["refuses a rollback while a timed-out Stop's run is still going", true],
3779 ["rolls back once a timed-out Stop's run has left the server", false],
packages/provider-opencode/src/server/v2/adapter.ts
+3
@@ -826,6 +826,9 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
826 lastError: string | null,
827 ) =>
828 Effect.gen(function* () {
829 + // The session is shared by every thread on this instance and is persisted
830 + // once per attached thread, so a repeat of the same state is not worth a write.
831 + if (session.status === status && session.lastError === lastError) return;
832 session = { ...session, status, lastError, updatedAt: yield* DateTime.now };
833 yield* emit({ type: "provider_session.updated", driver, providerSession: session });
834 });