Skip to content

fix: Randomize bash tool sentinel to prevent output truncation from LLM-generated commands#9

Open
Ryuketsukami wants to merge 1 commit intofacebookresearch:mainfrom
Ryuketsukami:fix/bash-sentinel-randomize
Open

fix: Randomize bash tool sentinel to prevent output truncation from LLM-generated commands#9
Ryuketsukami wants to merge 1 commit intofacebookresearch:mainfrom
Ryuketsukami:fix/bash-sentinel-randomize

Conversation

@Ryuketsukami
Copy link
Copy Markdown

Problem

The bash tool in agent/tools/bash.py appends ; 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}>>. Each BashSession gets a unique sentinel at construction time. Updated filter_error() to match the new <<EXIT_ prefix pattern for stderr cleanup.

Tests

Added tests/test_bash_sentinel.py (6 tests):

  • Sentinel is not the old static string
  • Matches expected pattern <<EXIT_[hex]>>
  • Each instance gets a unique sentinel
  • 50 instances all produce unique sentinels
  • Sentinel is used in the run command

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.

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>
@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Mar 25, 2026

Hi @Ryuketsukami!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 25, 2026
@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Mar 25, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant