Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

feat: side questions and turn recovery find chats on the new engine

ogsamrat4dec351fc26f
diff --git a/apps/server/src/engine-v2-next.test.ts b/apps/server/src/engine-v2-next.test.ts
index e86ae537..28959b9f 100644
--- a/apps/server/src/engine-v2-next.test.ts
+++ b/apps/server/src/engine-v2-next.test.ts
@@ -139,8 +139,8 @@ test("steering and automatic compaction use the 2.x engine's routes", async () =
expect(await tracker.classify("ses_busy")).toMatchObject({ steer: false, reason: "compacting" });
const engine = desktopAutoCompactEngine(target, "ses_busy", fetchImpl as never);
expect(await engine.busy()).toBe(true);
- await engine.removeMessage("cmp_1_summary");
- await engine.abort();
+ await engine.removeMessage!("cmp_1_summary");
+ await engine.abort!();
expect(calls).toContain("DELETE /api/session/ses_busy/inbox/cmp_1");
expect(calls).toContain("POST /api/session/ses_busy/interrupt");
});
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index 1b3c9458..ab3b85da 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -301,6 +301,7 @@ async function capturePermissionMode(config: ServerConfig): Promise<ApprovalMode
/** Automatic compaction (session-archive/auto-compact.ts), one per server: its counts live as long as the app. */
const autoCompactorsByServer = new WeakMap<ServerConfig, AutoCompactor>();
+const engineV2ByServer = new WeakMap<ServerConfig, EngineV2Preview>();
/**
* How long a prompt waits for its chat's automatic compaction: the window
* aborts a prompt request after 30 s, and the prompt's own capture steps
@@ -1115,6 +1116,15 @@ type EngineRequestTarget = { baseUrl: string; headers: Headers };
async function captureEngineTarget(config: ServerConfig, sessionId: string, workspaceId: string): Promise<EngineTarget | null> {
const workspace = config.workspaces.find((item) => item.id === workspaceId);
if (!workspace || workspace.workspaceType === "remote") return null;
+ // The 2.x engine (every chat since it shipped), when it has the chat in this workspace's folder.
+ const v2 = engineV2ByServer.get(config)?.connection();
+ if (v2) {
+ const headers = new Headers({ authorization: `Basic ${Buffer.from(`opencode:${v2.password}`).toString("base64")}` });
+ const search = `?${new URLSearchParams({ "location[directory]": workspace.path })}`;
+ const found = await loopbackFetch(buildOpencodeProxyUrl(v2.url, `/api/session/${encodeURIComponent(sessionId)}`, search), { headers, signal: AbortSignal.timeout(ENGINE_SESSION_CHECK_TIMEOUT_MS) })
+ .then(async (response) => { await response.body?.cancel().catch(() => undefined); return response.ok; }).catch(() => false);
+ if (found) return engineTarget(v2.url, headers, search, "v2");
+ }
const route = enginePoolForConfig(config)?.routeRequest("GET", `/session/${sessionId}/message`) ?? null;
const connection = route ? null : resolveWorkspaceOpencodeConnection(config, workspace);
const baseUrl = route?.target.baseUrl ?? connection?.baseUrl?.trim() ?? "";
@@ -1529,6 +1539,7 @@ export async function startServer(config: ServerConfig): Promise<ServeResult> {
if (config.workspaces.length > 0) cloudProviderSync.markReloadPending();
};
const engineV2Preview = createEngineV2Preview({ config, env, deferStart: true });
+ engineV2ByServer.set(config, engineV2Preview);
const bestPracticesReloads = new BestPracticesEngineReloads({
isBusy: (workspace) => engineHasActiveSessions(config, workspace, true),
reload: (workspace) => reloadOpencodeEngine(config, workspace, engineMcpServerState, { reason: "engine_reload" }),
diff --git a/apps/server/src/side-question.ts b/apps/server/src/side-question.ts
index 264d231b..36306ce5 100644
--- a/apps/server/src/side-question.ts
+++ b/apps/server/src/side-question.ts
@@ -11,6 +11,7 @@
*/
import { sideQuestionRoute, type SideAnswer } from "./btw/side-question.mjs";
import { loopbackFetch } from "./server-fetch.js";
+import { v1View } from "./engine-v2-view.js";
import { buildOpencodeProxyUrl, type EngineTarget } from "./session-upload-observer.js";
import { modelHasWebSearch, type WebSearchSwitch } from "./web-search.js";
import type { OmniRushModelCatalog } from "./omnirush-model-catalog.js";
@@ -43,6 +44,16 @@ export async function askSideQuestion(deps: SideQuestionDeps, input: unknown): P
const route = sideQuestionRoute({
readMessages: async (sessionId, limit) => {
if (!deps.engine) return [];
+ if (deps.engine.engine === "v2") {
+ // The 2.x engine's context (oldest first), in the 1.x shape the snapshot reads.
+ const response = await fetchImpl(buildOpencodeProxyUrl(deps.engine.baseUrl, `/api/session/${encodeURIComponent(sessionId)}/context`, deps.engine.search), {
+ headers: new Headers(deps.engine.headers),
+ signal: AbortSignal.timeout(10_000),
+ });
+ if (!response.ok) return [];
+ const payload = (await response.json()) as { data?: unknown };
+ return Array.isArray(payload?.data) ? v1View(payload.data, sessionId).slice(-limit) : [];
+ }
const search = deps.engine.search ? `${deps.engine.search}&limit=${limit}` : `?limit=${limit}`;
const response = await fetchImpl(buildOpencodeProxyUrl(deps.engine.baseUrl, `/session/${encodeURIComponent(sessionId)}/message`, search), {
headers: new Headers(deps.engine.headers),