Skip to content

Latest commit

 

History

History
1249 lines (997 loc) · 72 KB

git_flow.md

File metadata and controls

1249 lines (997 loc) · 72 KB

git_flow.md

This document defines the Git branching, rebasing, and merging discipline for Holon.


1) Core Principles

1.1 Git as Universal State Machine

  • Every intent gets its own branch
  • All work happens in branches, never directly on main
  • main is the canonical "promoted" state
  • Branches are cheap; exploration is encouraged

1.2 Fractal Intent Hierarchy

  • Intents can spawn sub-intents recursively
  • Each sub-intent gets its own intent branch, nested under the node whose stage decided the split (the deciding node, sections 2.2-2.3 and 8). The branch is cut from the deciding node's branch and merges back into it, and its provenance records that node
  • In practice a split is decided by a plan: the planner writes a ## Sub-intent list in its plan, and the flow runs each item as a sub-intent nested under that plan, which sits between the intent and its sub-intents in the hierarchy. This is what the flow does and what every worked example in this document shows. The model leaves other stages open -- a split may also be decided at the intent, execution or review stage, as long as the hierarchy is honoured (section 2.2)
  • Depth is capped: holon flow refuses to nest sub-intents more than MAX_SUB_INTENT_DEPTH levels below the root intent (see Stage 3 under the flow equivalence guarantee)

1.3 Human Review Boundary

  • Root intents (top-level intents) require human review before merging to main: the maintainer's PR merge is the only human step, and no stage before it waits for a human
  • Sub-intents merge only into the branch of their deciding node (in practice the plan branch that listed them), never directly into main. Below the root no human intervention is needed: the agent raises each sub-intent's PR automatically and merges it automatically into the deciding plan or execution branch, for leaf sub-intents and nested parents alike (sections 4.1, 4.2 and 13). Only the root intent's PR to main stops for a human (the flow behaviour is specified once, in Stage 3 under the flow equivalence guarantee)
  • This applies recursively: sub-sub-intents merge into the deciding node inside their parent sub-intent, and the root intent's whole tree reaches main only through the root PR

1.4 Terminology

  • Root Intent: Top-level intent that will eventually merge to main (requires human review)
  • Parent Intent: Immediate parent of a sub-intent in the tree (may itself be a sub-intent)
  • Deciding Node: The intent, plan or execution branch whose stage decided the split (in practice the plan). Its branch is the sub-intent's branch base and merge target
  • Sub-Intent: Any intent spawned from another intent, in practice by the plan that decided the split (can have its own sub-intents)

1.5 ID Generation

  • Root intent, sub-intent, plan and execution IDs are generated using the current Unix timestamp.
  • An intent ID is the timestamp plus the slug. A plan or execution ID is the timestamp plus the runner's ticker and the model code (section 2.5.2), so it is unique only under its parent: a plan is always keyed by its intent and plan ID together (plan file, calibration report, plans.jsonl lookups and the duplicate check), and an execution by its full I-.../P-.../E-... path.
  • Siblings under one deciding node always have different slugs, so their intent IDs (timestamp plus slug) cannot collide, even when they are created in the same second.
  • Example: I-1771422315-example-intent, P-1771422316-CLA-CS4.6, E-1771422317-CLA-CS4.6

2) Branch Naming Convention

Any branch in the hierarchy that can have child branches (including root intents, nested sub-intents, and plan variants) must finish with the /_ suffix. This serves as a terminal leaf node for that specific directory level, preventing branch/sub-branch naming collisions in Git and enabling the creation of a clean, filesystem-like hierarchy.

2.1 Root Intent Branch

I-{timestamp}-{slug}/_

Example:

I-1771890389-refactor-metrics/_

2.2 Sub-Intent Branch (Nested Under the Deciding Node)

A sub-intent's branch nests under the branch node whose stage decided the split, with no child marker in the name. An intent can have several competing plans (section 2.4), so a branch nested only under the intent would not say which plan spawned the sub-intent; nesting under the deciding node records it in the branch path itself.

Split decided by Sub-intent branch
The intent stage I-{timestamp}-{slug}/I-{timestamp}-{slug}/_
A plan (in practice) I-{timestamp}-{slug}/P-{timestamp}-{ticker}-{model code}/I-{timestamp}-{slug}/_
An execution I-{timestamp}-{slug}/P-{timestamp}-{ticker}-{model code}/E-{timestamp}-{ticker}-{model code}/I-{timestamp}-{slug}/_
A review The reviewed plan's node or the reviewed execution's node (either is acceptable; a review has no branch node of its own)

In practice, splits are decided by a plan: the planner writes a ## Sub-intent list in its plan, the executor records it, and the flow runs each item as a sub-intent nested under that plan. Example:

I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/_

For illustration of the general rule only, the same sub-intent would be named as follows had the split been decided at the intent stage or during execution:

I-1771890389-refactor-metrics/I-1771890392-improve-estimators/_
I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/E-1771890391-CLA-CS4.6/I-1771890392-improve-estimators/_

The sub-intent's own plan and execution branches continue below its node:

I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/_
I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/E-1771890399-CLA-CO4.6/_

Whichever node decided the split, the sub-intent branch is cut from the deciding node's branch and merges back into it (sections 3 and 4.1): a plan-decided sub-intent is cut from and merges into that plan branch (I-.../P-.../_), an execution-decided one is cut from and merges into that execution branch (I-.../P-.../E-.../_), and for an intent-stage split the deciding node is the intent branch itself (I-.../_). A sub-intent's flow checkpoint is keyed on its intent branch, so a child and a grandchild sharing a slug never overwrite each other's.

Provenance. A sub-intent's intents.jsonl row and its plan header record the node that decided the split:

  • parent_intent_id: the parent intent.
  • deciding_branch: the deciding node's branch (I-.../_, I-.../P-.../_ or I-.../P-.../E-.../_).
  • parent_plan_id: the deciding plan, when a plan, an execution of that plan or a review decided the split (a review-decided split records the reviewed plan).
  • parent_execution_id: the deciding execution, when an execution decided the split, or when a review-decided split nests under the reviewed execution.
  • target_branch: the branch the sub-intent merges into, which is the deciding node's branch (equal to deciding_branch).

The specific item of the deciding node's sub-intent list is identified by the sub-intent's own recorded goal and description.

{
  "intent_id": "I-1771890392-improve-estimators",
  "parent_intent_id": "I-1771890389-refactor-metrics",
  "deciding_branch": "I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_",
  "parent_plan_id": "P-1771890390-CLA-CS4.6",
  "target_branch": "I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_"
}

Promotion. If an operator promotes a sub-intent to its own root intent, the root intent records its source plan (parent_plan_id), so the lineage is not lost even though the new root no longer nests under that plan.

2.3 Sub-Sub-Intent Branch (Deeper Nesting)

Deeper nesting repeats the pattern. For plan-decided splits:

I-{timestamp}-{slug}/P-{timestamp}-{ticker}-{model code}/I-{timestamp}-{slug}/P-{timestamp}-{ticker}-{model code}/I-{timestamp}-{slug}/_

Example:

I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/I-1771890400-p-success/_

Pattern: Each level appends the deciding node and the sub-intent to the path, creating a filesystem-like hierarchy.

2.4 Plan Branch (Proposal)

Plan branches are created as siblings to the /_ node within the same intent directory, using a timestamped identifier to allow for multiple competing proposals.

