Repository navigation
Description
Context & Rationale
Running external tools has no single owner. run_subprocess and run_subprocess_async (core/process.py:218-343, :345-498) are near-copies that have drifted. Process-group termination is written four times (ai/harness/shell.py:314, ai/review/review_environment.py:225, k8s/port_forward_daemon.py:41, sandbox/host.py:41). Under dry-run the runner only prints "Would run command" and still executes, so 219 is_dry_run() calls across 64 files make the decision instead. The uv --preview-features flags are injected in three places with different sets (commands/ci.py:180, :271, commands/uv.py:54).
Five command modules copy a ~25-line _get/_LAZY_OBJECT_MAPPING block (138 call sites) whose main use is letting tests patch run_subprocess by name. Tests patch it in 29 modules (117 patches), and 12 test files patch subprocess.run globally.
Scope & Deliverables
- Deliverable:
core/processowns running tools: one implementation for sync and async, the process-group lifecycle and kill on timeout, the dry-run decision based on intent the caller declares, and tool argv preparation such as the uv flags.- Commands receive the runner through one seam; tests replace it with one shared recording fake.
- The
_getblocks become function-local imports. - Staged: process groups and the sync/async merge first.
- Constraint:
--dry-runnever executes a mutating command.
Strategic Alignment
- Design: none
- Depends on: none
Test design: the process fake (2026-10-07)
The owner decided on 2026-10-07, in the test design #1307, that tests double only process edges, each through one seam, and that every fake ships with a contract suite. This item's runner is the seam for the process edge: every program except git and bwrap, with shutil.which as part of the fake. Its "one shared recording fake" is that edge's fake.
The four process-group copies stay this item's to consolidate. At 5c45b1e they sit at ai/harness/shell.py:338, ai/review/review_environment.py:396 (which has no caller), k8s/port_forward_daemon.py:79 and sandbox/host.py:58. The package migrations (#1330, #1328, #1322 and #1335) only confirm that none remains in their packages.
Acceptance criteria (added).
- Ships the edge's fake under
tests/support/fakes/and its contract suite (fake and real side, the real side against recorded responses or a local tool, never a live service), per the ADR "Tests double only process edges, through seams" that docs(cli): docs/TESTING.md holds the test conventions, ADR 0005 records that tests double only process edges, and AGENTS.md and the contributor docs point to them #1308 delivers.
Housekeeping (added; the repository's standard gates, not new scope).
-
uv run devops cipasses.
Strategic alignment (added).
- Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase D).
- Depends on (added): test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312. Blocks (added): test(github): github/ is tested through its public interface over the gh process and session fakes, with no internal patches or private imports #1321, test(k8s): k8s/ is tested through its public interface over the Kubernetes API, process, HTTP and keyring fakes, with no internal patches or private imports #1322, test(k8s): devops k8s commands are thin adapters tested over edge fakes, and the _K8sModule patch forwarding is gone #1323, test(cli): devops pr, gh and repos are thin adapters tested over edge fakes, and merge readiness is tested in its package #1324, test(ci): devops ci, test, devcontainer, workspace, install-tools, uv, branches and pipeline are tested over edge fakes, with no lazy patch targets or PYTEST_CURRENT_TEST checks #1325, test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326, test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327, test(review): ai/review and review/ are tested through one public interface over the model, tool-executor and process fakes, with no mock detection in src #1328, test(ai): Wire rag once in ai/rag, test with edge fakes #1329, test(mcp): mcp, agent and tool tests run on edge fakes #1330, test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331, test(security): scanner, secret and crypto tests run on the executor, process, http and keyring fakes, and scanners stop looking for mocks #1332, test(cli): Use edge fakes and real git; drop test rebind hooks #1333, test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334, test(infra): infrastructure tests run on edge fakes #1335.
Update 2026-10-08: refinement
The constraint is weaker than the owner's dry-run rule (#412). It becomes: under a dry run the runner starts no child that makes an external request or changes state and returns its PlannedRequest; only a declared local read runs (core/process.py:363-393).
- With the process fake,
gh,kubectlandgit commitstart nothing under a dry run; a declaredgit rev-parseruns.
Proposed design
Problem statement
The devops-cli project has inconsistent and duplicated process execution logic across multiple files. There are near-identical functions for running subprocesses (run_subprocess and run_subprocess_async), multiple implementations of process-group termination, widespread use of a dry-run flag scattered across 64 files, and inconsistent injection of uv flags in three places.
Acceptance criteria
- Criterion 1: One process runner owns execution, process groups, and dry-run logic
Verification: All external tool execution goes through a single core/process.py implementation for both sync and async operations - Criterion 2: Process-group lifecycle is consolidated into one location
Verification: Four existing process-group termination implementations (ai/harness/shell.py:314, ai/review/review_environment.py:225, k8s/port_forward_daemon.py:41, sandbox/host.py:41) are consolidated into core/process.py - Criterion 3: Dry-run decision is made consistently based on caller intent
Verification: The dry-run behavior properly handles the declared local read operations while preventing external requests under --dry-run mode - Criterion 4: Tool argv preparation with uv flags is centralized
Verification: Three places injecting uv --preview-features flags are consolidated into one location in core/process.py - Criterion 5: Tests can patch run_subprocess through a single seam
Verification: Tests replace the shared runner with one recording fake, rather than patching 29 modules or globally patching subprocess.run
Key questions
- What is the test design approach?: Tests double only process edges, each through one seam, and every fake ships with a contract suite. The runner is the seam for the process edge. [sources: docs/adr/0007-tests-double-only-process-edges.md]
- Should the dry-run behavior execute external requests?: Under a dry run, the runner starts no child that makes an external request or changes state and returns its
PlannedRequest; only a declared local read runs (proposed)
Open questions
- What is the current structure of process execution in the codebase? (missing verified source)
- How are dry-run decisions currently made? (missing verified source)
- What is the scope of changes needed for this refactoring? (missing verified source)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 2, 2026
More evidence for this issue from the devsecops review session
20261001-224227(2026-10-02). Each finding below was triaged againstrelease/v0.2.25(c279c18), judged real and covered by this issue, and then upheld by a second agent that tried to refute it.src/devops_cli/ai/review/review_environment.py:225, re-rated LOW): review_environment._terminate_process_group (lines 225-230) callsos.killpg(os.getpgid(pid), SIGTERM)with no guards. Nothing calls it: a grep of src and tests finds only the definition, since criterion commands run through sandbox.host.HostSandbox. The claimed zombies and failed cleanup therefore have no path. It is dead code that duplicates the guarded helper in sandbox/host.py:41-56, which refuses PID 0/1, its own PID and its own PGID. Open issue refactor(cli): one process runner owns execution, process groups and dry-run #775 listsai/review/review_environment.py:225among the four copies of process-group termination that one process runner should own.Jayanthpulisheri commentedon Oct 3, 2026
Hey @dan-petty! Read your refactor issue around unifying process ownership, process groups, and dry-run execution. Check out veltra-agent—it acts as a single CLI execution harness that manages process lifecycles, dry-run policies, and command boundaries at the OS edge. Would love to get your thoughts on it.
dan-petty commentedon Oct 3, 2026
Consolidation (2026-10-03): #780 is a sub-issue of this item and its first stage. #780 brings the sync and async runners together on telemetry redaction and on killing the process group at timeout, using one helper in
core/process. This item then:ai/harness/shell.py:118,k8s/port_forward_daemon.py:79-102, andai/review/review_environment.py:396, which is dead code;Linked:
--dry-runpreviews for delegated commands #412, together with fix(ci):devops cichecks run for real under their own--dry-run#885, fix(review): a dry-run review writes no session directory or findings #872, chore(cli): every argument-taking--dry-runcommand path is recorded as read-only or mutating, one candidate per offender #986 and feat(cli): commands with no dry-run preview: read-only ones run, mutators gain one #886, defines which commands are read-only or mutating. This runner's refusal should read that same declaration, not define a second one.core/process.release prbefore it opens a PR #1124 pushes through GitPython outside this runner on purpose, socore/process.pystays unchanged by it.1 remaining item
dan-petty commentedon Oct 8, 2026
Amendment from the 2026-10-08 client-library audit (at 05e9388): four git children call
subprocess.rundirectly. They skiprun_subprocess, and with it the environment rule, the session'sGH_TOKENpin, its timeout handling and its span:github/metrics.py:147(git tag -l v* --format=...),:190(git rev-list --count) and:204-205(git log --pretty=format:%s%n%b);ai/rag/drift.py:55(git rev-parse HEAD).If this item's runner is the one execution path, these move onto it.
Folded here instead of a new issue: the agent filing quota (#1153) is spent for this cycle, and this refactor shares this item's change surface (every git child through the one runner). It is recorded here in full so it is not lost.
refactor(git): GitPython is removed and every git child runs through run_subprocess
Problem
Lines cited at 05e9388 (
release/v0.2.29).GitPython runs git in seven functions, while every other git child in
src(about 90 argv sites) runs throughcore/process.run_subprocess:git/operations.py:16imports it forclone_repo(:195-199),fetch_all(:202-209),pull_tracking(:212-221),create_branch(:224-231),list_branches(:234-247) anddelete_merged_branches(:250-270).commands/repos.py:62-69(_current_branch).What that costs:
GH_TOKENpin (docs/agent/tasks/task-767-github-session-per-identity.md:63), and GitPython'scustom_environment(NAME=None)cannot remove an inheritedGITHUB_TOKEN(docs/agent/tasks/task-1124-release-push-person-environment.md:33, checked with GitPython 3.2.0).Repo.clone_from,Remote.fetchandRemote.pullrun with GitPython's defaultkill_after_timeout=None, so one unreachable remote stallsdevops branches syncordevops repos clone-org.run_subprocessapplies a timeout.git version(docs/agent/tasks/task-836-mcp-command-contract.md:46).delete_merged_branchesparsesgit branch --mergedwith.lstrip("* ")and takesmain,masteror the first branch as the default (:250-263), whileai/review/runner.py:1646readsrefs/remotes/origin/HEAD.ai/knowledge_base/devops_cli/libraries/gitpython.md:32lists subprocess git as "Rejected: GitPython provides structured objects", and:19-21credit GitPython with review diffs andrepo.is_dirty(), whichai/review/runner.pyandgit/operations.py:273-279do with subprocess git.pygit2 and dulwich are not the alternative: neither runs git's credential helpers (
gh auth git-credential, or the person's own helper that #1124's pushes rely on), nor the OpenSSH host-key pinning #1114 builds on. The git CLI is the reference client, and the codebase already reads it in machine-readable form (git/operations.py:321,:380-414).Proposed remedy
Port the seven functions to
run_subprocesswith git's machine-readable output, and remove GitPython:git clone -- <url> <dest>;git fetch --all --prune; the same pull of the tracking branch as today.git check-ref-format --branch <name>, thengit switch -c <name>.git for-each-ref --format=%(refname:short) refs/heads/(andrefs/remotes/for--all), andgit symbolic-ref --short -q HEADfor the current branch.git for-each-ref --merged=<default> --format=%(refname:short) refs/heads/, thengit branch -d, with the default fromgit symbolic-ref --short refs/remotes/origin/HEAD.gitpythonfrompyproject.tomlanduv.lock,ai/knowledge_base/devops_cli/libraries/gitpython.md, its row indocs/KNOWLEDGE_BASE.mdand its entry inai/knowledge_base/devops_cli/python_packages.md.#1399 and #900 change three of these functions; whichever lands second rebases. #1333's criterion "git and GitPython run for real" becomes "git runs for real".
Acceptance criteria
rg -n "^\s*(import git\b|from git( |\.))" src testsandrg -n -i gitpython pyproject.toml uv.lock src docsprint nothing.origin/HEADnames a default other thanmain.gitonPATH(the process edge) andGITHUB_TOKEN=otherin the environment, the clone, fetch and pull children receive the session'sGH_TOKENand noGITHUB_TOKEN.uv run devops cipasses.changelog.d/<issue>.mdrecords the removed dependency under### Removed.Related: #767, #775, #900, #1114, #1124, #1333, #1399.
Found by the 2026-10-08 client-library audit.
test(security): the security and crypto tests run on the process, clo…