Skip to content

feat(harness): normalize recoverable tool arguments#71

Open
senamakel wants to merge 11 commits into
tinyhumansai:mainfrom
senamakel:feat/recoverable-tool-validation
Open

feat(harness): normalize recoverable tool arguments#71
senamakel wants to merge 11 commits into
tinyhumansai:mainfrom
senamakel:feat/recoverable-tool-validation

Conversation

@senamakel

@senamakel senamakel commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

  • add an opt-in NormalizeThenReturnToolError invalid-argument policy
  • decode JSON objects emitted as strings, including markdown-fenced payloads
  • coerce non-object arguments to {} only for schemas without required fields
  • preserve precise recoverable validation errors for required-field schemas

This moves provider-neutral argument recovery into the harness admission boundary, where it runs before schema validation and before tool execution.

Validation

  • cargo fmt --check
  • cargo test normalized_ --lib
  • cargo test normalization_preserves_required_field_validation_errors --lib

Summary by CodeRabbit

  • New Features

    • Added an argument-recovery policy that repairs common malformed tool inputs, including JSON-encoded strings, markdown-fenced payloads, and non-object values where empty objects are valid.
    • Valid normalized arguments can now proceed to tool execution automatically.
    • Invalid arguments that remain unresolved produce a clear tool error without invoking the tool.
  • Bug Fixes

    • Improved schema validation for non-object values and schemas supporting multiple value types.
  • Documentation

    • Updated guidance for schema-invalid tool-argument recovery.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 30 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 653e4304-0c63-4a0e-8538-d32b0d5039d4

📥 Commits

Reviewing files that changed from the base of the PR and between 3c13ec1 and b3cd4c8.

📒 Files selected for processing (3)
  • src/harness/agent_loop/test.rs
  • src/harness/agent_loop/tools.rs
  • src/harness/runtime/types.rs
📝 Walkthrough

Walkthrough

Adds NormalizeThenReturnToolError, normalizes common malformed object arguments before validation, preserves failures for unsatisfied required fields, updates typed-schema validation, and adds end-to-end tests and documentation.

Changes

Tool argument recovery

Layer / File(s) Summary
Recovery policy and schema validation
src/harness/runtime/types.rs, src/harness/tool/mod.rs
Adds the normalization policy and changes required and properties handling for explicitly typed non-object values.
Admission-time argument normalization
src/harness/agent_loop/tools.rs
Repairs JSON strings, fenced JSON, and eligible non-object arguments before validating tool calls, while reusing the captured schema.
End-to-end coverage and documentation
src/harness/agent_loop/test.rs, docs/modules/harness/tool.md
Adds normalization test tools, Tokio coverage, and documentation for schema-invalid recovery.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AgentLoop
  participant admit_tool_call
  participant normalize_tool_arguments
  participant SchemaValidation
  participant RegisteredTool
  AgentLoop->>admit_tool_call: submit tool call
  admit_tool_call->>normalize_tool_arguments: normalize malformed arguments
  normalize_tool_arguments-->>admit_tool_call: normalized or original arguments
  admit_tool_call->>SchemaValidation: validate against captured schema
  SchemaValidation-->>admit_tool_call: validation result
  admit_tool_call->>RegisteredTool: invoke valid arguments
Loading

Possibly related PRs

Suggested reviewers: m3ga-mind

Poem

I’m a rabbit with arguments, neatly repaired,
Fenced JSON unwrapped and carefully squared.
Required fields stay honest when clues disappear,
Valid tools hop onward; errors stop here.
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: normalizing recoverable tool arguments in the harness.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@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: b2307b665f

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/agent_loop/tools.rs
Comment thread src/harness/runtime/types.rs

@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: 105892bc0e

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/agent_loop/tools.rs
Comment thread src/harness/agent_loop/tools.rs Outdated

@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

arguments: call.arguments.clone(),

P2 Badge Snapshot raw args before normalization

When normalization decodes a stringified object but the decoded object still fails validation, for example "{\"query\":42}" for a string query, call.arguments has already been overwritten before this event is emitted. AgentEvent::InvalidToolArgs documents that it preserves the raw model-supplied arguments for replay/analysis, but this now records the normalized object instead; keep a pre-normalization snapshot and emit that on validation failures.

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/agent_loop/tools.rs

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/harness/agent_loop/test.rs`:
- Around line 1112-1113: Extend the assertions in the relevant test around
run.final_response and calls to verify that the emitted tool result preserves
the original JSON string "hello" unchanged. Keep the existing execution-count
assertion, and inspect the captured tool result using the test’s existing
result-access mechanism rather than relying only on schema validation.

In `@src/harness/agent_loop/tools.rs`:
- Around line 481-490: Update the object-capability detection in the schema
normalization flow around accepts_object so schemas whose enum contains object
values are recognized as object-capable. Inspect the enum array and treat it as
accepting objects when any enum entry is an object, preserving the existing
type, properties, and required checks and allowing validate_schema_value to
normalize matching stringified objects.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6e12bd4-0496-4c11-9f6c-da32b75e25d2

📥 Commits

Reviewing files that changed from the base of the PR and between 2583fcc and 3c13ec1.

📒 Files selected for processing (5)
  • docs/modules/harness/tool.md
  • src/harness/agent_loop/test.rs
  • src/harness/agent_loop/tools.rs
  • src/harness/runtime/types.rs
  • src/harness/tool/mod.rs

Comment thread src/harness/agent_loop/test.rs
Comment thread src/harness/agent_loop/tools.rs

@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: 3c13ec1035

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/agent_loop/tools.rs

@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: 2a4ccc1f95

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/agent_loop/tools.rs

@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: 5262493eb1

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/agent_loop/tools.rs

@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: 02d7425ff2

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/harness/agent_loop/tools.rs
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.

1 participant