I-{timestamp}-{slug}/P-{timestamp}-{ticker}-{model code}/_

Example:

I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_

2.5 Execution Branch (Action)

Execution branches are branched off a specific plan, appending the action slug to the plan's path to maintain a strict lineage from intent to proposal to implementation.

I-{timestamp}-{slug}/P-{timestamp}-{ticker}-{model code}/E-{timestamp}-{ticker}-{model code}/_

Example:

I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/E-1771890391-CLA-CS4.6/_

2.5.1 Branch Name Length Limit

GitHub rejects a push whose full ref name is too long. Measured against the real service, a full ref of 255 characters, counting the refs/heads/ prefix (11 characters), is accepted and 256 is rejected, so a branch name without the prefix can be at most 244 characters. One module, sandbox_executor/ref_names.py, owns the limit (MAX_REF_LENGTH = 255) and every branch name the engine creates goes through it: the root intent, plan, execution and calibration branches, and every decomposed child intent, plan and execution branch at any depth.

  • Calibration rule: the calibration branch ends in /calibrated where the others end in /_, which is 9 characters more. Every name is therefore measured as if it ended in /calibrated: len("refs/heads/" + name + "/calibrated") must be at most 255.
  • A name that fits is unchanged. No existing branch, checkpoint or ledger row changes.
  • Shortening order: when a name is over the limit, only the parts the engine controls are cut, in this order: the child slug, then the root intent slug. Plan and execution segments are short (section 2.5.2) and never shortened. A cut part keeps a prefix of its original text and ends in a 6-character hexadecimal digest (sha256, first six characters) of the full original text, so two different long inputs never collide and the same input always gives the same name. A part is cut only as far as needed and never below the digest alone.
  • Never touched: timestamps, tickers, model codes and the --{n}- child markers.
  • Room for what comes next: an intent branch is measured with room left for one plan and one execution segment below it, using the real ticker and model code of the configured runner and model (a reserved length when they are not known yet). A plan is measured with room for the execution below it.
  • Slug limit: a slug is at most 32 characters, for a root intent and for each child intent. A root slug supplied in the intent file that is longer is rejected when the intent is opened, before any branch exists, with a message giving the limit and the length; a slug the engine derives (from a description or a sub-intent title) is cut to 32 characters at a word boundary. A root intent and two levels of nested child intents, each with a 32-character slug, fit the limit (including refs/heads/ and /calibrated) with no shortening; deeper nesting falls back to the slug shortening above and the length check.
  • Resume: a resumed flow keeps the names it already created. The recorded branch (intent), the checkpoint and the per-child progress entries are used as they are and the shortening rule is never re-run on them.
  • Ledger: the original text stays recoverable. An intent row records original_slug only when its slug was shortened. Plan and execution rows record the full agent and model; the ticker and model code appear only in names. Older rows may still carry original_agent and original_model from the retired label shortening; readers accept them.
  • Failure: if a name cannot fit even after shortening, Stage 1 fails before any branch exists, naming the limit, the computed length and the segment that cannot be shortened (for example the segment that cannot be shortened is 'parent'). If a push is still rejected for ref length, the host push fails with ref too long: branch <name> (<n> characters). A child branch name that cannot fit at Stage 3 fails that stage with the same named limit rather than raising.

2.5.2 Plan and Execution Names

A new plan is P-{epoch}-{ticker}-{model code} and a new execution E-{epoch}-{ticker}-{model code}, with no hex, for example I-1794567515-sleepfix/P-1794567531-CLA-CS5.5/E-1794567598-CLA-CS5.5/calibrated.

  • Ticker: each runner that may run a flow declares a ticker of exactly three uppercase letters beside its definition in agent_defaults.py: claude-agent is CLA, antigravity-agent is ANA and pi-agent is PIA. A ticker is never reassigned or reused, and a test fails when two runners share one. A runner with no ticker is rejected by holon doctor and when an intent is opened, before any branch is created, with a message naming the runner; there is no fallback.
  • Model code: derived from the model name by a pure rule (sandbox_executor/naming.py, no table): anything before a / is dropped, each word contributes its first letter in upper case, version numbers are kept and joined with a dot, and every character invalid in a git ref is removed. claude-sonnet-5-5 is CS5.5, claude-fable-5 is CF5, gemini-3.8-flash-medium is G3.8FM, gpt-5-codex is G5C and anthropic/claude-opus-5-5 is CO5.5.
  • Same parent, same second: two plans or executions that would get the same name under the same parent never overwrite each other: the second gets a deterministic -2 (up to -9) variant, and fails clearly once those are taken. Two intents planned in the same second by the same runner and model may share a plan ID; they never collide, because every plan is keyed by its intent (its plan file, its calibration report and its plans.jsonl row), and every execution by its full path.
  • Older generations stay valid: P-{epoch}-{agent}-{model} and P-{epoch}-{hex}-{agent}-{model} (and the same for E-) are still parsed, found and calibrated everywhere. No existing ID is renamed, because existing IDs match the head branch names of the pull requests that carried them.

Plan files follow the branch name. The plan on {parent}/{plan id}/_ lives at plans/{parent}/{plan id}.md and its calibration report beside it at plans/{parent}/{plan id}_calibration.md, mirroring the full nesting: a root intent (plans/I-.../P-....md), a child intent (plans/I-...--{index}-{slug}/P-....md) and a plan nested under another plan (plans/I-.../P-.../P-....md). sandbox_executor/plan_paths.py owns the layout. Plans created before this layout were moved once by scripts/migrate_plan_layout.py; a plan file that no branch could be found for lives under plans/legacy/.

2.6 Hierarchy Summary

/_ is the Intent Root (The "What") /P-.../_ is the Plan (The "How") /P-.../E-.../_ is the Execution (The "Do")

2.7 The 5-Stage Holon Flow Lifecycle

The five stages form one lifecycle (Stage 3 admission, refresh):

Stage Name CLI Command Artifacts & Outputs
1. Intent Intent Initialisation holon intent <intent.json> Intent branch I-.../_ + holon-knowledge/ledger/intents.jsonl
2. Plan Plan Generation holon plan <intent_branch> Plan branch I-.../P-.../_ + plans/I-.../P-*.md + plans.jsonl
3. Execute Sandbox Execution holon execute <plan_branch> Execution branch I-.../P-.../E-.../_ + executions.jsonl
4. Review Loop PR Review Loop holon review-loop <execution_branch> PR raised + sandboxed reviewer ensemble (unanimity) + micro-actions in executions.jsonl
5. Calibrate Calibration Analysis holon calibrate <execution_branch> /calibrated branch + plans/I-.../P-*_calibration.md (included in PR diff)

Target Worktree and the Default Branch

