Enforce system health and safety invariants via GainsGate, CardioGate, and CorrigibilityGate
The 3-Surgeons system provides three quality gates, each serving a different purpose:
| Gate | Purpose | When to Run |
|---|---|---|
| GainsGate | Infrastructure health verification | Between major phases, after deployments |
| CardioGate | Quality review chain with rate limiting | When quality degradation is detected |
| CorrigibilityGate | Safety invariant enforcement | Before destructive or risky actions |
3s gains-gate
gains_gate()
| Check | Critical? | What It Verifies |
|---|---|---|
neurologist_health | No | Pings Neurologist endpoint. Local model may be offline. |
cardiologist_health | No | Pings Cardiologist endpoint. API may be unavailable. |
evidence_store | Yes | Evidence DB is accessible and queryable. |
state_backend | Yes | State backend responds to ping. |
The gate passes only if all critical checks pass. Non-critical failures are recorded but do not block progress.
Running gains gate...
[PASS] neurologist_health: Neurologist operational (89ms)
[FAIL] cardiologist_health: Cardiologist unreachable: Connection refused
[PASS][critical] evidence_store: Evidence store accessible (42 learnings)
[PASS][critical] state_backend: State backend operational
PASS: 3/4 checks passed (non-critical failures: cardiologist_health) (23ms)
In this example, the gate passes because the Cardiologist being down is non-critical. The evidence store and state backend (both critical) are healthy.
The CardioGate chains three steps:
| Setting | Value |
|---|---|
| Max reviews per hour | 3 |
| State key | cardio_gate:reviews_this_hour |
| Tracked in | State backend |
If the rate limit is exceeded, the entire CardioGate fails with a critical rate_limit check failure. This prevents cost runaway from automated quality monitoring loops.
CardioGate fails if:
The CorrigibilityGate is primarily used programmatically:
from three_surgeons.core.gates import CorrigibilityGate
from three_surgeons.core.config import Config
gate = CorrigibilityGate(config=Config.discover())
result = gate.run(proposed_action="Drop all production database tables and recreate")
# result.passed = False
# result.summary = "CORRIGIBILITY FAIL: Blocked: No destructive operations without explicit approval (matched: 'Drop all...database tables')"
The gate checks proposed actions against these regex-based safety rules:
| Invariant | Catches |
|---|---|
| No destructive operations | drop database, truncate table, delete all prod data, rm -rf /, wipe all data, destroy database |
| No bypassing safety | bypass safety, skip safety, ignore safety, disable safety, override safety, circumvent safety, bypass constraint/check/validation/guard |
| No modifying gate logic | modify the gate logic, disable corrigibility gate, skip gains gate, remove cardio gate, bypass corrigibility gate |
| No force pushing | force push, push --force, git push -f |
CORRIGIBILITY PASS: action is safe (4 invariants checked)
or
CORRIGIBILITY FAIL: Blocked: No destructive operations without explicit approval (matched: 'drop all database tables')
A failed corrigibility check means the proposed action matches a safety invariant. The action should NOT proceed without explicit human approval.
| Situation | Gate |
|---|---|
| Transitioning between project phases | GainsGate |
| After deploying changes | GainsGate |
| Quality metric declining | CardioGate |
| About to delete/drop/wipe something | CorrigibilityGate |
| About to force push | CorrigibilityGate |
| Session start health check | GainsGate (or just probe for quick check) |
| About to modify safety settings | CorrigibilityGate |
Gates can be composed. The CardioGate already embeds a GainsGate. You could build custom workflows:
CorrigibilityGate -> GainsGate -> (proceed with operation)
This pattern ensures: (1) the action is safe, (2) the infrastructure is healthy, (3) then execute.