Skip to content

Spec: Deepen Command execution for Git and GitHub #465

Closed
3 of 3 issues completed
Closed

Description

@JacobStephens2

Problem Statement

A Command records SIGINT, SIGTERM and SIGHUP so that it can finish through normal cleanup. Its Harness sessions and child Runs already own their execution, but Git and GitHub operations still wait inside blocking captured CLI calls. Interrupting only the factory process can therefore leave a Run, Spec run or Pass waiting for git, gh, or a child holding an output pipe.

This is observable on main at 1fbb06b: an isolated probe called the existing GitHub capture with a fixture CLI that waited for 20 seconds. Parent-only SIGTERM set the factory's interrupt flag, but the capture was still blocked after 500 ms and returned only after the fixture's recorded PID was stopped. The probe was removed after verification.

Making every CLI call refuse interruption would also break existing guarantees: an interrupted Failed run still saves its work, a confirmed Self-merge still finishes its cleanup, and a Spec run still accounts for its Tickets. Those operations need explicit permission to finish.

Solution

Deepen Command execution into one owning module shared by Harness, Git and GitHub execution. Ordinary captured Git/GitHub work observes interruption and stops its owned execution before returning. Existing finishing operations use an explicit completion view that keeps their current behavior without clearing the recorded interruption or allowing more Run work to start.

User Stories

  1. As the Day shift, I want a parent-only interrupt to stop a Command waiting on Git, so that a scheduled Run can end through its normal Failed run path.
  2. As the Day shift, I want a parent-only interrupt to stop a Command waiting on GitHub, so that a slow CLI call does not keep an interrupted Pass or Run alive.
  3. As the Day shift, I want a recorded interrupt to prevent an ordinary CLI call from starting, so that cancellation cannot turn into another read or mutation.
  4. As the Day shift, I want an interrupted command's child and output readers to finish before it returns, so that process ownership survives output-pipe failures.
  5. As the Day shift, I want an interrupted Failed run to abort an unfinished merge and save its work, so that a Continuation can take it over.
  6. As the Day shift, I want a Failed run whose salvage push fails to keep its worktree and Issue branch, so that local work is not lost.
  7. As the Day shift, I want an interrupted Failed run to find its open pull request and convert it to a draft, so that unfinished work does not remain ready for review.
  8. As the Day shift, I want a merge whose CLI was interrupted after GitHub accepted it to be recognized at the requested head, so that a completed Self-merge is reported correctly.
  9. As the Day shift, I want a merge at a different head to remain a failure, so that interruption cannot weaken the exact-head check.
  10. As the Day shift, I want a confirmed Self-merge to finish deleting its Issue branch and closing its issue after interruption, so that its existing completion guarantees survive.
  11. As the Day shift, I want Claim release and removal to finish after interruption, so that the tracker continues to show what can be taken over.
  12. As the Day shift, I want both kinds of worktree to be removed after interruption when their work need not be kept, so that cancellation does not leave avoidable local state.
  13. As the Day shift, I want an interrupted Spec run to drain active Tickets and publish their final checklist, so that its Spec PR and Run notification agree about what happened.
  14. As the Day shift, I want interruption to prevent another Ticket or Spec review from starting, so that completion accounting cannot resume the Spec run's work.
  15. As the Day shift, I want Git diagnostics, retries and GitHub parsing to retain their current behavior, so that this refactor changes execution ownership without changing command answers.
  16. As a maintainer, I want execution faults tested through one owning interface, so that fixes have locality and leverage across all three callers.
  17. As the Day shift, I want every Harness's existing stop behavior and streamed-state recovery to survive, so that the new shared implementation does not regress sessions, checks or Resume.

Implementation Decisions