holon flow runs host git operations (checkouts, commits, pushes) in its target worktree, so it never uses a worktree that has the default branch checked out. Naming the main worktree as --target-worktree, or running from it with the default ., selects the repository and the base branch only:

  • Redirect: when the target worktree has the intent's target_branch checked out (origin/main and main are the same branch here), the run happens in the sibling worktree flow-<slug> next to the repository's top-level directory, on branch flow-<slug> branched off origin/<target_branch>. An existing flow-<slug> worktree is reused as it is. The redirect is logged at info level and happens after the pre-flight probe and before any stage, so every stage, the checkpoint and the run summary (target worktree: <path>, and target_worktree in --json output) use the flow worktree. The main worktree's HEAD, branch and git status are never changed.
  • Other branches: a target worktree on any other branch is used as it is. A detached HEAD is not a default-branch checkout. Bare and absent targets keep the existing auto-provisioning.
  • Checkpoints: a new checkpoint records the flow worktree. Resuming from a checkpoint whose recorded target_worktree has the default branch checked out fails before any stage runs, with an error naming the flow-<slug> worktree to pass as --target-worktree (passing the main worktree explicitly redirects the resume as above). Nothing is created by the refusal.
  • Engine guard: run_flow_pipeline also fails the first stage, before any stage or checkpoint, when the context's target worktree has the base branch checked out, so callers that bypass the CLI are protected too.
  • Direct commands: holon review (and its review-loop and pr-review-loop aliases) and holon calibrate commit review and calibration records to the branch they run on, so they refuse a worktree that has the repository's default branch (the branch origin/HEAD points at, otherwise main) checked out, with an error naming the path and how to create a dedicated worktree. Run them in the flow-<slug> worktree of the run instead.

Flow Equivalence Guarantee

holon flow <intent.json> is equivalent to running the five commands above by hand, in order. Stages 1-3 call the same dispatch function as holon intent, holon plan and holon execute (dispatch_role_agent in cli.py), so they launch the same containers with the resolved runner and model: holon/agent-<runner> for the planner and executor, and holon/orchestrator for the intent creator (which does not run a model). Those containers author every Stage 1-3 branch, plan file and ledger row; the flow only fetches origin, adopts the branch each container pushed and validates it, except that it appends a superseding failure row to an empty execution's branch (see the limits below). A branch is adopted only if it was not on origin before the container was dispatched and its name carries the dispatched runner and model; when no such branch or more than one appears, the stage fails instead of guessing, so neither clock skew between host and container nor a concurrent run under the same parent branch can redirect the flow. Stages 4 and 5 run the same review loop and calibration code as holon review-loop and holon calibrate. Because Stages 1-3 leave the host checkout where holon flow started, Stages 4 and 5 each first check out the adopted execution branch (and fail if it cannot, for example because local changes would be overwritten; nothing is discarded), so the review loop's ledger rows and the Stage 5 calibration report and ledger reconciliation land on that branch even on a resume that enters at Stage 5. The conflict probes of Stages 2-5 name the branch each stage works from (Stage 1 has none yet), and the review records the execution branch's tip, freshly fetched from origin, as the reviewed commit, never the operator's HEAD.

Stage 5 also syncs with origin before it reads or branches anything, because containers and out-of-band conflict resolution push to origin/<execution_branch> without moving the local ref (flow/calibrate_sync.py owns this):

  • Fetch and base: Stage 5 fetches the execution branch and fast-forwards a local ref that is behind. The /calibrated branch is created from the origin head, so calibration analyses exactly the reviewed and approved head. When origin has no such branch (a --skip-push run), the local ref is used.
  • Divergence: a local ref holding commits that origin lacks stops Stage 5 with an error naming the branch, both SHAs and the recovery (git push origin <branch>, or a deliberate git branch -f <branch> origin/<branch>, then resume). Nothing is reset, forced or overwritten.
  • Guaranteed fast-forward: because the /calibrated branch descends from the origin head, merge --ff-only onto the execution branch succeeds and the report reaches the PR without a merge commit. A failure is logged, not ignored. An existing /calibrated branch that lacks the origin head is reported as stale, with the command to delete it.
  • Restored worktree: the branch (or detached commit) that was checked out before the flow first moved HEAD is checked out again when Stage 5 ends, including on failure. A failed restore is a warning and never changes the stage result.

