Skip to content

feat(agent): split Work and Code into specialized runtimes with first-class delegation #99

Closed

Description

@mdev34-lab

Scope

Keep this implementation deliberately small. The goal is to establish the basic Work/Code agent distinction, not to redesign AlphaCode's runtime, CLI, permissions, context system, or orchestration architecture.

Required behavior

  • Work is the general-purpose agent.
  • Code is the software-engineering agent.
  • Work can delegate to Code.
  • Code cannot delegate to Work.
  • Code has access to LSP functionality.
  • Work does not have access to LSP functionality.

Delegation should use the existing task/subagent mechanism and preserve the existing result/finish contract. Enforce directionality at the actual agent/tool configuration seam, not only through prompts.

LSP availability must be enforced through actual tool/context registration, not merely instructions. Reuse existing LSP tooling for Code; do not build a parallel LSP system.

Explicitly out of scope

Do not add:

  • automatic cwd/project inference
  • alphacode code / alphacode work CLI entry points
  • new permission models
  • new context systems or context-firewall architecture
  • bounded orchestration frameworks
  • recursive delegation machinery
  • workspace/project detection
  • separate runtime implementations unless the existing architecture genuinely requires one
  • unrelated Work/Code specialization

The six required behaviors above are the acceptance criteria. Everything else is unnecessary unless required by the existing architecture to implement them correctly.

Tests

Add focused regression coverage for:

  1. Work resolves to Work.
  2. Code resolves to Code.
  3. Work can delegate to Code through the real delegation path.
  4. Code cannot delegate to Work.
  5. Code receives LSP tools/context.
  6. Work does not receive LSP tools/context.
  7. Existing unrelated agent/delegation behavior remains unchanged.

Do not add hypothetical CLI/runtime tests for features outside this scope.

Implementation / PR requirements

Start from current dev. Inspect the existing agent definitions, tool registration, delegation/task mechanism, and LSP integration before changing anything. Reuse existing infrastructure wherever possible.

Run focused tests, relevant package tests, typecheck, and lint/format checks. Inspect the final diff and remove unnecessary changes.

Open the PR against dev and use the repository PR template exactly. The PR must close this issue (Closes #99), use the correct change type, contain a concise concrete explanation of what changed and why it works, include actual verification results, and include a screenshot/recording only if the implementation genuinely changes UI. Do not paste a large AI-generated PR description.

Activity

  1. added
    enhancement
    on Sep 9, 2026
  2. mdev34-lab commented on Sep 15, 2026

    @mdev34-lab
    OwnerAuthor

    Autopsy of PR #132

    PR #132 was closed without merge after 9 commits and 38 changed files. The implementation did not fail because the core idea was invalid. It failed because the first implementation was too broad, and the review cycle kept expanding the surface area instead of converging on the smallest contract that #99 actually required. urlPR #132https://github.com/mdev34-lab/alphacode/pull/132

    What went wrong

    1. The issue bundled several architectural changes into one PR.
      feat(agent): split Work and Code into specialized runtimes with first-class delegation #99 asks for two specialized agents, launch selection, first-class delegation, a context firewall, and bounded nesting. PR feat(agent): split Work and Code into specialized runtimes with first-class delegation #132 implemented all of that at once: new agent-selection infrastructure, a Code prompt/project overview, a new delegate runtime, permission isolation, commit policy, timeout/cancellation, result derivation, CLI behavior, and TUI inference. That made every review finding capable of triggering another cross-cutting change.

    2. The delegation contract was initially underspecified in code.
      The first implementation mixed Work/Code topology with subagent_depth. Review then had to disentangle two separate concepts: which delegation edges are legal versus how deep delegation may nest. Later commits moved the topology check into the delegate runtime and made subagent_depth a pure depth limit. Future work should define these invariants before implementation:

      • only work → code and code → work are legal;
      • depth is independent of topology;
      • invalid delegation is a recoverable model-visible failure.
    3. Security/permission semantics were initially implemented with identity lists.
      The first version used hardcoded EDIT_TOOLS/READ_TOOLS groupings. Review correctly rejected that as brittle. The eventual fix moved permission identity and mutates into tool metadata and derived the read-only deny set from the registry. Future implementations should start from the metadata contract instead of introducing a second source of truth.

    4. allowCommit was initially stronger in prose than in enforcement.
      The implementation evolved through several rounds of commit-form matching and eventually had to clarify the distinction between prevention and post-hoc detection. The final contract became: known commit forms are denied up front; a HEAD change is a bypass detector and marks the result unverified. Future work must specify this boundary explicitly rather than treating a post-hoc check as a permission mechanism.

    5. The result contract initially claimed more than the implementation could observe.
      changedFiles implied an exhaustive workspace diff, while the implementation only observed files touched through specific file-editing tools. This was eventually renamed to observedFiles and documented honestly. Future work should choose an observation model first: either take an actual before/after workspace snapshot, or explicitly expose tool-observed mutations. Do not call the latter changedFiles.

    6. Too much behavior was validated at the unit layer before the real runner path was covered.
      The later review forced a real runner-level delegation integration suite: a live child mutates a fixture, read-only writes are blocked, and timeout cancels a live child. That is the right level for this feature. Future attempts should build the end-to-end contract test early, then add unit tests only for deterministic helpers.

    7. The implementation accumulated scope while already under review.
      The commit history shows repeated review-driven hardening: permission metadata, validation ordering, topology rules, result extraction, typed ToolFailure, and more. Each individual correction was reasonable, but together they turned the PR into a large moving target. The final branch had 2,441 additions across 38 files for an issue whose central invariant can be expressed much more narrowly. citeturn24file0turn27file0

    Why it was closed

    There is no separate review submission explaining a single fatal technical blocker: GitHub reports the PR as closed/unmerged, and its formal review collection is empty. citeturn24file0turn28file0 The evidence instead points to scope and convergence failure: a large architectural PR accumulated multiple rounds of corrective commits and was ultimately abandoned rather than merged.

    Rules for the next attempt

    Do not resurrect #132 wholesale. Re-implement #99 from the contract outward.

    • Keep Work and Code genuinely distinct, but do not redesign unrelated agent infrastructure.
    • Make delegation a small, explicit runtime primitive with a typed result.
    • Enforce exactly two legal edges: work → code and code → work.
    • Keep nesting depth as an independent generic limit.
    • Derive permission behavior from tool metadata; no hardcoded tool-name sets.
    • Make read-only and commit guarantees enforceable at the actual child-session boundary.
    • Decide whether file reporting is tool-observation or workspace diff before naming the field.
    • Use real runner-level tests for delegation, isolation, timeout, and result delivery.
    • Keep launch-agent inference separate from precedence (--agent/positional → configured default → inference).
    • Resist adding convenience UX, extra agent relationships, or generalized abstractions until the core Work/Code contract is merged and stable.

    Bottom line: #132 was not killed by one catastrophic bug. It was killed by trying to land the entire architecture in one pass, then repeatedly widening the implementation to satisfy review. The next PR should be substantially smaller, contract-first, and integration-tested from the beginning.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions