bytedance / bytedance/trae-agent

[Bug]: JSONEditTool rejects explicit null values for set and add

Open Beginner friendly
#458 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
12.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

### What happened?

`JSONEditTool` treats an explicit JSON `null` value as if the `value` argument were missing. As a result, both `set` and `add` reject valid tool calls that contain `"value": null`.

Minimal reproduction:

```python
import asyncio
import json
import tempfile
from pathlib import Path

from trae_agent.tools.base import ToolCallArguments
from trae_agent.tools.json_edit_tool import JSONEditTool

async def main():
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / "data.json"
path.write_text('{"value": 1, "items": []}')
tool = JSONEditTool()

set_result = await tool.execute(
ToolCallArguments(
{
"operation": "set",
"file_path": str(path),
"json_path": "$.value",
"value": None,
}
)
)
add_result = await tool.execute(
ToolCallArguments(
{
"operation": "add",
"file_path": str(path),
"json_path": "$.items[0]",
"value": None,
}
)
)

print(set_result.error)
print(add_result.error)
print(json.loads(path.read_text()))

asyncio.run(main())
```

Observed output:

```text
A 'value' parameter is required for the 'set' operation.
A 'value' parameter is required for the 'add' operation.
{'value': 1, 'items': []}
```

The check currently uses `value is None`, which cannot distinguish an omitted argument from an explicitly supplied JSON `null`.

### What did you expect to happen?

When the tool call contains the `value` key, `None` should be treated as the JSON value `null`. The example above should produce:

```json
{"value": null, "items": [null]}
```

Only a missing `value` key should return the required-parameter error.

### Traceback

No exception is raised. The tool returns `error_code=-1` with the required-parameter message shown above.

### What is your system, Python, dependency version?

- OS: macOS arm64
- Python: 3.12.14
- trae-agent commit: `e839e55`

### Additional information that you believe is relevant to this bug

In OpenAI strict mode, optional tool parameters are included in `required` and made nullable by `Tool.get_input_schema()`. The generated schema can therefore permit an explicit `null` value while `JSONEditTool.execute()` rejects it at runtime.

The intended fix is to check whether `"value"` is present in the arguments rather than checking whether its value is `None`. Regression tests should cover setting a field to `null`, adding `null` to an array, and continuing to reject an omitted `value` argument.

Contributor guide

Open the contributing guide

Research direction

Start in trae_agent/tools/json_edit_tool.py and inspect JSONEditTool.execute(), using ToolCallArguments from trae_agent/tools/base.py to understand how argument presence is represented. Add regression coverage for setting and adding null values while preserving the missing-value error, then run the relevant JSONEditTool test suite and verify the reproduced JSON output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.