AFAdocs
Gates

Nine Gates

Every enhancement must pass all nine quantitative gates before AFA commits it.

Nine Gates

AFA evaluates every enhancement candidate through nine quantitative gates. All nine must pass for an enhancement to be committed. If any gate fails, the enhancement enters a redesign loop (up to 3 retries) or is rejected.

Gate summary

#GateWhat it measuresThresholdHard floor?
1RiskRisk reduction ratioDelta >= 2.0No
2ProfitProfit improvement ratioDelta >= 2.0No
3NoveltyNew concepts introducedG(N) >= 0.8No
4ComplexityStructural simplicityC_norm >= 0.5Yes
5QualityAggregate code qualityQ >= 0.7, no zero sub-scoresNo
6UtilityEconomic value vs. costLCB(U) > 1.5No
7EntropyDiff meaningfulnessH(diff) >= 0.25No
8Supply ChainBuild provenanceSLSA v1.0 validNo
9KPIBusiness alignmentR-squared >= 0.6No

Evaluation order

Gates are evaluated in a specific order to fail fast on cheap checks:

  1. Complexity (hard floor first -- instant reject if < 0.5)
  2. Risk / Profit (disjunctive -- either suffices)
  3. Novelty
  4. Quality
  5. Utility
  6. Entropy (includes anti-gaming checks)
  7. Supply Chain
  8. KPI

Gate details

1. Risk gate

Measures how much an enhancement reduces risk relative to the baseline.

Delta_Risk = baseline_risk / max(proposed_risk, epsilon)

Gate passes when Delta_Risk >= 2.0 OR Delta_Profit >= 2.0 (disjunctive -- either suffices).

2. Profit gate

Measures improvement in profit proxy (deployment velocity, error reduction, etc.).

Delta_Profit = proposed_profit / max(baseline_profit, epsilon)

Both risk and profit deltas are validated through Bayesian posterior probability: P(Delta >= 2 | data) > 0.95.

3. Novelty gate

Prevents trivial changes from consuming pipeline resources. Uses a logistic function:

G(N) = 1 / (1 + e^(-k * (N - N0)))

Where N is the number of new concepts introduced, k is the logistic slope (default 5.0), and N0 is the logistic center (default 3.5). Gate passes when G(N) >= 0.8.

4. Complexity gate

The only non-overridable gate. See Complexity deep-dive.

5. Quality gate

Aggregate quality score across security, performance, maintainability, and documentation. Gate passes when Q >= 0.7 AND no individual sub-score equals zero.

The zero-sub-score rule prevents gaming: an enhancement cannot have perfect security but zero maintainability.

6. Utility gate (economic optimization)

Answers "is this enhancement worth the cost?" using a utility function with a lower confidence bound:

U = (Delta_P_H + gamma * Delta_V_L) + kappa * |Delta_R| - (phi_S * Delta_C_S + phi_D * Delta_C_D) - Delta_OPEX
LCB(U) = U - z_alpha * sqrt(Var(U))

Gate passes when LCB(U) > 1.5 (configurable). Uses PERT three-point estimation for variance.

7. Entropy gate (anti-gaming)

Prevents trivially small or artificially inflated changes by measuring Shannon entropy of the diff token distribution:

H(diff) = -sum(p_i * log2(p_i))

Gate passes when H(diff) >= 0.25 (configurable). Also runs three anti-gaming detectors:

DetectorThresholdDetects
Dead code0.8Unreachable code added to pad metrics
Edit locality0.3Scattered edits across unrelated areas
Generated code0.5Minified or machine-generated output

8. Supply chain gate

Validates build integrity: SLSA level check, signature validity, and SBOM change allowlisting. Gate passes when all three conditions hold.

9. KPI alignment gate

Ensures enhancements align with business objectives. Gate passes when R-squared >= 0.6.

What happens when a gate fails

  1. Near miss (all scores within 1.1x of their threshold): eligible for redesign retry
  2. Hard failure: enhancement is rejected
  3. Hard floor violation (complexity < 0.5): immediate rejection, no retry

Use afa explain <enhancement-id> to see exactly which gates failed and why.

Operating modes

ModeGate engineUse case
StandaloneBuilt-in threshold comparisonsMost teams
AEGIS-connectedFull Bayesian posterior evaluationEnterprise governance

In standalone mode, gates use simple threshold comparisons. With the optional AEGIS connector, gates use full Bayesian posterior evaluation with confidence intervals, SHA-256 audit hash chains, and governance workflows.

On this page