Skip to content

Stravin Run ⟷ Stravin Gate

This specification defines the contract between Stravin Run (CI runners and pipeline execution) and Stravin Gate (speculative merge queues and merge policy).

Contract Status: Proposed Contract (vNext) — Neither Stravin Run nor Stravin Gate is implemented in stravin-dev/core v1.12.x. Both teams build directly to this specification. External runner pool isolation, app_id verdict binding, partitioned tree_oid reuse, and Run-only INFRA_ERROR boundaries follow ADR-0002: External Runner Seam, State-Machine Ownership, and OIDC App Authentication; declarative workflow execution and the stravin-runner runtime follow ADR-0005: Declarative YAML Workflow Execution, First-Party Action Repositories, and Runner Runtime.

1. Boundary & Ownership

Concern Source of Truth Private Implementation Details (Never Crosses Boundary)
Speculative merge-queue topology, required check names, batching/bisection strategy, merge decision Stravin Gate Queue state machine, batch bisection algorithm, policy_version rules, Core AtomicRefCAS
Check execution, runner pool, artifact/test caching, individual check verdicts Stravin Run MicroVM scheduling, cache hit computation, step logs, retry of flaky infra errors
Verdict binding (tenant_id, repo_id, tree_oid, commit_oid, policy_version, app_id) Stravin Run (attests execution / validates external app_id) -> Stravin Gate (evaluates policy) Gate accepts a verdict only when tree_oid, commit_oid, policy_version, and app_id match the exact speculative merge commit and active rule set

2. Interaction Flow

sequenceDiagram
    participant Gate as Stravin Gate (Temporal Workflows)
    participant Core as Stravin Core
    participant Run as Stravin Run (Temporal Workflows)
    participant NATS as NATS JetStream (STRAVIN_RUN)

    Gate->>Core: ComputeMergeTree -> refs/stravin/gate/main/qe_01... (commit_oid, tree_oid)
    Gate->>Run: POST /v1/gate-builds (Idempotency-Key, queue_entry_id, commit_oid, tree_oid, required_checks[])
    Run-->>Gate: 202 Accepted (batch_run_id, check_runs[])

    alt All required checks pass
        Run->>NATS: Publish stravin.run.<tenant>.<repo>.gate_verdict.ready (Nats-Msg-Id, traceparent)
        NATS-->>Gate: Durable consumer delivery (gate-run-verdicts)
        Gate->>Gate: Verify (tenant_id, repo_id, tree_oid, commit_oid, policy_version, app_id) & advance merge
    else Earlier queue entry evicted (speculative chain invalidated)
        Gate->>Run: POST /v1/gate-builds/{batch_run_id}/cancel (reason: QUEUE_RESET)
        Run-->>Gate: 202 Accepted (terminating runners immediately)
        Gate->>Core: Rebuild speculative commit on new base
        Gate->>Run: POST /v1/gate-builds (new commit_oid, new tree_oid)
    end

3. Auth, Tenancy & Trust Boundary

  • Cilium eBPF Transport & Network Policy: Bidirectional HTTP/2 or gRPC calls and NATS JetStream traffic traverse Cilium (eBPF) transparent WireGuard/SPIFFE mTLS with CiliumNetworkPolicy allowlists (or app-level TLS 1.3 mTLS locally), plus signed service JWTs (tenant_id, scopes: ["run:gate-build", "run:cancel"] for Gate -> Run; scoped NATS publish/subscribe credentials on STRAVIN_RUN).
  • Mandatory App-Level Tenancy Check: Cilium verifies workload identity, NOT tenant_id. Both Gate and Run MUST verify tenant_id in constant time in application code on every HTTP request and NATS JetStream message.
  • Tamper-Evident Verdict Attestation & External app_id Binding (ADR-0002): Every verdict event published by Run to STRAVIN_RUN carries (tenant_id, repo_id, queue_entry_id, commit_oid, tree_oid, policy_version, app_id, check_name, conclusion) (with optional detached attestation signature for high-assurance compliance policies). Gate rejects any verdict whose tenant_id, repo_id, commit_oid, tree_oid, policy_version, or app_id does not match its active speculative entry and policy allowlist. For Phase 2 external Checks API apps, each OIDC App installation is bound to an explicit (tenant_id, repo_id, check_name_prefix) allowlist matching an active batch_run_id.
  • Pool Isolation & Run-Only INFRA_ERROR Boundary: Gate builds execute exclusively on protected/gate runner pools—never on untrusted-pr pools. INFRA_ERROR classification is strictly Run-only; external Checks API callers can never self-assert INFRA_ERROR to trigger automated Gate front-of-queue requeues or merge-queue pauses.
  • No Unbounded Runner Waste: Gate's fast-cancel API (POST /v1/gate-builds/{batch_run_id}/cancel) is high-priority and bypasses normal rate limits so evicted speculative batches stop burning runner CPU within seconds. (Phase 2 BYO-CI external engines run in a degraded tier without < 200 ms runner-kill guarantees and rely on Gate's timeout_seconds and 30 s reconciliation backstop.)

