Skip to content

fix(tool-execute-before): strip null bytes from bash commands to prevent crash (fixes #2220)#2801

Merged
code-yeongyu merged 1 commit intocode-yeongyu:devfrom
MoerAI:fix/null-byte-sanitization
Mar 24, 2026
Merged

fix(tool-execute-before): strip null bytes from bash commands to prevent crash (fixes #2220)#2801
code-yeongyu merged 1 commit intocode-yeongyu:devfrom
MoerAI:fix/null-byte-sanitization

Conversation

@MoerAI
Copy link
Copy Markdown
Contributor

@MoerAI MoerAI commented Mar 24, 2026

Summary

  • Sanitize null bytes from bash tool command arguments before execution to prevent shell process crashes

Problem

When context compaction or model fallback occurs, the LLM can hallucinate null bytes (\x00) in tool call arguments. Node.js child_process rejects these with: The shell argument must be a string without null bytes. Received "\0". This crashes the bash tool and leaves the session in an error state.

This affects long-running sessions with context management features enabled (aggressive_truncation, preemptive_compaction, dynamic_context_pruning) and model fallback chains.

Fix

Added null byte sanitization at the very beginning of the tool.execute.before handler chain in tool-execute-before.ts. When the tool is bash and the command string contains null bytes, they are stripped before any other hooks process the command. A log entry is emitted for debugging.

This runs before all other hooks to ensure clean input for downstream processing.

Changes

File Change
src/plugin/tool-execute-before.ts Added null byte detection and removal for bash commands at the top of the handler chain

Fixes #2220


Summary by cubic

Removes null bytes from bash tool commands before execution to stop Node child_process from rejecting the shell args and crashing. This prevents session failures when models emit \x00 during context compaction or fallback. Fixes #2220.

  • Bug Fixes
    • Sanitizes bash command strings in the earliest tool.execute.before handler by stripping \x00, and logs the event for debugging.

Written for commit c56a01c. Summary will update on new commits.

@MoerAI
Copy link
Copy Markdown
Contributor Author

MoerAI commented Mar 24, 2026

I have read the CLA Document and I hereby sign the CLA

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Minimal, safe fix to prevent Node.js crashes when LLMs emit null bytes in bash commands. Logic is well-guarded and only targets the specific failure condition.

@code-yeongyu code-yeongyu merged commit 26ac413 into code-yeongyu:dev Mar 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Null bytes in tool arguments after context compaction/model fallback crash bash tool

2 participants