Skip to content

feat(relay): per-cell switches for the rejection fence and the lost-reply margin - #27057

Merged
Jinwoo-H merged 2 commits into
mainfrom
relay-cell-switches-fence-timeout
Oct 10, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
relay-cell-switches-fence-timeout

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​127 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​103

Summary

This PR adds two per-cell runtime switches to the relay cell's switch file (cells/<cellId>.json) and makes the cell report switch names it does not understand. Each switch flips on one cell within one poll (about 5 s), with no roll. Stacked on #27049.

  • rejectionFence (default on, which is today's behaviour). The unhandled-rejection fence (fix(relay): a database fault reaching unhandledRejection no longer kills the process #26817) logs some database rejections instead of ending the process. Off restores Node's default for that cell: any unhandled rejection ends the process. Before, the only way back was a new image.
  • readTimeoutMarginMs (whole milliseconds, 1,000 to 60,000; absent keeps the boot value). This is how long past statement_timeout the cell waits for a reply before treating the connection as lost. When the switch is set, the cell sends that timeout on every query through pg's per-query query_timeout (read from the query config object, pg client.js:660). That covers plain statements, transaction statements, BEGIN/COMMIT, and the commit-with-final-write path. Before, the margin was fixed at boot.
  • ignoredKeys. A switch file that names keys this image does not know (a newer writer's switch, or a typo) still applies the keys the image does know. The applied log line and flagsApplied now list the unknown names, so the switch tool can refuse a read-back that silently dropped a switch (fix(relay): the cell switch tool changes only the named switches #27056). Directors parse flagsApplied without strict mode, so older directors ignore the new field.

With no switch file, or a file without these keys, behaviour is byte-identical to today.

Why this approach

Per query query_timeout changes the margin for queries already in flight on pooled connections, without rebuilding the pool. Rebuilding the pool on a flip would drop live connections in the middle of a stall, which is exactly when the margin matters.

Testing

  • Full relay suite against Postgres 16: 133 files, 1,172 tests pass, 1 skipped.
  • New Postgres test: "applies the switch file margin per query". The switch overrides the boot margin, and removing it restores the boot margin.
  • Fence test: rejections are fatal with the switch off.
  • Flag channel test: unknown keys are applied around and reported.
  • tsc is clean.

Jinwoo-H added a commit that referenced this pull request Oct 10, 2026
…es not support

It reads supportedFlags from runtime-status (#27057). An image from before that field takes only
readinessLocal and ticketCheck off/shadow, so ticketCheck=enforce cannot void an old cell's object.
…eply margin, and report ignored keys

rejectionFence (default on) turns the unhandled-rejection fence off without a roll.
readTimeoutMarginMs (1-60 s) replaces the boot margin per query through pg's query_timeout.
The applied log line and flagsApplied name keys this image does not know.
…accepts

The flag tool checks a write against it, so it can refuse ticketCheck=enforce (or any key)
on an image that would void or drop it.
@Jinwoo-H
Jinwoo-H force-pushed the relay-cell-switches-fence-timeout branch from 1368e38 to e505a90 Compare October 10, 2026 05:43
@Jinwoo-H
Jinwoo-H changed the base branch from relay-flag-seen-generation to main October 10, 2026 05:43
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →Review in Change Stack →

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: d59391e0-7ea7-4f77-baf2-72c0f4fdbcfb



📥 Commits

Reviewing files that changed from the base of the PR and between 94b7936 and e505a90.




📒 Files selected for processing (10)
  • cloud/apps/relay/src/app.ts
  • cloud/apps/relay/src/cell-flags.ts
  • cloud/apps/relay/src/cell-seat-feed.test.ts
  • cloud/apps/relay/src/database.ts
  • cloud/apps/relay/src/index.ts
  • cloud/apps/relay/src/postgres-lost-reply-postgres.test.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-database-rejection-fence.test.ts
  • cloud/apps/relay/src/relay-database-rejection-fence.ts



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





📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The relay adds rejectionFence and bounded readTimeoutMarginMs cell flags. Runtime status reports supported flags, and the control channel records unknown flag keys. The applied flags now control unhandled database rejection handling and provide a per-query timeout margin for PostgreSQL queries.





Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to e505a

The runtime switches appear ready to merge after normal checks.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description explains the main changes, rationale, and testing, but it omits required template sections, including an explicit Linked Issue entry, Visual Proof with N/A justification, review and co… Update the description to follow the repository template. Add the linked issue under "Linked Issue" using the required issue format, add "N/A" with a reason under "Visual Proof" because this is not a UI change, complete or explain the Testi…
✅ Passed checks (3 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 and concisely identifies the two main changes: per-cell rejection-fence and lost-reply margin switches.

Full details: Description check

Explanation

The description explains the main changes, rationale, and testing, but it omits required template sections, including an explicit Linked Issue entry, Visual Proof with N/A justification, review and compatibility notes, and checklist confirmations.

Resolution

Update the description to follow the repository template. Add the linked issue under "Linked Issue" using the required issue format, add "N/A" with a reason under "Visual Proof" because this is not a UI change, complete or explain the Testing, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections, and include explicit ELI5, What Changed, and Why headings.


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

@Jinwoo-H
Jinwoo-H merged commit 9c41d9e into main Oct 10, 2026
31 of 50 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 10, 2026
)

* fix(relay): the cell switch tool changes only the named switches and checks every key on read-back

A cell resets a key missing from its switch file to its default, so the tool now reads the
current object and changes only what --set names. The read-back compares every known key and
fails when the cell reports ignoredKeys.

* fix(relay): the cell switch tool refuses a switch the cell's image does not support

It reads supportedFlags from runtime-status (#27057). An image from before that field takes only
readinessLocal and ticketCheck off/shadow, so ticketCheck=enforce cannot void an old cell's object.

* fix(relay): the switch tool validates the whole object, refuses voided files, and records admitMode in Postgres

Every key and value of the object to be written is checked against what the image accepts (an
image without the list: only the keys it applies, ticketCheck off/shadow). A file the cell did
not apply is refused. admitMode=reserve needs a typed RESERVE <cell>; Postgres records reserve
before the file is written, and db only after the cell reports every control leased again.

* feat(relay): the switch tool knows reregisterInFlight (1-16), the flip-back pace

* fix(relay): the switch tool closes the cache gap before reserve, undoes a refused write, and has a break-glass db flip

After recording reserve in Postgres it waits past every director's 5 s cache and records it
again (re-running the open-flow check) before writing the file. A file write refused outright
(412 or 4xx) puts Postgres back to db; after a 5xx it stays reserve. An object the cell did not
apply is repaired when the new object passes the image check. Break glass (typed BREAK GLASS
<cell>) records db for a dead or unreachable reserve cell without its read-back.

* fix(relay): a director deploy refuses a traffic move across reserve-mode support while any cell is reserve

* fix(relay): the flip-back wait scales with the cell's controls and pace, and says how to finish

* fix(relay): the switch tool refuses to re-arm a tripped cell, breaks glass only on a silent one, and undoes reserve if the second post is refused

* feat(relay): director deploys set reserve placement, and refuse turning it off while any cell is reserve

* fix(relay): Terraform keeps the deploy-owned placement and shadow cells, and the deploy guard reads placement as built and refuses dropping a reserve cell from the shadow list

* fix(relay): director deploys take --admin-audience alone, name a drifted deploy identity, and carry the shadow seat-feed cells

Staging passes --admin-audience for the reserve guard without durable rehome
verification, which the parser refused. Only the generation and control
origin now travel together, and they still need the audience.

The guard decodes the caller from its token and refuses, by name, a revision
whose ORCA_RELAY_DEPLOY_SERVICE_ACCOUNT is another account, instead of
reading into a 401.

--shadow-seat-feed-cells (preserve, all, or a cell list) is a workflow input
on both director deploys; preserve keeps the serving value. A contract test
parses every workflow's real argv for both deploy scripts.

* fix(relay): the flag tool paces a flip back from the pool size the cell reports

An image from before the field falls back to the deployed sizes.
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