feat(flows): use the 180-minute cap for Software Garden robustness, not a longer plan

Merged
KH
2mo ago
+1179-140

Founder rule

The Software Garden flow stays slim. AgentWorkforce/cloud#4270 raises the hosted run cap from 60 to 180 minutes. This PR treats that extra time as margin, not as room for more work. It adds no plan step, no extra review round, no extra prototype agent and no longer build. All new time goes to recovering from failures. The happy path stays the same length, and a test enforces that.

Before and after

FLOW_TIMEBeforeAfterWhy this is robustness
headerMinutes (cloud wallclock)60 ("1h")120 ("2h")Leaves an hour under Cloud's 180-minute cap for setup and teardown.
buildByMinutes (new)effectively 34 (52m body less 18m publishing reserve)34Discovery, prototypes, comparator and implementer must finish where the 60-minute plan ended them, so the build is no longer.
discoveryMinutes1015Discovery took 9m24s in bda21b91, close to its 10m limit. It runs inside the unchanged build window.
repairMinutes1520 (Cloud only)bda21b91's first repair took 19m27s. A 15m limit stops it just before it finishes.
repairRounds (new)12 (Cloud only)The second round runs only if the re-check still fails and the first repair finished, not timed out. It also needs enough time left for the review's floor and the base check. A clean run never plans it.
localRepairMinutes / localRepairRounds (new)15 / 115 / 1A local run keeps its single 15m repair, because a local agent has no limit to stop it.
forgeMinutes35Pushes and forge calls to large repositories ran past their limit (ccbc27c8, agentrelay.com#135).
pushMinutes (derived)7112 × forge + followUp.
publishMinutes (derived)1725Publishing with every step at its limit.
buildReserveMinutes (new, derived)—78Everything after buildByMinutes. It always fits the checks, a repair at its floor, its re-check and publishing.
checkTotalMinutes (new)14 (one lease)30 (several leases)flows#626 / run b71c1687: a check.sh that mirrors CI hit the 840s limit. The branch check now runs detached and is waited on across leases (see below).
checkPolls (new, derived)—3The most waits one 30m check takes. Each check reserves 1 + checkPolls = 4m of clock reads and lease slack, up from 2m.
checkLimitMinutes / checkMinutes14 / 15unchangedNow the longest single wait on a branch check, and the base-commit check's single-lease limit. f.run still refuses a lease above 15 minutes.
reviewMinutes, implementerFloorMinutes, prototype/comparator, floors, setupMinutes, followUpMinutes—unchanged
Agent limit ceiling6060relayflows still refuses an agent timeout above 60m (AgentWorkforce/flows#606).

Happy path's planned allowances (build window + one check + publishing + review): 34 + 14 + 17 + 20 = 85m before, 34 + 30 + 25 + 20 = 109m after (+28%). The first commit alone came to 93m (+9.4%). The check budget (14 to 30) then took it over the 10% line. Every increase is time spent waiting on something outside the agents: a test suite or a forge. A clean run only spends what those actually take. The agents' own allowances (build window 34m + review 20m = 54m) are exactly where the 60-minute plan had them. The test pins the 109m ceiling and the 54m agent share explicitly. The measured typical run still lands in 30–45 minutes.

Generator changes (web/lib/flow-workflows.ts)

  • Prototypes, comparator and implementer now reserve building (everything after minute 34 on Cloud) where they used to reserve publishing. Their limits come out as before (the implementer still stops at about 23–33m), and the time after the build is never spent on building.
  • The checks section runs repairs in a loop of at most repairRounds on Cloud and 1 locally. Round 1 keeps its journal name check-repair, so resumes still work. Round 2 is named check-repair-2, runs only when the checks are still broken, and states its own timeout like every Cloud agent. A repair stopped at its limit ends the repairs ("no further repair is tried").
  • The review keeps its minimum time. Every step after the build reserves reviewing in workflows that review: the check, both repairs, the re-checks and the base-commit check. reviewing is the review floor plus the review reserve, using the same target-aware floor as the review guard: 8m on Cloud, the whole 20m locally. A second round also reserves the base-commit check as compareWithBase budgets it, and its re-check is held to that. As a result the full-limit sweep never reaches the time-stop path on Cloud. The path stays in as a guard.
  • minutesLeft, allowance and the floors are unchanged. They read the new body (112m). The header still comes from FLOW_TIME.headerMinutes in flow-onboarding.ts.
  • Local target: keeps the 3h budget, sets no agent limits, reserves publishing for the build steps as before, and keeps one 15m repair.
  • Side effect: on Cloud the "Skipped the checks" fail-fast branch can no longer be reached, because the build always ends by minute 34. The branch stays in as a guard for the local target.

Check runs that span several leases (flows#626)

Run b71c1687 failed at step run-11 because it hit RELAYFLOW_CHECK_TIMEOUT 840s. Its check.sh correctly mirrors the repo's CI: a kernel release build, cargo tests, the schema, the surface gate and the full SDK tests. No single lease can be raised, so a check now spans several:

  • With RELAYFLOW_CHECK_WAIT set, FLOW_CHECK_RUN_COMMAND starts check.sh detached, in a process group of its own, with every descriptor redirected away from the lease. It uses setsid, else perl -e 'setpgrp(0,0); exec @ARGV' with SIGHUP ignored (macOS). Where neither exists it is not detached: nothing there could stop the suite's children, so the check runs in the step itself under the limiter, within the wait that step may hold its lease. With no limiter at all (no timeout, no gtimeout, no perl) the check is not started: nothing could stop it, so it would hold the step's lease until the runner killed the step and the run would end with no verdict — the failure this plan exists to prevent. The command reports a new unrunnable verdict instead, exits 0 like every other verdict, and names what to install. Cloud's image always has coreutils timeout, so only a local run can reach this. The detached shell records its own group (check.log.group). The log goes to .relayflow/check.log, and the exit status goes to a file that is written then renamed into place.
  • Each call waits at most RELAYFLOW_CHECK_WAIT and prints running if the check has not finished. The flow (spannedCheck) calls again in bounded steps of at most 14m, each leased at no more than 15m, until the check finishes or checkTotal (30m) runs out.
  • The waiting step enforces the total. At RELAYFLOW_CHECK_TIMEOUT it sends the check's whole group SIGTERM, waits up to 5s, sends SIGKILL, and reports timeout (exit 124), never fail. The signal reaches the suite and everything it started, not a wrapper. The kill uses the kill -TERM "-PGID" form, because dash (/bin/sh on Ubuntu and E2B) rejects --. A check that dies without an exit status is a fail. A suite's own exit 124 (for example an inner timeout in a CI-shaped check.sh) is also a fail: only a check this flow stopped counts as a timeout.
  • A check stopped for time leaves .stopped beside its status, so a resumed waiter with the same ID also reports timeout. The detached check keeps its own deadline, a minute past the total, so it ends even when nothing is waiting on it any more.
  • Before a new ID starts a check, it stops any check an earlier attempt left running. With ps it first confirms the group is still that check, so a recycled pid is never signalled; without ps it stops a live group with no status anyway, because a second check writing the same .relayflow files is the worse risk.
  • Resumable. Each check carries RELAYFLOW_CHECK_ID (the run's start time plus a counter, both deterministic on replay). A call with an ID already started only waits, so a resumed run picks up the check it started. No agent step or existing step was renamed.
  • Floors and the review's minimum time are kept. The check and every re-check reserve publishing and the review's floor. The check floor (5m) and the repair floors are unchanged.
  • Without RELAYFLOW_CHECK_WAIT, the command runs in-line as before. The base-commit check still runs that way, within one lease (13m), and is skipped as before when the branch check took longer than that.

Check outcome wording

The pull request's check report now tells the cases apart. The command records .relayflow/check.log.exit, .elapsed and .limit, and the report reads them:

  • Failed: "The checks failed (exit N). The end of their output is below.", followed by the log tail.
  • Timed out: "The checks timed out: they ran for 30m03s of their 30m00s budget and were stopped before they finished, so this is a time limit, not a test failure. Run them locally (sh .relayflow/check.sh) to see how long they take, or raise the check budget (checkTotal in the flow) and run the flow again."
  • Not run: unchanged: "Relayflow ran out of time before it could run this repository's checks" (relaycast-cloud#216).
  • Could not be run: "Relayflow could not run this repository's checks: the machine it ran on has no timeout, gtimeout or perl, so there was no way to stop the suite at a time limit… This is not a test failure, and nothing here says the change is broken." The flow repairs nothing, compares no base commit, still reviews, and opens a draft.
  • The base-commit sentences that follow no longer repeat "The checks failed". The flow's own journal messages also say "The checks timed out (stopped at their time budget, not a test failure)" instead of "The checks fail".

Dependency

Satisfied. cloud#4270 is confirmed live in production (health buildSha e88433bd3 = deploymentSha, contains 4540e9701): the hosted v2 run budget max is 180 minutes, so a "2h" header is honoured. A production proving run of the 30-minute detached check is planned before merge.

Interaction with #174 / #175 (catalog single source)

#175 merged first. Its test requires the published artifact to match the generator byte for byte, and that is why "Tests and typecheck" first failed on the merge commit. This PR merges main and re-cuts the artifact with web/scripts/publish-software-garden.mts. That adds web/public/flows/software-garden/v2.flow.ts (sha256 516ccd18…1d60fb) and moves manifest.json to v2. v1 is untouched, so published versions stay immutable, and no catalog file is touched here.

For whoever re-lands #179 (the catalog pin): #179 was merged into the deleted trunk and is lost, so main's catalog still points at the 14 KB flows-repo example while v1.flow.ts (sha b89a36e2) is published and live. This PR moves the manifest to v2 but pins nothing. If #179 lands first, this PR only needs its artifact re-cut (one publish-software-garden.mts run, bumping to v3) — the catalog pin itself does not conflict. If this PR lands first, #179 should pin v2 (516ccd18…1d60fb), not v1, because v2 is what the generator produces once this is in. Either order works as long as the pin names the version the generator then produces.

Tests

  • flow-budget.test.ts

    • plans within Cloud's 180-minute run cap: header is 120 and at most 180, all agent allowances are at most 60 (agentLimitMaxMinutes === 60), the build window fits discovery plus the implementer floor, and the build reserve fits checks, repair floor, re-check and publishing.
    • new keeps the happy path's planned allowances at 109m, with the agents' share where the 60-minute plan had it: pins buildBy + checkTotal + publish + review <= 109 (85m before) and buildBy + review <= 54, so a future change cannot quietly lengthen the plan.
    • declares the 2h wallclock: every workflow's parsed header is at most 180 minutes. Local stays 3h.
    • The full-limit sweep (about 1,450 simulated runs over 3 workflows) now bounds the run by headerMinutes. It checks that every agent limit is between 1 and 60, that every workflow reaches check-repair-2, and that Cloud never skips the checks.
    • new gives a failed check the extra repair room: bda21b91's 19.5m repair now finishes and leaves a ready PR. With a 5m suite, the second round runs and the review still runs afterwards.
    • new: second round only when the re-check still fails; never after a repair stopped at its limit; skipped (with a message) when it would take the review's floor.
    • Rewritten: the old "fails fast when no time to check" test is now stops a slow implementer where the 60-minute plan did, and still checks, publishes and reviews.
  • flow-onboarding.test.ts, flow-agent-settings.test.ts: "2h" header, and a second check-repair-2 when the checks keep failing.

  • Spanning leases (flow-workflows.test.ts, real shell). A check longer than one wait finishes across calls, and its exit status is honoured: pass gives 0, fail gives exit 3 with its output. Each call returns within its wait. A check past its total is reported as timeout with exit 124, its elapsed time and its limit. An ID that was already started is waited on and not restarted, while a new ID starts a new check.

  • Spanning leases (flow-budget.test.ts, simulated clock). A 20-minute check is waited on across several leases, each at most 15m, and runs to the end (20m, not 14). Its pass or fail verdict reaches the report and the draft decision. A 45-minute check is stopped at the 30m budget and reported as check=timeout, and the journal says "timed out", not "fail".

  • Process group (flow-workflows.test.ts, real shell). A suite that ignores SIGTERM and starts a child of its own is stopped at its total: the group, its leader and the child are all gone. On a PATH without setsid, the check still gets a group of its own, which is gone after the timeout. On a PATH without setsid and without perl, the check is not detached at all and runs in the step, within its wait, under a timeout stub the fixture provides (macOS has neither timeout nor gtimeout, so without the stub that case would never reach the timeout path). With no limiter at all the command refuses to start the checks on both paths, bounded and explicit, and the suite never runs; the report calls that "could not run", and the flow drafts, reviews and repairs nothing. Other tests: a suite's own exit 124 is a failure, a resumed waiter is told about a stopped check, and a check an earlier attempt left running is stopped first (with and without ps). I also ran all four paths by hand under /bin/dash, the /bin/sh of Ubuntu and E2B: pass across leases, a total timeout that stays a timeout on resume, a leftover check stopped, and the no-setsid/no-perl in-step fallback.

  • Check keys (flow-budget.test.ts). Every branch check carries RELAYFLOW_CHECK_ID, _TIMEOUT (at most 30m) and _WAIT (at most 14m), with one ID per check. The base check carries only its limit. plain() in the onboarding and local tests now strips only that exact prefix.

  • Local (flow-budget.test.ts). A local run keeps a single 15m repair and no second round.

  • Sweep. Each poll is charged its lease minute under fullTimeouts. No Cloud workflow reaches the time-stop path, and every workflow still reaches check-repair-2 and the base check.

  • Wording (flow-workflows.test.ts). A failed check, a timed-out check (with and without timings) and checks that never ran each get their own message.

  • Happy-path assertion: now pins the 109m ceiling and the 54m agent share (see above).

Local results:

  • cd web && npx vitest run: 45 files, 544 tests passed
  • cd web && npx tsc --noEmit -p .: clean
  • npm run verify:recommended-flows: passed (catalog gates, software-factory v2.0.42, babysitter)
  • npm run verify:setup-skills: passed
  • npm --workspace router run test fails with "No test files found". That happens on main as well and this PR does not touch it.

Do not merge until the dependency above is live. The lead will merge.

🤖 Generated with Claude Code


[!NOTE]
Medium Risk
Changes hosted flow time budgeting, check execution/kill logic, and repair loops—high impact on CI outcomes and run duration, but heavily tested and scoped to generated Relayflow workflows.

Overview
Raises Software Garden’s cloud wallclock from 1h to 2h (under Cloud’s 180-minute cap) and reframes the extra time as recovery margin, not a longer happy path: the build still ends at buildByMinutes (34), agent allowances stay pinned, while check budgets (up to 30m across leases), publishing/forges, and up to two 20m repair rounds on cloud grow.

Detached, resumable checks replace single-lease runs: FLOW_CHECK_RUN_COMMAND can start check.sh in its own process group and poll with RELAYFLOW_CHECK_ID / RELAYFLOW_CHECK_WAIT, stop the whole suite at the total budget, and return running, timeout, unrunnable (no timeout/perl on local), plus .exit/.elapsed/.limit for PR reports that distinguish failure vs timeout vs could-not-run. Generated workflows use spannedCheck instead of one-shot checks; drafts open on unrunnable; local runs keep one 15m repair.

Ships Software Garden catalog v2 (v2.flow.ts, manifest bump) and broad test updates for the new time plan and check runner.

Reviewed by Cursor Bugbot for commit 572c42152f0e735b50753020243fe0c007d7cddd. Bugbot is set up for automated code reviews on this repo. Configure here.


Agent Relay sessions

  • claude session ad3755aa · opened via gh pr create · last active 2026-10-09
  • claude session eae07e25 · contributor · ran gh pr commands · last active 2026-10-08