4. Synchronous Interfaces

4.1 Gate -> Run: Speculative Batch Build Request — Proposed Contract (vNext)

POST /v1/gate-builds HTTP/1.1
Host: stravin-run.internal
Content-Type: application/json
Authorization: Bearer <service-jwt>
Idempotency-Key: acme:monorepo:qe_01JDF9C4...:c3d4e5f6...
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01

{
  "tenant_id": "acme",
  "repo_id": "monorepo",
  "queue_entry_id": "qe_01JDF9C4D5E6F7G8H9J0K1L2M3",
  "target_ref": "refs/heads/main",
  "speculative_ref": "refs/stravin/gate/main/qe_01JDF9C4D5E6F7G8H9J0K1L2M3",
  "commit_oid": "c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4",
  "tree_oid": "d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5",
  "object_format": "sha1",
  "policy_version": "pol_01JDE0...",
  "required_checks": ["go-test-race", "lint", "e2e-smoke"],
  "priority": "high",
  "allow_tree_oid_reuse": true,
  "timeout_seconds": 1800
}

Response (202 Accepted):

{
  "batch_run_id": "br_01JDF9E6F7G8H9J0K1L2M3N4P5",
  "reused_checks": ["lint"],
  "scheduled_checks": ["go-test-race", "e2e-smoke"]
}

4.2 Gate -> Run: Fast Cancellation on Queue Eviction/Reset — Proposed Contract (vNext)

POST /v1/gate-builds/br_01JDF9E6F7G8H9J0K1L2M3N4P5/cancel HTTP/1.1
Host: stravin-run.internal
Content-Type: application/json
Authorization: Bearer <service-jwt>

{
  "tenant_id": "acme",
  "repo_id": "monorepo",
  "queue_entry_id": "qe_01JDF9C4D5E6F7G8H9J0K1L2M3",
  "reason": "QUEUE_RESET",
  "superseded_by_commit_oid": "e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6"
}
  • Run MUST acknowledge cancellation in < 200 ms, revoke server-side job-lease tokens (and any external git:write jtis), and propagate SIGTERM -> SIGKILL / cancel-poll directives to hosted and Phase 1 external runners asynchronously. Phase 2 BYO-CI external engines have no < 200 ms runner-kill guarantee and fall back to Gate's timeout_seconds and 30 s reconciliation backstop.

4.3 Gate -> Run: Verdict Reconciliation Pull — Proposed Contract (vNext)

  • GET /v1/gate-builds/{batch_run_id} — Returns current status and per-check verdicts so Gate can recover after missed JetStream events or restarts.

5. Asynchronous Events & Streams

5.1 Run -> Gate: Check Verdict & Batch Completion Events (STRAVIN_RUN JetStream)

Published to stream STRAVIN_RUN with NATS headers Nats-Msg-Id: <idempotency_key>, Stravin-Event-Type, Stravin-Schema-Version: 1.0, and W3C traceparent (consumed by Gate via durable pull consumer gate-run-verdicts):

  • stravin.run.<tenant_id>.<repo_id>.gate_check.completed (event_type: "run.gate_check.completed") — Emitted per individual required check as soon as it finishes (enables fail-fast eviction: if lint fails in 15 s, Gate immediately evicts the entry and cancels the 20-minute e2e-smoke job).
  • stravin.run.<tenant_id>.<repo_id>.gate_verdict.ready (event_type: "run.gate_verdict.ready") — Emitted when all required_checks have reached a terminal conclusion:
{
  "event_id": "evt_01JDF9F7G8H9J0K1L2M3N4P5Q6",
  "event_type": "run.gate_verdict.ready",
  "schema_version": "1.0",
  "occurred_at": "2026-11-24T22:26:40Z",
  "tenant_id": "acme",
  "repo_id": "monorepo",
  "traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
  "idempotency_key": "br_01JDF9E6F7G8H9J0K1L2M3N4P5:verdict",
  "data": {
    "batch_run_id": "br_01JDF9E6F7G8H9J0K1L2M3N4P5",
    "queue_entry_id": "qe_01JDF9C4D5E6F7G8H9J0K1L2M3",
    "commit_oid": "c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4",
    "tree_oid": "d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5",
    "policy_version": "pol_01JDE0...",
    "overall_verdict": "PASSED",
    "checks": [
      {"name": "go-test-race", "run_id": "run_01JDF9...", "app_id": "stravin-run", "runner_pool": "gate", "conclusion": "success", "reused_from_tree_oid": false},
      {"name": "lint", "run_id": "run_01JDF8...", "app_id": "stravin-run", "runner_pool": "gate", "conclusion": "success", "reused_from_tree_oid": true},
      {"name": "e2e-smoke", "run_id": "run_01JDF9...", "app_id": "stravin-run", "runner_pool": "gate", "conclusion": "success", "reused_from_tree_oid": false}
    ]
  }
}
  • Independent Temporal Workflow Engines: Both Stravin Run and Stravin Gate run on Temporal behind their own service boundaries without ever coupling workflow histories. Gate's speculative merge-queue workflow invokes POST /v1/gate-builds and /cancel as idempotent Temporal activities (with Idempotency-Key), polls GET /v1/gate-builds/{batch_run_id} for reconciliation, and receives STRAVIN_RUN JetStream verdict events as workflow signals; Run maps those commands to its own Temporal CI pipeline DAG workflows (fan-out/fan-in, heartbeating, retries, timeouts, and fast cancellation).

