Each lesson gave you one piece: evaluator, criteria, guard, shortcuts, evals, judge. The gate lines them up in a queue, from cheapest to most expensive: whatever the code rejects never gets to spend quota on a model. In this lesson you build the gate, plug it into the headless loop from course 2, and leave with a dated plan for building your own.
1The five layers and the order: cheap first, model last
2portao.env outside the repo: the agent doesn't edit the judge
3The gate as the final test of loop-longrun.sh
4The course map and your dated plan
Goal: build the gate in layers (criteria, guard, shortcuts, evals, evaluator) and plug it into your loop, with the dated plan.
01 · Five layers, one exit
Click each layer. All of them run; the model evaluator only runs if the cheap ones pass.
Click each block in the diagram to see what it does.
A layer without configuration shows up as skipped, never as silently approved.
02 · Watch the gate run
Each layer is a step. On the first run the guard fails: fix it and run again.
layers to run
layer in progress
approved
rejected
Illustrative simulation in the browser. The real gate, with fake agents, is right below.
03 · Rehearsal: the gate against chumba and bom
The portao.env stays outside the project. AVALIADOR_CMD points to the fake evaluator: zero calls.
Terminal · gate
K=~/projetos/loop-r-eng-verificacao-v72/kit
cat > /tmp/ensaio-verif-portao.env <<EOF
GOAL=/tmp/ensaio-verif/goal.md
GUARDA_DIR=/tmp/ensaio-verif/guarda
ESCONDIDOS=/tmp/ensaio-verif/escondidos
AVALIADOR_CMD=$K/avaliador-falso.sh
EOF
for modo in chumba bom; do
bash $K/ensaio.sh > /dev/null && cd /tmp/ensaio-verif/proj
cp $K/goal-ensaio.md ../goal.md && sed -i '/limpo e bem documentado/d' ../goal.md
GUARDA_DIR=/tmp/ensaio-verif/guarda python3 $K/guarda-testes.py congelar . > /dev/null
$K/agente-falso.sh $modo < /dev/null > /dev/null
echo "## $modo"; $K/portao.sh . /tmp/ensaio-verif-portao.env; echo "saída: $?"
done
Example from the repository
## chumba
criterios REPROVADO → /tmp/portao/criterios.log
guarda OK
atalhos REPROVADO → /tmp/portao/atalhos.log
evals pulada (sem configuração)
avaliador pulada (camada barata já reprovou: não gaste cota)
PORTÃO: REPROVADO em criterios atalhos
saída: 1
## bom
criterios OK
guarda OK
atalhos OK
evals pulada (sem configuração)
avaliador OK
PORTÃO: APROVADO
saída: 0
With chumba the guard passes (the judge is intact); what fails it is the function criterion with new input (acao-reacao) and the hidden tests.
If the portao.env, the goal.md or the hidden tests sit inside the repository, the agent can edit them, and the gate becomes the agent's. Keep all three outside (in the rehearsal, in /tmp; in your project, in a folder like ~/portoes/[projeto]/).
04 · The gate as the final test of the headless loop
In the loop-longrun.sh from course 2, TESTE_FINAL decides "done". Put the gate there. Run it after the previous block (it uses the same portao.env).
2026-10-19 06:19:56 início: rápido=0 passed · agente=codex · teto 2x2min · mem 1G
2026-10-19 06:19:56 ciclo 1: começa
2026-10-19 06:19:56 ciclo 1: agente saiu rc=0 em 0s
2026-10-19 06:19:56 ciclo 1: rápido=3 passed (melhor antes: 0)
2026-10-19 06:19:56 ciclo 1: checkpoint commitado
(… ciclo 2 igual, rápido=3 passed …)
2026-10-19 06:19:58 PARADO: teto de 2 ciclos atingido sem passar o teste final
saída: 1
2026-10-19 06:19:59 início: rápido=3 passed · agente=codex · teto 2x2min · mem 1G
2026-10-19 06:19:59 ciclo 1: começa
2026-10-19 06:19:59 ciclo 1: agente saiu rc=0 em 0s
2026-10-19 06:19:59 ciclo 1: rápido=3 passed (melhor antes: 3)
2026-10-19 06:19:59 ciclo 1: checkpoint commitado
2026-10-19 06:20:00 CONCLUÍDO no ciclo 1: teste final passou ()
saída: 0
With chumba the quick test went from 0 to 3 passed: by the visible test, it looked like progress. The gate held back the "done". The empty parentheses just mean the gate doesn't print "N passed".
The loop-longrun.sh commits the checkpoint before running the TESTE_FINAL. By the time the gate runs, git diff HEAD is already empty: the CHUMBADO and SILENCIA lines from atalhos.py and the evaluator's diff don't see the cycle's work. In the rehearsal, what failed it were the criteria and the hidden tests. If you rely on reading the diff in the loop, compare against the base commit (before the first cycle), not against HEAD.
05 · Final practice
The gate in the rehearsal and in your loop.
E21 · Gate against chumba and bom
10 min
Run the gate block and then the loop-with-gate block.
Done when: the gate prints PORTÃO: REPROVADO em criterios atalhos (saída: 1) for chumba and PORTÃO: APROVADO (saída: 0) for bom; the loop ends first with PARADO: teto de 2 ciclos and then with CONCLUÍDO no ciclo 1.
E22 · The gate for your loop
60 min
In your project: goal.md checked (lesson 2), guard frozen at the base commit (lesson 3), 3 hidden tests (lesson 4) and, if the task changes an agent's behavior, the golden set (lesson 5). Write portao.env outside the repo (with the golden set: EVAL_AGENTE, EVAL_BASE, EVAL_CASOS and EVAL_PROMPT pointing to your files from lesson 5) and run the gate before and after the work.
Done when: before the work, $K/portao.sh . [your portao.env]; echo $? → PORTÃO: REPROVADO and 1; after, → PORTÃO: APROVADO and 0, with at most one layer pulada.
06 · The course map
Four deliverables, in order. Click an exercise to see its "done when".
Lesson 806 · The course mapFour deliverables, in order. Click an exercise to see its "done when".
Day 1Who checks
lessons 1 and 2
3 exercises
Separate evaluator and goal.md checked by command.
You got {a} of {n} right. Get them all right and the lesson is marked as complete.
Pick an option. The explanation appears after you try.
09 · The course in three sentences
Whoever did it doesn't check itSeparate evaluator, command-based criterion, and printed proof: the agent's report decides nothing.
The judge stays out of reachFrozen tests with everything pytest reads, hidden ones, and portao.env outside the repo; a suspicious test becomes a report, never an adjustment.
Measure honestlyGolden set with regression, calibrated judge, and pass^k with variance; and the layered gate as the loop's final test.