Skip to content

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

@RaviTharuma

Description

@RaviTharuma

Problem

After context compaction or model fallback, the LLM sometimes generates tool call arguments containing null bytes (\x00). Node.js child_process rejects these with:

The shell argument must be a string without null bytes. Received "\0"

This error occurs during bash tool execution when the command string contains embedded null bytes.

Root Cause

When OmO's context management features trigger (aggressive truncation, preemptive compaction, deduplication recovery), the conversation history gets manipulated. After this manipulation, the model sometimes produces corrupted tool call arguments containing null bytes.

This appears to happen most frequently:

  1. After preemptive compaction -- the summarized context may cause the model to hallucinate garbled bytes in subsequent tool calls
  2. During model fallback -- when switching models mid-conversation, the new model may misinterpret the context
  3. After aggressive truncation -- tool outputs replaced with [TOOL RESULT TRUNCATED] may confuse the model

Suggested Fix

Add null byte sanitization in the pre-tool-use hook chain, specifically for the bash tool:

// In pre-tool-use hook for bash tool
if (input.tool === 'bash' && typeof input.input?.command === 'string') {
  if (input.input.command.includes('\x00')) {
    // Strip null bytes and log warning
    input.input.command = input.input.command.replace(/\x00/g, '');
    log('[sanitize] Stripped null bytes from bash command', { sessionID: input.sessionID });
  }
}

Alternatively, this could be a general tool argument sanitizer that strips null bytes from all string arguments across all tools.

Environment

  • OmO v3.9.x with experimental features enabled:
    • aggressive_truncation: true
    • preemptive_compaction: true
    • dynamic_context_pruning: enabled with deduplication + supersede_writes + purge_errors
  • Models: Claude Opus 4.6 with fallback chain to Kimi K2.5, GLM-5, Claude Sonnet 4.6
  • Session with 7000+ messages over 2 days (very long session)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage:bugConfirmed bug with repro steps

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions