Skip to content

Conversation

@roomote
Copy link

@roomote roomote bot commented Nov 4, 2025

This PR attempts to address Issue #9022 by adding an optional background parameter to the execute_command tool.

Summary

When background is set to true:

  • Commands run without requiring user interaction
  • The agent is immediately unblocked to continue with other tasks
  • Command output continues to stream to the terminal UI
  • Commands return immediately without waiting for completion

Changes

  • Added background parameter to tool type definitions and TypeScript interfaces
  • Updated executeCommandTool.ts to handle the background parameter
  • Commands with background=true return immediately after a brief delay to capture initial output
  • Added comprehensive test coverage for background execution behavior
  • Updated tool documentation with clear examples

Testing

  • All existing tests pass
  • Added 4 new test cases covering:
    • Background execution without user interaction
    • Default behavior (background=false) still requires interaction
    • Background commands bypass timeout restrictions
    • String-to-boolean parameter parsing

Example Usage

<execute_command>
  <command>npm run dev</command>
  <background>true</background>
</execute_command>

Fixes #9022

Feedback and guidance are welcome!


Important

Adds background parameter to execute_command tool for non-blocking command execution.

  • Behavior:
    • Adds background parameter to execute_command tool, allowing commands to run without blocking.
    • Commands with background=true return immediately, streaming output to terminal UI.
  • Code Changes:
    • Updates executeCommandTool.ts to handle background parameter.
    • Modifies executeCommand function to support immediate return for background commands.
  • Testing:
    • Adds tests for background execution in executeCommand.spec.ts, covering non-blocking behavior and parameter parsing.
  • Documentation:
    • Updates tool documentation with examples of background execution.

This description was created by Ellipsis for 23011af. You can customize this summary. It will automatically update as commits are pushed.

- Add optional background boolean parameter to execute_command tool
- When background=true, commands run without requiring user interaction
- Commands return immediately without blocking when background is enabled
- Output continues to stream to terminal UI in background
- Add comprehensive test coverage for background execution

Fixes #9022
@roomote roomote bot requested review from cte, jr and mrubens as code owners November 4, 2025 15:12
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. documentation Improvements or additions to documentation enhancement New feature or request labels Nov 4, 2025
@roomote
Copy link
Author

roomote bot commented Nov 4, 2025

See this task on Roo Code Cloud

Review completed. Found 2 issues that need attention:

  • Background process reference not cleaned up - task.terminalProcess persists after early return, preventing proper management of concurrent commands
  • Initial output uses wrong variable - displays result (only set on completion) instead of accumulatedOutput (actual captured output)

Mention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 4, 2025
Comment on lines +264 to +277
// If background=true, return immediately without waiting for process to complete
if (background) {
// Give a brief moment for initial output to be captured
await delay(100)

return [
false,
[
`Command is running in the background in terminal from '${terminal.getCurrentWorkingDirectory().toPosix()}'.`,
result && result.length > 0 ? `Initial output:\n${result}\n` : "",
"The command will continue running without blocking. You will be updated on the terminal status and new output in the future.",
].join("\n"),
]
}
Copy link
Author

Choose a reason for hiding this comment

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

The early return for background commands bypasses the cleanup code that sets task.terminalProcess = undefined (lines 312, 319). This means the process reference persists on the task even after this function completes. If another command is executed while a background command is still running, the new command will overwrite task.terminalProcess, orphaning the previous background process reference. Users won't be able to interact with (continue/abort) the background process via handleTerminalOperation since the reference will be lost.

Consider managing background process references differently, perhaps by storing them in a separate collection that tracks multiple concurrent processes, or documenting that only one command (background or foreground) should run at a time per task.

Fix it with Roo Code or mention @roomote and request a fix.

Comment on lines +269 to +273
return [
false,
[
`Command is running in the background in terminal from '${terminal.getCurrentWorkingDirectory().toPosix()}'.`,
result && result.length > 0 ? `Initial output:\n${result}\n` : "",
Copy link
Author

Choose a reason for hiding this comment

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

The background return logic checks result for initial output, but result is only set in the onCompleted callback (lines 221-229), which fires when the command finishes - not during execution. For long-running background commands, onCompleted won't be called within the 100ms delay window, so result will always be empty and "Initial output:" will never show anything useful. The actual output during this window is accumulated in accumulatedOutput (line 196) via the onLine callback, but that variable isn't used for the background return value. Consider using Terminal.compressTerminalOutput(accumulatedOutput, ...) instead of result to show actual captured output.

Fix it with Roo Code or mention @roomote and request a fix.

@bozoweed
Copy link

bozoweed commented Nov 4, 2025

so use full <3

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Nov 5, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: PR [Needs Prelim Review]

Development

Successfully merging this pull request may close these issues.

feat: Allow background command execution via optional parameter

4 participants