fix: Randomize bash tool sentinel to prevent output truncation from LLM-generated commands#9
Conversation
The bash tool used a static "<<exit>>" sentinel to detect
command completion. If LLM-generated code outputs this exact
string, the tool incorrectly truncates real output.
Now uses a per-instance UUID sentinel (<<EXIT_{uuid4().hex}>>)
that is unique to each BashSession. Updated filter_error()
to match the new sentinel prefix pattern.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hi @Ryuketsukami! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Problem
The bash tool in
agent/tools/bash.pyappends; echo '<<exit>>'to every command and waits for this exact string in stdout to detect completion. This is a well-known fragile pattern — if LLM-generated code outputs the literal string<<exit>>(e.g., in test output, debug logging, or string manipulation), the tool prematurely truncates the real output.In a self-improving agent framework where the meta-agent generates arbitrary code, this is a realistic failure mode.
Solution
Replaced the static sentinel with a per-instance random UUID:
<<EXIT_{uuid4().hex}>>. EachBashSessiongets a unique sentinel at construction time. Updatedfilter_error()to match the new<<EXIT_prefix pattern for stderr cleanup.Tests
Added
tests/test_bash_sentinel.py(6 tests):<<EXIT_[hex]>>Question for maintainers
Was the static sentinel chosen for simplicity, or does any downstream parsing depend on the exact
<<exit>>string? The change is backward-compatible for command execution — only the detection mechanism is different.