Skip to content

fix(relay): anchor same-cap monitor evidence freshness to the run's authorisation, not job startup - #24349

Merged
Jinwoo-H merged 2 commits into
mainfrom
fix/relay-monitor-evidence-age
Oct 1, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
fix/relay-monitor-evidence-age

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​175 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​175
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​151 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​123

ELI5

Before a production relay roll, a 15-minute health check has to pass and be "fresh". Today the roll checks that freshness late, after its machine has spent a few minutes starting up. So a check that was fresh when the operator pressed go can count as stale by the time the roll looks at it. The roll then fails, and the health check is already used up. This change checks freshness when the roll is approved, and then only asks each later step to start promptly after that.

What Changed

Before. The same-cap roll's first cell job re-checked that the monitor dry-run had finished at most 5 minutes earlier, on the cell job's own clock. By then the run had already spent gate-job and cell-job startup time. The gate job had already marked the evidence consumed, so a late failure wasted the monitor run.

Measured from today's runs (step timestamps from gh run view --json jobs; monitor completion is the monitor's seal step):

Run Dispatched after monitor finished Dispatch to gate consume Dispatch to cell verify Evidence age at cell verify Result
36837655330 13:24 1:39 3:19 16:43 failed, stale
36839965464 0:16 2:09 3:59 4:15 passed
36844930522 1:40 1:36 3:37 5:17 failed, stale

Gate consume to cell verify was 1:40 to 2:01. So an operator had about one minute after the monitor finished to dispatch.

After.

  • The gate job downloads the monitor evidence and runs the full authority check itself, on its own clock: provenance, hashes, same code, a green completed window, and evidence at most 5 minutes old. This runs before the evidence is marked consumed.
  • If that passes, the gate writes the consumed marker as a small record. The record holds this run's ID, the monitor run and attempt, and the instant the gate authorised it. Before, the marker held only the run ID.
  • Each cell job reads that marker from its own run. It checks that the marker names this run and this monitor attempt. It checks that the evidence was at most 5 minutes old at the recorded instant. It checks that the cell job started at most 5 minutes after that instant, plus 75 minutes for each earlier cell in the batch.
  • The live preflight in every wave is unchanged and still rechecks current health. It still enforces its own 10-minute evidence bound, plus 75 minutes per earlier cell.

Run 36844930522 would now pass, with evidence 3:17 old at the gate. Run 36837655330 would now fail at the gate, before consuming the evidence.

The rehome enable job also uses verify-authority. It verifies and consumes in one job, so it keeps its existing behaviour when neither new flag is passed.

Why

The decision "is this evidence fresh enough to act on" belongs where the run is approved, which is the gate job. The cell job's job is to prove it is acting for that approval. Its own startup time should not count against the evidence.

The 5-minute cell startup allowance is tied to two things. The measured gate-to-verify gap is about 2 minutes. And 5 plus 5 equals the live preflight's existing 10-minute bound. So no evidence passes cell verification that the preflight would not also accept.

Alternatives rejected:

  • Raise the 5-minute constant. Nothing would anchor it. A run that queued behind the deployment lock, or started slowly, would carry the same extra slack.
  • Measure age against the run's creation time from the GitHub API. A run waiting on the production-cloud-sql-rollout concurrency group is created long before it is approved. Also, the gate never looked at the evidence, so stale evidence would still be consumed before failing.
  • Have the cell job look up the gate job's finish time through the API. That works, but it adds a token-scoped API read and a parsing path. The run-scoped marker already exists and is already trusted for single use.

Trust in the recorded instant: only jobs in the same workflow run can upload an artifact to that run. The cell job downloads the marker with run-id: github.run_id, and the gate still rejects any repo-wide marker with the same name. The recorder writes with an exclusive create, and it refuses to record for any wave but the first. The gate also refuses a re-run attempt before it consumes anything, because cell jobs already refuse one. Single use, needs chaining, the first-attempt-only rule, and the per-wave live preflight are unchanged.

Rollout note: this changes the trusted evidence code paths. Monitor evidence sealed before this merges will not verify afterwards, so run a fresh monitor after merge.

Linked Issue

N/A, internal rollout-tooling fix.

Visual Proof

N/A. This is a CI workflow and script change with no UI.

Testing

  • cloud/dev/scripts/relay-monitor-evidence.test.mjs adds coverage for each case:

    • Evidence 4 minutes old at gate authorisation and 9 minutes old at cell verify passes. The old rule rejects that same evidence.
    • Evidence 6 minutes old at the gate fails and records nothing.
    • A cell job that starts more than 5 minutes after authorisation fails.
    • The later-wave extension holds at its exact edges for waves 1 and 9.
    • A wrong consumer run, a wrong monitor attempt, a non-canonical timestamp, or an instant before the evidence fails.
    • The recorder refuses to overwrite, refuses later waves, and refuses a missing consumer run.
    • Workflow ordering, read step by step: the gate rejects reuse and re-runs, downloads, authorises, then consumes. The cell job downloads the marker, then verifies, both before the lease and the preflight.
  • I ran the full pretest and the node --test list from cloud/package.json: 845 tests, all passing.

  • oxlint is clean on the changed scripts, and pnpm run check:code-quality:changed passes.

  • Automated tests added/updated

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

No impact on desktop, mobile, SSH, or cross-platform behaviour. Only production relay workflows change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…uthorisation, not job startup

The same-cap gate now verifies the dry-run on its own clock and records the
authorisation instant in the single-use consumed marker; each cell job checks
the evidence age at that instant and bounds its own start after it.

Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
…; tighten order tests

Claude-Session: ced32ebb-7155-4413-adad-1eccd14c2010
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Critical risk] Changes how production deployment authorization freshness is verified.

The PR should not merge until a cell that passes authorization can reliably reach the live preflight without immediately expiring already-consumed evidence.

Findings

  1. P1 Evidence expires before preflight ▶

Summary

The PR moves same-cap monitor freshness authorization into the gate and records its time in the single-use marker for cell jobs to verify.

  • The gate now validates downloaded evidence before consuming it; cells bind their checks to the recorded run, monitor attempt, and authorization time.
  • The cell allowance can still admit evidence that expires before the subsequent live preflight, after it has been consumed.
Diagram
sequenceDiagram
  participant Gate
  participant Marker
  participant Cell
  participant Preflight
  Gate->>Gate: Validate evidence age ≤ 5 min
  Gate->>Marker: Record authorization and consume evidence
  Cell->>Marker: Read run-bound authorization
  Cell->>Cell: Check startup ≤ 5 min after authorization
  Cell->>Preflight: Authenticate, set up gcloud, acquire lease, then recheck
  Note over Cell,Preflight: Evidence can pass cell verification but exceed<br/>preflight's 10-minute limit by this point
Loading

Reviews (1) · Last reviewed commit: "fix(relay): refuse a re-run same-cap gat..."

