can1357/oh-my-pi · error · ToolError

agent() isolated apply failed for ${result.id}${summary ? `:

Error message

agent() isolated apply failed for ${result.id}${summary ? `: ${summary}` : ""}${recoveryHint}

What it means

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.

Source

Thrown at packages/coding-agent/src/eval/agent-bridge.ts:178

					...(options.signal !== undefined ? { signal: options.signal } : {}),
					...(options.emitStatus
						? { onProgress: (progress: AgentProgress) => emitProgressStatus(options.emitStatus, progress) }
						: {}),
				}),
			{ deferExternalAbort: true },
		);
		const { result, policy, mergeSummary, changesApplied, artifactsDir } = execution;
		if (result.exitCode !== 0 || result.error || result.aborted) {
			const failureMessage = buildSubagentFailureMessage(policy.agentName, result)
				.replace(/<\/?system-notification>/g, "")
				.trim();
			const recoveryHint = policy.isIsolated ? await buildStructuredSubagentRecoveryHint(result, artifactsDir) : "";
			throw new ToolError(`${failureMessage}${recoveryHint}`);
		}
		if (policy.isIsolated && changesApplied === false) {
			const summary = mergeSummary.replace(/<\/?system-notification>/g, "").trim();
			const recoveryHint = await buildStructuredSubagentRecoveryHint(result, artifactsDir);
			throw new ToolError(
				`agent() isolated apply failed for ${result.id}${summary ? `: ${summary}` : ""}${recoveryHint}`,
			);
		}

		const structuredOutput = result.structuredOutput;
		const structured = structuredOutput?.source !== undefined && structuredOutput.source !== "none";
		if (structured && mergeSummary.includes("<system-notification>")) {
			const recoveryHint = await buildStructuredSubagentRecoveryHint(result, artifactsDir);
			throw new ToolError(
				`agent() isolated nested patch apply failed for ${result.id}: ${mergeSummary.replace(/<\/?system-notification>/g, "").trim()}${recoveryHint}`,
			);
		}

		const hasData = structured && structuredOutput !== undefined && Object.hasOwn(structuredOutput, "data");
		const data = structuredOutput?.data;
		const text = structured ? result.output : result.output + mergeSummary;
		const schemaSource = structuredOutput?.source === "none" ? undefined : structuredOutput?.source;
		const schemaMode = structured ? structuredOutput?.mode : undefined;

View on GitHub (pinned to 9690622007)

Solutions

  1. Read mergeSummary and the recovery hint to see why apply reported false
  2. Re-run the subagent with fresh parent state (re-read files before isolating)
  3. Check nested patch/artifact output for conflicting hunks and resolve manually
  4. Ensure the subagent's changes target files within the apply scope

Example fix

// before: parent files changed while subagent worked; apply conflicts
await agent({ isolated: true, prompt: 'edit src/a.ts' })
// after: minimize parent edits during isolation, or merge explicitly
const r = await agent({ isolated: true, merge: false, prompt });
await applyMerge(r.id); // inspect conflicts here
Defensive patterns

Strategy: try-catch

Validate before calling

const src = await Bun.file(target).text(); // refresh parent state before isolating
if (staleCache !== src) invalidateCache();

Type guard

null

Try / catch

try { await agent({ isolated: true, ...args }) } catch (e) { if (/isolated apply failed/.test(e.message)) { manualMergeFromArtifacts(e.message); } else throw e }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/1c5cf85580d0f1eb. Report an issue: GitHub.