Repository navigation
feat(relay): one-cell flag write workflow with dry run, compare-and-swap and read-back - #26837
Conversation
…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.
|
Warning Review limit reachedYou'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. View limit detailsLimit details: You’ve used all 10 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds 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 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)✅ Passed checks (4 passed)Full details: Docstring CoverageExplanation 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 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
adb1a8d6-78b9-45b2-b7c2-af7e5f06c52b
📒 Files selected for processing (8)
.github/workflows/cloud-operate-relay-production-cell-flags.ymlcloud/dev/scripts/operate-relay-cell-flags.mjscloud/dev/scripts/operate-relay-cell-flags.test.mjscloud/dev/scripts/relay-production-identity-boundaries.test.mjscloud/dev/scripts/relay-public-workflow-contract.test.mjscloud/dev/scripts/workload-identity-attribute-conditions.test.mjscloud/infra/terraform/relay-github-actions.tfcloud/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.
| 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) } |
There was a problem hiding this comment.
🗄️ 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 -100Repository: 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.mjsRepository: 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.mjsRepository: 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 1Repository: 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.
| 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.
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
Operate Relay Production Cell Flags(.github/workflows/cloud-operate-relay-production-cell-flags.yml), manual dispatch only, gated onORCA_CLOUD_OPERATIONS_ENABLED. Inputs:cell-id: exactly one cell. There is no fleet mode, because the object is per cell.mode:dry-run(default) orwrite.readiness-local(false/true) andticket-check(off/shadow): the full desired switch set, written as one object.expected-generation: the exact current object generation from a dry run, or0to create.confirmation:writerequires exactlyWRITE_RELAY_CELL_FLAGS <cell-id>.cloud/dev/scripts/operate-relay-cell-flags.mjs, which does all of the work so it can be tested:/v1/admin/runtime-statuswith the deploy identity (one retry on a transient 5xx or network error, through the sharedrelay-admin-transient-retryhelper). The origin must answer as that cell (role: cell, matchingcellId), and it must reportflagsApplied, 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).expected-generation, or the run stops.orca_relay_cell_flags_planline (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.write: a multipart upload withifGenerationMatch=<expected>, so a concurrent writer gets 412 and the run refuses. The object carries custom metadatawrittenBy,runIdandrunAttempt.orca_relay_cell_flags_applied_read_back. Otherwise it fails and says the object is written but not applied.GITHUB_TRIGGERING_ACTOR, which is right on a re-run) and the run. The job summary records them with every plan, write, read-back andorca_relay_cell_flags_failed {message}line, even on failure. The concurrency group serialises writes.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.tfplanGo: exactly
0 to add, 1 to change, 0 to destroy, and the only diff is one addedassertion.workflow_ref == '…/cloud-operate-relay-production-cell-flags.yml@refs/heads/main'clause inattribute_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.
.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):enforce, missing generation, missing or wrong confirmation, an origin naming another cell, a foreign origin.actionlintclean.workload-identity-attribute-conditions(rendered through Terraform) passes, under the GCP length limit. The fullcloudnode 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
Notes
Order:
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)