feat: add nohup parameter for background shell job execution#2706
Open
chengyixu wants to merge 2 commits intoantinomyhq:mainfrom
Open
feat: add nohup parameter for background shell job execution#2706chengyixu wants to merge 2 commits intoantinomyhq:mainfrom
chengyixu wants to merge 2 commits intoantinomyhq:mainfrom
Conversation
Add `nohup: bool` parameter to the Shell tool that allows running commands in the background using nohup. When enabled, the command runs via `nohup <command> > /tmp/<log>.log 2>&1 &` and returns the log file path and PID immediately. Key changes: - Shell struct gains `nohup: bool` field (default false) - When nohup=true, command is wrapped in nohup and returns PID + log path - Console displays "Spawned" instead of "Execute" for background commands - Log file paths are extracted from tool results and preserved through context compaction via SummaryTool::Shell's new `log_file` field - Compaction template shows "Spawned (background)" with log file path Fixes antinomyhq#2635 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment on lines
+67
to
+68
| let timestamp = Utc::now().format("%Y%m%d-%H%M%S"); | ||
| let log_path = format!("/tmp/{sanitized}-{timestamp}.log"); |
Contributor
There was a problem hiding this comment.
Path Traversal Risk: The log file path uses /tmp/ with a sanitized command name, but doesn't handle potential collisions or validate the directory exists. If multiple processes run the same command within the same second, they'll overwrite each other's log files due to timestamp resolution.
Fix: Add a random component or use process ID:
let timestamp = Utc::now().format("%Y%m%d-%H%M%S");
let log_path = format!("/tmp/{sanitized}-{timestamp}-{}.log", std::process::id());Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
This comment came from an experimental review—please leave feedback if it was helpful/unhelpful. Learn more about experimental comments here.
Author
|
recheck |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #2635 - adds the ability to run shell commands as background jobs using
nohup.Changes
nohup: boolparameter added to theShelltool input schema (defaultfalse)nohup=true, the command runs vianohup <command> > /tmp/<sanitized>-<timestamp>.log 2>&1 &* [HH:MM:SS] [Spawned] <command>for background jobsSummaryTool::Shell's newlog_filefieldFiles changed
forge_domain/src/tools/catalog.rsnohup: boolfield toShellstructforge_domain/src/tools/descriptions/shell.mdforge_domain/src/compact/summary.rslog_filetoSummaryTool::Shell+ extraction from tool resultsforge_app/src/services.rsShellServicetrait signature withnohupparamforge_app/src/tool_executor.rsforge_app/src/fmt/fmt_input.rsforge_app/src/git_app.rsnohup: falseforge_app/src/system_prompt.rsnohup: falseforge_app/src/orch_spec/orch_runner.rsnohupparamforge_app/src/transformers/trim_context_summary.rs..pattern for new fieldforge_services/src/tool_services/shell.rstemplates/forge-partial-summary-frame.mdTesting
test_shell_service_nohup— verifies nohup returns PID and log file pathtest_sanitize_for_filename— verifies command sanitization for log filenamesDesign Decisions
Compaction preservation: The log file path is extracted from the tool result output (which contains
Log file: /tmp/...) and stored inSummaryTool::Shell { log_file }. During compaction, the template renders it as**Spawned (background):** ... Log file: ...so the agent always knows about running background processes.Log file path quoting: The nohup command uses single quotes around the log path to prevent shell injection when paths contain spaces or special characters.
Backwards compatibility: The
nohupfield defaults tofalseand is skipped during serialization when false, so existing tool calls are unaffected./claim #2635