AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

ShellSession Incorrectly Times Out When Command Output Does Not End With A Newline

ShellSession uses marker detection with startswith, causing unterminated command output to be merged with completion marker, resulting in false timeout and session restart.

highConfidence 95%LangchainMemoryVector StoresEmbeddingsAffected V1.2.12

Origin Analysis

The _collect_output method in ShellSession detects completion by checking data.startswith(marker). When a command writes output without a trailing newline, the stdout readline() returns a single string containing the command output followed immediately by the completion marker and exit code. Since marker is not at the start, the detection fails, leading to timeout.
Run the provided Python script that uses ShellToolMiddleware to execute `printf 'hello-without-newline'`. Observe that the command is reported as timed out with output empty, exit_code None, and the session is restarted.

Fixing Code Block

Edge Case Audit

The fix assumes the marker does not appear legitimately in command output; use a unique UUID-based marker to minimize collision risk. The change should be tested with commands producing multi-line output, output containing marker-like strings, and on both POSIX and Windows line endings. Rollback: if issues arise, revert to previous startswith check but recommend ensuring commands always append newline. Ensure output truncation logic is applied to the prefix to avoid memory issues.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state