{"record":{"id":"d06ad81fb8af8991","repo":"can1357/oh-my-pi","slug":"rewrite-received-invalid-arguments-params-summa","errorCode":null,"errorMessage":"rewrite received invalid arguments: ${params.summary}","messagePattern":"rewrite received invalid arguments: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/compress/protocol.ts","lineNumber":181,"sourceCode":"\t\t\t);\n\t\t}\n\t\tthis.#approved = true;\n\t\tthis.#verdict = verdict;\n\t\treturn draft;\n\t}\n\n\t/** Tool that records a draft. Thin adapter over {@link submit}. */\n\trewriteTool(): ToolDefinition {\n\t\treturn {\n\t\t\tname: \"rewrite\",\n\t\t\tlabel: \"Rewrite\",\n\t\t\tdescription: rewriteDescription.trim(),\n\t\t\tparameters: rewriteSchema,\n\t\t\tapproval: \"read\",\n\t\t\tstrict: true,\n\t\t\texecute: async (_toolCallId, rawParams) => {\n\t\t\t\tconst params = rewriteSchema(rawParams);\n\t\t\t\tif (params instanceof type.errors) throw new Error(`rewrite received invalid arguments: ${params.summary}`);\n\t\t\t\tconst draft = this.submit(params.text, params.losses);\n\t\t\t\tconst metrics = this.metrics(draft);\n\t\t\t\tconst percent = (metrics.ratio * 100).toFixed(1);\n\t\t\t\tconst summary = `Draft ${draft.round} recorded: ${metrics.sourceTokens} → ${metrics.draftTokens} tokens (${percent}% smaller), ${draft.losses.length} declared loss(es). A review turn follows.`;\n\t\t\t\tconst details: RewriteDetails = {\n\t\t\t\t\tround: draft.round,\n\t\t\t\t\tdraftTokens: metrics.draftTokens,\n\t\t\t\t\tlosses: draft.losses.length,\n\t\t\t\t};\n\t\t\t\treturn { content: [{ type: \"text\", text: summary }], details };\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Tool that accepts the newest reviewed draft. Thin adapter over {@link accept}. */\n\tapproveTool(): ToolDefinition {\n\t\treturn {\n\t\t\tname: \"approve\",","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/compress/protocol.ts#L163-L199","documentation":"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.","triggerScenarios":"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\"`).","commonSituations":"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.","solutions":["Re-invoke `rewrite` with exactly `{ text: <non-empty string>, losses: [{content, reason}] }` and no extra keys","Read `params.summary` in the thrown message — it lists each violated path and expected type","Ensure each loss object has both non-empty `content` and non-empty `reason`; pass `[]` when nothing was dropped"],"exampleFix":"// before\nrewrite({ text: \"\", summary: \"shrunk\" })\n// after\nrewrite({ text: \"full compressed text\", losses: [{ content: \"dropped example\", reason: \"illustrative only\" }] })","handlingStrategy":"validation","validationCode":"const parsed = rewriteSchema(rawParams);\nif (parsed instanceof type.errors) {\n  // repair/retry the tool call using parsed.summary before executing\n}","typeGuard":"function isRewriteArgs(p: unknown): p is { text: string; losses: { content: string; reason: string }[] } {\n  return rewriteSchema(p) instanceof type.errors === false;\n}","tryCatchPattern":"try {\n  await rewriteTool.execute(id, rawParams);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"rewrite received invalid arguments\")) {\n    // feed err.message (schema summary) back to the model as corrective feedback\n  } else throw err;\n}","preventionTips":["Send the schema summary from the error back to the model so its retry conforms","Keep tool args to exactly the schema keys (schema rejects unknown properties)","Use `strict: true` tool-calling mode with providers that support constrained JSON","Validate losses entries have non-empty `content` and `reason` before submission"],"tags":["validation","schema","tool-arguments"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}