truncation: avoid mid-rune cut with ToValidUTF8

This commit is contained in:
Levi Neely 2026-05-17 12:59:49 +02:00
parent 7237980ff5
commit 93c0b374d5
1 changed files with 1 additions and 1 deletions

View File

@ -345,7 +345,7 @@ func run(ctx context.Context, cfg agentConfig, state state) error {
}
if !isErr && cfg.ToolResultMaxBytes > 0 && len(result) > cfg.ToolResultMaxBytes {
orig := len(result)
result = result[:cfg.ToolResultMaxBytes]
result = strings.ToValidUTF8(result[:cfg.ToolResultMaxBytes], "")
result += fmt.Sprintf("\n\n[HARD LIMIT: %s output truncated — %d of %d bytes shown. This is a safety ceiling, not a semantic boundary.]",
tc.Name, cfg.ToolResultMaxBytes, orig)
}