The design tree was settled in four rounds: scope and compatibility; execution interface and policy; transitive completion paths; then tests, documentation and Ticket size. Every branch below is settled; there is no decision reserved for a human.

  1. Scope the deepening to local CLI execution on behalf of a Command. Share ownership mechanics already used by Harness execution, then migrate Git and GitHub captures. Reason: the friction is reproduced, and these callers exercise the same spawn, capture, supervision and cleanup machinery. Child Run ownership retains its separate graceful protocol because a child Run must finish its own domain cleanup and report its ending.
  2. Use two synchronous execution operations: captured output and streaming with retained consumer state. The owner receives a prepared command, optional stdin, a diagnostic name, interruption policy and the real stop action; streaming additionally receives its consumer and state. Keep the current Harness-facing interface, with its adapter preparing environment and stop behavior. Reason: callers already finish one CLI execution at a time; public start/poll/wait handles would add lifetime and ordering obligations without a current caller needing that flexibility.
  3. Bind interruption policy to immutable Git and GitHub views. Git remains ordinary by default; a completion view returns an independent value for the same directory. GitHub operations become methods on an ordinary-by-default value with an independent completion view. Nested reads, mutations and parsers use the same value. Pass these values through branch and label helpers where required, and remove the migrated free-function implementations rather than retaining a second convenience interface. Reason: binding once carries the policy through the whole operation and prevents a nested helper from silently reverting to ordinary execution.
  4. Ordinary work observes the recorded flag before spawn, during supervision and before returning. Once observed, interruption wins over exit status or transport failure, after cleanup, and returns the existing interrupted error. Completion execution ignores that flag for its own lifetime and retry waits, but does not modify it or any ordinary view. Reason: normal work must stop while finishing work retains the permission it already has; a global or thread-local override would grant unrelated work that permission.
  5. Ownership begins immediately after spawn. Concurrent readers drain both captured byte streams; optional stdin is written once and closed. Every fallible setup step, worker failure, panic and unwind after spawn is covered by a guard. A return follows child reaping and joining every started worker; execution failure stops the known child tree and owned process groups first. EOF alone does not finish an execution. Reason: prompt writers, readers and pipe holders can outlive the direct child, and cleanup must retain locality even after partial startup.
  6. Preserve the existing stop and successful-completion behavior. Each CLI runs in its own process group. Git/GitHub use SIGTERM with the existing ten-second grace, then SIGKILL of known descendants and owned groups. Harness uses its adapter's existing stop action and signals. Move the current process-tree implementation with the owner; its own process snapshot remains a direct capture to avoid recursive cleanup. Successful execution still leaves background work that owns none of its I/O alone. Reason: reuse the established mechanism without changing Harness behavior or claiming a new guarantee of discovering every escaped descendant after its ancestry has been lost.
  7. Keep result interpretation in Git and GitHub. The owner returns bytes and uninterpreted status. Git retains its ten-second held-lock retry, error-first stderr and stdout tails; ordinary retries observe cancellation. Git's boolean exit-answer operation returns false only for a completed nonzero status, and propagates cancellation or transport failure as errors. GitHub retains trimmed text, JSON, paginated-item parsing and existing diagnostic wording. Captured stdout stays captured. Reason: process lifetime and domain answers are different responsibilities, and cancellation must not become an absent ref, a negative ancestry answer or missing merge state.
  8. Audit optional and fallback reads for swallowed cancellation. Existing best-effort notification metadata and Setup suggestions may keep their fallback behavior, with their enclosing interrupt checks still preventing work or writes. State probes that select branches, classify a merge or authorize work must propagate interruption before proceeding. Reason: converting an execution error with an optional-read shortcut must not turn cancellation into permission to continue.
  9. Select completion inside existing finishing domain operations, including their transitive helpers. This covers Failed run merge detection/abort, staging, diff checks, failure commit, push, PR lookup and draft conversion; post Self-merge branch deletion and origin reconciliation, issue state and closure; Claim ending's origin/PR discovery, label/state reads, label creation and edits; both worktree Drops' common-directory lookup, removal and branch deletion, plus kept-worktree head reporting. Reason: these operations already run after interruption, and protecting only their final write would still block their prerequisites. Existing retry, warning, Policy refusal and keep-worktree behavior stays in those modules.
  10. Reconcile a failed or cancelled merge through a completion GitHub view. Accept it as a merge only when GitHub reports MERGED at the requested head. The merge request itself remains ordinary. Reason: cancellation can occur after the remote mutation committed, and only the existing exact-head evidence authorizes postmerge completion.
  11. Use completion for Spec accounting after child endings. After ordinary Spec PR resume, its accounting operations and Ticket graph rereads following child endings use completion views, including checklist publication during interruption drainage and restoration after failed Spec review. Scheduling continues reading the unchanged interrupt flag before every new Ticket or review. Reason: accounting must reach the existing Spec PR even while children finish, without permitting new implementation work. Initial selection, branch setup and Spec PR resume stay ordinary.
  12. Keep unrelated waits outside this refactor. Native file-lock acquisition, HTTP requests, new command timeouts and continuous descendant discovery are unchanged. Final Run notification sending needs no completion migration because it uses bounded HTTP rather than Git/GitHub children. Base fix mark release is native filesystem work. Reason: this candidate is captured CLI ownership; expanding it would introduce independent behavior and obscure verification of the chosen seam.
  13. Sharpen the existing domain definitions through the last Ticket. Record in the domain glossary that ordinary CLI work of an interrupted Command stops, while Failed run salvage, confirmed Self-merge completion, Claim ending and Spec accounting still finish. No new domain term or ADR is needed. Reason: this clarifies existing concepts and their behavior; the interface refactor is reversible and contradicts none of ADRs 0002, 0004, 0006, 0008, 0010, 0012 or 0013.
  14. Publish three sequential Tickets. First extract the shared owner as a green prefactoring; then migrate Git and its completion paths; finally migrate GitHub and all transitive completion paths. Reason: each change is verifiable in one fresh context window, while a single Ticket would combine execution extraction, broad GitHub call-site migration and sensitive workflow verification. The GitHub Ticket depends on Git's completion views for mixed Claim and branch reads; there is no separate final integration Ticket because that Ticket completes and verifies the whole path.
  15. Choose the synchronous bound-view design after comparing alternatives. Reject the flexible owned-handle design because it exposes start/poll/consume/drop ordering and mode selection to callers that immediately wait anyway. Take the minimal design's single owner, but reject separate root operations coupled to Harness types: Harness preparation belongs in its existing adapter. Take the common-caller design's ordinary defaults and immutable completion views. Reason: this combination yields the most depth at the execution interface and locality for transitive completion permission, despite the mechanical GitHub migration.
  16. Wake supervision when a worker completes, with a maximum 100 ms wait between interrupt checks. Keep wake notification internal to the owner and send only completion notifications, including on worker unwind; do not poll short-lived captures through a mandatory 100 ms sleep. Reason: Git and GitHub make many short calls, so inheriting the Harness owner's fixed sleep for every call would introduce avoidable latency. Child status and all worker results must still be checked before returning.

