From 42a3809b9479a4967cef119126a8784213b986c0 Mon Sep 17 00:00:00 2001 From: Charles Howard <96023061+charlesrhoward@users.noreply.github.com> Date: Sun, 30 Aug 2026 15:33:43 -0400 Subject: [PATCH] Allow resumed chats to use saved sandbox --- app/api/chat/_lib/session-context.ts | 7 --- tests/unit/chat-session-context.test.ts | 74 ++++++++++++------------- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/app/api/chat/_lib/session-context.ts b/app/api/chat/_lib/session-context.ts index 2af51d7..41b89ba 100644 --- a/app/api/chat/_lib/session-context.ts +++ b/app/api/chat/_lib/session-context.ts @@ -164,13 +164,6 @@ export async function resolveChatSessionContext( ); } - if (body.sandboxId && body.sandboxId !== conversation.sandbox_id) { - throw new ChatSessionContextError( - "The conversation sandbox is no longer available.", - 404 - ); - } - let sandbox: ChatSandboxContextRecord | null = null; if (conversation.sandbox_id) { try { diff --git a/tests/unit/chat-session-context.test.ts b/tests/unit/chat-session-context.test.ts index 4677ddb..1a90e9c 100644 --- a/tests/unit/chat-session-context.test.ts +++ b/tests/unit/chat-session-context.test.ts @@ -147,46 +147,46 @@ test("native chat rejects a missing conversation and a mismatched sandbox", asyn ); }); -test("native chat rejects a sandbox saved to another same-repository workspace conversation", async () => { +test("native chat ignores a stale browser sandbox hint and uses the saved conversation sandbox", async () => { let loadedSandboxId: string | null = null; - await assert.rejects( - resolveChatSessionContext( - new Request("https://app.mogplex.com/api/chat"), - "user-1", - { - messages: [], - conversationId: "conversation-workspace-a", - sandboxId: "sandbox-workspace-b", - }, - { - loadConversation: async () => ({ - id: "conversation-workspace-a", - user_id: "user-1", + const resolved = await resolveChatSessionContext( + new Request("https://app.mogplex.com/api/chat"), + "user-1", + { + messages: [], + conversationId: "conversation-workspace-a", + sandboxId: "sandbox-workspace-b", + }, + { + loadConversation: async () => ({ + id: "conversation-workspace-a", + user_id: "user-1", + repo_id: "repo-1", + workspace_session_id: "workspace-a", + sandbox_id: "sandbox-workspace-a", + model: "openai/gpt-5.6-sol", + }), + loadRepo: async () => ({ + id: "repo-1", + full_name: "Mogplex/mogplex", + owner: "Mogplex", + name: "mogplex", + default_branch: "main", + }), + loadSandbox: async ({ sandboxId }) => { + loadedSandboxId = sandboxId; + return { + id: sandboxId, repo_id: "repo-1", - workspace_session_id: "workspace-a", - sandbox_id: "sandbox-workspace-a", - model: "openai/gpt-5.6-sol", - }), - loadRepo: async () => ({ - id: "repo-1", - full_name: "Mogplex/mogplex", - owner: "Mogplex", - name: "mogplex", - default_branch: "main", - }), - loadSandbox: async ({ sandboxId }) => { - loadedSandboxId = sandboxId; - return { - id: sandboxId, - repo_id: "repo-1", - working_branch: "fix/workspace-a", - }; - }, - } - ), - (error) => error instanceof ChatSessionContextError && error.status === 404 + working_branch: "fix/workspace-a", + }; + }, + } ); - assert.equal(loadedSandboxId, null); + assert.equal(loadedSandboxId, "sandbox-workspace-a"); + assert.equal(resolved.sandboxId, "sandbox-workspace-a"); + assert.equal(resolved.workspaceSessionId, "workspace-a"); + assert.equal(resolved.repoBranch, "fix/workspace-a"); });