wgwfn3 7d50f3fc7b
fix(sandbox): keep the exit marker last when appending audit warnings (#6307)
* fix(sandbox): keep the exit marker last when appending audit warnings

The medium-risk warning was appended after the bash exit marker and the ToolMessage was rebuilt from four fields. The subagent executor anchors its exit-status regex on the trailing 'Exit Code: N' (and fullmatches 'Command exited with code N'), so a failed command was harvested as success; the rebuild also dropped deerflow_tool_meta, artifact and id. Insert the warning before a trailing marker, leave a bare remote marker untouched, and copy the message instead of rebuilding it.

Document the warning placement in agents/middlewares/AGENTS.md.

* docs(changelog): reference #6307 in the sandbox audit entry

* fix(sandbox): keep a trailing remote exit marker last as well

Match the full sandbox.tools._BASH_EXIT_MARKER_TAIL_RE alternation when
choosing where to insert the medium-risk warning, so output that ends in
`Command exited with code N` after other text keeps the marker last too.

* test(sandbox): import the middleware tail regex inside its test

A module-level import of the new name made the whole file fail to collect
against main, hiding which tests the fix turns green.
2026-10-05 19:36:05 +08:00
..