#6456 [Engine] String tool-call arguments are emitted with \uXXXX escapes (ensure_ascii=True in OutputParser._scan)

open · @LagutArt · 2 comentarios · En GitHub

Server & APINVIDIA / CUDAWindows

Descripción

### Area
[Engine] (the server and API)

### Environment
- Strata: 0.2.17
- OS: Windows 10
- GPU: RTX A4000 16 GB 
- RAM: 64 GB

### Related
Follow-up to the second observation in #4630 (escaped Unicode in string arguments).  
The newline/array fix from 0.2.8 does not cover this.

### What happens
When a tool parameter is declared as `"type": "string"` and contains non-ASCII text (Cyrillic, CJK, emoji, etc.), the `arguments` field in both streaming and non-streaming responses contains escaped Unicode:

```json
"arguments": "{\"path\":\"\\u041f\\u0430\\u043f\\u043a\\u0430\"}"
```
instead of the readable form:
```json
"arguments": "{\"path\":\"Папка\"}"
```

Array/object parameters and ordinary assistant text are fine.
### Where
`terminal/serve/frontend.py`, method `OutputParser._scan()` — the four places that emit string parameter content via `json.dumps` without `ensure_ascii=False`.

Nearby `_close_scan()` already does it correctly:
```python
json.dumps(v, ensure_ascii=False)
```

The streamed fragments are later concatenated for non-stream responses as well, so the escapes appear in both modes.

### Suggested fix
```diff
--- a/terminal/serve/frontend.py
+++ b/terminal/serve/frontend.py
@@ -2253,7 +2253,8 @@ class OutputParser:
                         declared = self.sdeclared.get(pname) if pname else None
                         v = coerce_value(inline, declared) if pname else _SKIP
                         if v is not _SKIP and declared == "string":
-                            args(("" if self.sfirst else ",") + json.dumps(pname) + ":" + json.dumps(v))
+                            args(("" if self.sfirst else ",") + json.dumps(pname, ensure_ascii=False)
+                                 + ":" + json.dumps(v, ensure_ascii=False))
                             self.sfirst = False
                             self.sset.add(pname)
                         elif v is not _SKIP:
@@ -2263,7 +2264,7 @@ class OutputParser:
                     if pname is not None and self.sdeclared.get(pname) == "string":
                         self.sset.add(pname)
-                        args(("" if self.sfirst else ",") + json.dumps(pname) + ':"')
+                        args(("" if self.sfirst else ",") + json.dumps(pname, ensure_ascii=False) + ':"')
                         self.sfirst = False
                         self.ss, self.sval_started = "str", False
                     else:
@@ -2291,7 +2292,7 @@ class OutputParser:
                     value = rest[:end]
                     if value.endswith("\n"):
                         value = value[:-1]
-                    args(json.dumps(value)[1:-1] + '"')
+                    args(json.dumps(value, ensure_ascii=False)[1:-1] + '"')
                     self.sp += end + close_len(rest, end, self.scloser)
                     self.ss = "between"
                     continue
@@ -2301,7 +2302,7 @@ class OutputParser:
                 if safe > 0 and rest[safe - 1] == "\n":   # may be the trailing newline before </parameter>
                     safe -= 1
                 if safe > 0:
-                    args(json.dumps(rest[:safe])[1:-1])
+                    args(json.dumps(rest[:safe], ensure_ascii=False)[1:-1])
                     self.sp += safe
                 return out
```
I applied this locally and confirmed that string arguments with Cyrillic now appear unescaped.

### How to reproduce
Any tool with a string parameter that receives non-ASCII text (e.g. `path = "Папка"` or `"Отчёт.md"`).

### Note
Root cause and the exact locations were identified with the help of an AI coding assistant; the fix was verified manually.

En el sitio

Enlaces a install, modelos, releases.