Testing Decisions

  1. The interface is the test surface. Move the existing ownership tests to the shared execution interface, retaining Harness-specific assertions at the Harness seam. Replace the old mechanics tests when the implementation moves; do not keep parallel suites asserting private worker layout. Reason: one implementation should earn leverage across callers, and tests should survive internal refactors.
  2. Use local-substitutable dependencies. Exercise the same execution interface with fixture executables, real temporary Git repositories, and the existing fake GitHub executable for workflow tests. These supply concrete adapters at the executable seam; no new remote port or mock trait is required. Reason: process lifetime can be reproduced locally without GitHub network access or live Harness turns.
  3. Test captured lifecycle and policy in isolated subprocesses. Cover each recorded signal, refusal before spawn, active ordinary cancellation, completion after an already-recorded interrupt, signal arrival during completion, independence of ordinary and completion views, concurrent stdout/stderr drain, nonzero status, partial startup/worker faults, and an exited CLI whose owned group still holds an output pipe. Cover detached descendants while their ancestry is available and preserve existing stop-grace tests. Track and clean up fixture PIDs directly. Reason: the interrupt flag is process-wide, and timing or pipe faults must not be replaced by tests of private flags.
  4. Preserve Harness transport recovery. A normally returned streaming consumer still yields its state after ordinary transport failure; consumer panic/startup failure yields none, and recorded interruption suppresses recovery and retained reads. Reason: the recent interpretation fixes depend on these distinctions.
  5. Verify policy through existing Command workflows. Preserve interrupted Failed run salvage, failed-push retention, Claim release/removal, worktree removal, postmerge interruption and exact-head merge reconciliation. Add parent-only Git/GitHub interruption fixtures and the missing case where a Spec PR already exists when interruption drains Tickets: its persisted checklist must show final outcomes and no new Ticket or Spec review may start. Reason: testing only the owner would miss wrong completion policy in a domain adapter.
  6. Preserve domain answers and diagnostics. Keep real Git failure/held-lock tests and GitHub text/JSON/pagination tests; add cancellation cases for boolean and optional state probes. Reason: this refactor must not reinterpret cancellation as a normal command answer.
  7. Check representative short captures for an added polling floor, without a timing-sensitive CI benchmark. Reason: worker wakes are an implementation detail, while imposed per-command latency is part of the interface; a noisy shared machine should not make a tight runtime assertion fail.
  8. Baseline evidence: 13 Harness process tests and 106 existing Failed run, Merge run, process-tree and Spec run integration tests passed on the reviewed head. The temporary GitHub interrupt probe reproduced the gap; it was removed. Each Ticket runs relevant checks, and the final Ticket runs formatting, all-target Clippy with warnings denied, and the full test suite. Reason: those tests already encode the completion guarantees this design preserves.