6. Shared Data Contracts & Identifiers

  • Verdict Binding Tuple: (tenant_id, repo_id, tree_oid, commit_oid, policy_version, app_id).
    • Partitioned tree_oid Verdict Reuse (ADR-0002): When allow_tree_oid_reuse: true, Run may satisfy a deterministic check using a prior passing run ONLY with identical (tenant_id, repo_id, tree_oid, check_name, app_id, runner_pool, policy_version) (e.g., when a commit is rebased onto main with an identical resulting tree), setting reused_from_tree_oid: true. Partitioning by app_id, runner_pool, and policy_version ensures untrusted-pr pools or lower-trust external apps can never poison or satisfy protected gate verdicts.
    • Gate's policy may disallow tree_oid reuse for non-hermetic integration checks by setting allow_tree_oid_reuse: false.
  • Overall Verdict Enum: PASSED | FAILED | INFRA_ERROR | TIMED_OUT | CANCELLED (where INFRA_ERROR is strictly Run-only; external Checks API transient failures map to non-retrying conclusions such as external_infra_error or failure -> FAILED).

7. Failure Modes, Timeouts & Idempotency

Failure Scenario Behavior & Degradation Timeout / Retry Policy
Check fails with infra_error (Run-only: runner crash / Core 503) Run auto-retries once internally; if still INFRA_ERROR, Gate does NOT blame the PR — it requeues at the front of the queue (up to 2 retries) before pausing the queue and alerting operators. External Checks API callers CANNOT self-assert INFRA_ERROR; their transient failures map to external_infra_error or failure (non-retrying in Gate). Prevents innocent PRs from being evicted on Run outages while preventing external CI apps from amplifying queue retries or pausing Gate.
Speculative batch exceeds timeout_seconds Gate sends /cancel (reason: "QUEUE_TIMEOUT") and evicts the entry with QUEUE_TIMEOUT. Default timeout_seconds: 1800 (30 m).
JetStream verdict event delayed or dead-lettered Durable gate-run-verdicts consumer redelivers (with STRAVIN_DLQ advisory on exhaustion); Gate also polls GET /v1/gate-builds/{batch_run_id} every 30 s for any active batch without a recent event. Ensures queue head never stalls silently.
Stale verdict arrives after queue reset Gate checks (queue_entry_id, commit_oid, policy_version) and discards verdicts for superseded commit_oids. Idempotent and safe against out-of-order delivery.

8. Meet-in-the-Middle Bridge Checklist

Side A: Stravin Run Build Checklist

  • Implement idempotent POST /v1/gate-builds, POST /v1/gate-builds/{id}/cancel, and GET /v1/gate-builds/{id} (backed by Temporal CI DAG workflows) with app-level tenant_id check.
  • Publish stravin.run.<tenant_id>.<repo_id>.gate_check.completed and gate_verdict.ready to STRAVIN_RUN JetStream with Nats-Msg-Id and traceparent immediately on individual failures for fail-fast eviction.
  • Support tree_oid verdict reuse strictly partitioned by (tenant_id, repo_id, tree_oid, check_name, app_id, runner_pool, policy_version) and gated by allow_tree_oid_reuse.
  • Enforce Run-only INFRA_ERROR classification (mapping external Checks API transient errors to non-retrying external_infra_error/failure) and (tenant_id, repo_id, check_name_prefix) allowlists for external OIDC App installations.

Side B: Stravin Gate Build Checklist

  • Bind every speculative build request and verdict verification to (tenant_id, repo_id, tree_oid, commit_oid, policy_version, app_id) with deterministic Idempotency-Keys in Gate's Temporal activities.
  • Bind durable JetStream consumer gate-run-verdicts on STRAVIN_RUN and call /cancel immediately whenever an entry is evicted or a speculative chain resets.
  • Poll GET /v1/gate-builds/{batch_run_id} as a staleness backstop for active queue entries.
  • Requeue (rather than evict) on INFRA_ERROR up to the configured retry budget.

Shared Contract-Test Fixtures

  • fixtures/run-gate/speculative-build-pass.json — Request, 202 Accepted, and STRAVIN_RUN JetStream gate_verdict.ready (PASSED, including one reused_from_tree_oid: true check).
  • fixtures/run-gate/fail-fast-cancel.json — Early gate_check.completed (failure) JetStream message triggering POST /v1/gate-builds/{id}/cancel.
  • fixtures/run-gate/infra-error-requeue.json — INFRA_ERROR verdict fixture verifying non-blame requeue behavior.