Repository navigation
fix: tolerate extra agent tool fields - #2128
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR introduces lenient JSON input decoding for all agent tool handlers. A new ChangesLenient Tool Input Decoding
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@internal/agent/tools.go`:
- Line 106: The code currently swallows json.Unmarshal errors for matched fields
(the call using json.Unmarshal(raw, field.Addr().Interface())), which hides
type/parse failures; change it to capture the error (err := json.Unmarshal(...))
and propagate or handle it per-field: if the struct field/tag indicates leniency
(e.g., a custom tag like `lenient:"true"` on the reflected field) then
log/ignore the error and continue, otherwise return or wrap and return the error
with context (include the field.Name and raw payload) so callers can fail fast;
update the reflection code that examines field (the variable named field and
raw) to read the tag and branch accordingly instead of using `_ =
json.Unmarshal(...)`.
🪄 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: dd4f2dbc-d0f6-43cc-a42c-64986395a075
📒 Files selected for processing (20)
internal/agent/ask_user.gointernal/agent/bash.gointernal/agent/dag_def_manage.gointernal/agent/dag_run_manage.gointernal/agent/delegate.gointernal/agent/navigate.gointernal/agent/output.gointernal/agent/patch.gointernal/agent/patch_test.gointernal/agent/policy.gointernal/agent/read.gointernal/agent/remote_agent.gointernal/agent/remote_list.gointernal/agent/runbook_manage.gointernal/agent/session_search.gointernal/agent/system_prompt.txtinternal/agent/tool_registry_test.gointernal/agent/tools.gointernal/agent/tools_test.gointernal/agent/web_tools.go
| if !field.CanSet() { | ||
| continue | ||
| } | ||
| _ = json.Unmarshal(raw, field.Addr().Interface()) |
There was a problem hiding this comment.
Do not silently drop decode errors for known fields
At Line 106, unmarshal errors are ignored for every matched field. That also suppresses type errors on fields the selected action actually depends on, coercing malformed inputs to zero values and weakening parse/type guarantees. Consider making leniency opt-in per field/action instead of global.
🤖 Prompt for 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.
In `@internal/agent/tools.go` at line 106, The code currently swallows
json.Unmarshal errors for matched fields (the call using json.Unmarshal(raw,
field.Addr().Interface())), which hides type/parse failures; change it to
capture the error (err := json.Unmarshal(...)) and propagate or handle it
per-field: if the struct field/tag indicates leniency (e.g., a custom tag like
`lenient:"true"` on the reflected field) then log/ignore the error and continue,
otherwise return or wrap and return the error with context (include the
field.Name and raw payload) so callers can fail fast; update the reflection code
that examines field (the variable named field and raw) to read the tag and
branch accordingly instead of using `_ = json.Unmarshal(...)`.
Summary
Testing
Summary by CodeRabbit
Release Notes
Bug Fixes
Improvements