const sinceAuthorizationMs = nowMs - evidenceCheckedAtMs
if (
sinceAuthorizationMs < 0 ||
sinceAuthorizationMs > AUTHORIZATION_STARTUP_ALLOWANCE_MS + predecessorMs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Evidence expires before preflight When evidence is close to five minutes old at gate authorization, a cell can pass this five-minute startup check but fail the live preflight moments later. For example, evidence aged 4:45 at the gate passes cell verification 4:30 later. Authentication, gcloud setup, and lease acquisition then run before preflight; if they take another 46 seconds, preflight rejects the evidence under its ten-minute limit. The roll stops even though the gate has already consumed the monitor evidence, recreating the late failure this change aims to avoid. The startup allowance needs to leave time for those steps, or the two freshness checks need to be aligned.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one reasoning gap worth a look.

Reviewed changes

  • Gate owns same-cap freshness. The same-cap gate job now downloads the monitor evidence, runs verify-authority on its own clock, and records a JSON authorization (--record-authorization) into the single-use consumed marker; cell jobs bind to it via --authorization rather than re-checking evidence age on their own clock.
  • Authorization record + startup bound. relay-monitor-evidence.mjs adds readAuthorization/consumerRunIdOf/waveIndexOf, the two new flags, and a 5-minute AUTHORIZATION_STARTUP_ALLOWANCE_MS (plus 75 min per predecessor wave) that bounds cell start after the recorded instant; the evidence-age check itself stays fixed at 5 minutes.
  • Gate refuses re-runs. The gate rejects GITHUB_RUN_ATTEMPT != 1 before consuming, so a re-run cannot burn evidence the cell jobs would refuse anyway.
  • Docs and tests. relay-incident-monitor.md / relay-workflows.md updated; tests cover the gate/cell freshness split, wave boundaries, marker tampering, EEXIST, arg pairing, and workflow step ordering (node --test passes 15/15).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +11 to +12
// Same-cap gate authorization to wave-0 verify measured 1:40-2:01 on 2026-10-01; 5 min keeps the
// verify-time total (5 + 5) at the live preflight's own 10-minute evidence bound.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment's invariant does not hold. The cell's verify-authority and the live preflight measure evidence age on different clocks, and .github/workflows/cloud-deploy-relay-production-same-cap-job.yml runs deploy-auth, setup-gcloud, and the lease step between them, so with a 5-minute allowance the cell accepts evidence up to 10min + wave*75 old — the preflight's own ceiling, measured later. Evidence in the (10min-Δ, 10min] band passes the cell and then fails the preflight, after the gate has already consumed the single-use evidence.

Technical details
# The "cell verify is a subset of the preflight" claim is false

## Affected sites
- `cloud/dev/scripts/relay-monitor-evidence.mjs:296-311` — `--authorization` path: evidence ≤ 5 min at `authorizedAt`, start ≤ 5 min + `wave*75` after it, so evidence at cell verify can reach `10min + wave*75`.
- `cloud/dev/scripts/relay-monitor-evidence.mjs:11-13` — the constant/comment asserting `5 + 5` equals the preflight bound.
- `cloud/apps/relay-ops/src/incident-live-preflight-cli.ts:30,172-190` — preflight still rejects `now - completedAt > 10min + wave*75`, sampled on its own later clock.
- `.github/workflows/cloud-deploy-relay-production-same-cap-job.yml:199-214` — `deploy-auth`, `setup-gcloud`, and the lease step run between cell verify and the preflight, so Δ > 0 always.

## Required outcome
- Leave the verify→preflight gap as headroom (e.g. evidence + allowance + Δ ≤ preflight bound), or age the preflight from the recorded authorization, or reword the comment to stop claiming subset-acceptance.

## Open questions for the human
- Is the `(10min-Δ, 10min]` band acceptable as a fail-closed outcome (fresh monitor recovers it) given the gate already consumed the evidence and re-runs are refused?

## Note
- The net usable window is still wider than before (~10−Δ vs the old ~5), so this is a fail-closed robustness/reasoning gap, not a safety regression.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 77950365-bc5f-40a7-b18a-7561fdba0fa6

📥 Commits

Reviewing files that changed from the base of the PR and between 5f728f7 and 958129f.

📒 Files selected for processing (6)
  • .github/workflows/cloud-deploy-relay-production-same-cap-job.yml
  • .github/workflows/cloud-deploy-relay-production-same-cap.yml
  • cloud/dev/scripts/relay-monitor-evidence.mjs
  • cloud/dev/scripts/relay-monitor-evidence.test.mjs
  • cloud/docs/relay-incident-monitor.md
  • cloud/docs/relay-workflows.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The same-cap gate now validates monitor evidence and records a run-bound authorization timestamp. Cell jobs verify that authorization before rollout. The evidence checker applies a five-minute evidence-age limit at authorization and permits cell starts within five minutes plus 75 minutes per predecessor wave. The workflows reject gate reruns. Documentation also describes the separate live-preflight limit of 10 minutes plus 75 minutes per predecessor wave.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 95812

The gate records fresh, run-bound authorization that cell jobs verify before rollout. Existing rehome behavior is preserved; no merge-blocking issue was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 95812

The rollout gate now grants time-bounded authorization that each cell must verify before proceeding. The broader startup window retains run binding, single-dispatch restrictions, sequential rollout, and live safety checks. No introduced security bypass was established, but deployed identity permissions and platform behavior were not independently verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The authority controls production relay rollout in onorca-cloud, not tenant-local work. A batch selects two to ten cells serially and reaches relay administrative controls and selected-cell Terraform/GCE mutation through existing deployment and capacity identities. The maximum permissions of those deployed identities were not verified.

Security Findings and Attack Paths

  • inferred — No new marker-substitution or cross-run replay path was established in the inspected flow. Cells retrieve authorization from their current run and enforce consumer-run and monitor-attempt identity before privileged rollout steps. This conclusion assumes the workflow platform correctly enforces artifact ownership.

Trust Boundaries and Controls

  • observed — Operator-selected evidence references cross into rollout authority only after gate validation. The pre-existing break-glass alternative intentionally skips aggregate evidence, requires digest-bound confirmation and a bounded printable reason, is revalidated by the reusable workflow, and still invokes live per-wave preflight. Inspection did not establish that this PR expands that alternative authority.

Resilience and Maintainability Implications

  • inferred — The authorization transition fails closed at repository-controlled boundaries: failed validation creates no record, missing publication prevents cell verification, and identity or timing failures stop before rollout credentials and lease acquisition. Normal same-cap runs are serialized by workflow concurrency; exclusive local creation is not, by itself, a cross-run atomic reservation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (4 skipped: 4… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: anchoring same-cap monitor evidence freshness to run authorization instead of job startup.
Description check ✅ Passed The description follows the required template and explains the change, rationale, testing, scope, and compatibility considerations. It marks the issue as internal and documents the remaining unchecked…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (4 skipped: 4 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jinwoo-H
Jinwoo-H merged commit c422936 into main Oct 1, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant