can1357/oh-my-pi · error

rewrite received invalid arguments: ${params.summary}

Error message

rewrite received invalid arguments: ${params.summary}

What it means

The `rewrite` tool validates its raw tool-call arguments against `rewriteSchema` (`{ text: string>0, losses: Array<{content, reason}> }` with unknown-key rejection). When ArkType validation fails, the executor throws with the schema error summary. This means the model emitted arguments that are missing, empty, wrongly typed, or contain unexpected fields.

Source

Thrown at packages/coding-agent/src/compress/protocol.ts:181

			);
		}
		this.#approved = true;
		this.#verdict = verdict;
		return draft;
	}

	/** Tool that records a draft. Thin adapter over {@link submit}. */
	rewriteTool(): ToolDefinition {
		return {
			name: "rewrite",
			label: "Rewrite",
			description: rewriteDescription.trim(),
			parameters: rewriteSchema,
			approval: "read",
			strict: true,
			execute: async (_toolCallId, rawParams) => {
				const params = rewriteSchema(rawParams);
				if (params instanceof type.errors) throw new Error(`rewrite received invalid arguments: ${params.summary}`);
				const draft = this.submit(params.text, params.losses);
				const metrics = this.metrics(draft);
				const percent = (metrics.ratio * 100).toFixed(1);
				const summary = `Draft ${draft.round} recorded: ${metrics.sourceTokens} → ${metrics.draftTokens} tokens (${percent}% smaller), ${draft.losses.length} declared loss(es). A review turn follows.`;
				const details: RewriteDetails = {
					round: draft.round,
					draftTokens: metrics.draftTokens,
					losses: draft.losses.length,
				};
				return { content: [{ type: "text", text: summary }], details };
			},
		};
	}

	/** Tool that accepts the newest reviewed draft. Thin adapter over {@link accept}. */
	approveTool(): ToolDefinition {
		return {
			name: "approve",

View on GitHub (pinned to 9690622007)

Solutions

  1. Re-invoke `rewrite` with exactly `{ text: <non-empty string>, losses: [{content, reason}] }` and no extra keys
  2. Read `params.summary` in the thrown message — it lists each violated path and expected type
  3. Ensure each loss object has both non-empty `content` and non-empty `reason`; pass `[]` when nothing was dropped

Example fix

// before
rewrite({ text: "", summary: "shrunk" })
// after
rewrite({ text: "full compressed text", losses: [{ content: "dropped example", reason: "illustrative only" }] })
Defensive patterns

Strategy: validation

Validate before calling

const parsed = rewriteSchema(rawParams);
if (parsed instanceof type.errors) {
  // repair/retry the tool call using parsed.summary before executing
}

Type guard

function isRewriteArgs(p: unknown): p is { text: string; losses: { content: string; reason: string }[] } {
  return rewriteSchema(p) instanceof type.errors === false;
}

Try / catch

try {
  await rewriteTool.execute(id, rawParams);
} catch (err) {
  if (err instanceof Error && err.message.startsWith("rewrite received invalid arguments")) {
    // feed err.message (schema summary) back to the model as corrective feedback
  } else throw err;
}

Prevention

When it happens

Trigger: Calling the `rewrite` tool with: `text` missing or empty string; `losses` not an array or containing entries missing/empty `content` or `reason`; any extra top-level property (schema uses `"+": "reject"`).

Common situations: A weaker model omits the losses array or passes losses as objects with renamed keys; a prompt-injected or hand-rolled tool call includes extra fields like `summary`; JSON argument truncation yields partial objects.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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