perf(agent): avoid preview allocations for non-truncated strings (fix #894) (#924)

* perf(agent): avoid preview allocation on non-truncated strings

* Update src/worker/container.rs

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* chore(ci): annotate test assertions for no-panics gate

* fix: remove unnecessary allocation and consolidate tests

- Remove redundant `.to_string()` on `&String` in container.rs error arm
- Bind `format!()` result to a let in job.rs to avoid Cow borrowing from temporary
- Merge borrowed/owned Cow assertions into existing tests, drop misleading comments

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* fix: restore separate test functions for CI regression check

Keep dedicated `test_truncate_short_string_borrows` and
`test_truncate_long_string_owns` tests so the PR diff contains
new `#[test]` functions, satisfying the regression test enforcement check.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
Nige
2026-03-22 00:04:02 -07:00
committed by GitHub
co-authored by gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> [email protected] <[email protected]> Claude Opus 4.6
parent a09c023642
commit 1a62febe67
3 changed files with 22 additions and 5 deletions
+1 -1
View File
@@ -472,7 +472,7 @@ impl LoopDelegate for ContainerDelegate {
"tool_name": tc.name,
"output": match &result {
Ok(output) => truncate_for_preview(output, 2000),
Err(e) => format!("Error: {}", truncate_for_preview(e, 500)),
Err(e) => format!("Error: {}", truncate_for_preview(e, 500)).into(),
},
"success": result.is_ok(),
}),
+5 -1
View File
@@ -800,12 +800,16 @@ Report when the job is complete or if you encounter issues you cannot resolve."#
});
}
let error_preview = {
let msg = format!("Error: {}", e);
truncate_for_preview(&msg, 500).into_owned()
};
self.log_event(
"tool_result",
serde_json::json!({
"tool_name": selection.tool_name,
"success": false,
"output": truncate_for_preview(&format!("Error: {}", e), 500),
"output": error_preview,
}),
);