{"record":{"id":"1c5cf85580d0f1eb","repo":"can1357/oh-my-pi","slug":"agent-isolated-apply-failed-for-result-id-su","errorCode":null,"errorMessage":"agent() isolated apply failed for ${result.id}${summary ? `: ${summary}` : \"\"}${recoveryHint}","messagePattern":"agent\\(\\) isolated apply failed for (.+?)(.+?)` : \"\"\\}(.+?)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/eval/agent-bridge.ts","lineNumber":178,"sourceCode":"\t\t\t\t\t...(options.signal !== undefined ? { signal: options.signal } : {}),\n\t\t\t\t\t...(options.emitStatus\n\t\t\t\t\t\t? { onProgress: (progress: AgentProgress) => emitProgressStatus(options.emitStatus, progress) }\n\t\t\t\t\t\t: {}),\n\t\t\t\t}),\n\t\t\t{ deferExternalAbort: true },\n\t\t);\n\t\tconst { result, policy, mergeSummary, changesApplied, artifactsDir } = execution;\n\t\tif (result.exitCode !== 0 || result.error || result.aborted) {\n\t\t\tconst failureMessage = buildSubagentFailureMessage(policy.agentName, result)\n\t\t\t\t.replace(/<\\/?system-notification>/g, \"\")\n\t\t\t\t.trim();\n\t\t\tconst recoveryHint = policy.isIsolated ? await buildStructuredSubagentRecoveryHint(result, artifactsDir) : \"\";\n\t\t\tthrow new ToolError(`${failureMessage}${recoveryHint}`);\n\t\t}\n\t\tif (policy.isIsolated && changesApplied === false) {\n\t\t\tconst summary = mergeSummary.replace(/<\\/?system-notification>/g, \"\").trim();\n\t\t\tconst recoveryHint = await buildStructuredSubagentRecoveryHint(result, artifactsDir);\n\t\t\tthrow new ToolError(\n\t\t\t\t`agent() isolated apply failed for ${result.id}${summary ? `: ${summary}` : \"\"}${recoveryHint}`,\n\t\t\t);\n\t\t}\n\n\t\tconst structuredOutput = result.structuredOutput;\n\t\tconst structured = structuredOutput?.source !== undefined && structuredOutput.source !== \"none\";\n\t\tif (structured && mergeSummary.includes(\"<system-notification>\")) {\n\t\t\tconst recoveryHint = await buildStructuredSubagentRecoveryHint(result, artifactsDir);\n\t\t\tthrow new ToolError(\n\t\t\t\t`agent() isolated nested patch apply failed for ${result.id}: ${mergeSummary.replace(/<\\/?system-notification>/g, \"\").trim()}${recoveryHint}`,\n\t\t\t);\n\t\t}\n\n\t\tconst hasData = structured && structuredOutput !== undefined && Object.hasOwn(structuredOutput, \"data\");\n\t\tconst data = structuredOutput?.data;\n\t\tconst text = structured ? result.output : result.output + mergeSummary;\n\t\tconst schemaSource = structuredOutput?.source === \"none\" ? undefined : structuredOutput?.source;\n\t\tconst schemaMode = structured ? structuredOutput?.mode : undefined;","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/eval/agent-bridge.ts#L160-L196","documentation":"For isolated agent() calls (isolated/apply/merge mode), the subagent's changes are only applied to the parent if the merge step reports changesApplied. When the subagent succeeded but the apply/merge explicitly reported false, the bridge throws with the subagent result id, merge summary, and a structured recovery hint.","triggerScenarios":"agent({ isolated: true, apply: ... }) where the subagent ran fine (exit 0) but its changes could not be applied — e.g. patches conflict with current parent files, the apply step found nothing to apply, or the merge was rejected.","commonSituations":"Subagent edited files based on stale content while the parent moved on; patch format the applier rejects; subagent produced diffs outside the allowed scope so nothing applied.","solutions":["Read mergeSummary and the recovery hint to see why apply reported false","Re-run the subagent with fresh parent state (re-read files before isolating)","Check nested patch/artifact output for conflicting hunks and resolve manually","Ensure the subagent's changes target files within the apply scope"],"exampleFix":"// before: parent files changed while subagent worked; apply conflicts\nawait agent({ isolated: true, prompt: 'edit src/a.ts' })\n// after: minimize parent edits during isolation, or merge explicitly\nconst r = await agent({ isolated: true, merge: false, prompt });\nawait applyMerge(r.id); // inspect conflicts here","handlingStrategy":"try-catch","validationCode":"const src = await Bun.file(target).text(); // refresh parent state before isolating\nif (staleCache !== src) invalidateCache();","typeGuard":"null","tryCatchPattern":"try { await agent({ isolated: true, ...args }) } catch (e) { if (/isolated apply failed/.test(e.message)) { manualMergeFromArtifacts(e.message); } else throw e }","preventionTips":["Don't modify parent files while an isolated subagent runs","Keep subagent edits inside the apply scope","Re-run isolation from a clean state after failures","Review mergeSummary before relying on applied changes"],"tags":["subagent","isolation","patch-apply","eval"],"backgroundTag":"patch-apply-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}