Skip to content

feat(relay): one-cell flag write workflow with dry run, compare-and-swap and read-back - #26837

Merged
Jinwoo-H merged 2 commits into
mainfrom
relay-cell-flags-workflow
Oct 9, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
relay-cell-flags-workflow

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​187 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​185
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​353 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​352

Evidence code: this edits cloud/package.json (adds the new test to the node test list), which is in the relay evidence-code set. Merge it between cell rolls, never during a wave.

ELI5

Each relay cell now reads a small settings file of its own (#26805), and #26835 creates the storage bucket for those files. This PR adds the button operators press to change one cell's settings safely: it previews the change first, refuses if someone else changed the file in the meantime, records who changed it, and then checks that the cell actually picked the change up.

What Changed

  • New workflow Operate Relay Production Cell Flags (.github/workflows/cloud-operate-relay-production-cell-flags.yml), manual dispatch only, gated on ORCA_CLOUD_OPERATIONS_ENABLED. Inputs:
    • cell-id: exactly one cell. There is no fleet mode, because the object is per cell.
    • mode: dry-run (default) or write.
    • readiness-local (false/true) and ticket-check (off/shadow): the full desired switch set, written as one object.
    • expected-generation: the exact current object generation from a dry run, or 0 to create.
    • confirmation: write requires exactly WRITE_RELAY_CELL_FLAGS <cell-id>.
  • Script cloud/dev/scripts/operate-relay-cell-flags.mjs, which does all of the work so it can be tested:
    1. Validates every input. The cell origin is derived from the cell id and must name the same cell.
    2. Calls the cell's /v1/admin/runtime-status with the deploy identity (one retry on a transient 5xx or network error, through the shared relay-admin-transient-retry helper). The origin must answer as that cell (role: cell, matching cellId), and it must report flagsApplied, which proves its image has the flag channel (that field is added in feat(relay): per-cell runtime switches read from Cloud Storage every 5 s #26805).
    3. Reads the current object; after the plan line, its generation must equal expected-generation, or the run stops.
    4. Logs one orca_relay_cell_flags_plan line (current generation and object, what the cell has applied, desired object) before the generation check, so even a refused dry run shows the generation to pass next. Dry run stops here.
    5. write: a multipart upload with ifGenerationMatch=<expected>, so a concurrent writer gets 412 and the run refuses. The object carries custom metadata writtenBy, runId and runAttempt.
    6. Read-back: polls runtime status every second for up to 15 s. A failed poll is retried and never ends the wait early. It requires the new generation and the exact flags to be applied, then logs orca_relay_cell_flags_applied_read_back. Otherwise it fails and says the object is written but not applied.
  • Audit: bucket versioning and soft delete (feat(relay): Cloud Storage bucket for the per-cell runtime switch files (targeted apply only) #26835) keep every generation. Each object names the triggering actor (GITHUB_TRIGGERING_ACTOR, which is right on a re-run) and the run. The job summary records them with every plan, write, read-back and orca_relay_cell_flags_failed {message} line, even on failure. The concurrency group serialises writes.
  • Trust: the production deploy Workload Identity provider (google_iam_workload_identity_pool_provider.github) admits the new workflow file. This is a Terraform change that needs its own targeted apply (below) before the workflow can authenticate. The reviewed condition snapshot, the workflow census (25 → 26) and the deploy-identity reader list are updated.

Before: no way to change a cell's switches. After: one reviewed, one-cell, compare-and-swap write with read-back. To revert a flip, write the previous flags with the new generation as expected-generation.

Apply needed for the trust change (targeted only; never a root plan)

From cloud/infra/terraform, production credentials, after review:

terraform init -backend-config=backend/production.hcl
terraform plan -var-file=environments/production.tfvars \
  -target='google_iam_workload_identity_pool_provider.github[0]' -out=relay-flags-trust.tfplan
terraform show relay-flags-trust.tfplan
terraform apply relay-flags-trust.tfplan

Go: exactly 0 to add, 1 to change, 0 to destroy, and the only diff is one added assertion.workflow_ref == '…/cloud-operate-relay-production-cell-flags.yml@refs/heads/main' clause in attribute_condition. Anything else means stop.

Why

Design §2.1 and PR 5 in §6. The shape follows the rehome-control workflow: typed confirmation, one target, a compare-and-swap, and a read-back.

  • Read-back target: the read-back goes to the cell's own runtime status, which the deploy identity can already reach. The design read back through the director's whereabouts route, but that route is keyed by host, not by cell, so it cannot report a cell with no hosts.
  • Cell list: "a cell not in the inventory refuses" is enforced by the cell answering as itself, not by a copied cell list.
  • Freeze rule: this is a .github/workflows/cloud-* file, so it must land before the cell image is published.

Linked Issue

N/A (internal relay redesign, step-5 prep).

Visual Proof

N/A: operations workflow, no UI.

Testing

  • operate-relay-cell-flags.test.mjs (8 tests, fake GCS and cell):

    • Malformed requests are refused: mode, cell id, enforce, missing generation, missing or wrong confirmation, an origin naming another cell, a foreign origin.
    • A dry run writes nothing.
    • A write uses compare-and-swap, stamps the actor and run, and is read back; flipping back needs the new generation.
    • A stale expected generation is refused, and so is a concurrent writer between the read and the write (412).
    • An origin answering as another cell is refused, and so is an image without the flag channel.
    • A cell that never applies the write fails after 15 s.
    • A dry run against a stale generation still logs the plan, with the current generation, before refusing.
    • A transient 503 on the first read and on a read-back poll is ridden out.
  • actionlint clean. workload-identity-attribute-conditions (rendered through Terraform) passes, under the GCP length limit. The full cloud node test list passes (748/748).

  • Not dispatched (by brief).

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Order:

  1. The bucket (feat(relay): Cloud Storage bucket for the per-cell runtime switch files (targeted apply only) #26835) and this trust change must both be applied.
  2. Cells must be running an image with feat(relay): per-cell runtime switches read from Cloud Storage every 5 s #26805.
  3. Run a dry run, then write.

Staging needs its own workflow and identity (the staging deploy provider lives in another root); not built here. Do not merge, apply or dispatch without the owner's go.

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)

…wap and read-back

Operate Relay Production Cell Flags writes cells/<cellId>.json for one
cell: it checks the origin answers as that cell with a flag channel,
refuses a stale expected generation, writes with ifGenerationMatch,
stamps the actor and run on the object, and waits up to 15 s for the
cell's runtime status to report the new generation applied. The deploy
Workload Identity condition admits the new workflow.
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b56c836b-518b-439f-9caa-6857d9b425d0

📥 Commits

Reviewing files that changed from the base of the PR and between 7541259 and 65724b4.


📒 Files selected for processing (3)
  • .github/workflows/cloud-operate-relay-production-cell-flags.yml
  • cloud/dev/scripts/operate-relay-cell-flags.mjs
  • cloud/dev/scripts/operate-relay-cell-flags.test.mjs


📝 Walkthrough

Walkthrough

Adds a CLI and production workflow to preview or update runtime flags for one relay cell. The operation validates inputs and runtime identity, checks the current object generation, and uses a generation-matched write. After a write, it polls runtime status for the new generation and flag values. The workflow is manually dispatched, gated by a repository variable, and records operation output in the GitHub step summary. Identity allowlists and tests now include the workflow and CLI tests.


Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 75412

A concurrent flag update can interrupt an operation before it produces a plan, but the failure does not bypass the generation-matched write. This is a bounded risk suitable for owner follow-up.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. (3 skipped: 3… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed The title clearly identifies the main change: a relay workflow for one-cell flag writes with dry-run, compare-and-swap, and read-back behavior.
Description check Passed The description is detailed and covers the required change, rationale, testing, visual-proof status, review notes, and checklist. The Linked Issue field is marked N/A, but the author identifies the in…

Full details: Docstring Coverage

Explanation

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



✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: adb1a8d6-78b9-45b2-b7c2-af7e5f06c52b
📥 Commits

Reviewing files that changed from the base of the PR and between 7b1242b and 7541259.

📒 Files selected for processing (8)
  • .github/workflows/cloud-operate-relay-production-cell-flags.yml
  • cloud/dev/scripts/operate-relay-cell-flags.mjs
  • cloud/dev/scripts/operate-relay-cell-flags.test.mjs
  • cloud/dev/scripts/relay-production-identity-boundaries.test.mjs
  • cloud/dev/scripts/relay-public-workflow-contract.test.mjs
  • cloud/dev/scripts/workload-identity-attribute-conditions.test.mjs
  • cloud/infra/terraform/relay-github-actions.tf
  • cloud/package.json

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

Comment on lines +91 to +95
const media = await fetchImpl(objectUrl(request, `?alt=media&ifGenerationMatch=${generation}`), {
headers
})
if (!media.ok) throw new Error(`object read returned ${media.status}`)
return { generation: String(generation), object: await media.json().catch(() => null) }

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '60,140p' cloud/dev/scripts/operate-relay-cell-flags.mjs
rg -n 'versioning|control.bucket|control_bucket|ifGenerationMatch|alt=media' cloud/infra/terraform cloud/dev/scripts | head -100

Repository: stablyai/orca

Length of output: 4099


🏁 Script executed:

set -eu
printf '%s\n' '--- relay control bucket references ---'
rg -n -i -F --glob '!**/.git/**' -- 'relay-control' cloud .github || test "$?" -eq 1
printf '%s\n' '--- versioning and lifecycle references near relay control infrastructure ---'
rg -n -i --glob '*.{tf,tfvars,md,yaml,yml,json,mjs}' 'versioning|object version|noncurrent|relay.?control|control.?bucket' cloud .github || test "$?" -eq 1
printf '%s\n' '--- script top and tests ---'
sed -n '1,145p' cloud/dev/scripts/operate-relay-cell-flags.mjs
sed -n '1,180p' cloud/dev/scripts/operate-relay-cell-flags.test.mjs

Repository: stablyai/orca

Length of output: 19028


🌐 Web query:

Google Cloud Storage JSON API objects.get media download generation ifGenerationMatch query parameter official documentation

💡 Result:

Yes. Google’s `objects.get` method supports `ifGenerationMatch` alongside `alt=media`:

```http
GET https://storage.googleapis.com/storage/v1/b/BUCKET/o/OBJECT?alt=media&ifGenerationMatch=GENERATION
```

`alt=media` returns the object’s data; `ifGenerationMatch` makes the request conditional on the object’s **current generation** matching the supplied value. A mismatch means the download does not proceed. ([docs.cloud.google.com](https://docs.cloud.google.com/storage/docs/json_api/v1/objects/get?utm_source=openai))

Note: `ifGenerationMatch` checks the **current** generation. To select a particular object revision, use the separate `generation` parameter. ([docs.cloud.google.com](https://docs.cloud.google.com/storage/docs/json_api/v1/objects/get?utm_source=openai))

Citations:

- 1: https://docs.cloud.google.com/storage/docs/json_api/v1/objects/get?utm_source=openai
- 2: https://docs.cloud.google.com/storage/docs/json_api/v1/objects/get?utm_source=openai

🏁 Script executed:

set -eu
printf '%s\n' '--- relay control bucket references ---'
rg -n -i -F --glob '!**/.git/**' -- 'relay-control' cloud .github || test "$?" -eq 1
printf '%s\n' '--- versioning and lifecycle references ---'
rg -n -i --glob '*.{tf,tfvars,md,yaml,yml,json,mjs}' 'versioning|object version|noncurrent|relay.?control|control.?bucket' cloud .github || test "$?" -eq 1
printf '%s\n' '--- relevant script and tests ---'
sed -n '1,145p' cloud/dev/scripts/operate-relay-cell-flags.mjs
sed -n '1,180p' cloud/dev/scripts/operate-relay-cell-flags.test.mjs

Repository: stablyai/orca

Length of output: 18999


🏁 Script executed:

set -eu
printf '%s\n' '--- all repository references ---'
rg -n -i -F --glob '!**/.git/**' -- 'relay-control' . || test "$?" -eq 1
printf '%s\n' '--- all versioning declarations and lifecycle rules ---'
rg -n -i --glob '!**/.git/**' 'versioning\s*\{|versioning|noncurrent|lifecycle_rule|retention' . || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 45653


🌐 Web query:

site:cloud.google.com/storage/docs/json_api/v1/objects/get generation ifGenerationMatch alt=media

💡 Result:

For `objects.get`, `alt=media` returns the object’s data. You can also supply `generation` to select a particular object revision, and `ifGenerationMatch` to make the request conditional on a generation match. They serve different purposes: `generation` selects the revision; `ifGenerationMatch` is a precondition. ([docs.cloud.google.com](https://docs.cloud.google.com/storage/docs/json_api/v1/objects/get?utm_source=openai))

Example:
```http
GET https://storage.googleapis.com/storage/v1/b/BUCKET/o/OBJECT?alt=media&generation=GENERATION
```

If you instead use `ifGenerationMatch`, it checks the object’s current generation and fails with `412 Precondition Failed` if it doesn’t match. ([docs.cloud.google.com](https://docs.cloud.google.com/storage/docs/request-preconditions?utm_source=openai))

Citations:

- 1: https://docs.cloud.google.com/storage/docs/json_api/v1/objects/get?utm_source=openai
- 2: https://docs.cloud.google.com/storage/docs/request-preconditions?utm_source=openai

Use generation for the media read, with bucket versioning guaranteed.

GCS treats ifGenerationMatch as a precondition on the object’s current generation. If another writer replaces the object after the metadata read, this request can return 412 and abort the plan.

Use generation to read the exact version returned by the metadata request. This requires Object Versioning on the ${projectId}-relay-control bucket. The repository currently asserts versioning only in a comment and does not define that bucket’s versioning contract. Without versioning, the prior generation may no longer be readable. Keep the write CAS so a later replacement still returns 412.

Proposed fix
--- "a/cloud/dev/scripts/operate-relay-cell-flags.mjs"
+++ "b/cloud/dev/scripts/operate-relay-cell-flags.mjs"
@@ -88,7 +88,7 @@
   }
   if (!metadata.ok) throw new Error(`object metadata read returned ${metadata.status}`)
   const { generation } = await metadata.json()
-  const media = await fetchImpl(objectUrl(request, `?alt=media&ifGenerationMatch=${generation}`), {
+  const media = await fetchImpl(objectUrl(request, `?alt=media&generation=${generation}`), {
     headers
   })
   if (!media.ok) throw new Error(`object read returned ${media.status}`)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const media = await fetchImpl(objectUrl(request, `?alt=media&ifGenerationMatch=${generation}`), {
headers
})
if (!media.ok) throw new Error(`object read returned ${media.status}`)
return { generation: String(generation), object: await media.json().catch(() => null) }
const media = await fetchImpl(objectUrl(request, `?alt=media&generation=${generation}`), {
headers
})
if (!media.ok) throw new Error(`object read returned ${media.status}`)
return { generation: String(generation), object: await media.json().catch(() => null) }

…ore the generation check, and names the failure

Runtime-status reads go through the shared one-retry admin helper, and a
failed read-back poll no longer ends the wait early. The plan line is
logged before the generation check, a failure is logged as one JSON line
the job summary carries, and the object and summary name the triggering
actor.
@Jinwoo-H
Jinwoo-H merged commit d358e59 into main Oct 9, 2026
23 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