Production Parallel Lifecycle¶
parallel-specialists needs a completed production lifecycle and shared artifact validation. Schema 2 carries parallel patches. Schema 3 carries authorized topic commits. The exact-plan dispatch record, including workflow-default, proves only the chosen route; it never proves execution, integration, or source application and must not be described as plan-specific user approval. The route is local to code-remediate, and generic write_parallel_promoted remains false.
Inspect PLUGIN_ROOT/bin/python PLUGIN_ROOT/shared/parallel_worktrees.py --help, then use its parent-owned commands in this order: prepare, one create-handover per terminal child, one join containing every handover file, one collect per joined node, integrate, reconcile if integration reports a collision, apply-source, then cleanup. Handover and reconciliation files must remain inside source-local run directory. If selected work is indivisible, dependent, or capacity is unavailable, use an available parent-owned or sequential route and record the concrete reason and actual mode. Do not ask permission to use that fallback. Unsafe operations still stop at the affected action unless a verified isolation alternative makes them safe.
Preparation requires no merge, cherry-pick, revert, or rebase in progress and no unmerged index entries; exact plan and dispatch-record digests; matching baseline HEAD/tree; exact new lifecycle-state basename in plan/run directory; two to four independent buckets; compatible resource locks; actual source-local context-pack paths and SHA-256 values; fixed code-remediate-shared-quality-gates reference; and generated detached worktrees. Schema 2 permits exact shared-file overlap. Schema 3 requires disjoint owned paths and binds the full attached source branch ref. Tracked and untracked source changes may remain when they do not overlap owned paths or paths an operation may overwrite. Preserve pre-existing staged changes. For grouped delivery an occupied source index prevents fast-forward, so keep the patch route if the initial index is occupied. Re-hash every context pack at preparation and each authority transition. Reject arbitrary bucket fields such as plan-driven shell commands, caller-selected or pre-existing state/output paths, source drift, path aliases or ancestor overlap, symlinks, ignored or untracked child output, unauthorized commits, staged child content, deletes, renames, file-mode/type changes, undeclared paths, or operation-state changes. Every declared owned path is required to change.
Use the supported sibling .codex-rig-worktrees location or a source-local Git-ignored .reports/codex/code-remediate-worktrees/<run-id> root, preferring source-local when available. A worktree root must resolve to the source repository or one child directory, must not traverse a symlink or escape its allowed boundary, and the run-specific root must not already exist. Do not broaden filesystem permissions to make a root eligible.
Limit each bucket's verification to its assigned modules and directly affected tests, including relevant regressions and integration tests. Record exact test selectors in the frozen context pack before dispatch. Use these selectors for baseline and postimage checks. The plan binds the context pack by digest and carries the fixed verification_gate reference.
Each parallel child context pack must preserve zero ignored or untracked output at handover by naming exact no-cache or no-output verification commands for every required child check. Prefer tool-native flags or environment controls that suppress disposable caches, coverage files, bytecode, reports, and equivalent generated output. Before hashing the plan, preflight every exact child verification command against the unchanged baseline in a disposable clean worktree; require unchanged tracked files and zero ignored or untracked output. Record expected baseline regression failures separately from command-launch, configuration, or output-boundary failures; a failing assertion that the selected fix must repair does not block dispatch. Do not create planned postimages before dispatch. Freeze only byte-identical command text that passed preflight’s command and output-boundary checks. Changing a command or its environment after preflight requires a new plan digest and dispatch record. A child must not delete verification output after the command because deletion would hide an observed boundary violation. When a required check cannot meet the output boundary, record the concrete limitation and continue that work parent-owned or sequentially without an approval prompt.
Freeze one dependency-ready wave before child dispatch. Each child receives one worktree. Its terminal handover contains canonical status, summary, changed paths, and patch SHA-256. Schema 2 workers leave patches uncommitted. Schema 3 workers finish one draft commit per topic and add its full commit_oid to the handover. Assign this commit in the frozen context pack only when the user explicitly selected topic commits and the commitment remains authorized. The dispatch record grants no commit consent. For each grouped handover, retain a run-local JSON verification receipt and pass it with create-handover --verification <receipt>. The receipt contains node_id, commit_oid, and ordered checks. Each check has the exact frozen command, numeric exit_code=0, run-relative stdout path, and stdout_sha256. Record only checks that ran against the same postimages as the draft commit. The receipt is the worker's own advisory statement: it never replaces the gates that run on the integration tip, which the helper re-validates immediately before delivery. Keep receipt and logs intact through finalization. The worker reviews and stages only the exact owned paths and uses the shared commit template and verification, including the Codex trailer. Inspect the commit command’s actual hooks under the same execution policy as tests. Apply the protected-execution protocol when a hook needs confinement or the user requested it. Where the parent must own that execution, the worker prepares the reviewed commit and the parent runs the exact authorized command in the worker's detached checkout after targeted checks and the writer barrier.
Parent-coordinated PR verification¶
Ordinary worker checks on every PR origin use current host permissions after the execution decision in Contributed Code Execution. Use the numbered verification phases below for checks requiring confinement and for any retained protected interval. The parent owns every protected execution. A linked worktree shares Git state, and a sibling draft or parent ledger inside the invoking checkout can change a watched ignored path. Parallelize the edits between verification phases.
- Put the edit and verification phases in each child's frozen context pack. Children edit only their assigned paths, yield to the parent before any contributor execution, and resume edits only on explicit parent release. For a new regression, yield the test edits first so the parent can record the expected failure before releasing the source fix. Use the same parent protocol for baseline preflight, other reproductions and final postimage checks. Freeze the project command, its options and environment policy. Supply the verified checkout and child-specific evidence destination at launch for each phase.
- Before taking a snapshot, confirm all child writers have yielded or finished and that their tools and background jobs have drained. Include other parent-owned work in this check. An idle-looking agent, timeout or pending tool call is insufficient. Finish pending parent ledger and lifecycle writes before the snapshot. If a writer is still active, wait for acknowledgement and completion. Before dispatch, choose sequential execution if the host cannot coordinate these pauses.
- Keep writers paused and check one bucket at a time through snapshot, execute, verify. During baseline preflight, identify the parent-created disposable checkout and any existing draft checkouts before execution. After preparation, bind each prepared worktree to its bucket ID using the parent's frozen plan and verified preparation result. For every distinct checkout, run the shared integrity helper's
snapshot --repo <checkout> --watch-surface --main-checkout <invoking-checkout> --out <interval-evidence>/integrity-<bucket>.json. Use a dedicated interval evidence directory outside every draft, retain each path and its printed SHA-256 in the parent's context, and require every snapshot to succeed before execution. The same rule covers sibling roots outside and inside the invoking checkout. Before dispatch choose sequential execution if the host cannot fingerprint every draft or keep its writers paused. - Run the exact selected check in its verified checkout, capture its exit status and wait for the process and its children to finish. During the interval write logs only to the snapshots' already excluded evidence directory. On every exit, including launch errors and expected failures, verify every retained digest with
verify --snapshot <file> --expect <kept-sha256>. Keep sibling edits, parent ledger updates, Git operations and handovers paused until every verifier exits successfully. On the first failed verification, stop immediately and preserve the original snapshots, digests, logs and drafts under the integrity stop rule. - Check the required postimages and output boundary before any watched ledger or lifecycle write. Keep interim results in the excluded evidence directory and verify all snapshots immediately before each required Git command. Once these checks finish, record the results in the parent ledger with each bucket, original snapshot path, kept digest and verifier result. After authorized ledger writes or edits, take fresh snapshots for the next execution only if every earlier execution passed all integrity checks. Reuse the red/green acceptance criteria below. Start the next protected interval with all writers still paused, or release the next edit phase and establish quiescence again before verification. A failed interval stays failed. To restart, preserve the failed snapshot and original digest for every affected checkout, reestablish the writer barrier and apply the verified target-branch fast-forward procedure for sole
common:refsdrift or Restart after inspected integrity drift to every affected snapshot before retrying the interrupted check.
Handover and integration¶
After implementation and before handover, require exit zero on every exact approved child check, unchanged intended tracked postimages, and zero ignored or untracked output. Expected baseline regression failures are no longer acceptable at this stage. A failing postimage check blocks handover and integration; preserve its evidence and return control to parent. This postimage gate precedes structural collection and integration steps below.
The parent re-derives every patch from its child worktree, validates its report and exact ownership, and joins every required terminal handover. Schema 2 applies the patches in lexical bucket ID order in a separate integration worktree. Exact shared files may integrate without conflict. On a patch collision, leave authoritative source untouched and record needs-reconciliation. The parent resolves the integration worktree, writes a run-local record binding the baseline, joined patch hashes, failed node, approved paths, and final postimage hashes, then runs reconcile to verify it before source application. A missing or invalid reconciliation blocks completion.
Schema 3 also verifies each draft is a single direct child of the baseline in a clean detached worktree. It cherry-picks verified commits into the integration checkout in lexical bucket ID order and checks each resulting parent and exact patch. Integration records structurally-verified after checking Git structure, exact paths, and postimages. It does not execute or claim plan-provided commands. The parent runs the configured full test suite once on the consolidated source at the step 09 shared quality gates. For schema 2, run them after source application, following the documented skip and rerun rules. For schema 3, run them on the detached integration tip before source application and require the full test command to pass. An unexpected cherry-pick conflict or source change needed after the final checks blocks delivery. Preserve the failed wave and diagnose the affected topic. Use fresh lifecycle evidence for corrected draft commits, reusing independently verified changes where applicable, and run gates against the newly integrated tip. If diagnosis shows shared ownership, use the patch-and-reconciliation route for the coupled work.
Only the parent may apply the integrated bundle to the authoritative repository. Immediately before application, recheck the exact HEAD/tree, clean operation state, and every approved path preimage. Persist one durable reverse patch plus its SHA-256 before writing; preflight one parent-generated forward bundle; apply it once; then verify every expected postimage. This is parent-authoritative operational postcondition containment with capability_sandbox_verified=false, not per-child capability isolation and not a hostile-child security boundary. Each run takes an exclusive per-run lock (.production-lifecycle.json.apply-lock beside the state) around source application, rollback, resume and cleanup. Concurrent runs on one source repository are unsupported because that lock is per run: once another run moved the source, a later run stops with source-repository-head-drift before writing (reopened as preflight-failed when its intent was already saved), or is saved failed with its observed_head when the other run's fast-forward lands during its own, and nothing of the later run reaches the source. A live holder stops the second command with lifecycle-apply-locked. A holder recorded on another host stops it with lifecycle-apply-locked-foreign-host: followed by the holder's process ID, host and lock time; check that host before removing the lock. Only a same-host holder whose process is gone is reclaimed. Every restore rereads the state first and restores nothing when another run changed it. Without a repository-wide external lock, source application is conditionally reversible rather than globally atomic. A preflight failure writes nothing to the source: the run stays integrated, the attempt is recorded as preflight-failed, and the parent applies again once the drift is repaired. When Git shows the delivery already landed (another run finished it first), the run is recorded as applied instead, and every state save rereads the state file and stops with lifecycle-state-concurrent-update when another run changed it.
If any affected path after apply failure matches neither its recorded preimage nor expected postimage, record rollback-ambiguous, retain all worktrees and patches, and stop without automatic restoration. Otherwise restore only known approved paths to frozen baseline (and only when each path's index mode, and on POSIX its working-tree file type and executable bit, still equal the baseline, since a mode change is the user's own work), recompute every path hash, and record failed-rolled-back only when all restored hashes equal frozen preimages; restore error or mismatch becomes rollback-ambiguous. Retain durable reverse patch as independent recovery evidence. Perform non-force cleanup only after durable source application and exact postcondition verification; cleanup failure retains evidence and blocks completed.
For schema 3, pass the run's gates.json to apply-source --gates. The parent rechecks the branch, baseline, paths, clean index, integration tip, and gate receipt before a local fast-forward to the exact tested commit. The helper retains forward and reverse patches as evidence and leaves failed fast-forwards or postcondition failures for diagnosis; when Git shows the exact delivery landed on the moved branch, a later failure is recorded as applied, and a branch moved to any other commit stays failed. It does not reset the branch. Check the resulting HEAD and owned paths before non-force cleanup. At step 12, use the integrated commit IDs in the commit plan and final disposition.
Rerun the same command after a crash. Collection adopts an existing regular, non-symlink patch file only when its bytes equal the re-derived child patch; a partly written or different file stops with patch-output-exists. Integration adopts a fresh baseline checkout after interrupted creation. After interrupted application, it recreates the registered, detached integration checkout from the baseline only when Git shows every index and working tree change, including untracked and ignored files, is within the owned paths. In patch mode HEAD must still be at the baseline. In grouped mode the commits must form a linear prefix of the recorded patches in node order. A pending merge, rebase, or revert blocks recovery. Unproven checkouts are preserved and report integration-worktree-exists.
Delivery records a landing Git shows as exact, performs it when the source is untouched, and finishes it after restoring approved paths to the baseline when the branch is still at the baseline and every approved path's file and index entry matches its recorded preimage or postimage (a leftover index.lock stops it until the lock is cleared). Cleanup reconciles only the one recorded pending removal: when its directory is gone it counts as removed, and when Git still registers it because the removal crashed part-way, cleanup prunes that registration only while Git reports no other prunable worktree. When the crash left the directory partly deleted (its .git file or some tracked files gone), cleanup deletes the rest and prunes the registration only under Git's own non-force check, read through the worktree's administrative directory: every remaining tracked file unmodified, nothing untracked or staged, no populated submodule, the worktree unlocked, and no other worktree prunable. Ignored files go with the directory, as git worktree remove deletes them. Anything else stops with cleanup-partial-worktree-unclean or cleanup-unrecorded-worktree-removal and keeps the pending removal, so cleanup finishes once the operator resolves it; a failed delete stops with cleanup-partial-worktree-removal-failed and is retried the same way. Unproven delivery and cleanup states stop with a named error and preserve the checkout.
Keep gate output outside the integration checkout so the cleanup command can remove it without force. The gate runner redirects standard pytest cache, bytecode and coverage output. For other tools, use the project's supported output location or no-output options. When the configured gates must leave output in the checkout and cannot redirect it, use the patch route. As with the other lifecycle Git operations, helper-run cherry-picks and fast-forward disable repository hooks. Run the configured commit hooks on each worker's draft and the configured shared gates on the integrated tip.
Bind the final lifecycle projection into CODE_REMEDIATE_METADATA.resolution_workplan.production_lifecycle with its run-relative path, SHA-256, and status. The projection must reconcile the plan digest, baseline, joined node/path/patch hashes, every retained parent-derived child patch, deterministic structural integration order, source preimages/postimages, the retained parent forward bundle, source-application status, rollback artifact, cleanup outcome with force=false, and containment limitation. For schema 3 it also binds the source branch, the recorded upfront choice, the worker verification evidence, the ordered integrated commit objects and their parent links, the delivered integration head and the gates receipt digest. Never emit a completed remediation result from plan metadata alone or without passing shared-gate evidence.