Stage 3 never halts for a human. The executor's outcome is judged against the plan's persisted entropy budget (see Turn and Stage Budgets):

  • Fits the budget: the plan is executed as usual.

  • Explicit sub-intent list: the plan row holds the list; the executor only records a decomposed summary that refers to it (plan_decision, see Ledger Schema) and writes no intents.jsonl rows. The flow then runs each item as a child intent, strictly one after another and never concurrently, through the full pipeline (intent, plan, execute, review, calibrate). Nesting is bounded by MAX_SUB_INTENT_DEPTH, checked against the plan before the executor is dispatched when the plan can be read.

    • Nesting under the plan branch. Each child is named {plan}--{n}-{slug} (the plan branch without /_, the item's 1-based position and its sanitised slug) and records the plan branch that listed it as both its target_branch and its parent_intent_id, never the intent branch and never main. Stage 1 cuts the child from origin/{plan branch}, so it starts from the plan branch tip as it stands then. The plan branch comes from the flow context, else from the decision record; when neither is known, Stage 3 fails rather than fall back.
    • One after another, each merged before the next. A child is ready to merge when its own Stage 4 reached consensus approval (StageStatus.APPROVED, or legacy StageStatus.HALTED_FOR_HUMAN) and its Stage 5 succeeded (or was skipped by flag). The flow then merges the child's PR into the plan branch with flow/github/merge.py: a merge commit when the repository allows it, otherwise a squash (gh pr merge --merge or --squash, always with --match-head-commit; a failed merge-method lookup or neither method allowed refuses), CI green and MERGEABLE, after first merging the plan branch into the child head if it moved; a base of main, master, the repository default branch or anything other than the plan branch is refused, as is a PR head that is protected or is not the child's recorded execution branch (see Safety). Only after that merge does the next child start, so it is cut from a tip that already holds every earlier child's merge or squash commit. The first child that fails or is not ready marks its progress failed; one refused only by the merge guard stays review_done with a merge_error, so a resume retries just the merge. Either way the parent's Stage 3 fails, naming the child; later children do not start. --dry-run and --skip-push fail at the first child (no consensus approval, no PR number to merge).
    • The combined PR. After the last child merged, Stage 3 merges the plan branch into the parent execution branch with a merge commit and appends a superseding decomposed summary row with integrated: true, the plan_branch and the list of children (slug, intent and execution branch, PR number and URL, merge commit). The parent's own Stage 4 and Stage 5 then run as for any execution: Stage 4 raises and reviews one combined PR from the parent execution branch into the intent's target_branch, carrying the parent plan, the parent execution record and every child's plan, execution record and code, and completes APPROVED for maintainer merge when that target is main. A child that itself decomposed is merged into this plan branch through its own combined PR in the same way.
    • Resume. Per-child progress (children_progress: intent branch, execution branch, PR, status and merge commit) lives in the parent's Stage 3 payload and is checkpointed after every change, and each child keeps its own checkpoint keyed on its branch. Resuming a decomposed Stage 3 never dispatches the parent executor: the recorded progress is reconciled with origin (origin wins), merged children are skipped, a reviewed child is merged, a child with an execution branch or a PR resumes from its own checkpoint, and only a child with nothing recorded anywhere is dispatched. Ledger-only conflicts during these merges keep every row of the checked-out side in place and insert the merged side's appended rows at their created_at slot; any other conflict fails the stage. The same reconciliation runs on a fresh Stage 3 (--from-stage execute without the parent checkpoint), and an unexpected exception in the loop fails Stage 3 while keeping the recorded progress.

    The holon flow summary lists each child's PR (or branch) and whether it was merged into the plan branch, nests a child that itself decomposed with its own children below it, and names the combined PR that Stage 4 raises.

  • Over budget without a list: the flow returns to Stage 2 automatically, asking for a smaller plan or an explicit sub-intent list (only a smaller plan when the intent is at the sub-intent depth limit), at most MAX_REPLAN_ATTEMPTS times; then Stage 3 fails with a message naming the entropy, the budget and the attempts. When the plan can be read, the flow refuses each over-budget plan before dispatching the executor, so those attempts create no execution branch and append no executions.jsonl row; each rejected plan keeps its plans.jsonl row, and the refusals are recorded only in the flow's stage results, log and checkpoint. When the plan cannot be read before dispatch, the executor refuses the plan itself and the flow reads the over_budget row it records on an execution branch (exit code 3). That row also covers a direct holon execute run, which exits with code 3 (so the refusal is not mistaken for success) only when that row is committed and then either pushed or kept local because pushing is disabled, and with code 1 otherwise (see Entropy Budget and Decomposition Evaluation).

The guarantee has five deliberate limits:

  • No fabricated plans. If no planner agent produced plans/I-.../P-*.md on a plan branch under the intent branch, Stage 2 fails; the flow never writes a plan from a template. On entry to Stage 2, the stage adopts the newest complete plan branch of the intent when one already exists (complete: its plans.jsonl row and the plan file that row records both exist at the branch ref), pushes it first when it exists only locally, and logs the adopted branch and every candidate it ignored. The checkpoint names the plan branch before the host pushes it. An engine re-plan (over budget or a touch-set violation) always plans afresh; to plan afresh by hand, delete the plan branch locally and on origin, then resume with --from-stage plan.
  • Empty executions fail. An execution branch with no changes outside holon-knowledge/ledger/, plans/ and executions/ relative to its plan branch (content merged in from the target branch does not count) is recorded as status: "failed" (failure_reason: "empty_diff", no test_pass_rate), Stage 3 fails and no PR is created or updated. The same guard runs inside holon execute and in every non-dry holon review-loop run, whatever --auto-pr is, whether or not gh is installed and for every target (a PR number or URL is first resolved to its head SHA and base branch, and the head SHA is compared with the PR's own base branch, or with the intent's target branch when gh reports no base; a PR whose base cannot be resolved or fetched is diff_unverified); for an execution branch it first fetches the execution and plan branches and compares the origin copies the PR is opened from, and for any other branch it fetches both that branch and the base, so stale or unpushed local branches never decide it (a failed fetch, or a git command that times out, skips the PR as diff_unverified; only a repository without an origin remote compares its local branches). Inside the mounted review-loop container the guard never fetches, because the container has no ssh: before dispatch the host fetches the plan, execution and base branches into refs/remotes/origin/, and the guard only resolves those refs. A ref the host did not fetch is diff_unverified with a refusal naming the branch and saying the host must fetch it before dispatch (a branch that exists only locally in the container is refused as well, even when it resolves); a failed host fetch stops the stage before the container starts. The execution-branch comparison (_execution_effective_diff) follows the same rule, and no other fetch is reachable from the review-loop container: the remaining git fetch callers are host-side code (among others: the child-branch prefix and snapshot fetches of Stages 1 to 3, the merge helper, calibration, git_flow.fetch_origin_branch, the PR-worktree provisioning fetch) or guarded by workspace_mounted() (_pr_head_ref). When the guard refuses the PR (empty_diff or diff_unverified), the review loop fails closed: it does not wait for CI, runs no review iteration and posts no consensus, so no evidence -- not even a Stage 3 test_pass_rate of 1.0 or green CI on an existing PR -- can approve it. The loop returns approved: false with the refusal as its error (an empty_diff refusal appends no ledger rows; a diff_unverified refusal appends only a failed "halted without consensus" summary row naming it and the review action event, with no ACT-REV, ACT-FIND or ACT-POST rows), and Stage 4 fails with the refusal's own reason (Autonomous review halted: Refusing to create or update a PR for ...), never as a test failure or as unmeasured tests, so Stage 5 does not run. An empty diff has consensus status rejected and an unverifiable one failed. Dry runs never invoke the guard, dispatch no reviewer and are never approved: a clean simulation reports not_measured. A consensus whose post to the PR fails or raises is post_failed and not approved, and holon review-loop exits 1 unless the ensemble verdict is APPROVED and the consensus is approved and posted.
  • Dispatch needs origin. --dry-run validates the payload and names the branches without dispatching anything. --skip-push is rejected outside --dry-run -- on every run, including a --from-stage or --checkpoint resume from any stage -- before any stage runs, because the host fetches from and pushes to origin for the role containers, Stage 4 opens the PR from origin, Stage 5 pushes /calibrated (push checks).
  • Unmeasured tests are never a pass. The executor container runs uv run task test after the agent's turn and before the execution commit, and records test_pass_rate, the counts, test_exit_code and any test_run_error in its executions.jsonl summary row (bounded by HOLON_TEST_MEASUREMENT_TIMEOUT_SECONDS, default 900). Stage 3 carries them; when the row records no rate, it is null ("not measured"). A measured rate below 1.0, or a non-zero test exit code, is a failed test result that Stage 3 and Stage 4 treat as failed. Stage 4 reports test_results with its source and counts (pass_rate: null, measured: false, passed: null when unmeasured). The Stage 4 test gate judges the current HEAD commit, never reusing stale Stage 3 results across commits, by the precedence in Test evidence and its source; only when review_local cannot execute does it report NOT_MEASURED and withhold consensus. Before a clean gate's CI probe, when the head lacks confirmed resolver or Stage 3 evidence, the loop waits for CI checks to register on the PR (when gh is available; up to HOLON_CI_REGISTRATION_TIMEOUT seconds, default 180, 0 disables the wait), without consuming review iterations or writing ledger rows. If none register and review_local cannot run, the loop stops after that single iteration with consensus status not_measured (one iteration's review rows and one summary row), Stage 4 fails with test results not measured: no recorded Stage 3 test result and no CI checks, and the pipeline halts before Stage 5 calibration runs. Checks that registered but are still pending are waited out on their own CI wait budget (see CI wait budget and outcomes), never the iteration's review_iteration budget. --dry-run does not wait, and its simulated consensus reports not_measured. Stacked sub-intent pull requests, whose base is the plan branch that listed them, receive the same checks as pull requests into main, because every CI workflow runs for pull requests into any base branch (see .github/workflows/README.md).
  • Token reduction is auto-detected. holon flow (like holon review-loop) resolves token reduction with detect_holon_coherence: unless HOLON_TOKEN_REDUCE opts out (0, false, no, off), it is enabled by --token-reduce, --mitm-web, a truthy HOLON_TOKEN_REDUCE or HOLON_PASSIVE_MONITORING, a reachable proxy port, a local holon-coherence or mitmproxy image, or a holon-coherence binary on PATH, and the result is passed to the Stage 1-3 containers. holon intent, holon plan and holon execute enable it only on the explicit opt-ins (--token-reduce, --mitm-web, HOLON_TOKEN_REDUCE, HOLON_PASSIVE_MONITORING), so on a host where detection succeeds the flow routes the role containers through the proxy and the manual commands do not. To launch identical containers either way, pass --token-reduce to the manual commands or set HOLON_TOKEN_REDUCE=0 for both.

Reviewer ensemble. Every Stage 4 iteration is decided by real reviewers: after the mergeability and CI probes, run_review_loop() runs --ensemble-size (default 3, on both holon flow and holon review-loop) independent, mutually blind reviewer agent turns on the real diff between the base and the resolved head SHA (sandbox_executor/review_ensemble.py). Approval needs every reviewer to approve with zero findings, plus a mergeable PR and green CI; zero or failed reviewers, any finding (a single nit) and unknown CI never approve. There is no automatic resolver: the first iteration that is not approved stops the stage, its ACT-FIND rows are recorded in executions.jsonl and the command exits 1. The posted report contains only real reviewer data and is posted only when at least one reviewer completed. Reviewer turns run only inside the sandbox. holon review-loop runs the loop in the review-loop role container. When holon flow Stage 4 runs on the host, it dispatches reviewer turns into the review-loop role container via _dispatch_role() and retrieves verified reviewer outcomes across a structured result file transport, preserving host ownership of mergeability verification, CI gating, and official review posting. If container dispatch fails, it fails closed before any PR review is approved. See the sandbox-executor README.

Consensus integrity. The loop decides consensus only from what the reviewers returned; role, container and adjudication checks can only withhold an approval. See review_consensus.md.

Host worktree workspace. Every Stage 4 reviewer-ensemble and resolver dispatch runs in a fresh --rm container that works in place on the run's flow-<slug> worktree, bind-mounted from the host together with the git directories its .git pointer names; the repository config, hooks, git pointers and the whole worktrees/ administrative directory are mounted read-only, so no sibling worktree's admin files are reachable, with only the mounted worktree's own admin directory re-mounted read-write on top. The container never clones, fetches, pushes, resets or cleans: it validates that HEAD is on the review branch and equals the resolved head SHA, and fails closed otherwise. Edits, logs and tmp/review/ scratch are on the host at once and survive a container crash. No Docker volume or root init container is involved. Canonical ACT-REV/ACT-FIND/ACT-RES/ACT-POST rows and the summary row remain host-written. A standalone holon review-loop <PR> reuses the worktree that has the PR's head branch checked out (normally flow-<slug>) and creates a pr<N>-<slug> worktree only when none exists. See the sandbox-executor README. One worktree for every stage. The Stage 1 intent creator, Stage 2 planner, Stage 3 executor and Stage 4 review-loop and resolver all run in the same mounted flow-<slug> worktree with the same protections; none clones. No container touches the remote: roles only commit, the host fetches the base before each container starts and pushes the committed branch after it returns (Stage 1 the intent branch, Stage 2 the new plan branch, Stage 3 every new execution branch including a failed one, Stage 4's resolver head fast-forward only). Before the Stage 4 review-loop container starts, the host also fetches the plan, execution and base branches, so the container's diff check resolves them without fetching. A failed host fetch or push names the operation, branch and remote. No ssh-agent or repository URL variable is involved, so an SSH origin works.

CI wait budget and outcomes

Waiting for CI and judging code run on different clocks. After the reviewers approve, the review loop waits for pending GitHub checks under a wall-clock CI wait budget of HOLON_REVIEW_CI_WAIT_SECONDS (default 1800 s, in seconds, at most 7 days). A value that is not a number, is not finite, is zero, negative or above 7 days is invalid: the loop logs a warning that names the variable and keeps 1800 s, so the wait cannot be switched off through the variable. The wait is not drawn from the review_iteration budget, so a slow runner never costs an iteration. Polling backs off from CI_REGISTRATION_POLL_SECONDS (15 s), doubling each poll to a ceiling of CI_WAIT_POLL_CEILING_SECONDS (120 s), so the intervals are 15, 30, 60, 120, 120 s and so on. The wait ends as soon as no check is pending, or as soon as any check has failed (that is already a CI failure, so the remaining checks are not waited on).

That first-failure rule applies to the review gate only. Before the host pushes a resolver fix, the loop waits for the pipeline run being fixed to settle, under the same HOLON_REVIEW_CI_WAIT_SECONDS budget and without stopping at the first failure, because a pull-request push cancels the run still in progress and the failures it would report later would be lost. The wait runs only when a push will follow (the pass succeeded, its head moved, skip_push is off and the target has a head branch) and only for GitHub CI. A spent budget logs the checks still pending and pushes; a probe or failure-lookup error is logged and never blocks the push.

The settled run is recorded per fixed head in the checkpointed review state as review_state.fixed_runs[<sha>]: checks (each failed check with name, run_id, conclusion, failed_steps, its classification from the CI failure routing, failing_test_ids and log_tail), handed (the failed checks the resolver pass already saw), pending (the checks still pending when the wait ended) and recorded_at (UTC, YYYY-MM-DDTHH:MM:SSZ), with review_state.last_fixed_head naming the latest. Both log fields come from gh run view <run> --log-failed, scoped with --job <job> when the check link names a job and falling back to the whole run otherwise: failing_test_ids lists the pytest node ids that failed, and log_tail keeps the last 25 non-empty log lines, redacted and then cut to at most 1500 characters. An unreadable log leaves [] and '' and never blocks the push or loses the rest of the record. The next resolver pass receives one FIND-CI-<iteration>-RUN finding naming each recorded check, with its run id, failed steps, failing test ids and log tail, that is classified as a defect, was not handed over yet, and is neither passing nor already failing on the current head (a failing one is already in that iteration's FIND-CI finding), so it does not wait for the new head's run to report the failure again. Each check is handed over once. A timing-gate, runner or cancelled failure is recorded with its class but never handed over, and the row is added only after the approval checks, so an approved head is never blocked by it.

A CANCELLED or STALE check counts as failed, never as passed, while a NEUTRAL one still passes. After a clean review on the host, each failed run is classified on its own, and every noise run (a timing gate, a runner failure or a cancelled run) is rerun once: a cancelled run as a whole, any other noise run by its failed jobs. This holds when the noise classes are mixed and when the noise sits beside a defect, in which case the defect goes to the resolver at once without waiting for the rerun. A noise check that shares its run with a defect is not rerun, because rerunning the run's failed jobs would also rerun the defect. The names of the noise checks rerun on the head are kept in the checkpointed review_state.ci_routing.noise_rerun, and those checks are left out of the FIND-CI-<iteration> finding; when only such checks failed, no FIND-CI finding is handed over. A noise check still red after its one rerun is no longer left out and goes to the resolver as before.

The budget applies per wait, not per loop: each iteration that reaches the post-review CI gate gets a fresh wait, so a loop of N iterations whose checks each settle after a long wait can spend up to N times the budget. A wait that ends because the budget is spent is recorded in the loop result (and the posted consensus data) as ci_wait (state: pending, budget_seconds, waited_seconds, pending_checks); while the same checks stay pending, later iterations on the same head do not wait again. The record is cleared once a later iteration sees nothing pending, or when the resolver pushes a new head (the new head's pending checks get their own wait), so it never contradicts the final ci_checks. Checks still pending at the deadline are unknown: never all_passed, never a failed test run, and after a clean review no FIND-CI finding is recorded for them unless the local test run itself failed. A dry run, a dirty mergeability state, a missing ref or a review infrastructure failure skips the wait, and there pending checks still count as not passed and record FIND-CI.

When the review ends without approval, the Stage 4 error says which outcome occurred:

Outcome Stage 4 error
CI still pending CI still pending after the wait budget: <names> still running after <budget> s ...; no test failed.
CI failed CI failed: <every failed check name>.
Tests not measured test results not measured: no recorded Stage 3 test result and no CI checks.

test suite reported failures appears only when the local test run really failed. When nothing specific blocked the review, the error says no specific blocker was recorded instead of blaming the tests.

Final-head CI check (Stage 5)

Stage 5 pushes the calibration commit to the execution branch, which starts CI again on a head the reviewers did not vote on. After that push, and only then, Stage 5 waits for the checks on that head with the same wait facility and budget (HOLON_REVIEW_CI_WAIT_SECONDS) and records the outcome as final_head_ci in the stage result, the stage log and the flow summary:

State Meaning
success Every check on the final head passed.
failed At least one check failed, a CI Timing Gate step included; the names and durations are kept.
unknown CI was not measured, or checks were still pending when the budget ran out. Never success.
skipped Nothing was pushed: a dry run, --skip-push or a failed calibration.

A job that exceeds its time limit is a failed check, so a timing-gate failure fails the final-head check like any other. The job's failed steps and duration come from one extra gh run view call and only annotate the failure, for example final head CI: failed: macos-unit (CI Timing Gate, 6 min).

A runner can be slow on identical code, so a timing-gate failure on unchanged code is rerun before consensus is withdrawn. When every failing check failed only in its timing-gate step, no check is pending, and every path changed between the approved head and the measured head is a bookkeeping record (plans/, executions/, holon-knowledge/) or nothing changed, Stage 5 reruns the failed jobs up to three times in sequence. Each attempt starts only when the previous one is still a timing-gate-only failure on unchanged code, and the first green result ends the loop. Any changed code, test or workflow path, an unreadable diff, any other failing check or any pending check means no rerun. The record final_head_ci.timing_rerun keeps attempted, run_ids (of the first attempt), outcome (of the last attempt), attempts and outcomes (one state per attempt), and reason when a rerun could not be dispatched. Consensus is withdrawn only when the last attempt still fails.

The rule applies to every check whose failed steps are all timing-gate steps: a step whose name starts with CI Timing Gate or a step named exactly Timing gate. That covers the unit jobs on ubuntu-latest and macos-latest, including both macOS unit shards (CI Timing Gate (compare with main)), the Workspace survival and build-images jobs (Timing gate), and the hygiene, integration, make, docker-build, CI durations and promote-ledger jobs (CI Timing Gate (Check ...)).

Stage 5 then re-verifies the head it published and records ci_verdict in the stage result, with the approved head, the final head and whether the head moved:

  • green (or nothing pushed): Stage 5 ends as a success.
  • red: Stage 5 ends as failed, with an error naming each failing check. The pull request is not reported as ready to merge, and a child sub-intent is not merged. The calibration commit stays pushed.
  • unverified: CI was not measured or was still pending. The report says "not verified" and "not merge-ready"; it is never reported as ready to merge.

When the verdict is red and Stage 4 posted an approval, Stage 5 posts one follow-up comment saying the consensus approval no longer stands. It names the head the approval covered, the failing head and each failing check, with the duration for a timing gate. A hidden marker holding the failing SHA keeps it to one comment per head; a pull request whose comments cannot be listed gets no comment. The approval itself names the head it covers and the measured CI result at that commit (for example "11 of 11 checks passed"), so a re-approval on a later green head names its own head.

When the only failing check is a timing gate, the resolver finding names the slowest tests of the failing job (five at most, from the ci-timing-* artefact or the job log's --durations section) and says to speed them up or split the job. It never offers a rerun. When the tests cannot be fetched, the finding says so and points at pytest --durations=10. Apart from the bounded rerun on unchanged code, Stage 5 never reruns CI; it never changes the 300 s timing limit, and the merge stays with the human maintainer.

Approval & Merge Boundary

Merging to main is reserved for the human maintainer. On Stage 4 consensus approval (StageStatus.APPROVED, [REVIEW APPROVED]) and Stage 5 calibration, the flow completes and leaves the PR ready for human merge; it never merges itself. StageStatus.HALTED_FOR_HUMAN ([SAFETY HALT]) is reserved for dry-run and manual-intervention halts; no earlier stage waits for a human, and merging the PR is the only human step.


3) Mandatory Rebase Discipline

3.1 Dual Rebase Rule

Every sub-intent must rebase from its deciding node's branch (in practice the plan branch I-.../P-.../_), not the parent intent branch (section 2.2):

  1. Before execution (to get that branch's latest state)
  2. After execution (to ensure clean merge)

Building on siblings. Siblings build on each other through the deciding node's branch: a sub-intent that depends on earlier siblings starts from, or rebases onto, that branch only after those siblings have merged into it, so no sub-intent is implemented blind to the work it depends on. The before-execution rebase of the dual rebase rule is that step. holon flow cuts each child from the plan branch tip only after the previous child merged into it (see Stage 3 under the flow equivalence guarantee).

3.2 Rebase Commands

Before execution:

$ git checkout I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/_
$ git fetch origin
$ git rebase origin/I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_

After execution:

$ git fetch origin
$ git rebase origin/I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_

3.3 Conflict Handling

If rebase fails:

  1. Log conflict to ledger
  2. Spawn reactive intent to resolve conflict
  3. If unresolvable automatically, escalate to human

4) Merge Rules

4.1 Sub-Intent → Deciding Node Merge (Automatic)

Trigger: Sub-intent execution completes successfully. The agent raises the sub-intent's PR into the deciding plan or execution branch automatically and merges it automatically, with no human intervention. This holds for a leaf sub-intent and for a nested parent alike; a nested parent merges once its own sub-intents have merged into their deciding node inside it, and its PR carries that deciding node's branch. holon flow performs these merges with merge commits (squashes on a squash-only repository) through the guarded child merge (see Stage 3 under the flow equivalence guarantee).

In the worked commands a leaf sub-intent's merge source is written as its intent branch (I-.../_), shorthand for the branch that carries its work and that its PR carries; a nested parent's merge source is the branch of the deciding node inside it (the plan or execution that decided its own sub-intents), which its PR carries.

Process:

  1. Evaluate all completed sub-intents under the same deciding node
  2. Compute merge_value for each:
    merge_value = impact_actual - conflict_risk - entropy_actual - redundancy_penalty
    
  3. Filter by success (success_actual == 1)
  4. Sort by merge_value (descending)
  5. Merge sequentially or in parallel (based on conflict detection)

Example:

# Sub-intent completes: the agent merges it into the deciding plan branch
$ git checkout I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_
$ git merge --no-ff I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890394-add-logging/_
# Automatic for every sub-intent, no human review
$ git push origin I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_

Ledger event:

{
  "event_type": "git_merge_attempted",
  "payload": {
    "intent_id": "I-1771890394-add-logging",
    "from_branch": "I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890394-add-logging/_",
    "to_branch": "I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_",
    "status": "success",
    "merge_type": "automatic_sub_intent",
    "human_review_required": false
  }
}

4.2 Root Intent → Main Merge (Human Review Required)

Trigger: All sub-intents merged, root intent ready for promotion

Root PR: once all sub-intents have merged into their deciding node's branch, the root intent's PR to main is raised, reviewed (Stage 4) and calibrated (Stage 5) on the combined diff, stopping at the human merge boundary. This is the only human stop in the tree. A nested parent is a sub-intent and merges automatically into its deciding node's branch as in section 4.1. In holon flow the root PR is the combined PR that the root's own Stage 4 raises from its execution branch after the plan branch was integrated into it (see Stage 3 under the flow equivalence guarantee).

Process:

  1. Generate review package:
    • Intent goal and constraints
    • Predicted vs actual metrics
    • Diff summary
    • Test results
    • Calibration errors
  2. Request human review
  3. Human approves or rejects
  4. If approved, merge to main

Example:

# Human reviews
$ holon review approve I-1771890389-refactor-metrics

# System merges
$ git checkout main
# The root PR carries the deciding plan branch, into which every sub-intent merged
$ git merge I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_
$ git push origin main

Ledger event:

{
  "event_type": "intent_promoted_to_main",
  "payload": {
    "intent_id": "I-1771890389-refactor-metrics",
    "merge_sha": "abc123",
    "reviewer": "human@example.com"
  }
}

4.3 Merge Constraints

Forbidden:

  • Sub-intent merging directly to main or into any branch other than its deciding node's branch (the tree reaches main only through the root intent's PR)
  • Merging without prior rebase
  • Merging failed intents (unless explicitly overridden by human)

Allowed:

  • Discarding sub-intents (close branch without merging)
  • Multiple sub-intents merging into the same deciding node's branch
  • Recursive sub-intent trees up to MAX_SUB_INTENT_DEPTH levels below the root intent

5) Automatic Merge Evaluation

5.1 Merge Value Calculation

def compute_merge_value(sub_intent):
    return (
        sub_intent.impact_actual
        - estimate_conflict_risk(sub_intent)
        - sub_intent.entropy_actual
        - compute_redundancy_penalty(sub_intent)
    )

5.2 Conflict Risk Estimation

def estimate_conflict_risk(sub_intent):
    # Check file overlap with other pending sub-intents
    overlapping_files = find_overlapping_files(sub_intent)

    # Check if files are "hot" (frequently modified)
    hot_file_penalty = sum(is_hot_file(f) for f in sub_intent.files_modified)

    return len(overlapping_files) * 5.0 + hot_file_penalty * 2.0

5.3 Redundancy Detection

def compute_redundancy_penalty(sub_intent):
    # Check if another sub-intent already solved the same problem
    siblings = get_sibling_intents(sub_intent)

    for sibling in siblings:
        if solves_same_problem(sub_intent, sibling):
            if sibling.merge_value > sub_intent.merge_value:
                return 1000.0  # High penalty, discard this one

    return 0.0

6) Merge Strategies

6.1 Sequential Merge (Safe Default)

def sequential_merge(sub_intents, deciding_branch):
    # Sort by merge_value descending
    sorted_subs = sorted(sub_intents, key=lambda s: s.merge_value, reverse=True)

    for sub in sorted_subs:
        rebase_onto(sub, deciding_branch)
        if rebase_successful():
            merge_into(sub, deciding_branch)
            log_merge(sub, "automatic_sequential")
        else:
            handle_conflict(sub)

6.2 Parallel Merge (Optimised)

def parallel_merge(sub_intents, deciding_branch):
    # Cluster by file overlap
    clusters = cluster_by_file_overlap(sub_intents)

    for cluster in clusters:
        if cluster.no_internal_conflicts():
            # Merge all in parallel
            for sub in cluster:
                rebase_and_merge(sub, deciding_branch)
        else:
            # Fall back to sequential within cluster
            sequential_merge(cluster, deciding_branch)

7) Branch Lifecycle

7.1 Creation

# Root intent
$ git checkout main
$ git checkout -b I-1771890389-refactor-metrics/_

# Deciding plan: cut from the root intent branch and pushed, so sub-intents can be cut from it
$ git checkout -b I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_ I-1771890389-refactor-metrics/_
$ git push origin I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_

# Sub-intent: nested under the plan that decided the split, cut from that plan branch, which it targets
$ git checkout -b I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890394-add-logging/_ origin/I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_

7.2 Execution

  • Work happens in the branch
  • Commits are made
  • Tests run in sandbox
  • Metrics measured

7.3 Rebase (Post-Execution)

$ git rebase origin/I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_

7.4 Merge (Automatic for Sub-Intents)

The agent raises the sub-intent's PR and merges it automatically into the deciding plan branch, whether the sub-intent is a leaf or a nested parent (section 4.1).

# The sub-intent branch merges automatically into the deciding plan branch
$ git checkout I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_
$ git merge --no-ff I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890394-add-logging/_
$ git push origin I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_

7.5 Promotion (Human Review for Root Intents)

$ holon review approve I-1771890389-refactor-metrics
$ git checkout main
# The root PR carries the deciding plan branch, into which every sub-intent merged
$ git merge I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_
$ git push origin main

7.6 Cleanup

# Delete merged branches
$ git branch -d I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890394-add-logging/_
$ git branch -d I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_
$ git branch -d I-1771890389-refactor-metrics/_

8) Example: Multi-Level Intent Tree

