PeaLang Code Library

Release Engineering

Semver, canaries, smoke checks, reversibility and release gates for software delivery.

1. Release candidate smoke gate before rollout

Use case. A release passes unit tests but fails on real startup semantics. Smoke test key user journeys after build; block promotion if critical path smoke fails in candidate.

# smoke_results booleans.
const REQUIRED = ["login", "create_order", "charge"]

function smoke_ok(results) {
    let i = 0
    while i < len(REQUIRED) {
        if not results[REQUIRED[i]] { return {"ok": false, "failed": REQUIRED[i]} }
        i += 1
    }
    return {"ok": true, "failed": null}
}

print "SMOKE={smoke_ok({"login":true,"create_order":true,"charge":false}).ok}"

Save as release-engineering_01.pea; check pea fmt --check release-engineering_01.pea && pea check release-engineering_01.pea; run pea run release-engineering_01.pea.

2. Rollback decision from canary error delta

Use case. After canary, abort if error rate or latency exceeds baseline beyond guard; decide automatically, not from Slack scrollback.

# deltas and counts from telemetry.
const MAX_ERROR_DELTA = 0.01
const MAX_P95_DELTA = 0.15

function rollback_needed(error_delta, p95_delta, sample_size) {
    if sample_size < 500 {
        return {"decision": "HOLD", "reason": "INSUFFICIENT_DATA"}
    }
    if error_delta > MAX_ERROR_DELTA or p95_delta > MAX_P95_DELTA {
        return {"decision": "ROLLBACK", "reason": "GUARD_BREACH"}
    }
    return {"decision": "PROMOTE", "reason": "WITHIN_GUARDS"}
}

print "ROLLBACK={rollback_needed(0.02, 0.08, 2000).decision}"

Save as release-engineering_02.pea; check pea fmt --check release-engineering_02.pea && pea check release-engineering_02.pea; run pea run release-engineering_02.pea.

3. Migration reversibility checker

Use case. A destructive schema migration deploys but rollback chart lacks downgrade. Block promotion unless rollback path exists or change is explicitly marked non-reversible with approval.

# operations and rollback_available from CI.
const DESTRUCTIVE = ["DROP_TABLE", "DROP_COLUMN"]

function reversible(ops, rollback_available) {
    let destructive = false
    let i = 0
    while i < len(ops) {
        if ops[i] in DESTRUCTIVE { destructive = true }
        i += 1
    }
    if destructive and not rollback_available {
        return {"ok": false, "reason": "NO_ROLLBACK"}
    }
    return {"ok": true, "reason": "SAFE_OR_APPROVED"}
}

print "REVERSIBLE={reversible(["ADD_INDEX"], false).ok}"

Save as release-engineering_03.pea; check pea fmt --check release-engineering_03.pea && pea check release-engineering_03.pea; run pea run release-engineering_03.pea.

4. Artifact attestation presence gate

Use case. An attacker can replace binaries between build and deploy. Require signed provenance and checksum match before environment accepts the artifact.

# signed boolean from CI; checksum_match from verify step.
function attestation_ok(signed, checksum_match) {
    if not signed { return {"ok": false, "reason": "UNSIGNED"} }
    if not checksum_match { return {"ok": false, "reason": "CHECKSUM_MISMATCH"} }
    return {"ok": true, "reason": "ATTESTED"}
}

print "ARTIFACT={attestation_ok(true, false).ok}"

Save as release-engineering_04.pea; check pea fmt --check release-engineering_04.pea && pea check release-engineering_04.pea; run pea run release-engineering_04.pea.

5. Compatibility window for platform deprecation

Use case. A dependency announces end of life and removal date. Ensure migration cohort has exceeded 80% adoption before final cutover; otherwise the last one-fifth absorbs the blast radius.

# migrated and total raw counts from telemetry.
const CUBTOVER_PCT = 0.8

function cutover_ready(migrated, total) {
    if total == 0 { return {"ready": false, "reason": "NO_USAGE_DATA"} }
    let ratio = migrated / total
    return {"ready": ratio >= CUBTOVER_PCT, "reason": "ADOPTION_CHECK", "ratio": ratio}
}

