feat(harness): normalize recoverable tool arguments#71
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds ChangesTool argument recovery
Estimated code review effort: 3 (Moderate) | ~25 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
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 Codex Review
tinyagents/src/harness/agent_loop/tools.rs
Line 256 in f33dd5b
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".
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
docs/modules/harness/tool.mdsrc/harness/agent_loop/test.rssrc/harness/agent_loop/tools.rssrc/harness/runtime/types.rssrc/harness/tool/mod.rs
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
…-validation # Conflicts: # src/harness/agent_loop/tools.rs
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 65f56c076d
ℹ️ 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".
| self.policy.invalid_args, | ||
| InvalidArgsPolicy::NormalizeThenReturnToolError | ||
| ) { | ||
| normalize_tool_arguments(call, &schema); |
There was a problem hiding this comment.
Normalize arguments before tool middleware
When NormalizeThenReturnToolError is enabled and a registered tool receives a stringified or fenced JSON object, this normalization runs after run_before_tool has already inspected or approved the call. Argument-sensitive hooks such as a HumanApprovalMiddleware ApprovalFn or a custom policy middleware can therefore see only the raw string and allow it, while the tool later executes with the decoded object; normalize before the before_tool hooks, or otherwise make those hooks run on the final arguments that will be executed.
Useful? React with 👍 / 👎.
Summary
NormalizeThenReturnToolErrorinvalid-argument policy{}only for schemas without required fieldsThis moves provider-neutral argument recovery into the harness admission boundary, where it runs before schema validation and before tool execution.
Validation
cargo fmt --checkcargo test normalized_ --libcargo test normalization_preserves_required_field_validation_errors --libSummary by CodeRabbit
NormalizeThenReturnToolErrorfor schema-invalid tool-argument recovery, repairing common malformed inputs such as JSON encoded-as-strings and markdown-fenced payloads.required/propertieswhen inputs are non-objects, especially for schemas with explicit types or permissive object shapes.