Skip to content

refactor(workspace): bounded worktree allocation and cleanup run control operations - #1272

Merged
chubes4 merged 10 commits into
mainfrom
refactor/1243-worktree-allocation-operation
Aug 27, 2026
Merged

refactor(workspace): bounded worktree allocation and cleanup run control operations#1272
chubes4 merged 10 commits into
mainfrom
refactor/1243-worktree-allocation-operation

Conversation

@chubes4

@chubes4 chubes4 commented Aug 26, 2026

Copy link
Copy Markdown
Member

Refs #1243 — this branch advances the issue but does not close it. It lands the first bounded application operations (worktree allocation, cleanup run control) and the shared standalone test runner, covering sequencing steps 1–4 for the worktree-allocation slice. The remaining #1243 scope (repository lifecycle, inventory/inspection, workspace locking services, full operation-declared metadata, bootstrap special-case removal) is not addressed here.

What changes

Typed allocation contract and operation

  • New WorktreeAllocationRequest (inc/Workspace/WorktreeAllocationRequest.php): a readonly typed input object with one from_input() normalizer that replaces ~19-positional-parameter calls and duplicated default handling across adapters.
  • New WorktreeAllocationOperation (inc/Workspace/WorktreeAllocationOperation.php): the canonical application operation for plan() and add(). It owns task-tracker admission, local-primary detection, remote-backend routing, local fallback, and the remote-unsupported admission refusals (percentage-byte-floor exception, capacity remediation) that previously lived inline in WorkspaceAbilities::worktreeAdd().
  • WorkspaceWorktreeLifecycle gains worktree_plan_request() / worktree_add_request() taking the typed request; the legacy positional worktree_plan() / worktree_add() remain as thin adapters.

Adapters route through the operations

  • WorkspaceAbilities::worktreeAdd()/worktreePlan() delegate to WorktreeAllocationOperation; the duplicated input normalization, remote admission checks, and hasLocalPrimaryCheckout() were deleted (~170 lines).
  • CodeTaskCreator, WorkspaceCodeTaskWorkspace, and CodeTaskWorkspaceInterface now pass a WorktreeAllocationRequest instead of 10 positional arguments.
  • WorkspaceRepositoryLifecycle primary-refresh builds the typed request instead of a positional call.

Cleanup run control operation

  • New CleanupRunControlOperation (inc/Cleanup/CleanupRunControlOperation.php) with constructor-visible dependencies (evidence store, command runner, ability resolver). It owns job-backed drain (parent + child passes, drainability repairs) and resume/cancel control with typed \WP_Error results.
  • WorkspaceCommand delegates drain_cleanup_run_to_status() and control_cleanup_run_job() to it and no longer references SystemTaskDrainability directly (~180 lines removed).

Model tools projected from abilities

  • inc/Tools/WorkspaceTools.php deleted (1,793 lines); its tools are projected from canonical abilities via AbilityToolProjections.
  • GitHubTools reduced from ~1,500 lines of wrappers to two bespoke adapters (manage_github_issue composition, add_label_to_issue collection adaptation); one-to-one GitHub tools are registered through AbilityToolProjections (adds worktree-plan, publish-runner, and six GitHub projections).
  • Plugin bootstrap no longer instantiates WorkspaceTools.

Behavioral fixes on the operation boundary

  • Plan capacity identity only binds byte/inode measurements when operator intent is present, keeping plan digests stable across re-reviews; stale plans now report changed_sections naming the evidence sections that invalidated the digest.
  • WorktreeStalenessProbe::fetch() classifies Git's "couldn't find remote ref" diagnostic separately from transport failure (missing_remote_ref), and the allocation preflight can proceed from a local ref or explicit base when the remote ref is absent.

Shared test infrastructure

  • New canonical runner bin/dmc-test (isolated per-test PHP processes, targeted paths supported) and tests/support/bootstrap.php; tests/TESTING.md documents it.
  • New tests: worktree-allocation-request, workspace-operation-architecture (asserts ability/CLI adapters cannot bypass the operations and that deleted tool wrappers stay deleted), ability-tool-projections, cleanup drainability-repair coverage, and staleness fetch-retry cases. Superseded contract tests removed.

Net: +1,069 / −3,753 lines across 29 files.

Verification

Command Result
bin/dmc-test 145/145 tests passed (0 failures)
php -l over all 23 changed PHP files all pass, no syntax errors
git status clean; branch rebased check: 0 commits behind origin/main (no rebase needed)

Notes: the repository defines no locally installable lint/static-analysis tooling (no composer.json scripts, no vendor dependencies, no phpcs/phpstan binary in the environment; phpstan.neon exists but PHPStan is not vendored). CI lint/test/audit run through the Homeboy review workflow (review audit, review lint, review test) on this PR.

AI assistance disclosure

  • Model: Z.AI GLM 5.3
  • Tool: OpenCode (interactive CLI coding agent)

An earlier AI session (under human direction) implemented the branch commits. This publication pass — issue review, branch/diff inspection, verification (bin/dmc-test, php -l), push, and this draft PR — was performed by Z.AI GLM 5.3 via OpenCode. Chris Huber directs the work and remains responsible for reviewing and merging it.

@chubes4
chubes4 force-pushed the refactor/1243-worktree-allocation-operation branch from e821798 to 3adc424 Compare August 27, 2026 23:21
@chubes4
chubes4 marked this pull request as ready for review August 27, 2026 23:23
@chubes4
chubes4 merged commit 2b8c488 into main Aug 27, 2026
18 checks passed
@chubes4
chubes4 deleted the refactor/1243-worktree-allocation-operation branch August 27, 2026 23:39
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