Intent Hierarchy and Git Branch Structure

Intent Hierarchy (each split decided by a plan):

I-1771890389-refactor-metrics (root)
└── P-1771890390-CLA-CS4.6 (plan, decided the split)
    ├── I-1771890392-improve-estimators (sub-intent)
    │   └── P-1771890398-CLA-CO4.6 (plan, decided the split)
    │       ├── I-1771890400-p-success (sub-sub-intent)
    │       ├── I-1771890401-entropy (sub-sub-intent)
    │       └── I-1771890402-impact (sub-sub-intent)
    ├── I-1771890394-add-logging (sub-intent)
    └── I-1771890395-add-tests (sub-intent)

Git branch structure:

main
└── I-1771890389-refactor-metrics
    ├── _
    ├── P-1771890390-CLA-CS4.6
    │   ├── _
    │   ├── I-1771890392-improve-estimators
    │   │   ├── _
    │   │   └── P-1771890398-CLA-CO4.6
    │   │       ├── _
    │   │       ├── I-1771890400-p-success
    │   │       │   └── _
    │   │       ├── I-1771890401-entropy
    │   │       │   └── _
    │   │       └── I-1771890402-impact
    │   │           └── _
    │   ├── I-1771890394-add-logging
    │   │   └── _
    │   └── I-1771890395-add-tests
    │       └── _
    └── P-1771890397-ANA-G3.6F
        ├── _
        └── E-1771890403-CLA-CS4.6
            └── _

P-1771890397-ANA-G3.6F is a competing plan for the same root intent; the sub-intents sit under P-1771890390-CLA-CS4.6, the plan whose ## Sub-intent list created them.

Merge Flow

Sub-intents merge into the deciding plan branch, not the parent intent branch. Every merge below the root is raised and merged automatically by the agent.

  1. Depth 2 → deciding plan inside the sub-intent (automatic):

    • I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/I-1771890400-p-success/_ → I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/_
    • I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/I-1771890401-entropy/_ → I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/_
    • I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/I-1771890402-impact/_ → I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/_
  2. Depth 1 → root's deciding plan (automatic):

    • I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890394-add-logging/_ → I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_ (leaf sub-intent)
    • I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890395-add-tests/_ → I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_ (leaf sub-intent)
    • I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/I-1771890392-improve-estimators/P-1771890398-CLA-CO4.6/_ (the nested parent's PR, carrying the deciding plan branch inside it) → I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_ (nested parent, after step 1)
  3. Root → Main (human review, the only human step):

    • The root intent's PR, carrying the combined diff of I-1771890389-refactor-metrics/P-1771890390-CLA-CS4.6/_, → main (after human approval)

9) Conflict Resolution

9.1 Automatic Resolution (Attempted First)

def auto_resolve_conflict(sub_intent, deciding_branch):
    # Try simple strategies
    if conflict_is_whitespace_only():
        accept_deciding_branch_version()
        return True

    if conflict_is_import_order():
        sort_imports()
        return True

    if conflict_is_non_overlapping():
        accept_both_changes()
        return True

    return False  # Escalate

