|
| 1 | +<!-- |
| 2 | +Copyright (c) 2026 Gili Tzabari. All rights reserved. |
| 3 | +Licensed under the CAT Commercial License. |
| 4 | +See LICENSE.md in the project root for license terms. |
| 5 | +--> |
| 6 | +# CAT Execution Model |
| 7 | + |
| 8 | +This document is the canonical reference for CAT's execution hierarchy and wave-based parallelism model. |
| 9 | + |
| 10 | +## Hierarchy |
| 11 | + |
| 12 | +CAT organizes work in a five-level hierarchy: |
| 13 | + |
| 14 | +``` |
| 15 | +version |
| 16 | + └── issue |
| 17 | + └── sub-issue (decomposed from a parent issue when context is too large) |
| 18 | + └── wave (a batch of work items executed by one subagent) |
| 19 | + └── subagent (executes one wave in an isolated worktree) |
| 20 | +``` |
| 21 | + |
| 22 | +| Level | Description | |
| 23 | +|-------|-------------| |
| 24 | +| **version** | A major or minor release (e.g., `v2.1`). See `plugin/concepts/hierarchy.md`. | |
| 25 | +| **issue** | An atomic unit of work within a version. | |
| 26 | +| **sub-issue** | A child issue created by decomposing a parent issue that exceeds the context-size threshold. | |
| 27 | +| **wave** | A batch of work items assigned to one subagent. Items within a wave run in parallel; waves run sequentially only when a dependency exists between them. | |
| 28 | +| **subagent** | An isolated Claude instance that executes one wave inside a dedicated git worktree. | |
| 29 | + |
| 30 | +## Waves |
| 31 | + |
| 32 | +A **wave** is defined by a `### Wave N` subsection under `## Execution Waves` (or `## Sub-Agent Waves`) in plan.md. |
| 33 | +Each wave contains one or more top-level bullet items (`- `) listing the work to be done. Sub-items |
| 34 | +(indented bullets with ` - `) are informational and do not spawn additional subagents. |
| 35 | + |
| 36 | +```markdown |
| 37 | +## Execution Waves |
| 38 | + |
| 39 | +### Wave 1 |
| 40 | +- Implement parser module |
| 41 | +- Add parser tests |
| 42 | + |
| 43 | +### Wave 2 |
| 44 | +- Implement formatter module |
| 45 | +- Add formatter tests |
| 46 | +- Run full test suite |
| 47 | +``` |
| 48 | + |
| 49 | +### Wave Parallelism |
| 50 | + |
| 51 | +**All waves spawn simultaneously in a single API response.** There is no sequential waiting between |
| 52 | +waves unless an explicit dependency between them is declared. Within each wave, all items also run in |
| 53 | +parallel (each item is handled by the same subagent). |
| 54 | + |
| 55 | +Ordering is sequential **only when a dependency exists** between waves (e.g., Wave 2 requires output |
| 56 | +produced by Wave 1). When no dependency exists, treat all waves as launching at the same time. |
| 57 | + |
| 58 | +### When to Use Multiple Waves |
| 59 | + |
| 60 | +Use multiple waves **only** when: |
| 61 | + |
| 62 | +- Work items are genuinely independent (no data or file dependencies between waves) |
| 63 | +- Items in different waves modify **different files** (overlapping files cause merge conflicts) |
| 64 | +- The parallelism benefit justifies the added complexity |
| 65 | + |
| 66 | +**Do NOT use multiple waves when:** |
| 67 | + |
| 68 | +- Items must run in sequence (later items consume output from earlier ones) |
| 69 | +- Items modify the same files |
| 70 | +- The issue is small enough that parallelism adds no benefit |
| 71 | + |
| 72 | +Plans with only 1 wave (or no waves at all) use single-subagent mode, spawning one implementation |
| 73 | +subagent with all items. Only plans with 2 or more distinct waves spawn parallel subagents. |
| 74 | + |
| 75 | +## Sub-Issue Decomposition |
| 76 | + |
| 77 | +A **sub-issue** is created when an issue's context size exceeds the safe threshold (approximately 80 K tokens |
| 78 | +or when compaction events occur). Decomposition splits the parent issue into smaller, focused child issues |
| 79 | +that each fit within a single subagent's context window. |
| 80 | + |
| 81 | +Triggers for decomposition: |
| 82 | +- Token report shows issue approaching 40% threshold (80 K tokens) |
| 83 | +- Subagent has experienced compaction events |
| 84 | +- Pre-emptive analysis reveals the issue is too large before execution begins |
| 85 | + |
| 86 | +After decomposition, the sub-issues are organized into waves following the same dependency analysis rules |
| 87 | +described above. See `plugin/skills/decompose-issue-agent/first-use.md` for the full decomposition workflow. |
| 88 | + |
| 89 | +## Worktree Sharing and Push Coordination |
| 90 | + |
| 91 | +All wave subagents share the same worktree (`WORKTREE_PATH`). They commit and push to the same issue branch. |
| 92 | +Each subagent must `git pull --rebase` before pushing to incorporate commits from other waves that completed |
| 93 | +first. |
| 94 | + |
| 95 | +When pushing encounters a non-fast-forward rejection, the subagent retries up to 3 times, rebasing before |
| 96 | +each retry. See `plugin/concepts/parallel-execution.md` for the full push coordination protocol. |
| 97 | + |
| 98 | +## index.json Ownership |
| 99 | + |
| 100 | +`index.json` must be updated exactly once per issue run. The last wave alphabetically owns the index.json |
| 101 | +update: |
| 102 | + |
| 103 | +- All waves except the last: do NOT update `index.json` |
| 104 | +- Last wave: updates `index.json` to `"status": "closed"` in its final commit |
| 105 | + |
| 106 | +## Architecture Summary |
| 107 | + |
| 108 | +``` |
| 109 | +work-with-issue (main agent) |
| 110 | + | |
| 111 | + +---> Read plan.md directly |
| 112 | + | Detect ## Execution Waves / ### Wave N sections |
| 113 | + | Count top-level bullet items per wave |
| 114 | + | |
| 115 | + +---> [if 2+ waves] Spawn all wave subagents simultaneously |
| 116 | + | Wave 1: subagent handles all items in Wave 1 (parallel) |
| 117 | + | Wave 2: subagent handles all items in Wave 2 (parallel) |
| 118 | + | Worktree: shared |
| 119 | + | index.json: NO (all waves except last) / YES (last wave) |
| 120 | + | |
| 121 | + +---> Collect commits from all waves |
| 122 | + | |
| 123 | + +---> stakeholder-review (single review of combined work) |
| 124 | + | |
| 125 | + +---> work-merge (squashes all commits, single merge) |
| 126 | +``` |
0 commit comments