Fix the reset correlation check for a Go service
Your task
Your Go service throws intermittent "connection reset by peer" errors under load. An AI concluded with high confidence that a missing read timeout was the cause. Before shipping that fix, you check which population the resets actually track: old pooled connections, or slow requests.
An assistant wrote rank_reset_hypothesis(samples). It is in the editor. It has a bug. Find it and fix it.
Input and output:
samples: one request each,"outcome|connection_age_seconds|request_ms". The outcome isokorreset.- Return
"idle_keepalive_reuse","slow_upstream_timeout","inconclusive"or"insufficient_evidence".
Rules the tests check:
- Skip a sample that does not split on
|into exactly 3 fields, and a sample whose outcome is not exactlyokorreset. - A number is an optional
-followed by one or more ASCII digits. Any other text counts as 0. - If there are no resets, or no oks, return
"insufficient_evidence". - Connection age is elevated when the resets' average age is at least twice the oks' average age, and the resets' total age is above 0. Latency is elevated by the same rule on
request_ms. Compare exactly, with no rounding. - Only age elevated:
"idle_keepalive_reuse". Only latency elevated:"slow_upstream_timeout". Both or neither:"inconclusive".
Examples
rank_reset_hypothesis(samples: list[str]) -> strExample 1
Input
rank_reset_hypothesis(["reset|300|40", "reset|280|45", "ok|10|40", "ok|12|42", "ok|8|38"])Output
"idle_keepalive_reuse"Example 2
Input
rank_reset_hypothesis(["reset|10|5000", "reset|12|4800", "ok|11|100", "ok|9|120"])Output
"slow_upstream_timeout"