9.2 Reactive Intent (If Auto-Resolution Fails)

Target-sync code conflicts first go to the conflict-resolver role. The reactive intent is decided during the sub-intent's execution, so it nests under that execution (section 2.2): its deciding_branch and target_branch are both that execution branch, which it is cut from and merges back into automatically. Like Example 3 in Examples, this illustrates the general rule only; the plan-decided split stays the practice.

import time


def handle_conflict(sub_intent):
    spawn_intent(
        {
            "intent_id": f"I-{int(time.time())}-resolve-conflict",
            "parent_intent_id": sub_intent.intent_id,
            "deciding_branch": sub_intent.execution_branch,
            "parent_plan_id": sub_intent.plan_id,
            "parent_execution_id": sub_intent.execution_id,
            "target_branch": sub_intent.execution_branch,
            "goal": f"Resolve rebase conflict in {sub_intent.conflict_files}",
            "intent_type": "reactive",
            "trigger": "rebase_conflict",
        }
    )

10) Ledger Events

All Git operations are logged to the ledger:

{
  "event_type": "git_branch_created",
  "payload": {
    "branch": "I-1771890389-refactor-metrics/_"
  }
}
{
  "event_type": "git_rebase_completed",
  "payload": {
    "status": "success",
    "conflict_files": []
  }
}
{
  "event_type": "git_merge_attempted",
  "payload": {
    "status": "success",
    "merge_type": "automatic_sub_intent"
  }
}
{
  "event_type": "intent_promoted_to_main",
  "payload": {
    "merge_sha": "abc123"
  }
}

