From a325fa337ec20b40593c52bbc30d57425826ae05 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 10 Aug 2026 18:58:29 +0200 Subject: [PATCH] fix(server): port round-3 main fixes into the v2 orchestrator - a6c9b41f90 (agents open pasted images): ClaudeAdapterV2 now grants the attachments dir alongside cwd via additionalDirectories and appends '[Attached ... is saved at: path]' lines to the turn text so tools can dereference pasted images (pixels alone are not tool-readable). - 5bb8c03664 (settle leaves monitors running): thread.settle now joins archive/delete in the provider-session detach set, so PR monitors, dev servers and subagent fleets stop when the user parks the thread. The settle guard already rejects active runs, and serialized dispatch closes the re-engage race the v1 fix handled with onlyIfSettled. - e70cdb478d (Claude resume handshakes) and 2c7267ad43 (reaper vs live background subagents) are already covered structurally in v2: results are turn-scoped with explicit zero-turn handshake drops, and idle release is pinned while background work is pending. Co-Authored-By: Claude Fable 5 --- .../Adapters/ClaudeAdapterV2.ts | 36 ++++++++++++++-- .../src/orchestration-v2/Orchestrator.ts | 43 ++++++++++++------- 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 2e831d2bad..99fe5437c3 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -641,6 +641,13 @@ export function makeClaudeQueryOptions(input: { readonly resume: boolean; readonly resumeSessionAt?: string; readonly cwd: string | null; + /** + * The attachments dir grant lets the agent Read/copy pasted images at the + * paths appended to the turn text, without an approval prompt. It is a leaf + * directory holding only attachment files; siblings like secrets/ and + * state.sqlite stay ungranted. + */ + readonly attachmentsDir?: string; readonly settings?: ClaudeSettings; readonly sdkSettings?: string | ClaudeSdkSettings; readonly environment?: NodeJS.ProcessEnv; @@ -704,7 +711,13 @@ export function makeClaudeQueryOptions(input: { }), ...(Object.keys(extraArgs).length === 0 ? {} : { extraArgs }), }; - return input.cwd === null ? options : { ...options, cwd: input.cwd }; + const additionalDirectories = [ + ...(input.cwd === null ? [] : [input.cwd]), + ...(input.attachmentsDir === undefined ? [] : [input.attachmentsDir]), + ]; + const withDirectories = + additionalDirectories.length === 0 ? options : { ...options, additionalDirectories }; + return input.cwd === null ? withDirectories : { ...withDirectories, cwd: input.cwd }; } export const CLAUDE_T3_MCP_TOOL_WILDCARD = "mcp__t3-code__*"; @@ -1012,9 +1025,25 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input: }); } + // The model's tools cannot dereference inlined pixels. Appending the + // on-disk path is what lets a turn like "include this screenshot in the + // PR" copy the actual file (the query grants attachmentsDir for reads). + const attachmentPathLines = input.attachments.flatMap((attachment) => { + const attachmentPath = resolveAttachmentPath({ + attachmentsDir: input.attachmentsDir, + attachment, + }); + return attachmentPath === null + ? [] + : [`[Attached ${attachment.type} "${attachment.name}" is saved at: ${attachmentPath}]`]; + }); + const textWithAttachmentPaths = [input.text, attachmentPathLines.join("\n")] + .filter((part) => part.length > 0) + .join("\n\n"); + const content: Array = []; - if (input.text.length > 0) { - content.push({ type: "text", text: input.text }); + if (textWithAttachmentPaths.length > 0) { + content.push({ type: "text", text: textWithAttachmentPaths }); } for (const attachment of input.attachments) { @@ -4263,6 +4292,7 @@ export function makeClaudeAdapterV2( resume: shouldResume, ...(resumeSessionAt === undefined ? {} : { resumeSessionAt }), cwd: turnInput.runtimePolicy.cwd, + attachmentsDir, settings: adapterOptions.settings, environment: adapterOptions.environment, tools: queryPolicy.tools ?? CLAUDE_CODE_PRESET_TOOLS, diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index fb209a7de4..41cdb1c93d 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -1819,8 +1819,17 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio }); } + // Settle joins archive/delete here: all three mean "done with this + // thread", so a live provider session must not keep running background + // work (PR monitors, dev servers, subagent fleets) after any of them + // lands. The settle guard above already rejects active or blocked runs, + // so for settle this only ever stops an idle session; commands are + // decided serially against the projection, so a turn start that + // re-engages the thread cannot race this detach. const detachSessionIds = new Set( - command.type === "thread.archive" || command.type === "thread.delete" + command.type === "thread.archive" || + command.type === "thread.delete" || + command.type === "thread.settle" ? projection.providerSessions.map((session) => session.id) : command.type === "thread.metadata.update" && command.worktreePath !== undefined && @@ -1860,13 +1869,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio reason: command.type === "thread.archive" ? "Thread archived." - : command.type === "thread.delete" - ? "Thread deleted." - : command.type === "thread.metadata.update" - ? "Workspace changed." - : command.type === "thread.runtime-mode.set" - ? "Runtime mode changed." - : "Provider or model selection changed.", + : command.type === "thread.settle" + ? "Thread settled." + : command.type === "thread.delete" + ? "Thread deleted." + : command.type === "thread.metadata.update" + ? "Workspace changed." + : command.type === "thread.runtime-mode.set" + ? "Runtime mode changed." + : "Provider or model selection changed.", }, }); const pendingEffect = { @@ -1879,13 +1890,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio detail: command.type === "thread.archive" ? "Thread archived." - : command.type === "thread.delete" - ? "Thread deleted." - : command.type === "thread.metadata.update" - ? "Workspace changed." - : command.type === "thread.runtime-mode.set" - ? "Runtime mode changed." - : "Provider or model selection changed.", + : command.type === "thread.settle" + ? "Thread settled." + : command.type === "thread.delete" + ? "Thread deleted." + : command.type === "thread.metadata.update" + ? "Workspace changed." + : command.type === "thread.runtime-mode.set" + ? "Runtime mode changed." + : "Provider or model selection changed.", // Terminal detaches revoke the thread's MCP credentials; other // detach reasons keep them so a re-attaching provider process // stays authorized.