Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(mcp): write operations reject unknown parameters in every strict_params mode (#5970)

garrytand0d177471312
diff --git a/docs/architecture/key-files/mcp.md b/docs/architecture/key-files/mcp.md
index a110e7688d..f2f910a7ad 100644
--- a/docs/architecture/key-files/mcp.md
+++ b/docs/architecture/key-files/mcp.md
@@ -27,4 +27,4 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `src/mcp/tool-defs.ts` — `buildToolDefs(ops, opts?)` helper; the stdio MCP server, the OAuth HTTP `tools/list`, and the subagent tool registry all consume it, byte-for-byte equivalence pinned by `test/mcp-tool-defs.test.ts`. `opts.strictParams: true` (when `mcp.strict_params` resolves `'reject'`) additionally declares the `_meta`/`dry_run` passthrough keys in `properties` and closes each schema with `additionalProperties: false` (schema-validating clients must not strip `_meta.session_id`); both emission states pinned. Exports the recursive `paramDefToSchema(p: ParamDef)` — single source of truth for ParamDef→JSON Schema mapping shared by `buildToolDefs` and `src/core/minions/tools/brain-allowlist.ts` (subagent registry). Recursive on `items` so nested array-of-arrays preserves inner shape on the wire, and on object `properties` (closed with `additionalProperties: false`, member `required` keys). Key ordering (type, description, enum, default, items, properties) is intentional so `JSON.stringify` output stays byte-stable. `toolAnnotations(op)` is the one annotation rule: curated op annotations win; else `readOnlyHint: true` for a read-scope op tagged `mutating: false`, `readOnlyHint: false` for one tagged `mutating: true`, nothing for untagged ops. `test/mcp-tool-defs.test.ts` has a `findArrayWithoutItems` walker that fails on any `type: 'array'` lacking `items.type`. Annotations: curated `op.annotations` win; else `readOnlyHint: true` iff `mutating === false`, `readOnlyHint: false` (+ `idempotentHint: true` when `idempotent`) iff `mutating === true`; every op declares both tags (`test/ops-mutation-tags.test.ts`).
-- `src/mcp/validate-params.ts` — param normalization + validation for dispatch (direct unit surface). `validateParams` (required/type/enum — enum membership is a TYPE error in BOTH strict modes; the caller's raw value is never echoed into the message), `normalizeOptionalParams` (null/`''` optional-param idioms become truly absent, copy-on-write), `findUnknownParams` (unknown top-level keys on the NORMALIZED object; `UNKNOWN_PARAM_ALLOWLIST` = `_meta` + `dry_run`; per-op did-you-mean from the op's OWN declared params only), `buildUnknownParamWarnBlock` (the model-visible warn notice), `resolveStrictParamsMode(engine, config)` (dual-plane `mcp.strict_params`, DB > file > `'warn'`; a failed DB read applies the LAST successfully read DB mode, held per process — fail-closed, so a transient config outage on a reject-mode server cannot re-open the warn grace period; test seam `resetStrictParamsModeCache()`). Privacy: raw unknown key names reach the CALLER only, never `mcp_request_log`. Pinned by test/validate-params.test.ts.
+- `src/mcp/validate-params.ts` — param normalization + validation for dispatch (direct unit surface). `validateParams` (required/type/enum — enum membership is a TYPE error in BOTH strict modes; the caller's raw value is never echoed into the message), `normalizeOptionalParams` (null/`''` optional-param idioms become truly absent, copy-on-write), `findUnknownParams` (unknown top-level keys on the NORMALIZED object; `UNKNOWN_PARAM_ALLOWLIST` = `_meta` + `dry_run`; per-op did-you-mean from the op's OWN declared params only, plus the explicit `PARAM_ALIAS_HINTS` aliases edit distance cannot reach, e.g. `add_timeline_entry` `content` → `detail`; dispatch rejects unknown keys on every `mutating` op regardless of `mcp.strict_params`, so a typo never commits a write), `buildUnknownParamWarnBlock` (the model-visible warn notice), `resolveStrictParamsMode(engine, config)` (dual-plane `mcp.strict_params`, DB > file > `'warn'`; a failed DB read applies the LAST successfully read DB mode, held per process — fail-closed, so a transient config outage on a reject-mode server cannot re-open the warn grace period; test seam `resetStrictParamsModeCache()`). Privacy: raw unknown key names reach the CALLER only, never `mcp_request_log`. Pinned by test/validate-params.test.ts.
diff --git a/docs/guides/troubleshooting.md b/docs/guides/troubleshooting.md
index 935100f96a..34b62d4d6a 100644
--- a/docs/guides/troubleshooting.md
+++ b/docs/guides/troubleshooting.md
@@ -15,6 +15,7 @@
| Recall returns conversation facts like "Date said …", "Attendees said …" or "Summary said …" | `gbrain repair conversation-labels` previews them ([conversation labels](repair.md#conversation-labels)); apply the printed command with `--yes` | agent, after the user agrees | `destructive` | `gbrain doctor --only conversation_label_facts --json` is ok |
| Conversation facts are dated 1970-01-01 | same preview: `gbrain repair conversation-labels` (an undated page's pre-fix facts carry a `segment 1970-01-01` context); add a `date:` to the page frontmatter before re-extracting it | agent, after the user agrees | `destructive` | `gbrain doctor --only conversation_label_facts --json` is ok |
| `remember` or `put_page` refused `source_changed` "The canonical file contains an uncoordinated local edit" on many pages nobody edited, or doctor `lost_caller_writes` warns | upgrade to v0.60.157.0 or later (a database-only v0.13.1 `validate: false` stamp was read as a file edit, #6429); then `gbrain repair failed-writes --source <id>` previews the refused writes and prints the apply command ([failed writes](repair.md#failed-writes)) | agent; the apply after the user agrees | none to preview | `gbrain doctor --only lost_caller_writes --json` is ok |
+| A write (`add_timeline_entry`, `put_page`, `remember`, any `mutating` tool) refused `invalid_params` "unknown parameter … write operations always reject unknown parameters; nothing was written" | the call named a parameter the tool does not declare (for example `content` instead of `detail`); the `suggestion` names the submitted key and the declared one; resend with the declared name. Reads keep the `mcp.strict_params` warn grace period | agent | none | the resent call returns no `invalid_params` and no `unknown_param` warning |
| A gbrain call failed with a code you don't recognize | follow `fix.next` ([protocol](../protocol/AGENT_OPERATOR_v1.md)); `gbrain errors <code>` | agent | as the fix's `consent` | the fix's `verify` |
| A graph read omits a relationship you know existed, or says someone still works somewhere they left | the default read returns relationships true today: repeat with `status: "all"` or `as_of`; to record an end, add a dated timeline line (`Ended works_at [[companies/x]]`) or `add_link ... valid_until` ([temporal edges](temporal-edges.md)) | agent | none | `gbrain doctor --only edge_validity --json` |
| A command exited 3 (`confirmation_required`) | relay `user_message`; run `fix.command` only after the user agrees | agent, after the user agrees | the payload's `effects` | the fix's `verify` |
diff --git a/docs/operations/mcp-surface-runbook.md b/docs/operations/mcp-surface-runbook.md
index 60b30b61ee..f4ad3f903d 100644
--- a/docs/operations/mcp-surface-runbook.md
+++ b/docs/operations/mcp-surface-runbook.md
@@ -149,7 +149,10 @@ clients with an explicit `rescope-client --surface full` before flipping it.
`warn` (default) accepts the call, surfaces `_meta.warnings` + a
model-visible notice block, and logs the success as
`status='success_with_warnings'`; `reject` returns `invalid_params` with
-did-you-mean suggestions.
+did-you-mean suggestions. The mode governs reads only: a write
+(`mutating: true`, such as `add_timeline_entry`, `put_page`, `remember`)
+rejects an unknown parameter in every mode, because the warn grace period
+would commit the row with the misnamed field dropped.
**Flip criterion (evidence-based):** near-zero
`success_with_warnings` rows over 30 days of production traffic —
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 476921ed75..464ef8e42a 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -376,6 +376,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }
{ since: '0.60.157.0', text: 'A page whose database frontmatter carries the v0.13.1 grandfather `validate: false` while its canonical file does not is no longer refused `source_changed` on write; the next coordinated write publishes the stamp to the file. `remember` and other caller writes that were refused that way are counted by doctor (`lost_caller_writes`) and replayed by `gbrain repair failed-writes --source <id>` on the brain host, after the user agrees to the previewed set.' },
// Wave 14 PR3 (GBRA-79); `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.
{ since: '0.60.157.0', text: 'The dream `consolidate` phase no longer merges two facts that differ in a negation, number, date or amount ("Invoice A due Monday" and "Invoice B due Tuesday" stay two facts), and facts without a typed metric now need a 0.95 embedding match (the explicit-duplicate bar) instead of the 0.85 `cycle.consolidate.cluster_threshold`, which keeps governing typed metric facts. Expect fewer takes from untyped event facts. `gbrain dream --phase consolidate --dry-run` lists the clusters it would write under `details.clusters`. Facts an earlier run wrongly merged keep the `valid_until` that run stamped: previous intervals were not retained, so there is no exact undo; `gbrain recall` still returns the facts, and `remember … replaces` records a correction.' },
+ { since: '0.60.157.0', text: 'A write tool call (`add_timeline_entry`, `put_page`, `remember`, every tool marked mutating) that names a parameter the tool does not declare is now refused `invalid_params` with nothing written, in every `mcp.strict_params` mode; the suggestion names the submitted key and the declared one (`content` → `detail` on `add_timeline_entry`). Before, the default warn mode committed the row with the misnamed field dropped. Reads keep the warn grace period.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/operation-manifest.generated.ts b/src/core/operation-manifest.generated.ts
index ec69c2871f..4eaed11ab4 100644
--- a/src/core/operation-manifest.generated.ts
+++ b/src/core/operation-manifest.generated.ts
@@ -1321,6 +1321,16 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"type": "string",
"description": "UUID; retry with it on timeout."
},
+ "expected_revision": {
+ "type": "string",
+ "description": "Revision read; omit to merge onto the current page.",
+ "fullSurfaceOnly": true
+ },
+ "force": {
+ "type": "boolean",
+ "description": "Ignore the revision.",
+ "fullSurfaceOnly": true
+ },
"slug": {
"type": "string",
"required": true,
@@ -1353,6 +1363,16 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"type": "string",
"description": "UUID; retry with it on timeout."
},
+ "expected_revision": {
+ "type": "string",
+ "description": "Revision read; omit to merge onto the current page.",
+ "fullSurfaceOnly": true
+ },
+ "force": {
+ "type": "boolean",
+ "description": "Ignore the revision.",
+ "fullSurfaceOnly": true
+ },
"slug": {
"type": "string",
"required": true,
@@ -1719,6 +1739,16 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"type": "string",
"description": "UUID; retry with it on timeout."
},
+ "expected_revision": {
+ "type": "string",
+ "description": "Revision read; omit to merge onto the current page.",
+ "fullSurfaceOnly": true
+ },
+ "force": {
+ "type": "boolean",
+ "description": "Ignore the revision.",
+ "fullSurfaceOnly": true
+ },
"slug": {
"type": "string",
"description": "Page slug.",
@@ -3498,6 +3528,16 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"type": "string",
"description": "UUID; retry with it on timeout."
},
+ "expected_revision": {
+ "type": "string",
+ "description": "Revision read; omit to merge onto the current page.",
+ "fullSurfaceOnly": true
+ },
+ "force": {
+ "type": "boolean",
+ "description": "Ignore the revision.",
+ "fullSurfaceOnly": true
+ },
"local_dir": {
"type": "string",
"description": "Trusted CLI directory hint; must equal the registered source root."
@@ -3558,6 +3598,16 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"type": "string",
"description": "UUID; retry with it on timeout."
},
+ "expected_revision": {
+ "type": "string",
+ "description": "Revision read; omit to merge onto the current page.",
+ "fullSurfaceOnly": true
+ },
+ "force": {
+ "type": "boolean",
+ "description": "Ignore the revision.",
+ "fullSurfaceOnly": true
+ },
"local_dir": {
"type": "string",
"description": "Trusted CLI directory hint; must equal the registered source root."
@@ -3602,6 +3652,16 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"type": "string",
"description": "UUID; retry with it on timeout."
},
+ "expected_revision": {
+ "type": "string",
+ "description": "Revision read; omit to merge onto the current page.",
+ "fullSurfaceOnly": true
+ },
+ "force": {
+ "type": "boolean",
+ "description": "Ignore the revision.",
+ "fullSurfaceOnly": true
+ },
"local_dir": {
"type": "string",
"description": "Trusted CLI directory hint; must equal the registered source root."
@@ -3662,6 +3722,16 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"type": "string",
"description": "UUID; retry with it on timeout."
},
+ "expected_revision": {
+ "type": "string",
+ "description": "Revision read; omit to merge onto the current page.",
+ "fullSurfaceOnly": true
+ },
+ "force": {
+ "type": "boolean",
+ "description": "Ignore the revision.",
+ "fullSurfaceOnly": true
+ },
"local_dir": {
"type": "string",
"description": "Trusted CLI directory hint; must equal the registered source root."
@@ -3727,6 +3797,16 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
"type": "string",
"description": "UUID; retry with it on timeout."
},
+ "expected_revision": {
+ "type": "string",
+ "description": "Revision read; omit to merge onto the current page.",
+ "fullSurfaceOnly": true
+ },
+ "force": {
+ "type": "boolean",
+ "description": "Ignore the revision.",
+ "fullSurfaceOnly": true
+ },
"local_dir": {
"type": "string",
"description": "Trusted CLI directory hint; must equal the registered source root."
diff --git a/src/core/ops/tags.ts b/src/core/ops/tags.ts
index 4e356e52b3..debacd7c8d 100644
--- a/src/core/ops/tags.ts
+++ b/src/core/ops/tags.ts
@@ -8,7 +8,7 @@
import type { Operation } from './contract.ts';
import { enforceClientSlugFence, readPolicyOpts } from './context.ts';
import { submitPageMutation } from '../persistence/page-mutations.ts';
-import { WRITE_REQUEST_PARAM } from '../persistence/params.ts';
+import { MERGE_PRECONDITION_PARAMS, WRITE_REQUEST_PARAM } from '../persistence/params.ts';
// --- Tags ---
@@ -19,6 +19,7 @@ const add_tag: Operation = {
description: 'Add one tag to a page (idempotent). Use when filing or grouping pages for later get_tags / list_pages tag filters. Needs write scope. On page_not_found: resolve the slug with resolve_slugs, then call again.',
params: {
request_id: WRITE_REQUEST_PARAM,
+ ...MERGE_PRECONDITION_PARAMS,
slug: { type: 'string', required: true, description: "Slug of the page to tag, e.g. 'people/alice-example'." },
tag: { type: 'string', required: true, description: "Tag to add — a plain string like 'founder' or 'follow-up', not a slug." },
},
@@ -40,6 +41,7 @@ const remove_tag: Operation = {
description: 'Remove one tag from a page. Use when a tag was wrong or no longer applies. Needs write scope. On page_not_found: resolve the slug with resolve_slugs, then call again.',
params: {
request_id: WRITE_REQUEST_PARAM,
+ ...MERGE_PRECONDITION_PARAMS,
slug: { type: 'string', required: true, description: 'Slug of the page to untag.' },
tag: { type: 'string', required: true, description: 'Tag to remove (exact match against the tags get_tags returns).' },
},
diff --git a/src/core/ops/takes.ts b/src/core/ops/takes.ts
index 6490315cb1..ac48bbcf4c 100644
--- a/src/core/ops/takes.ts
+++ b/src/core/ops/takes.ts
@@ -1,5 +1,5 @@
import { submitPageMutation } from '../persistence/page-mutations.ts';
-import { WRITE_REQUEST_PARAM } from '../persistence/params.ts';
+import { MERGE_PRECONDITION_PARAMS, WRITE_REQUEST_PARAM } from '../persistence/params.ts';
/**
* Takes + think operation cluster — pure move from operations.ts (v0.46.x
* tranche 1). Op consts stay module-private; `takesOperations` below lists
@@ -382,6 +382,7 @@ const takes_add: Operation = {
'allow-list (stdio default: world).',
params: {
request_id: WRITE_REQUEST_PARAM,
+ ...MERGE_PRECONDITION_PARAMS,
local_dir: { type: 'string', description: 'Trusted CLI directory hint; must equal the registered source root.' },
slug: { type: 'string', required: true, description: 'Page slug to attach the take to (page must exist).' },
claim: { type: 'string', required: true, description: 'The claim text (one line).' },
@@ -414,6 +415,7 @@ const takes_update: Operation = {
'allow-list; other rows present as not_found.',
params: {
request_id: WRITE_REQUEST_PARAM,
+ ...MERGE_PRECONDITION_PARAMS,
local_dir: { type: 'string', description: 'Trusted CLI directory hint; must equal the registered source root.' },
slug: { type: 'string', required: true, description: 'Page slug.' },
row_num: { type: 'number', required: true, description: 'Take row number on the page (from takes_list).' },
@@ -444,6 +446,7 @@ const takes_supersede: Operation = {
'Markdown-canonical; remote holder fencing as in takes_update.',
params: {
request_id: WRITE_REQUEST_PARAM,
+ ...MERGE_PRECONDITION_PARAMS,
local_dir: { type: 'string', description: 'Trusted CLI directory hint; must equal the registered source root.' },
slug: { type: 'string', required: true, description: 'Page slug.' },
row_num: { type: 'number', required: true, description: 'Row number of the take being superseded.' },
@@ -478,6 +481,7 @@ const takes_resolve: Operation = {
'must be in the caller\'s holder allow-list. Markdown-canonical.',
params: {
request_id: WRITE_REQUEST_PARAM,
+ ...MERGE_PRECONDITION_PARAMS,
local_dir: { type: 'string', description: 'Trusted CLI directory hint; must equal the registered source root.' },
slug: { type: 'string', required: true, description: 'Page slug.' },
row_num: { type: 'number', required: true, description: 'Take row number to resolve.' },
@@ -510,6 +514,7 @@ const takes_remove: Operation = {
'CLI: `gbrain takes remove <slug> --row N`.',
params: {
request_id: WRITE_REQUEST_PARAM,
+ ...MERGE_PRECONDITION_PARAMS,
local_dir: { type: 'string', description: 'Trusted CLI directory hint; must equal the registered source root.' },
slug: { type: 'string', required: true, description: 'Page slug.' },
row_num: { type: 'number', required: true, description: 'Take row number to remove (from takes_list).' },
diff --git a/src/core/ops/timeline.ts b/src/core/ops/timeline.ts
index 47bc7a3f93..411c3e4904 100644
--- a/src/core/ops/timeline.ts
+++ b/src/core/ops/timeline.ts
@@ -1,5 +1,5 @@
import { submitPageMutation } from '../persistence/page-mutations.ts';
-import { WRITE_REQUEST_PARAM } from '../persistence/params.ts';
+import { MERGE_PRECONDITION_PARAMS, WRITE_REQUEST_PARAM } from '../persistence/params.ts';
/**
* Timeline operation cluster — pure move from operations.ts (v0.46.x
* tranche 1). Op consts stay module-private; `timelineOperations` below
@@ -27,6 +27,7 @@ const add_timeline_entry: Operation = {
description: 'Append a dated entry to a page timeline. Replaying the same entry changes nothing. A page\'s Timeline section needs no call.',
params: {
request_id: WRITE_REQUEST_PARAM,
+ ...MERGE_PRECONDITION_PARAMS,
slug: { type: 'string', description: 'Page slug.', required: true },
date: { type: 'string', required: true, description: 'YYYY-MM-DD.' },
summary: { type: 'string', required: true, description: 'One line.' },
diff --git a/src/core/persistence/params.ts b/src/core/persistence/params.ts
index 570699fdef..8c4ea94e94 100644
--- a/src/core/persistence/params.ts
+++ b/src/core/persistence/params.ts
@@ -42,6 +42,16 @@ export const PAGE_MUTATION_PARAMS: Record<string, ParamDef> = {
request_id: WRITE_REQUEST_PARAM,
};
+/**
+ * #5970: the precondition a merging page write (`add_tag`, `remove_tag`, `add_timeline_entry`, `takes_*`) accepts.
+ * The coordinator always honored `expected_revision` / `force` on these; declared so a strict dispatcher admits them.
+ * Full surface only, like `content_origin`: accepted on every surface, off the starter schema budget.
+ */
+export const MERGE_PRECONDITION_PARAMS: Record<string, ParamDef> = {
+ expected_revision: { type: 'string', description: 'Revision read; omit to merge onto the current page.', fullSurfaceOnly: true },
+ force: { ...PAGE_MUTATION_PARAMS.force, fullSurfaceOnly: true },
+};
+
/**
* #5575 CEO-26/DX-8: where the content of an agent write came from. Optional
* and additive (MEMORY_VERBS-compatible); `tool_output` stores the write as
diff --git a/src/mcp/dispatch.ts b/src/mcp/dispatch.ts
index 2993781455..cfe64a4149 100644
--- a/src/mcp/dispatch.ts
+++ b/src/mcp/dispatch.ts
@@ -810,10 +810,11 @@ export async function dispatchToolCall(
// `dry_run` are allowlisted inside findUnknownParams. The mode resolves
// dual-plane (DB > file > 'warn') once per dispatch, and only when an
// unknown key actually exists — the all-declared common case pays no
- // config read.
+ // config read. #5970: a write (`op.mutating`) rejects in every mode; the
+ // warn grace period would commit a row with the misnamed field dropped.
const unknownParamWarnings = findUnknownParams(op, safeParams);
if (unknownParamWarnings.length > 0) {
- const strictMode = await resolveStrictParamsMode(engine, opts.config ?? loadConfig());
+ const strictMode = op.mutating === true ? 'reject' : await resolveStrictParamsMode(engine, opts.config ?? loadConfig());
if (strictMode === 'reject') {
logVerb(false);
// Privacy (amendment 11): the raw unknown key rides `suggestion` ONLY.
@@ -827,7 +828,7 @@ export async function dispatchToolCall(
: `Unknown parameter "${w.param}".`)
.join(' ');
const strict = new OperationError('invalid_params',
- `${n} unknown parameter${n === 1 ? '' : 's'} not declared in the ${name} tool schema (mcp.strict_params=reject). See suggestion for the submitted name${n === 1 ? '' : 's'}.`,
+ `${n} unknown parameter${n === 1 ? '' : 's'} not declared in the ${name} tool schema (${op.mutating === true ? 'write operations always reject unknown parameters; nothing was written' : 'mcp.strict_params=reject'}). See suggestion for the submitted name${n === 1 ? '' : 's'}.`,
suggestion);
if (isVerb) strict.protocolVersion = MEMORY_VERBS_VERSION;
return errorResult(strict, opts, { op: name });
diff --git a/src/mcp/validate-params.ts b/src/mcp/validate-params.ts
index db9c8db5c8..c9476899d3 100644
--- a/src/mcp/validate-params.ts
+++ b/src/mcp/validate-params.ts
@@ -155,6 +155,15 @@ export function normalizeOptionalParams(op: Operation, params: Record<string, un
*/
export const UNKNOWN_PARAM_ALLOWLIST: ReadonlySet<string> = new Set(['_meta', 'dry_run']);
+/**
+ * #5970: names clients send for a declared param that edit distance cannot
+ * reach. The suggestion names only the op's own declared params (checked at
+ * use), so an alias can never point at another op's surface.
+ */
+const PARAM_ALIAS_HINTS: Readonly<Record<string, Readonly<Record<string, string>>>> = {
+ add_timeline_entry: { content: 'detail', text: 'detail', body: 'detail' },
+};
+
/**
* `_meta.warnings` entry shape (amendment 13) — documented in
* docs/protocol/MCP_META_CHANNELS.md. `suggestion` is the nearest DECLARED
@@ -182,10 +191,12 @@ export interface UnknownParamWarning {
export function findUnknownParams(op: Operation, params: Record<string, unknown>): UnknownParamWarning[] {
const declared = Object.keys(op.params);
const declaredSet = new Set(declared);
+ const aliases = PARAM_ALIAS_HINTS[op.name];
const warnings: UnknownParamWarning[] = [];
for (const key of Object.keys(params)) {
if (declaredSet.has(key) || UNKNOWN_PARAM_ALLOWLIST.has(key)) continue;
- const nearest = suggestNearest(key, declared);
+ const alias = aliases?.[key];
+ const nearest = alias && declaredSet.has(alias) ? alias : suggestNearest(key, declared);
warnings.push({ code: 'unknown_param', param: key, ...(nearest ? { suggestion: nearest } : {}) });
}
return warnings;
diff --git a/test/denied-after-list.test.ts b/test/denied-after-list.test.ts
index 3570278c46..d8cf501e3c 100644
--- a/test/denied-after-list.test.ts
+++ b/test/denied-after-list.test.ts
@@ -149,7 +149,8 @@ describe('real envelopes through dispatchToolCall', () => {
const res = await dispatchToolCall(
engine,
'put_page',
- { slug: 'other/page', title: 'x', content: 'x' },
+ // #5970: an unknown parameter is refused before the handler's fence check, so only declared ones are sent.
+ { slug: 'other/page', content: 'x' },
{ ...HTTP, auth: boundAuth() },
);
expect(res.isError).toBe(true);
diff --git a/test/persistence-reconcile.test.ts b/test/persistence-reconcile.test.ts
index a6b8f913da..2e7826d1c6 100644
--- a/test/persistence-reconcile.test.ts
+++ b/test/persistence-reconcile.test.ts
@@ -460,8 +460,9 @@ test('public warn-mode put_page rejects reserved reconciliation fields for local
}, { remote, sourceId: f.id, config: { engine: engine.kind }, auth: { token: 'fixture', clientId: 'fixture-client', scopes: ['read', 'write'], sourceId: f.id },
logger: { info() {}, warn() {}, error() {} } }));
expect(result.isError).toBe(true);
- expect(JSON.parse((result.content[0] as { text: string }).text)).toMatchObject({ error: 'invalid_params' });
- expect((result.content[0] as { text: string }).text).toContain('Reserved persistence fields');
+ // #5970: a write refuses every undeclared parameter at dispatch, in warn mode too, so the reserved field is
+ // named as unknown before admission's own reserved-field refusal would run; nothing is admitted either way.
+ expect(JSON.parse((result.content[0] as { text: string }).text)).toMatchObject({ error: 'invalid_params', suggestion: `Unknown parameter "${Object.keys(extra)[0]}".` });
}
expect(await engine.executeRaw('SELECT id FROM persistence_requests WHERE source_id=$1', [f.id])).toHaveLength(0);
}), 120_000);
diff --git a/test/validate-params.test.ts b/test/validate-params.test.ts
index 3279f51af3..9b55768cdd 100644
--- a/test/validate-params.test.ts
+++ b/test/validate-params.test.ts
@@ -401,3 +401,72 @@ describe('schema invalid_params hints (agent contract B3)', () => {
expect(search.suggestion).toMatch(/^Pass `query` as a string/);
});
});
+
+// ---------------------------------------------------------------------------
+// #5970 — write operations reject unknown parameters in every mode
+// ---------------------------------------------------------------------------
+
+describe('write operations reject unknown parameters even in warn mode (#5970)', () => {
+ const timelineOp = operations.find(o => o.name === 'add_timeline_entry')!;
+ const searchOp = operations.find(o => o.name === 'search')!;
+
+ test('add_timeline_entry with a complete request plus `content` → invalid_params before the handler runs', async () => {
+ const original = timelineOp.handler;
+ let handlerCalls = 0;
+ timelineOp.handler = async () => { handlerCalls += 1; return { ok: true }; };
+ try {
+ const out = await dispatchToolCall(stubEngine('warn'), 'add_timeline_entry', {
+ slug: 'people/alice-example', date: '2026-04-03', summary: 'Met for coffee', content: 'A long note that belongs in detail',
+ }, DISPATCH_OPTS);
+ expect(out.isError).toBe(true);
+ const envelope = body(out);
+ expect(envelope.error).toBe('invalid_params');
+ expect(handlerCalls).toBe(0);
+ // Privacy: the key rides `suggestion` only; `message` counts and explains why writes reject.
+ expect(envelope.message).toContain('1 unknown parameter');
+ expect(envelope.message).toContain('write operations always reject unknown parameters');
+ expect(envelope.message).not.toContain('content');
+ expect(envelope.suggestion).toContain('Unknown parameter "content"');
+ expect(envelope.suggestion).toContain('did you mean "detail"');
+ } finally {
+ timelineOp.handler = original;
+ }
+ });
+
+ test('a read with an unknown key still succeeds with the warning in warn mode', async () => {
+ const original = searchOp.handler;
+ let handlerCalls = 0;
+ searchOp.handler = async () => { handlerCalls += 1; return { results: [] }; };
+ try {
+ const out = await dispatchToolCall(stubEngine('warn'), 'search', { query: 'alice', limt: 3 }, DISPATCH_OPTS);
+ expect(out.isError ?? false).toBe(false);
+ expect(handlerCalls).toBe(1);
+ expect(out._meta?.warnings).toEqual([{ code: 'unknown_param', param: 'limt', suggestion: 'limit' }]);
+ } finally {
+ searchOp.handler = original;
+ }
+ });
+
+ test('allowlisted `_meta` and `dry_run` are still accepted on a write', async () => {
+ const original = timelineOp.handler;
+ let handlerCalls = 0;
+ timelineOp.handler = async () => { handlerCalls += 1; return { ok: true }; };
+ try {
+ const out = await dispatchToolCall(stubEngine('warn'), 'add_timeline_entry', {
+ slug: 'people/alice-example', date: '2026-04-03', summary: 'Met for coffee', _meta: { session_id: 's' }, dry_run: true,
+ }, DISPATCH_OPTS);
+ expect(out.isError ?? false).toBe(false);
+ expect(handlerCalls).toBe(1);
+ } finally {
+ timelineOp.handler = original;
+ }
+ });
+
+ test('every mutating op in the manifest is covered by the rule (no write keeps the grace period)', () => {
+ const writes = operations.filter(o => o.mutating === true).map(o => o.name);
+ expect(writes).toContain('add_timeline_entry');
+ expect(writes).toContain('put_page');
+ expect(writes).toContain('remember');
+ expect(writes).not.toContain('search');
+ });
+});