Repository navigation
feat(relay): per-cell runtime switches read from Cloud Storage every 5 s - #26805
Conversation
3651cb6 to
fc669e2
Compare
5023fd2 to
63b55c7
Compare
Cells read cells/<cellId>.json from the <project-id>-relay-control bucket, start on all-off defaults, keep their applied values when the object cannot be read, and report what they applied in the seat feed. No consumer reads the switches yet.
… census; it catches every failure
…me, and bound the read while streaming 404, 5xx, malformed-generation and lower-generation replies, and failed metadata replies, now cancel their bodies. The object read stops and cancels at the first byte past 64 KiB instead of buffering it whole.
…ag workflow's read-back
63b55c7 to
8c894b3
Compare
📝 WalkthroughWalkthroughThe relay adds cell flag parsing and a polling channel that reads versioned flag objects from Cloud Storage. Cell-role startup passes applied flags into the relay server and stops the channel during shutdown. The cell seat-feed and runtime-status responses conditionally include the applied flags. Tests cover parsing, polling behavior, and response values. Estimated code review effort Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to A temporary read failure can prevent a valid cell flag update from taking effect until another object generation is written. Fix the generation checkpoint before merging. Pre-merge checks |
|
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:
0fb637be-387c-4357-8479-0822a8b4eb68
📒 Files selected for processing (9)
cloud/apps/relay/src/app.tscloud/apps/relay/src/cell-flags.tscloud/apps/relay/src/cell-seat-feed-route.tscloud/apps/relay/src/cell-seat-feed.test.tscloud/apps/relay/src/floating-promise-census.test.tscloud/apps/relay/src/index.tscloud/apps/relay/src/relay-control-flag-channel.test.tscloud/apps/relay/src/relay-control-flag-channel.tscloud/apps/relay/src/relay-server.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| seenGeneration = generation | ||
| const text = await readBounded(response, MAX_OBJECT_BYTES) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Set seenGeneration only after the body read completes.
Line 128 records the generation before readBounded runs. The body read can fail after that point. For example, AbortSignal.timeout(REQUEST_TIMEOUT_MS) can fire mid-stream, or the socket can reset. In that case reader.read() rejects with an error that is not a ControlFlagPollError. poll logs that failure as network. seenGeneration still holds the new generation, so every later request sends ifGenerationNotMatch=<generation>. Cloud Storage then answers 304, and the channel never applies that valid object. It stays on the old flags until an operator writes a new generation. This conflicts with the stated rule that lost contact only "keeps the applied values".
Record the generation only after the read has finished. A malformed body or an oversized body still marks the generation as seen. A transient read error leaves the generation unseen, so the next poll reads it again.
🐛 Proposed fix
--- "a/cloud/apps/relay/src/relay-control-flag-channel.ts"
+++ "b/cloud/apps/relay/src/relay-control-flag-channel.ts"
@@ -125,9 +125,10 @@
discard()
return
}
- seenGeneration = generation
const text = await readBounded(response, MAX_OBJECT_BYTES)
+ // Only a completed read marks the generation seen; a transient stream error must re-read it.
+ seenGeneration = generation
if (text === null) throw new ControlFlagPollError('malformed')
let body: unknown
try {
body = JSON.parse(text)📝 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.
| seenGeneration = generation | |
| const text = await readBounded(response, MAX_OBJECT_BYTES) | |
| const text = await readBounded(response, MAX_OBJECT_BYTES) | |
| // Only a completed read marks the generation seen; a transient stream error must re-read it. | |
| seenGeneration = generation |
Stacked on #26803 (seat feed). Review that first; this PR's diff is only the switch channel.
ELI5
Later relay steps need to turn behaviour on for one cell at a time, in seconds, without shipping a new cell image. This PR gives every cell a small settings file in Cloud Storage that it re-reads every 5 seconds. Every setting starts off, and nothing uses them yet.
What Changed
cells/<cellId>.jsonfrom the bucket<project-id>-relay-control(production:onorca-cloud-relay-control) every 5 s (±20% jitter, one read at a time). Nothing a user sees changes; both switches default to off and have no consumer in this PR.relay-control-flag-channel.ts, the reader;cell-flags.ts, the cell's switch list):project/project-id; the read uses the VM's own access token (cloud-platformscope is already on the template). No env, script or template change.?alt=media&ifGenerationNotMatch=<last seen>, so an unchanged object answers 304. The object generation is the version.cellId, orvother than 1 voids the whole object.{ "v": 1, "cellId": "<cellId>", "flags": { "readinessLocal": false, "ticketCheck": "off" } }.ticketCheckacceptsoff | shadowin this image.orca_relay_cell_flags_applied {generation, flags}line, and the seat feed (GET /v1/admin/cell-seats, feat(relay): read-only seat feed on cells for the directors' shadow directory #26803) now carriesflagsApplied: {generation, flags}(generation 0 = defaults, nothing read yet). The sameflagsAppliedis also in the cell's deploy-authenticated/v1/admin/runtime-status, which the one-cell flag workflow (feat(relay): one-cell flag write workflow with dry run, compare-and-swap and read-back #26837) reads back from. Directors and the workflow act only on applied state, never on the desired object.Why
Design
DESIGN-step3-and-step5-prep-2026-10-09.md§2.1, PR 4 in §6. One object per cell keeps "never fleet-wide" structural, works with the database and the directors down, and needs no table or director endpoint. Reading the bucket name from metadata keeps the cell update image-only.Depends on (not in this PR): the bucket plus IAM (
T/relay-control-bucket.tf, cell runtime SAobjectViewer) and the one-cell write workflow. Until the bucket exists every read is a 404, which keeps the defaults.Linked Issue
N/A (internal relay redesign, step-5 prep).
Visual Proof
N/A: server-only, no UI.
Testing
relay-control-flag-channel.test.ts(fake metadata server and GCS): defaults until the first read; bucket and object path from the project id; on → off flip logs one applied line per generation; 304 path; 503 / 404 / network error / malformed body keep values with one warning per cause and no token in any output; lower generation ignored; unknown key ignored;ticketCheck: "enforce", a non-booleanreadinessLocal, and another cell's id each void the object and are not re-read until the generation changes; single-flight and the 5 s cadence, andstop()ends it.cell-seat-feed.test.ts: the feed reportsflagsAppliedand follows a flip.vitest runandtsc --noEmitincloud/apps/relay.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
Cost: 26 cells / 5 s ≈ 5 GCS reads/s, mostly 304s. Off GCE (local dev, tests) the metadata read fails and the cell stays on defaults with a single warning. Starts only for role
cell. Do not merge without the owner's go.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)