can1357/oh-my-pi · error · ToolError

agent() isolated nested patch apply failed for ${result.id}:

Error message

agent() isolated nested patch apply failed for ${result.id}: ${mergeSummary.replace(/<\/?system-notification>/g, "").trim()}${recoveryHint}

What it means

When an isolated subagent reports structured output but the merge summary contains a <system-notification> tag, the bridge infers a nested patch application failed inside the subagent run and throws with the sanitized summary plus a recovery hint. It flags partial/failed nested edits despite structured success.

Source

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

			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;
		const schemaStatus = structuredOutput?.status === "unavailable" ? undefined : structuredOutput?.status;

		const model = result.resolvedModel ?? policy.modelOverride;
		const nestedPatches = result.nestedPatches?.length ? result.nestedPatches : undefined;
		const isolationSummary = mergeSummary ? mergeSummary.trim() : undefined;
		return {
			text,
			...(hasData ? { data } : {}),
			details: {

View on GitHub (pinned to 9690622007)

Solutions

  1. Inspect the sanitized mergeSummary in the message for which nested patch failed
  2. Review subagent artifacts (recovery hint gives the dir) for the failing patch
  3. Re-run the subagent against the current parent state
  4. If nested patches are optional, run with merge disabled and apply manually

Example fix

// before: nested patch conflicts surface as thrown error
await agent({ isolated: true, prompt: 'apply nested edits' })
// after: catch, inspect artifacts, retry
try { await agent({ isolated: true, prompt }) }
catch (e) { const hint = /artifacts at (\S+)/.exec(e.message); /* inspect dir, retry */ }
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure subagent emits well-formed nested patches
const dry = await agent({ isolated: true, merge: false, prompt });
if (/<system-notification>/.test(dry.mergeSummary ?? '')) fixPrompt();

Type guard

null

Try / catch

try { await agent({ isolated: true, prompt }) } catch (e) { if (/nested patch apply failed/.test(e.message)) { inspectArtifactsAndRetry(e.message); } else throw e }

Prevention

When it happens

Trigger: agent() isolated call whose result has structuredOutput.source set (non-'none') while mergeSummary embeds <system-notification> — the subagent attempted to apply nested patches back and one failed.

Common situations: Nested patch from the subagent conflicts with parent state; subagent's internal apply hit a malformed patch; notification leaked into the merge summary after a silent nested failure.

Related errors


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