Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix: lost provider session recovery (#1938)
Ashvin Nihalanid18e43b67478
diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.tsindex ded64fb9e..fb4d13f07 100644--- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts+++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts@@ -1241,6 +1241,61 @@ describe("ProviderCommandReactor", () => {});});+ it("starts a fresh session when only projected session state exists", async () => {+ const harness = await createHarness();+ const now = new Date().toISOString();++ await Effect.runPromise(+ harness.engine.dispatch({+ type: "thread.session.set",+ commandId: CommandId.make("cmd-session-set-stale"),+ threadId: ThreadId.make("thread-1"),+ session: {+ threadId: ThreadId.make("thread-1"),+ status: "ready",+ providerName: "codex",+ runtimeMode: "approval-required",+ activeTurnId: null,+ lastError: null,+ updatedAt: now,+ },+ createdAt: now,+ }),+ );++ await Effect.runPromise(+ harness.engine.dispatch({+ type: "thread.turn.start",+ commandId: CommandId.make("cmd-turn-start-stale"),+ threadId: ThreadId.make("thread-1"),+ message: {+ messageId: asMessageId("user-message-stale"),+ role: "user",+ text: "resume codex",+ attachments: [],+ },+ interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,+ runtimeMode: "approval-required",+ createdAt: now,+ }),+ );++ await waitFor(() => harness.startSession.mock.calls.length === 1);+ await waitFor(() => harness.sendTurn.mock.calls.length === 1);++ expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({+ threadId: ThreadId.make("thread-1"),+ modelSelection: {+ provider: "codex",+ model: "gpt-5-codex",+ },+ runtimeMode: "approval-required",+ });+ expect(harness.sendTurn.mock.calls[0]?.[0]).toMatchObject({+ threadId: ThreadId.make("thread-1"),+ });+ });+it("reacts to thread.approval.respond by forwarding provider approval response", async () => {const harness = await createHarness();const now = new Date().toISOString();diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.tsindex a61bd0327..483b99cb3 100644--- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts+++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts@@ -285,14 +285,14 @@ const make = Effect.gen(function* () {createdAt,});+ const activeSession = yield* resolveActiveSession(threadId);const existingSessionThreadId =- thread.session && thread.session.status !== "stopped" ? thread.id : null;+ thread.session && thread.session.status !== "stopped" && activeSession ? thread.id : null;if (existingSessionThreadId) {const runtimeModeChanged = thread.runtimeMode !== thread.session?.runtimeMode;const providerChanged =requestedModelSelection !== undefined &&requestedModelSelection.provider !== currentProvider;- const activeSession = yield* resolveActiveSession(existingSessionThreadId);const sessionModelSwitch =currentProvider === undefined? "in-session"