Out of Scope

New Harnesses, sandbox or approval settings, new scheduling or concurrency settings, changes to Claim eligibility, native lock cancellation, universal CLI timeouts, new process-tree discovery guarantees, notification transport changes, and changes to the child Run protocol. No implementation, domain-document edit, commit, branch, push or pull request is part of this Architecture review.

Further Notes

Strength: Strong · Dependencies: local-substitutable · Covered by: no open issue (46 titles and bodies checked, then rechecked before publication).

Files: src/process.rs (new), src/harness/process.rs, src/harness/process_tree.rs, src/git.rs, src/github.rs, src/branch.rs, src/labels.rs, src/delivery.rs, src/claim.rs, src/worktree.rs, src/spec_run.rs, src/spec_run/spec_pr.rs, CONTEXT.md, tests/process_tree.rs, tests/failed_run.rs, tests/merge_run.rs, tests/spec_run.rs.

Before

flowchart LR
  C[Command] --> G[Git module]
  C --> H[GitHub module]
  C --> A[Harness adapter]
  G -. blocking capture .-> P[CLI children and I/O]
  H -. blocking capture .-> P
  A --> E[Command execution module]
  E --> P
  classDef leak stroke:#dc2626,stroke-width:2px;
  class G,H leak
Loading

After

flowchart LR
  C[Command] -->|ordinary or completion| G[Git module]
  C -->|ordinary or completion| H[GitHub module]
  C --> A[Harness adapter]
  G --> E[Command execution module]
  H --> E
  A --> E
  E --> P[CLI children and I/O]
  classDef deep stroke-width:3px;
  class E deep
Loading

Problem: Git and GitHub capture modules are shallow at the execution seam: callers must know why recorded interruption cannot finish their implementation's blocking wait.

Solution: Deepen the shared Command execution module so ordinary and completion views carry lifetime ownership behind one interface.

Wins

  • Locality: one execution owner
  • Leverage: Git, GitHub, Harness callers
  • Tests cross the owning interface
  • Completion permission stays explicit
  • Deletion redistributes supervision across callers

Sub-issues

Sub-issues

3 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. added
    needs-triage
    on Oct 7, 2026
  2. added
    ready-for-agent
    architect-plan
    in-progress
    and removed
    needs-triage
    ready-for-agent
    on Oct 7, 2026
  3. removed
    in-progress
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    architect-plan

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions