Repository navigation
fix(relay): bound control RTT samples per ping and per flush window - #19268
Conversation
An authenticated host chose how many round-trip samples a cell recorded: every pong carrying a recent plausible `t` was forwarded to the process-wide window, which grew unbounded until the 30s flush copied and sorted it for percentiles. Time a pong only when it echoes the `t` of the ping still outstanding on that session, so a flood yields at most one sample per ping the cell actually sent. A pong that lost the race to the next ping is dropped for timing but still counts as proof of life for the silence watchdog. Bound the process-wide window with a 1024-sample reservoir (Algorithm R) so the percentiles stay unbiased, keep `controlRttSamplesDelta` meaning round trips observed, and publish `controlRttSamplesDroppedDelta` for the ones the reservoir did not keep. Replace the leak guard's blanket `"credential":` string rewrite with an exact, path-scoped rename of the two schema keys that spell a policed word, and make the guard case-insensitive now that nothing legitimate trips it. Follow-up to #19232.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe relay now records RTT samples only when a pong matches the outstanding control ping timestamp. Host sessions reset this state during initialization and rebind operations. RTT observations use a 1,024-entry reservoir with Algorithm R replacement. Flush output reports observed and dropped sample counts. Tests cover unmatched pongs, pong floods, reservoir limits, and empty flushes. Terraform adds the dropped-sample metric and updates the sample metric description. Merge Risk: ⚪ Minimal · up to This change bounds relay RTT sampling and rejects unmatched pong timestamps while preserving liveness tracking. The updated metrics and Terraform descriptors align, with no current merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. (1 skipped: 1 unsupported.) Full details: Description checkExplanation The description explains the change, rationale, testing, compatibility, security, performance, and required checklist items. However, the required Linked Issue section explicitly states “No issue,” although the template requires an issue link.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
|
On the docstring-coverage pre-merge warning (33.33% against an 80% threshold): declining, with the description check now fixed above. This repository's |
…tablyai#19268) * fix(relay): bound control RTT samples per ping and per flush window An authenticated host chose how many round-trip samples a cell recorded: every pong carrying a recent plausible `t` was forwarded to the process-wide window, which grew unbounded until the 30s flush copied and sorted it for percentiles. Time a pong only when it echoes the `t` of the ping still outstanding on that session, so a flood yields at most one sample per ping the cell actually sent. A pong that lost the race to the next ping is dropped for timing but still counts as proof of life for the silence watchdog. Bound the process-wide window with a 1024-sample reservoir (Algorithm R) so the percentiles stay unbiased, keep `controlRttSamplesDelta` meaning round trips observed, and publish `controlRttSamplesDroppedDelta` for the ones the reservoir did not keep. Replace the leak guard's blanket `"credential":` string rewrite with an exact, path-scoped rename of the two schema keys that spell a policed word, and make the guard case-insensitive now that nothing legitimate trips it. Follow-up to stablyai#19232. * test(relay): prove the RTT reservoir samples the whole window

ELI5
The relay times how long a desktop takes to answer its heartbeat. It used to time any reply, so a desktop could send a million replies and make the relay hold a million measurements in memory until the next 30-second metrics flush. Now the relay only times the reply that answers the heartbeat it actually sent, and it never keeps more than 1024 measurements per window.
What Changed
Follow-up to #19232 (merged as ecfcc0d), addressing two CodeRabbit findings on that PR.
cloud/apps/relay/src/host-session-registry.ts: each session trackspendingPingAt, thetof the ping still awaiting an echo. A pong is timed only when it echoes that exact value, and the slot is cleared on use, on rebind, and on a fresh session. One sample per ping the cell actually sent, whatever a host floods. A pong that lost the race to the next ping is dropped for timing but still updateslastPongAt, so control-silence liveness is unchanged.cloud/apps/relay/src/relay-observability.ts: the process-wide window is now a 1024-sample reservoir (Algorithm R), so a flood cannot grow the heap and the percentiles stay unbiased rather than truncated to the first N.controlRttSamplesDeltakeeps its meaning, round trips observed in the interval, and the newcontrolRttSamplesDroppedDeltareports what the reservoir did not keep, so a non-zero value says the percentiles summarise a uniform sample.cloud/infra/terraform/relay-observability.tf: descriptor for the new field, plus a clarified description oncontrol_rtt_samples.cloud/apps/relay/src/relay-observability.test.ts: the leak guard now clones the entries and renames onlyclientAcceptsAbandonedByStageDelta.credentialandclientAcceptCredentialMsP95, both path- or key-exact, so a stray raw field or value elsewhere still trips it. The regex is case-insensitive now that nothing legitimate matches.Why
1. A host could choose how many RTT samples a cell recorded (major).
recordControlRtttimed everypongwhose echoedtwas a finite number within 120s of now. Nothing required that pong to answer a ping the cell had sent, so an authenticated host could stream pongs with fresh timestamps and push one sample per frame into the process-widecontrolRttSamplesMsarray. That array was only reset by the 30s flush, which copies and sorts it twice for the p50/p95. Heap growth and flush CPU were both attacker-chosen. The per-session window was already capped at 8, but it was capped after the process-wide forward.Requiring the echo to match the outstanding ping removes the attack surface at the source rather than clamping its symptom. The reservoir is the second line: it bounds any future caller of
recordControlRtttoo, and it keeps percentiles honest where a plain "drop beyond N" would bias every busy window toward its first samples.2. The leak guard could mask a real leak (minor).
scrubStageNamesranJSON.stringify(entries).replaceAll('"credential":', '"stage":')over the whole serialized event to exempt thecredentialaccept stage. Any accidental raw"credential"field anywhere in a future event would have been scrubbed the same way.Linked Issue
No issue; this is direct follow-up review feedback on #19232.
Visual Proof
N/A— relay server-side sampling and log-based metric fields only, no UI surface.Testing
Four new tests, each confirmed to fail against the pre-fix source and pass after:
controlRttSamplesDelta: 20480withcontrolRttSamplesDroppedDelta: 19456, which pins the retained window at the 1024 cap;Review
Relay-only change. No wire-format change: the ping and pong frames are byte-identical to before, so an old desktop paired with a new cell behaves exactly as it does today, and a new cell paired with any desktop build that echoes
tkeeps producing samples. Hosts that never echotproduced no samples before this change either.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
controlRttSamplesDeltakeeps its published meaning;controlRttSamplesDroppedDeltais additive and defaults to 0.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)