1E — Gate Chain & Auto-Merge
Overview
After an experiment run completes with at least one KEEP, the engine publishes results to GitHub and optionally merges. The flow:
Experiment KEEP
→ push branch to GitHub
→ create PR (branch → dev) with metric delta in body
→ auto-merge PR (squash)
→ create promotion PR (dev → main — operator approves)
→ run state-update.sh (close feedback loop)
This is engine-level behavior — every repo that uses autoresearch gets GitHub audit trail for free.
Gate Chain (gates.py)
Three built-in gates that run after the experiment loop:
| Gate | Function | Pass Condition |
|---|---|---|
security | Custom security command | Exit 0 |
tests | Custom test command | Exit 0 |
confidence | MAD-based statistical score | >= min_confidence (default 1.0) |
The engine’s per-experiment loop already handles metric improvement (is_improved()) and guard (guard.command). The gate chain only runs gates that add NEW validation beyond what the loop checked.
Gate Chain Flow
gate_result = run_gate_chain(repo_path, marker, result, marker.auto_merge.gates)
# Short-circuits on first failure
# Returns GateChainResult with .all_passed and .gates[]
GateResult Structure
@dataclass
class GateResult:
name: str # "security", "tests", "confidence"
passed: bool
reason: str # human-readable explanation
value: str # measured value for logging
Auto-Publish (_publish_results)
Runs for every experiment that produces at least one KEEP, regardless of gate chain results:
- Push branch —
git push origin autoresearch/sonar-quality-apr05-11 - Create PR —
gh pr create --base dev --head <branch>with body containing metric, experiments, status - Auto-merge —
gh pr merge --squash --auto(falls back to direct merge if auto-merge unavailable) - Promotion PR —
gh pr create --base main --head dev(no auto-merge — operator approves) - State update —
_run_state_update()callsautomation/state-update.sh
PR Body Format
## Autoresearch Experiment
**Marker:** sonar-quality
**Metric:** 163 → 133 (lower)
**Experiments:** 1 total, 1 kept, 0 discarded
**Status:** KEEP
---
Auto-generated by autoresearch engine.
Configuration
auto_merge:
enabled: true # enable the publish flow
target_branch: dev # PR target (branch → this)
gates: [security, tests, confidence] # optional gate chain
security_command: "..." # custom security check
test_command: "..." # custom test suite
min_confidence: 1.0 # MAD threshold (skip if < 3 keeps)
Files
| File | Purpose |
|---|---|
src/autoresearch/gates.py | Gate chain: GateResult, GateChainResult, run_gate_chain, 3 built-in gates |
src/autoresearch/engine.py | _publish_results(), _create_promotion_pr(), _run_state_update() |
src/autoresearch/marker.py | AutoMerge model |
tests/test_gates.py | 16 tests |