{"record":{"id":"fff3d2c59d009d45","repo":"can1357/oh-my-pi","slug":"isolated-subagent-execution-could-not-be-prepared","errorCode":null,"errorMessage":"Isolated subagent execution could not be prepared: ${message}","messagePattern":"Isolated subagent execution could not be prepared: (.+?)","errorType":"exception","errorClass":"StructuredSubagentError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/task/structured-subagent.ts","lineNumber":584,"sourceCode":"\t\t\t? (result: SingleResult) => request.session.recordEvalSubagentUsage?.(result.usage?.output ?? 0)\n\t\t\t: undefined;\n\ttry {\n\t\tconst id = await reserveStructuredSubagentId(request.session, {\n\t\t\t...request.identity,\n\t\t\tlabel: request.identity?.label ?? (request.invocationKind === \"eval\" ? \"EvalAgent\" : undefined),\n\t\t});\n\t\tconst baseOptions = buildExecutorOptions(request, policy, lease, id);\n\t\tbaseOptions.onCleanupDeferred = completion => {\n\t\t\tdeferredCleanup = completion;\n\t\t};\n\t\tbaseOptions.planReference = await loadPlanReference(request, policy);\n\t\tlet isolationContext: IsolationContext | null = null;\n\t\tif (policy.isIsolated) {\n\t\t\ttry {\n\t\t\t\tisolationContext = await prepareIsolationContext(request.session.cwd);\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new StructuredSubagentError(\n\t\t\t\t\t\"isolation\",\n\t\t\t\t\t`Isolated subagent execution could not be prepared: ${message}`,\n\t\t\t\t\t{ cause: error },\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tlet result: SingleResult;\n\t\tif (!isolationContext) {\n\t\t\tresult = await runSubprocess(baseOptions);\n\t\t\tonSubprocessResult?.(result);\n\t\t} else {\n\t\t\tresult = await runIsolatedSubprocess({\n\t\t\t\tbaseOptions,\n\t\t\t\tcontext: isolationContext,\n\t\t\t\tpreferredBackend: parseIsolationMode(request.session.settings.get(\"task.isolation.mode\")),\n\t\t\t\tagentId: id,\n\t\t\t\tmergeMode: policy.mergeMode,\n\t\t\t\tartifactsDir: lease.artifactsDir,","sourceCodeStart":566,"sourceCodeEnd":602,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/task/structured-subagent.ts#L566-L602","documentation":"Thrown at stage \"isolation\" when `prepareIsolationContext` fails while setting up isolated execution for a subagent. The original error message (git/worktree setup failure, missing tool, filesystem error) is wrapped into a StructuredSubagentError with the underlying error attached as `cause`.","triggerScenarios":"`policy.isIsolated` is true and `prepareIsolationContext(request.session.cwd)` throws — e.g. worktree creation fails because the directory is not a git repo, git is missing, or the worktree path already exists.","commonSituations":"Running isolated subagents in a non-git project or bare checkout; dirty/conflicting worktree state; git unavailable or version too old in CI images; permission errors on the repo path.","solutions":["Read the wrapped `cause` message and fix the underlying isolation setup failure (repo state, git availability)","Run the session from a valid git working tree when using worktree isolation","Disable isolation (`isolation.requested: false`/omit) if the environment cannot support it"],"exampleFix":"// before: isolated run in a non-git directory\nawait task({ agent: \"a\", isolation: { requested: true } });\n// after: init the repo first, or run without isolation\nawait task({ agent: \"a\" });","handlingStrategy":"try-catch","validationCode":"const probe = Bun.spawnSync([\"git\", \"rev-parse\", \"--is-inside-work-tree\"], { cwd: session.cwd });\nif (probe.exitCode !== 0) throw new Error(\"Isolation requires a valid git working tree\");","typeGuard":null,"tryCatchPattern":"try {\n  return await runStructuredSubagent(req);\n} catch (e) {\n  if (e instanceof StructuredSubagentError && e.stage === \"isolation\") {\n    logger.error(\"isolation prep failed\", { cause: e.cause });\n    return runStructuredSubagent({ ...req, isolation: undefined }); // fall back to non-isolated\n  }\n  throw e;\n}","preventionTips":["Verify git availability and repo state before enabling worktree isolation","Clean stale worktrees; monitor disk/permissions in CI","Have a non-isolated fallback path for environments that cannot isolate"],"tags":["subagent","isolation","git","worktree"],"backgroundTag":"isolation-setup-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}