Skip to content

fix(read): accept offset/limit aliases for line_offset/n_lines - #4561

Open
fxia0018 wants to merge 2 commits into
MoonshotAI:mainfrom
fxia0018:fix/read-tool-arg-aliases
Open

fxia0018 wants to merge 2 commits into
MoonshotAI:mainfrom
fxia0018:fix/read-tool-arg-aliases

Conversation

@fxia0018

Copy link
Copy Markdown

Summary

Closes #4559.

Models trained on other agent/file-reading tools frequently emit offset/limit, but the Read tool's schema declares line_offset/n_lines. Because toInputJsonSchema sets additionalProperties: false on every object node, a single stray alias key causes Invalid args for tool "Read": must NOT have additional property 'offset' and the whole turn is discarded.

Root cause

closeObjectNodes (in input-schema.ts) hard-codes additionalProperties: false, and the same schema object is used both as the LLM-facing tool description and the runtime validator in validateExecutableToolArgs. Strict rejection is intentional (see input-schema.test.ts), so this PR does not relax it.

Changes

  • toolContract.ts — add an optional argAliases declaration to ExecutableTool (Readonly<Record<string, string>>, alias → canonical name).
  • tool-args-parse.ts — add applyToolArgAliases, a pure helper that rewrites alias keys to canonical names before validation.
  • toolExecutorService.ts — apply applyToolArgAliases(tool.argAliases, parsedArgs.data) in preflightToolCall before validateExecutableToolArgs.
  • readTool.ts — declare argAliases = { offset: 'line_offset', limit: 'n_lines' }.
  • tool-args-parse.test.ts — new unit tests covering mapping, canonical-wins precedence, alias-key removal, non-mutation, and non-object passthrough.

Design notes

  • An alias only fills a canonical argument when that argument is absent; an explicitly provided canonical value always wins.
  • The alias key is always removed, so it can no longer trip additionalProperties even when both alias and canonical are present.
  • No global relaxation of additionalProperties: genuine typo arguments are still rejected, preserving the existing input-schema.test.ts contract.
  • The alias table lives next to the tool definition and is extensible to other tools (e.g. Glob, Grep) that face the same prior.

Verification

Local environment is Node 22 while the repo requires Node >=24.15, so the unit tests could not be executed locally against the toolchain; the applyToolArgAliases logic was verified with a standalone Node script for all cases. CI will run the full vitest + typecheck.

Models trained on other agent/file-reading tools frequently emit
`offset`/limit` where Read declares line_offset/n_lines, which fails
strict schema validation and discards the entire turn.

Add an optional argAliases declaration on ExecutableTool and apply it in
preflightToolCall before runtime validation, mapping the well-known
aliases for Read. An alias only fills a canonical argument when it is
absent, so an explicit canonical value always wins; the alias key is
always removed so it can no longer trip additionalProperties.
Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:18
@changeset-bot

changeset-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 291a1c5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/agent-core-v2 Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T18:22:22.585173Z 498ef80 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 498ef80a30

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +23 to +24
/**
* Rewrites well-known argument aliases (e.g. `offset` -> `line_offset`) to the

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove comments from the comment-free package

The new JSDoc here, the inline comment at lines 52–53, toolContract.ts lines 97–103, and the test comment at test/tool/tool-args-parse.test.ts:50 are all inside packages/agent-core-v2/{src,test}. scripts/check-no-comments.mjs scans exactly these trees, so pnpm lint will fail until all four comments are removed rather than merely moving the one here.

AGENTS.md reference: AGENTS.md:L51-L51

Useful? React with 👍 / 👎.

Comment on lines +224 to +226
readonly argAliases: Readonly<Record<string, string>> = {
offset: 'line_offset',
limit: 'n_lines',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a changeset for the user-visible Read fix

Accepting these aliases changes shipped CLI-visible Read behavior: calls that previously returned Invalid args now run. The diff contains no .changeset file, so this user-useful bug fix will be absent from the next release changelog; run the required changeset workflow and add a confirmed patch entry for @moonshot-ai/kimi-code.

AGENTS.md reference: AGENTS.md:L90-L91

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool calls rejected with "must NOT have additional property" when a model emits the common offset/limit aliases

2 participants