Skip to content

Latest commit

 

History

History
129 lines (98 loc) · 6.22 KB

gate_runner.md

File metadata and controls

129 lines (98 loc) · 6.22 KB

gate_runner.sh

Revision: 1 Last modified: 2026-12-04T19:00:00Z

Overview

gate_runner.sh is the fastcycle gate executor. It has two distinct modes:

  • Mode 1 (default), verdicts — run the gates selected for a change, ordered cheapest-failing-first by historical fail rate and cost, and write a machine-readable verdict document.
  • Mode 2, --mode shard — partition the gate set into write-disjoint shards so several gates can run in parallel without one shard writing what another reads.

This is the tool you run to actually execute a gate set. You do not usually decide which gates — that is affected_set.py — and you do not usually decide whether to trust a previous run — that is verdict_cache.py. gate_runner.sh consumes both and produces the verdicts.

Two design commitments matter when reading its behaviour:

  1. Ordering never changes the answer. AS-013 requires that running the same members ordered vs. unordered yields the identical verdict set. Ordering is a wall-clock optimisation, not a filter. The script runs every member to completion regardless of order, so the fast lane cannot silently drop a gate.
  2. Concurrency is clamped by the host, never hardcoded. The --n-shards value is a partition count. The actual parallelism handed to xargs -P is a separate value obtained from lib/host_guard.sh (nproc, §12.12 thread headroom, §12.6 memory ceiling). A constrained host degrades to fewer parallel jobs instead of failing to fork.

Prerequisites

  • sh, python3, xargs.
  • lib/gate_runner_order.py and lib/gate_runner_shard.py beside it (resolved relative to the script, not the caller's cwd).
  • lib/host_guard.sh for mode 2 (and for any mode that spawns parallel workers).
  • A gate config file whose history_log provides the historical fail_rate / mean_cost used for ordering, plus an --affected document naming the members.
  • No environment variables are read by this script directly; host_guard.sh reads its own FC_GUARD_* overrides.

Usage examples

# Mode 1: run the affected gates, cheapest-failing-first
sh scripts/fastcycle/gates/gate_runner.sh \
  --config gate_config.json \
  --affected affected.json \
  --order history-cost \
  --out verdicts.json

# Mode 1 with the verdict cache disabled (always re-execute)
sh scripts/fastcycle/gates/gate_runner.sh \
  --config gate_config.json --affected affected.json --no-cache --out verdicts.json

# Mode 2: carve the gate set into 4 write-disjoint shards
sh scripts/fastcycle/gates/gate_runner.sh \
  --mode shard --manifest gates.json --n-shards 4

Reading the result: in mode 1 the exit status is the verdict (0 all PASS, 1 any FAIL, 4 any BLIND). In mode 2 the exit status reflects the shard run, and the requested --n-shards is a partition count — expecting exactly 4 concurrent processes on a constrained host is the misreading this design explicitly avoids.

Exit codes

Code Meaning
0 Every declared gate produced a verdict, all PASS, and the verdict set is complete.
1 At least one gate produced FAIL.
2 Usage or config error (bad/missing flag, unreadable config).
4 At least one gate returned BLIND — no honest verdict was possible, which is never a pass.

Mode 2: sharding rules

A shard is a group of gates that may run concurrently with other shards. Two gates whose declared writes path sets intersect are always co-scheduled into the same shard (write-set-intersection union-find). Beyond that, two paths are additionally treated as globally exclusive and force their gates into a dedicated shard that runs strictly after the parallel batch, one at a time, never overlapping anything:

  • the tracker database docs/workable_items.db
  • the agent registry docs/requests/agent_registry.jsonl

Those two are the single-writer resources; parallel writes to them are the corruption risk this partition exists to prevent (§11.4.119 single-resource-owner).

Edge cases

  • Ordering requested but no history. Members are still run — ordering degrades, selection does not.
  • A gate that is both a member and a writer of a serialised path. The serial shard wins; it is never co-scheduled into the parallel batch.
  • --no-cache. Bypasses verdict_cache.py; every member is executed. Note the known --no-cache scope gap documented in lib/gate_runner_order.py's own header.
  • Host with no thread headroom. Concurrency falls (possibly to N=0), which for a zero-width fan-out means the work must be serialised rather than attempted and failed.
  • A missing gate script. Surfaces as a per-gate verdict rather than an abort; the run still produces a document so the absence is visible.

Internal behaviour

  1. Parses the mode and its flags; exit 2 on any usage error.
  2. Mode 1: delegates to lib/gate_runner_order.py, which reads the history log, orders members, executes each (through the cache unless --no-cache), and assembles the verdicts/v1 document.
  3. Mode 2: delegates to lib/gate_runner_shard.py, which builds the write-intersection union-find, extracts the serially-scheduled gates, asks lib/host_guard.sh for the real concurrency, and fans out with xargs -P.
  4. Writes --out and exits with the aggregate verdict.

Related scripts

Called by scripts/fastcycle/gates/backstop.sh (the full uncached lane) and scripts/fastcycle/gates/flake_ledger.py.

Calls scripts/fastcycle/gates/lib/gate_runner_order.py, scripts/fastcycle/gates/lib/gate_runner_shard.py, scripts/fastcycle/lib/host_guard.sh, scripts/fastcycle/gates/verdict_cache.py.

Guarded by scripts/fastcycle/tests/test_gate_order_red.sh (T054, ordering, AS-013) and scripts/fastcycle/tests/test_gate_shard_red.sh (T055, sharding, AS-014). Contract: specs/004-fast-dev-cycles/contracts/affected-set-and-verdict-cache.md.

See also docs/scripts/affected_set.py.md (which produces --affected), docs/scripts/verdict_cache.py.md (which decides reuse) and docs/scripts/host_guard.sh.md (the clamp).

Last verified

2026-12-04 — bash -n scripts/fastcycle/gates/gate_runner.sh → exit 0. sh scripts/fastcycle/gates/gate_runner.sh with no arguments prints its usage and exits 2.