print "CUTOVER={cutover_ready(9, 10).ready}"

Save as release-engineering_05.pea; check pea fmt --check release-engineering_05.pea && pea check release-engineering_05.pea; run pea run release-engineering_05.pea.

6. Release promotion stage matrix by capability

Use case. Not every release has the same blast radius. Choose promotion stage and approvers from capability risk tier automatically instead of every deploy following one path.

# risk tier from lint: low/medium/high.
const STAGES = {"low":"canary", "medium":"staged", "high":"dark-launch+approval"}

function promote_stage(risk) {
    if risk in STAGES {
        return {"stage": STAGES[risk], "reason": "RISK_MAPPED"}
    }
    return {"stage": "dark-launch+approval", "reason": "UNKNOWN_RISK"}
}

print "STAGE={promote_stage("medium").stage}"

Save as release-engineering_06.pea; check pea fmt --check release-engineering_06.pea && pea check release-engineering_06.pea; run pea run release-engineering_06.pea.

7. Dependency lock freshness gate for deploy

Use case. A deploy can go out with manually edited lockfile. Require lockfile hash matches package.json and registry pin before environment accepts artifact.

# registry_ok and lock_match booleans.
function lock_ok(lock_match, registry_pinned) {
    if not lock_match { return {"ok": false, "reason": "LOCK_MISMATCH"} }
    if not registry_pinned { return {"ok": false, "reason": "UNPINNED_SOURCE"} }
    return {"ok": true, "reason": "PINNED_LOCK"}
}

print "LOCK={lock_ok(true, false).ok}"

Save as release-engineering_07.pea; check pea fmt --check release-engineering_07.pea && pea check release-engineering_07.pea; run pea run release-engineering_07.pea.

8. Cold-start budget for serverless release

Use case. A cold start regression turns a 200-line deploy into a customer-visible lag. Gate rollout on p95 init time stays within budget in staging, or keep old image.

# p95_ms for init from synthetic pings.
const COLD_LIMIT_MS = 800

function cold_ok(p95_ms) {
    if p95_ms > COLD_LIMIT_MS {
        return {"ok": false, "reason": "COLD_START_BUDGET"}
    }
    return {"ok": true, "reason": "WITHIN_BUDGET"}
}

print "COLD={cold_ok(1200).ok}"

Save as release-engineering_08.pea; check pea fmt --check release-engineering_08.pea && pea check release-engineering_08.pea; run pea run release-engineering_08.pea.

9. Canary cohort blacklist for risky users

Use case. Internal or beta cohorts must not receive a high-risk canary when they already underpin production. Exclude cohorts before rollout; promote only to eligible segment.

# cohort_id from segment map.
const EXCLUDED = ["internal-prodlike", "vip-ops"]

function cohort_eligible(cohort_id) {
    let i = 0
    while i < len(EXCLUDED) {
        if EXCLUDED[i] == cohort_id { return {"eligible": false, "reason": "EXCLUDED"} }
        i += 1
    }
    return {"eligible": true, "reason": "ELIGIBLE"}
}

print "COHORT={cohort_eligible("vip-ops").eligible}"

Save as release-engineering_09.pea; check pea fmt --check release-engineering_09.pea && pea check release-engineering_09.pea; run pea run release-engineering_09.pea.

10. Automatic rollback trigger for crash loops

Use case. A pod crash loop can fill logs and starve dependencies. Detect N restart events within a window and trigger automated rollback before every instance dies.

# restart events in last 5 min window.
const RESTART_THRESHOLD = 3

function crash_loop(restart_count, healthy_replicas, total_replicas) {
    if restart_count >= RESTART_THRESHOLD and healthy_replicas < total_replicas {
        return {"action": "ROLLBACK", "reason": "CRASH_LOOP"}
    }
    return {"action": "HOLD", "reason": "WITHIN_BUDGET"}
}

print "CRASH={crash_loop(4, 2, 3).action}"

Save as release-engineering_10.pea; check pea fmt --check release-engineering_10.pea && pea check release-engineering_10.pea; run pea run release-engineering_10.pea.

← Back to the Code Library