Skip to content

review: whole-repo round — keep-alive stream stall (TCP_NODELAY), wrong comments, dead items, json! copies - #159

Open
CMGS wants to merge 7 commits into
mainfrom
review/round-2026-10-18
Open

CMGS wants to merge 7 commits into
mainfrom
review/round-2026-10-18

Conversation

@CMGS

@CMGS CMGS commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Whole-repo review round over main@55abd059: every production file read in full (82 files, 29.5k lines), README and docs checked against the code, a LOC-justify pass, then a full Linux regression on a test host. The run turned up one real defect, a ~44 ms stall at the end of every streamed response on a keep-alive connection. Everything else is comment corrections, small cuts and ownership fixes.

Commits

  • fix: set TCP_NODELAY on accepted connections: on a keep-alive connection every streamed response ended about 44 ms late. Nagle held the last small SSE write until the client's delayed ACK. SDK clients and reverse proxies pool connections, so every stream paid it. The listener now sets TCP_NODELAY on each accepted connection (axum::serve::ListenerExt::tap_io).
  • fix: comments the code contradicts, and one fact stated once: TenantConf.fallback_model still said a request over quota with no fallback passes through. Since model quota: refuse an over-quota request with no usable fallback #150 it is refused. The in-memory ledger_usage note said usage is never capped, but billing_record clamps every token count. The config generation's cache-key role was stated at three places. The README now names both triggers for account failover.
  • cut: a write-only response field, an unreachable break, a role nothing sends:
    • GatewayResponse.step: written on video replies and read nowhere.
    • pump_sse: a trailing if out.aborted { break } that every abort path had already left.
    • role::STORAGE: came with the initial import and no code creates such a turn. A client-sent one reaches the vendor, so the estimate counts it now.
  • cut: one rollup-bucket fold for the in-process store.
  • perf: move owned values into JSON envelopes instead of json! copies: four json! calls that deep-copied an owned Value.
  • review: one line per comment: six two-line inline comments and four multi-line private docs.
  • docs: docs/performance.md records the stall and the numbers below.

Net: production −33 lines, comments −20, tests −8.

Evidence

Gates

  • macOS: fmt and clippy (-D warnings) clean. cargo test --workspace against Postgres 17 + Redis 7: 763 passed / 0 failed / 4 ignored.
  • Every commit: clippy clean and tests green.
  • Linux test host (Rust 1.99.0, Postgres 17, Redis): fmt and clippy clean, 763 / 0 / 4, with the gwtest_* databases and Redis keys created by the env-gated suites.

Stream stall (Linux, oha against the mock upstream, main vs this branch):

Shape main this branch
/v1/chat/completions stream, 1 connection 22 req/s, p50 48 ms 7,255 req/s, p50 0.12 ms
/v1/messages stream, 1 connection 22 req/s, p50 44 ms 5,941 req/s, p50 0.16 ms
chat stream, 64 connections 1,445 req/s 52,820 req/s
messages stream, 64 connections 1,444 req/s 54,697 req/s
non-stream chat, 64 connections 50,656 req/s 57,248 req/s

Hot path: instructions per request (perf stat, 200k requests per arm, arms interleaved with order swapped).

  • Small and 52 KB chat in the plain, day-budget and Redis-budget configs: all within ±0.2% of main.
  • Streamed /v1/messages throughput: from ~1.4k to 40k–90k req/s.

Live vendor matrix (real keys, through the branch build): 191/194.

  • The 3 failures are the Bedrock cases in the grok group; no Bedrock key is currently valid.
  • An earlier pass on this branch (before the TCP_NODELAY commit) had 2 transient xAI reasoning-omission failures; the xai group then reran 23/23 on both main and the branch.

CMGS added 5 commits October 18, 2026 01:07
TenantConf.fallback_model said an over-quota request without one passes through; since #150 it is refused. The ledger_usage note claimed usage is never capped; billing_record clamps every token count. The config generation's cache-key role was stated at three sites; the cache-key hash keeps it. The README now names both failover triggers.
…g sends

GatewayResponse.step was set on video replies and read nowhere (views serve the vendor payload, never the response struct). In pump_sse every path that sets aborted inside the frame loop already returns, so the trailing check never fired. role::STORAGE came with the initial import; no code creates such a turn, and one a client sent would reach the vendor, so the estimate now counts it.
ledger_replay_batch and usage_rollup_advance built the same (minute, tenant, user, model) bucket entry inline.
json! serializes every interpolated expression, so an owned Value placed in it is deep-copied and dropped: the Anthropic content_block_start block, the synthesized Responses usage, the replayed message_start usage (already a clone), and the MCP JSON-RPC id. Each envelope is built first and the value moved in.
Six two-line inline WHY comments and four multi-line docs on private items, each compressed to one line with its fact intact.
@CMGS CMGS changed the title review: whole-repo round — wrong comments, three dead items, json! copies, one-line comments review: wrong comments, three dead items, json! copies, one-line comments Oct 17, 2026
CMGS added 2 commits October 18, 2026 02:20
On a keep-alive connection every streamed response ended about 44 ms late: the SSE tail goes out as small writes, Nagle holds the last one until the previous segment is acknowledged, and the client delays that ACK. Measured on Linux with oha against the mock upstream: one streaming request at a time ran at 22 requests/s with a p50 of 48 ms, while the same request on a fresh connection (curl) took under 1 ms. SDK clients and reverse proxies both pool connections, so every stream paid it.
@CMGS CMGS changed the title review: wrong comments, three dead items, json! copies, one-line comments review: whole-repo round — keep-alive stream stall (TCP_NODELAY), wrong comments, dead items, json! copies Oct 17, 2026

This branch has not been deployed

No deployments
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