11) Discard Policy

11.1 When to Discard Sub-Intents

Sub-intents should be discarded (branch closed without merging) when:

  1. Execution failed (success_actual == 0)
  2. Negative merge value (merge_value < 0)
  3. Redundant with higher-value sibling (another sub-intent solved the same problem better)
  4. Conflicts with higher-value sibling (unresolvable conflict, lower-value intent discarded)
  5. Entropy budget exceeded (sub-intent consumed too much entropy)

11.2 Discard Process

# Close branch and delete locally/remotely
$ git branch -D <branch-name>
$ git push origin --delete <branch-name>

11.3 Learning from Discarded Intents

Even discarded intents provide value:

  • Failure modes extracted to KB
  • Calibration data (predicted vs actual metrics)
  • Negative examples (what not to do)

12) Summary Table

Operation Automatic? Human Review? Rebase Required?
Sub-intent → Deciding node merge ✓ Yes ✗ No ✓ Yes (before & after)
Root intent → Main merge ✗ No ✓ Yes ✓ Yes (before)
Branch creation ✓ Yes ✗ No N/A
Conflict resolution Attempted If fails N/A
Sub-intent discard ✓ Yes ✗ No N/A

Key insight: Human review is required only at the root intent level: the root intent's PR to main is the only human stop. Every sub-intent merge, for leaf sub-intents and nested parents alike, is raised and merged automatically by the agent into the deciding node's branch, evaluation-based and with no human intervention.


13) Edge Cases

Sections 13.2 and 13.3 describe the decided model. In the current flow the children of a sub-intent list run one at a time, and the first failing child fails the parent's Stage 3, so the remaining children do not run, nothing is merged automatically and no stage waits for a human.

13.1 Root Intent with No Sub-Intents

If a root intent has no sub-intents (leaf intent):

  • Execute directly in root intent branch
  • Still requires human review before merging to main

13.2 All Sub-Intents Fail

If all sub-intents under a parent fail:

  • Parent intent is marked as failed
  • If parent is root intent, human review requested (may choose to retry or abandon)
  • If parent is sub-intent, it is discarded automatically

13.2a Resuming Over Interrupted Work

When Stage 3 is resumed (holon flow --checkpoint ... --from-stage execute) and the mounted worktree holds uncommitted edits from an interrupted run, the host commits them onto the failed execution branch of the plan as a partial-work commit (execute: <execution_id> partial work (interrupted) for plan <plan_branch>) and records it in executions.jsonl, then resumes from that commit. The ledgers and the execution notes file are excluded, so dirty engine-owned files alone produce no commit. Nothing is discarded, reset or amended, and the commit stays on the execution branch, never on main or the plan branch. A never-pushed execution branch reaches origin only in the one push that already carries its salvage row.

13.2b Where a Resumed Execution Starts

  • The override is recorded once per plan. A Stage 3 run admitted by --allow-overlap appends its admission_override row to the plan branch's executions.jsonl only when no such row for the plan exists yet, so a resume under the same override adds no commit to the plan branch.
  • Partial work from an earlier plan tip is kept. A recorded partial_head qualifies when it descends from the current plan tip, or when its fork point lies on the plan branch's first-parent history after the intent branch tip and every first-parent commit of the plan branch since changed only holon-knowledge/ledger/*.jsonl or is a Stage 3 refresh merge (plan_refresh.md). The executor then merges the current plan tip into the new execution branch (ledger conflicts keep the plan side's rows in place and insert the execution rows by created_at), so the branch always descends from today's plan tip. Any other merge conflict aborts the merge and the execution starts from the plan tip.
  • The branch tip is preferred. When the failed execution branch's tip strictly descends from the recorded partial_head, adds more than the failure commit's ledgers and notes, and passes the same lineage rule (a merge of origin/main to settle a sync conflict, for example), the resume starts from the tip; no hand-written ledger row is needed. A tip that does not contain the recorded head is passed over and the log says why.
  • An execution branch is pushed only with its ledger row. After Stage 3 dispatch the host pushes a new execution branch only when its tip carries the execution's summary row (any status). A branch whose executor failed before committing that row stays local in the host worktree, untouched, and the Stage 3 log names it.

13.3 Partial Sub-Intent Success

If some sub-intents succeed and others fail:

  • Successful sub-intents, leaf or nested parent, merge automatically into their deciding node's branch
  • Failed sub-intents discarded
  • Parent intent continues with merged work

13.4 Long-Running Root Intent

If a root intent remains open for extended period (e.g., weeks):

  • Periodic rebase from main recommended
  • System entropy monitoring triggers maintenance
  • Human may choose to merge incrementally or wait for completion

14) Best Practices

14.1 Keep Sub-Intents Focused

  • Each sub-intent should have a single, clear goal
  • Avoid "mega sub-intents" that do too much
  • Better to have more sub-intents with smaller scope

14.2 Monitor File Overlap

  • Track which files are "hot" (frequently modified)
  • Consider sequential execution for sub-intents touching hot files
  • Use finer-grained decomposition to reduce overlap

14.3 Rebase Frequently

  • Don't let branches diverge too far
  • Rebase from the deciding node's branch regularly, not just before/after execution
  • Reduces conflict resolution cost

14.4 Prune Aggressively

  • Discard low-value sub-intents early
  • Don't wait for all sub-intents to complete before merging high-value ones
  • Keep branch count low to reduce system entropy

Related Documents