-
Notifications
You must be signed in to change notification settings - Fork 52
feat: add --detach and --log-file support for agentcore launch --local #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pahud
wants to merge
18
commits into
aws:main
Choose a base branch
from
pahud:feature/local-detach-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
- Fix issue aws#123 where multibyte characters (Chinese, Japanese, Korean, etc.) are displayed as escaped Unicode sequences instead of readable text - Enhanced _handle_aws_response() to properly decode UTF-8 byte strings - Added JSON parsing with graceful fallback for decoded content - Maintains full backward compatibility with existing string/dict events - Added comprehensive unit tests for Unicode support - Tested with Chinese, Japanese, Korean, Arabic, Russian, and emoji characters
- Move LocalProcessManager import to module level in commands.py - Fix test_cli_imports function to use assertions instead of returns - Remove non-existent local_commands import from tests - Update main section to handle test functions properly Fixes: - AttributeError: LocalProcessManager not found in module - PytestReturnNotNoneWarning: Test functions should return None
Security improvements: - Add nosec B603 annotation for subprocess.Popen with list args (safe usage) - Explicitly set shell=False for subprocess security - Replace hardcoded /tmp usage with tempfile.TemporaryDirectory - Add security comments for file operations - Use secure temporary directories in tests Addresses Bandit security scan warnings while maintaining functionality.
- Add comprehensive unit tests for LocalAgentProcess class - Add extensive tests for LocalProcessManager functionality - Test error handling, edge cases, and concurrent scenarios - Add tests for AWS credentials handling and security settings - Test process lifecycle management and state persistence - Improve detach mode integration tests with lifecycle simulation - Add tests for corrupted state files and IO error handling - Test container name generation and subprocess security - Achieve near-complete test coverage for detach mode functionality
- Fixed broken function definition in test_local_process_manager.py - The syntax error was preventing proper module imports in CI environment - Tests now pass locally and should pass in CI - LocalProcessManager is properly imported and used in CLI commands
- Simplify agent stop tests to avoid complex generators - Remove complex subprocess mocking that could cause memory issues - Mark slow tests appropriately
…d fix function ordering
…hat may cause memory issues
…ed function-based tests - Root cause: Class-based tests with setup/teardown methods and heavy subprocess mocking were causing memory issues - Solution: Replaced with function-based tests using temporary directories per test - Removed complex subprocess.Popen and boto3.Session mocking that was consuming excessive memory - Tests now run successfully without crashes while maintaining good coverage - Kept original test file as backup (_original.py)
The test runner was picking up the _original.py backup file which contained the memory-intensive tests that were causing the crashes. Removing it completely to ensure only the stable simplified tests run.
- Fixed invalid escape sequences in regex pattern within f-string - Changed \s and \. to \\s and \\. to properly escape in f-string context - All tests now pass without warnings - Coverage remains at 88.74% (still needs improvement to reach 90%)
- Add complete test suite for logs.py utility functions (100% coverage) - Add extensive tests for LocalProcessManager detach mode functionality - Test start_agent, stop, _start_detached_process methods - Test error handling scenarios (no runtime, no AWS creds, boto3 missing) - Test process lifecycle management (graceful shutdown, force kill) - Coverage improved from 88.74% to 90.56%, meeting 90% requirement Related to detach mode PR - these tests cover the core functionality for running agents in detached/background mode.
I think this is significant complexity added into toolkit, which can be achieved with existing shell or docker commands, we discussed this internally and don't think right now its a good idea to bring this complexity |
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.
Description
Implements background execution support for local AgentCore agents by adding
--detach/-d
and--log-file
flags toagentcore launch --local
. This addresses the terminal blocking issue that affects AI IDEs like Kiro and other development workflows that need terminal reuse.Key Features:
--detach/-d
flag runs agents in background (Docker-style interface)--log-file
option redirects logs to custom files (implies --detach).agentcore/local_agents.json
--local
)Addresses Issue: Background daemon support for local mode (#144)
Type of Change
Testing
Test Coverage:
Manual Testing:
# Tested all flag combinations and validation agentcore launch --local --detach ✅ agentcore launch --local -d ✅ agentcore launch --local --log-file test.log ✅ agentcore launch --detach ❌ (proper error) agentcore launch --log-file test.log ❌ (proper error)
Checklist
Security Checklist
Security Notes:
.agentcore
directory (secure)Breaking Changes
List any breaking changes and migration instructions:
N/A - This is a fully backward-compatible addition. Existing
agentcore launch --local
behavior is unchanged.Additional Notes
Implementation Scope
This PR focuses specifically on the core detach functionality. Process management commands (
ps
,stop
,logs
) are intentionally excluded to maintain a focused, reviewable scope and will be addressed in future PRs if needed.Benefits for AI IDEs
-d/--detach
flag pattern for developersArchitecture Decisions
.agentcore/local_agents.json
--local
modeDocumentation Updates
Future Enhancements (Not in This PR)
Process management commands can be added in future PRs:
agentcore ps --local
- List running local agentsagentcore stop --local
- Stop local agentsagentcore logs --local
- View local agent logsTesting Strategy
This implementation provides a solid foundation for background agent execution while maintaining the project's quality standards and backward compatibility.