Skip to content

feat(relay): per-cell runtime switches read from Cloud Storage every 5 s - #26805

Merged
Jinwoo-H merged 5 commits into
mainfrom
relay-step3-cell-flag-channel
Oct 9, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
relay-step3-cell-flag-channel

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​253 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​251
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​279 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​277

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

  • Before: the only way to change how a cell behaves is a new image or a new startup script, which means moving every desktop on that cell.
  • After: a cell also reads cells/<cellId>.json from 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.
  • Mechanism (relay-control-flag-channel.ts, the reader; cell-flags.ts, the cell's switch list):
    • The bucket name comes from the metadata server's project/project-id; the read uses the VM's own access token (cloud-platform scope is already on the template). No env, script or template change.
    • Each read is a GCS GET ?alt=media&ifGenerationNotMatch=<last seen>, so an unchanged object answers 304. The object generation is the version.
    • Boot runs on defaults until the first good read; the cell does not wait for it.
    • Loss of contact (404, 5xx, timeout, malformed JSON) keeps the applied values and never turns anything on or off. One warning line per change of cause, never the token. Every reply it does not consume has its body cancelled, and the object read stops and cancels at the first byte past 64 KiB.
    • A generation below the applied one is ignored. Unknown keys are ignored (a newer writer may name switches this image lacks). A known key with a bad value, a wrong cellId, or v other than 1 voids the whole object.
    • Object shape: { "v": 1, "cellId": "<cellId>", "flags": { "readinessLocal": false, "ticketCheck": "off" } }. ticketCheck accepts off | shadow in this image.
  • How a flip is observed: each newly applied generation logs one 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 carries flagsApplied: {generation, flags} (generation 0 = defaults, nothing read yet). The same flagsApplied is 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 SA objectViewer) 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-boolean readinessLocal, 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, and stop() ends it.

  • cell-seat-feed.test.ts: the feed reports flagsApplied and follows a flip.

  • vitest run and tsc --noEmit in cloud/apps/relay.

  • 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

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

  • 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)

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.
…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.
@Jinwoo-H
Jinwoo-H force-pushed the relay-step3-cell-flag-channel branch from 63b55c7 to 8c894b3 Compare October 9, 2026 21:00
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

The 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 8c894

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 | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 9 files. 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: per-cell runtime switches read from Cloud Storage on a five-second cadence.
Description check Passed The description is complete and aligned with the template. It explains the user-facing change, mechanism, rationale, dependencies, testing, security considerations, visual-proof exception, and checkli…
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.


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🛠️ Fix failing CI checks 💡
  • 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: 0fb637be-387c-4357-8479-0822a8b4eb68
📥 Commits

Reviewing files that changed from the base of the PR and between d358e59 and 8c894b3.

📒 Files selected for processing (9)
  • cloud/apps/relay/src/app.ts
  • cloud/apps/relay/src/cell-flags.ts
  • cloud/apps/relay/src/cell-seat-feed-route.ts
  • cloud/apps/relay/src/cell-seat-feed.test.ts
  • cloud/apps/relay/src/floating-promise-census.test.ts
  • cloud/apps/relay/src/index.ts
  • cloud/apps/relay/src/relay-control-flag-channel.test.ts
  • cloud/apps/relay/src/relay-control-flag-channel.ts
  • cloud/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.

Comment on lines +128 to +129
seenGeneration = generation
const text = await readBounded(response, MAX_OBJECT_BYTES)

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.

🎯 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.

Suggested change
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

@Jinwoo-H
Jinwoo-H merged commit f0dd050 into main Oct 9, 2026
33 of 43 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