Skip to content

feat: add nsenter-based command execution in tools sidecar with full test coverage#41

Merged
l50 merged 2 commits into
mainfrom
jayson/cap-853-execute-commands-in-tools-sidecar-via-nsenter
Jan 14, 2026
Merged

feat: add nsenter-based command execution in tools sidecar with full test coverage#41
l50 merged 2 commits into
mainfrom
jayson/cap-853-execute-commands-in-tools-sidecar-via-nsenter

Conversation

@l50
Copy link
Copy Markdown
Contributor

@l50 l50 commented Jan 14, 2026

Key Changes:

  • Added logic to execute commands within the tools container using nsenter for
    improved isolation and compatibility
  • Introduced automated detection of the tools container PID via process listing
  • Implemented detailed integration tests for PID discovery and command execution
  • Updated dependencies and build config to support direct git reference installs

Added:

  • nsenter-based command execution: RedisWorkerAgent now runs commands in the
    tools sidecar's mount namespace using nsenter, requiring shareProcessNamespace
    and CAP_SYS_ADMIN for proper operation
  • Tools container PID discovery: Added method to scan running processes for
    "sleep infinity" and select the correct PID for namespace entry
  • Comprehensive integration tests: Test cases for PID discovery, error handling,
    command execution success/failure, permission errors, timeouts, and PID caching
    in test_redis_task_queue_integration.py
  • Direct dependency reference: Added rigging as a git-based dependency in
    pyproject.toml and uv.lock for up-to-date source usage

Changed:

  • RedisWorkerAgent command execution: Replaced previous subprocess logic with
    nsenter-based invocation, including error handling for missing tools container,
    missing capabilities, and general execution errors
  • Dependency management: Updated pyproject.toml and uv.lock to allow direct
    references and to pin rigging to a specific commit via git URL
  • Build config: Enabled allow-direct-references in Hatch metadata for direct
    dependency support

Removed:

  • Static wheel/sdist source URLs for rigging: These are now replaced by a git
    source reference for more precise dependency management

l50 added 2 commits January 13, 2026 23:34
Added:

- Added direct git dependency for rigging at a specific commit in pyproject.toml
- Enabled direct references in Hatch metadata to support non-PyPI dependencies

Changed:

- Updated uv.lock to track rigging as a git dependency rather than a PyPI release
- Modified uv.lock dependencies and requirements to include the direct git reference for rigging

Removed:

- Removed PyPI source distribution and wheel URLs for rigging in uv.lock since the package is now referenced directly from git
…cution

**Added:**

- Implement tools container PID discovery using `ps aux` and process name matching in
  RedisWorkerAgent, enabling targeted namespace entry for task execution
- Introduce command task execution in the tools sidecar container via `nsenter` into
  the tools container's mount namespace, supporting pod-level shareProcessNamespace
  and CAP_SYS_ADMIN requirements
- Add comprehensive integration tests for tools PID discovery, nsenter-based execution,
  error handling, PID caching, and edge cases in
  `test_redis_task_queue_integration.py`

**Changed:**

- Update command task execution logic to run commands in the tools container using
  nsenter, with improved error reporting for missing process namespace sharing or
  capabilities, and more robust subprocess result handling
- Enhance error logging for command execution failures to aid debugging
- Update docstrings for `_execute_command_task` to document new nsenter approach and
  requirements
@linear
Copy link
Copy Markdown

linear Bot commented Jan 14, 2026

CAP-853 Execute Commands in Tools Sidecar via nsenter

Description:
Update the RedisWorkerAgent to execute command tasks within the tools sidecar container using Linux namespace isolation (nsenter). This ensures commands run inside the correct container context by targeting the sidecar's mount namespace. Implements robust error handling and provides detailed results for command execution.


Objective:

Enable command execution within the tools sidecar container from the worker agent by leveraging nsenter, ensuring proper namespace targeting, error handling, and result reporting.


Scope of Work:

  • Implement _find_tools_container_pid() to locate the tools container process ID by parsing ps aux output for sleep infinity processes, excluding grep.
  • Update _execute_command_task() to:
    • Use nsenter with the located PID to run commands in the tools container's mount namespace.
    • Cache the tools container PID after first lookup for efficiency.
    • Provide clear error messages for: missing tools container, permission denied, and command timeouts.
    • Return stdout, stderr, and return code in the command results.
  • Ensure the pod configuration meets requirements (shareProcessNamespace: true, appropriate entrypoint, necessary capabilities).
  • Add or update tests:
    • 5 tests for _find_tools_container_pid()
    • 7 tests for _execute_command_task() with nsenter

Dependencies:

  • Pod must be configured with shareProcessNamespace: true
  • Tools container must use sleep infinity as its entrypoint
  • Worker container must have CAP_SYS_ADMIN capability
  • None identified beyond above prerequisites

Acceptance Criteria:

  1. Commands executed via the worker agent run within the tools sidecar container using nsenter.
  2. _find_tools_container_pid() reliably returns the correct PID or None if not found.
  3. _execute_command_task() returns stdout, stderr, and return code for each execution.
  4. Clear, actionable error messages are returned for missing container, permission issues, and timeouts.
  5. All new and updated tests for both methods pass successfully.

Additional Notes:


@l50 l50 merged commit 5c1c946 into main Jan 14, 2026
8 checks passed
@l50 l50 deleted the jayson/cap-853-execute-commands-in-tools-sidecar-via-nsenter branch January 14, 2026 07:37
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.

1 participant