Skip to content

Conversation

@Chesars
Copy link
Contributor

@Chesars Chesars commented Oct 9, 2025

Summary

Implements immediate interrupt functionality for interactive textual mode, matching the behavior of interactive.py. When the user presses 'i', the agent now interrupts immediately, even during long-running commands.

Changes:

  • Modified execute_action() to use subprocess.Popen() with polling instead of env.execute(), enabling process termination on interrupt
  • Added _current_process tracking to _TextualAgent
  • Modified action_interrupt() to terminate running subprocess before injecting KeyboardInterrupt
  • Added KeyboardInterrupt handlers in query() and execute_action()
  • Added tests for interrupt during command execution

The interrupt now works for:

  • Long-running commands.
  • LLM queries.
  • Any point in the agent loop.

Closes #332

… mode

Implements immediate interrupt functionality for interactive textual mode,
matching the behavior of interactive.py. When the user presses 'i', the
agent now interrupts immediately, even during long-running commands.

Changes:
- Modified execute_action() to use subprocess.Popen() with polling instead
  of env.execute(), enabling process termination on interrupt
- Added _current_process tracking to _TextualAgent
- Modified action_interrupt() to terminate running subprocess before
  injecting KeyboardInterrupt
- Added KeyboardInterrupt handlers in query() and execute_action()
- Added tests for interrupt during command execution

The interrupt now works immediately for:
- Long-running commands (e.g., sleep)
- LLM queries
- Any point in the agent loop

Fixes SWE-agent#332
@codecov
Copy link

codecov bot commented Oct 9, 2025

Codecov Report

❌ Patch coverage is 61.11111% with 49 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/minisweagent/agents/interactive_textual.py 42.25% 35 Missing and 6 partials ⚠️
tests/agents/test_interactive_textual.py 85.45% 1 Missing and 7 partials ⚠️
Files with missing lines Coverage Δ
tests/agents/test_interactive_textual.py 94.88% <85.45%> (-1.15%) ⬇️
src/minisweagent/agents/interactive_textual.py 82.53% <42.25%> (-8.76%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Documents the new 'i' keybinding that allows users to interrupt
the agent immediately during execution, including long-running commands.
if result: # Non-empty string means rejection
raise NonTerminatingException(f"Command not executed: {result}")
return super().execute_action(action)

Copy link
Member

Choose a reason for hiding this comment

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

no, we can't do this like that,this completely bypasses the environment setup (we might not be running locally but in a docker container for example). I thought it might be possible to just catch the keyboardinterrupt at the same place? Take a look at how this is done for the non-visual interactive mode

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.

Enh: Allow to interrupt agent run in textual mode

2 participants