Repository navigation
feat(edge): D1 Rust listen edge, passthrough + harness (not deployed) - #22921
Merged
Merged
Conversation
Add backend/edge, the listen-edge Rust crate from plan D (realtime gateway), in passthrough mode only: it accepts /v4/listen, opens the same path and query on the upstream listen service with the client's headers, and relays text/binary messages in order with identical payloads both ways. No decode, no VAD, no provider legs. - upstream handshake before the client's 101, so listen's rejections (e.g. 403) reach the client unchanged; 502/504 when upstream is down/slow - close codes and reasons relayed both ways; abnormal ends mirrored as drops - SIGTERM drain: /readyz 503 at once, accept during a deregistration delay, then close each session with 1012 over a spread window, relaying every frame the client sent before it saw the close; a client that vanishes still gives listen a clean 1012 close - enum-only Prometheus metrics, all series created at startup, with a unit test enforcing the label enums and a 120-series budget - FakeListen harness and integration tests for ordering, close codes, drops, rejection, headers, close timeout and drain with frames in flight - CI: backend-edge.yml runs fmt, build, clippy and test on backend/edge/** changes (workflow change named by David on 2026-10-20) Nothing builds an image or deploys this crate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- drain sends listen 1001, not the client's 1012: listen treats only 1000/1001 as ordinary and finalizes desktop conversations only on 1000, so 1001 keeps the conversation in progress for the reconnect (verified against routers/listen/runtime.py and the real-listen smoke) - a client that stops reading cannot stall drain: the session starts its close deadline from its own drain timer, and every close write is bounded - connections are tracked from accept, so drain waits for upgrades still in their upstream handshake; idle keep-alive sockets are shut down only after any in-flight request, since hyper's graceful shutdown breaks a 101 - drain deadline gains slack for the abort close and final flush (23s default) - load shedding: EDGE_MAX_SESSIONS, EDGE_MAX_PENDING_HANDSHAKES (503 + Retry-After) and EDGE_HEADER_READ_TIMEOUT_MS; new handshake result "overloaded" - the upstream pump relays already-buffered upstream frames before the drain close - CI and local toolchain pinned to 1.99.1 (rust-toolchain.toml) - tests: drain with a client that stops reading, drain with a handshake in flight, session cap 503, slow headers; gauge waits no longer race Failure-Class: none Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level
marked this pull request as ready for review
October 20, 2026 20:24
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
D1 of plan D (realtime gateway; internal KB
projects/backend-target-architecture/plan-d-realtime-gateway.md, §4 and §5). This addsbackend/edge/, thelisten-edgeRust crate (tokio, hyper and tokio-tungstenite), in passthrough mode only. It accepts/v4/listen, opens the same path and query on an upstream listen URL with the client's headers, and relays text and binary messages in both directions, in order, with byte-identical payloads. Nothing deploys it. No Dockerfile, chart, Helm or deploy workflow changes, and no change to listen's Python behaviour.The gateway exists so that a deploy stops dropping live sockets. D1 builds and proves that mechanism (the drain) before any decode or VAD work goes in.
In scope
EDGE_*). Everything is validated at startup, andEDGE_UPSTREAM_URLis the only required key. The table is inbackend/edge/README.md.X-Forwarded-For./readyzreturns 503 immediately, and new sockets are still accepted forEDGE_DRAIN_READY_DELAY_MS(5s) while the load balancer deregisters the pod.EDGE_DRAIN_SPREAD_MS(10s), so clients don't all reconnect at once.routers/listen/runtime.py_ordinary_client_closeand_teardown). With 1001 the conversation stays in progress for the reconnect, as it does today when a client drops.EDGE_MAX_SESSIONS(5000) andEDGE_MAX_PENDING_HANDSHAKES(512) return 503 withRetry-Afterbefore any upstream work.EDGE_HEADER_READ_TIMEOUT_MS(10s) guards against slow request headers./healthz,/readyz,/metricson the same port.outcome,result,direction,kind), plus a boundedrelease_shaonomi_edge_build_info.FakeListen(tests/common/mod.rs) is a fake listen upstream whose behaviour is chosen per connection by query parameters: echo, flood, blob, close with a code, drop, reject, slow handshake, mute, and linger..github/workflows/backend-edge.ymlrunscargo fmt --check, build,clippy -D warningsand test, only onbackend/edge/**changes.rust-toolchain.toml).contents: read, and the job has a CI budget entry.David named this workflow change on 2026-10-20 (two-lane lead session): CI job for backend/edge
Out of scope (D2+): Opus/LC3/AAC decode, Silero VAD, provider legs (Soniox, Modulate, Parakeet window), the SessionBrain gRPC stream, the FakeSoniox/FakeParakeet billing meters (F3, shared with plan F), the container image and deploy.
Product invariants affected
none
How it was verified
Crate (local, rustc 1.99.1, run through
omi-heavyat nice 19):After the review fixes, the full suite ran 30 times in a row with no failures. Cold build, clippy and test took 85s locally.
Mutation checks confirmed that the tests catch regressions:
drain_waits_for_handshakes_in_flightfails 3 times out of 3;drain_is_bounded_when_client_stops_readingfails.Real-path smoke: the real
/v4/listenbehind the edge. The stack was this branch's backend code running the real transcribe router, through the arch-d listenprof harness: Firestore emulator, local Redis, local protocol peers, demo project, loopback only, no credentials. The client was the arch-d Go listen client, sending real 20 ms Opus frames with ADMIN_KEY auth. The edge was the release binary (3 MB). The run used 10 sessions and a 30 s hold.omi_listen_ws_close_total)client_closed, 3client_dropped)SIGTERM to the edge mid-session:
/readyz503,/healthz200;drained;The smoke and the review found these, all fixed and now covered by tests:
close_completes_while_upstream_keeps_tcp_open).drain_gives_listen_a_clean_close_when_client_vanishes).drain_is_bounded_when_client_stops_reading). Handshakes in flight are tracked; hyper's graceful shutdown broke a pending 101 (drain_waits_for_handshakes_in_flight). Load shedding and a header timeout were added (session_cap_sheds_with_503,slow_headers_are_timed_out). Already-buffered upstream frames are relayed before the drain close. The CI toolchain is pinned.Listen behaviour this PR doesn't change: on a client-initiated close, listen sometimes keeps sending segments ("Listen segment delivery after close") instead of replying to the close at once. When that takes longer than
EDGE_CLOSE_TIMEOUT_MS, the edge records the session asclose_timeout. A direct client sees the same wait today.Not verified here: the goldens (#22203) and simulator replay (#22201) through passthrough, and anything on GKE. D1 is not deployed, so those gates belong to D2 and D3.
Tests
tests/passthrough.rs:tests/drain.rs:0..sentin order and then 1001, and the listener is closed afterwards;UI evidence
UI-Evidence: none -- backend Rust crate, no UI
Failure class (fixes)
Failure-Class: none
What D2 needs
EDGE_SHADOW_PERCENT). Decode (opus first) and Silero VAD then run in the edge, with VAD agreement and gate-timing metrics against listen. There are no provider legs and no vendor spend.listen-edgeimage built in B's train withOMI_RELEASE_SHA.terminationGracePeriodSecondsabove the 23 s drain deadline, and no preStop hook, because the edge handles SIGTERM itself.🤖 Generated with Claude Code