Skip to content

Conversation

@cagataycali
Copy link
Member

Description

Fixes the "WARNING: terminal is not fully functional" issue that causes the shell tool to hang indefinitely when running pager-based commands (like git diff, git log, man, etc.) in non-interactive mode.

Related Issues

Fixes #360

Root Cause

The CommandExecutor.execute_with_pty() method was not setting the TERM environment variable in the child process. When commands spawn pagers like less, the pager:

  1. Detects incomplete terminal setup
  2. Prints "WARNING: terminal is not fully functional"
  3. Gets stuck waiting for user input that never comes

Solution

  1. Set TERM environment variable: Sets TERM=xterm-256color if not already set, enabling proper terminal capability detection
  2. Disable pagers in non-interactive mode: Sets GIT_PAGER, PAGER, and MANPAGER to cat to bypass pagers entirely when running non-interactively

Changes

  • src/strands_tools/shell.py: Add environment setup in child process before executing command
  • tests/test_shell.py: Add test to verify the fix is in place

Testing

  • All 32 existing tests pass
  • Added new test test_command_executor_sets_pager_env_in_non_interactive
  • Manual testing confirms git commands no longer hang
# Before fix - HANGS
git log --oneline -3  # ❌ Times out

# After fix - WORKS
git log --oneline -3  # ✅ Returns immediately

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective
  • I have run ruff check and ruff format
  • All existing tests pass
  • My changes generate no new warnings

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

When running commands like 'git diff', 'git log', or 'man' in
non-interactive mode, the shell tool would hang indefinitely because:

1. TERM environment variable was not set, causing pagers like 'less'
   to print 'WARNING: terminal is not fully functional'
2. Pagers would wait for user input that never comes in non-interactive
   mode

This fix:
- Sets TERM=xterm-256color if not already set, enabling proper terminal
  emulation
- In non-interactive mode, sets GIT_PAGER, PAGER, and MANPAGER to 'cat'
  to bypass pagers entirely

Fixes strands-agents#360
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] Shell tool hangs with "terminal is not fully functional" for pager-based commands

1 participant