Skip to content

agent-cycle.sh's main flow is ~3,400 lines of undecomposed top-level script, and five of its functions are 280-645 lines

Id: TD-PPagop-26082408 · Status: open · Filed: 2026-08-24 · Review: reviews/project-review-2026-08-23 R-02 F-CODE-01 F-ARCH-01 F-ARCH-02 F-CODE-04

Severity: High

agent-cycle.sh is 9,920 lines and defines 95 functions directly, but the two largest contiguous regions of the file (roughly lines 6484-9360 and 9372-9920, ~3,400 lines together) run as top-level script, not inside any function — the pipeline’s actual cycle body: claim acquisition, all five stage dispatches, cleanup. review-cycle.sh (same author, same repo, 1,043 lines) fully decomposes into 19 named functions with no comparable block. Five named functions inside agent-cycle.sh are also unusually large: maybe_run_enabler (~645 lines, ~30 locals), coordinator_corroborate_retry_or_fallback (~328), run_approver_stage (~319), maybe_run_refiner (~292), and _landing_stage_attempt (~283) — contrast lib/handoff.sh, which decomposes comparable domain complexity into 17 functions averaging ~65 lines each.

This is the natural result of 42 days of fast, single-author iteration on the pipeline’s actual cycle body, which keeps growing new stage dispatches and verdict branches without a dedicated refactor pass ever catching up.

Ongoing cost: the undecomposed main flow cannot be unit-tested the way lib/*.sh functions are (nothing can source and call a slice of top-level script) — it is the highest-stakes, most-frequently-touched code in the repository, and a regression here is only caught by the full integration suite or by production. The five oversized functions’ flat local-variable scopes raise the risk that an edit to one verdict branch accidentally shadows state meant for another.

Suggested fix: extract the main flow’s major phases into named functions matching review-cycle.sh’s style; move the gather_*/exclude_*/ coordinator_* families into lib/ alongside their existing siblings (lib/coordinator-input.sh, lib/repo-order.sh); split the five oversized functions along their existing guard-clause/verdict-branch structure, matching lib/handoff.sh’s decomposition style. This is naturally sequenced with docs/ROADMAP.md’s D6/D8 repository-split work — coordinate timing with whoever owns that item. See reviews/project-review-2026-08-23/04-improvement-prompts.md’s prompt for R-02 for the full acceptance criteria and a suggested incremental sequence.

Migrated to https://github.com/Poetic-Poems/agent-ops/issues/964.