WAN: side-by-side latency test, the provider's "is it your router?" test, run by Gandalf #70

Merged
jared merged 1 commits from modem-ping-evidence into main 2026-11-26 23:20:14 -05:00
Owner

Why

AT&T asked for a test before replacing the BGW320: plug a device straight into the modem while the internet is slow, and see whether it's slow too. Gandalf can do this while the owner is away. A ping the modem sends itself never passes through the router, so if that ping is slow, the router isn't the cause.

Gandalf already had a modem ping, but it had three gaps:

  • Too infrequent: at most every 10 minutes, and only while UniFi flagged the current 5 minutes.
  • Wrong threshold: a fixed 150 ms. On 2026-11-26 at 15:02 UTC the modem's own ping averaged 110 ms on a line that normally answers in 14 ms, and Gandalf labelled it "clear".
  • Wrong comparison: it compared against UniFi's last reading, not a measurement taken at the same moment.

What it does now

Side by side. The modem pings 1.1.1.1 from its Troubleshoot page. At the same moment, Gandalf times TCP handshakes:

  • to 1.1.1.1:443, through the router
  • to the modem's own web port, which tests the hop from the router to the modem

A handshake is one round trip, like a ping. The monitor runs as www-data, which isn't allowed to send pings, so this needs no permission change.

Cadence.

  • While the internet is slow: every check, about every 2 minutes. "Slow" means UniFi flags the current period, a reading is slow, or the last test wasn't clear.
  • Otherwise: every 30 minutes, so Gandalf learns the line's normal latency.

What counts as slow. It's relative to the line's normal latency, which is the median of the modem's clean pings over 7 days (15 ms until there are 5 samples). Slow is three times normal and at least 40 ms over it: 54 ms on a 14 ms line.

Verdicts:

Verdict Meaning
upstream The modem's own ping is slow or lossy, so the delay is in the modem or the line. The router is cleared.
lan The hop to the modem is slow: the router, the cable, or the modem's LAN port.
gateway The modem's own ping and the hop to it are fine, but the internet through them is slow: the modem's forwarding or the router's WAN side. Only a laptop plugged straight into the modem separates these two.
clear All fine.

Evidence for AT&T.

  • Every test is kept for 7 days (modem_checks.ping_history).
  • The "Internet degraded" ticket includes what the tests showed while it built up.
  • Its "Cleared" note sums up the whole episode in words that can go straight to AT&T, e.g. "The modem's own ping ... was slow or lossy in 4 of 31 tests, worst 110 ms against a normal 14 ms, while Gandalf's own measurement through the router at the same moment was 14 ms ..."

Bug fixed along the way

The degraded ticket used to say "a ping from the modem itself was slow too" when the verdict was gateway, which means the modem's own ping was fine. It now uses the evidence summary, which can't contradict the verdict.

Verification

  • 724 tests pass. The new tests replay today's 110 ms reading against a 14 ms baseline (now upstream) and cover:
    • the cadence while slow and while healthy, and testing until a clear result
    • 7-day history pruning
    • falling back to UniFi's reading when Gandalf can't measure
    • every verdict, the evidence text, and the evidence in the ticket and the "Cleared" note
    • TCP timing against a real local socket
  • End to end on prod, as www-data, with this branch's code: the BGW320's own ping was 12.5 ms, Gandalf through the router 12.5 ms, Gandalf to the modem 0.9 ms. Verdict clear, and the whole test took 5.9 s.
  • flake8, bandit and eslint are clean. No em or en dashes.

Cost: while the internet is slow, each check spends about 6 s on this test, and the modem runs one 5-packet ping every 2 minutes. When the line is healthy it's one test every 30 minutes.

🤖 Generated with Claude Code

## Why AT&T asked for a test before replacing the BGW320: plug a device straight into the modem while the internet is slow, and see whether it's slow too. Gandalf can do this while the owner is away. A ping the modem sends itself never passes through the router, so if that ping is slow, the router isn't the cause. Gandalf already had a modem ping, but it had three gaps: - **Too infrequent:** at most every 10 minutes, and only while UniFi flagged the current 5 minutes. - **Wrong threshold:** a fixed 150 ms. On 2026-11-26 at 15:02 UTC the modem's own ping averaged **110 ms** on a line that normally answers in 14 ms, and Gandalf labelled it "clear". - **Wrong comparison:** it compared against UniFi's last reading, not a measurement taken at the same moment. ## What it does now **Side by side.** The modem pings 1.1.1.1 from its Troubleshoot page. At the same moment, Gandalf times TCP handshakes: - to 1.1.1.1:443, through the router - to the modem's own web port, which tests the hop from the router to the modem A handshake is one round trip, like a ping. The monitor runs as `www-data`, which isn't allowed to send pings, so this needs no permission change. **Cadence.** - While the internet is slow: every check, about every 2 minutes. "Slow" means UniFi flags the current period, a reading is slow, or the last test wasn't clear. - Otherwise: every 30 minutes, so Gandalf learns the line's normal latency. **What counts as slow.** It's relative to the line's normal latency, which is the median of the modem's clean pings over 7 days (15 ms until there are 5 samples). Slow is three times normal and at least 40 ms over it: 54 ms on a 14 ms line. **Verdicts:** | Verdict | Meaning | |---|---| | `upstream` | The modem's own ping is slow or lossy, so the delay is in the modem or the line. The router is cleared. | | `lan` | The hop to the modem is slow: the router, the cable, or the modem's LAN port. | | `gateway` | The modem's own ping and the hop to it are fine, but the internet through them is slow: the modem's forwarding or the router's WAN side. Only a laptop plugged straight into the modem separates these two. | | `clear` | All fine. | **Evidence for AT&T.** - Every test is kept for 7 days (`modem_checks.ping_history`). - The "Internet degraded" ticket includes what the tests showed while it built up. - Its "Cleared" note sums up the whole episode in words that can go straight to AT&T, e.g. *"The modem's own ping ... was slow or lossy in 4 of 31 tests, worst 110 ms against a normal 14 ms, while Gandalf's own measurement through the router at the same moment was 14 ms ..."* ## Bug fixed along the way The degraded ticket used to say "a ping from the modem itself was slow too" when the verdict was `gateway`, which means the modem's own ping was **fine**. It now uses the evidence summary, which can't contradict the verdict. ## Verification - 724 tests pass. The new tests replay today's 110 ms reading against a 14 ms baseline (now `upstream`) and cover: - the cadence while slow and while healthy, and testing until a clear result - 7-day history pruning - falling back to UniFi's reading when Gandalf can't measure - every verdict, the evidence text, and the evidence in the ticket and the "Cleared" note - TCP timing against a real local socket - **End to end on prod, as `www-data`, with this branch's code:** the BGW320's own ping was 12.5 ms, Gandalf through the router 12.5 ms, Gandalf to the modem 0.9 ms. Verdict `clear`, and the whole test took 5.9 s. - flake8, bandit and eslint are clean. No em or en dashes. **Cost:** while the internet is slow, each check spends about 6 s on this test, and the modem runs one 5-packet ping every 2 minutes. When the line is healthy it's one test every 30 minutes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-26 23:06:58 -05:00
WAN: side-by-side latency test, the provider's "is it your router?" test, run by Gandalf
Lint / JS (eslint) (push) Successful in 13s
Security / Python Security (bandit) (push) Successful in 1m0s
Lint / JS (eslint) (pull_request) Successful in 17s
Lint / Python (flake8) (pull_request) Successful in 52s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Lint / Python (flake8) (push) Successful in 1m4s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (pull_request) Successful in 1m11s
Test / Python Tests (pytest) (push) Successful in 1m23s
Test / Python Tests (pytest) (pull_request) Successful in 1m14s
8ed32b06e8
AT&T asked for a device plugged straight into the modem during a slow
spell. While the internet is slow, every check now has the BGW320 ping
1.1.1.1 itself while Gandalf, at the same moment, times TCP handshakes to
1.1.1.1 through the router and to the modem's LAN side (no raw socket
needed). A slow ping from the modem itself can't be the router's doing.

Slow is relative to the line's learned normal (median of the modem's own
pings over 7 days): three times normal and 40 ms over it. 2026-11-26's
110 ms on a 14 ms line was called "clear" by the fixed 150 ms.

Every result is kept 7 days; the "Internet degraded" ticket and its
Cleared note sum up the episode in words that can go to the provider.
Also fixes the degraded ticket saying "the modem's ping was slow too"
for the verdict that meant the opposite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared scheduled this pull request to auto merge when all checks succeed 2026-11-26 23:20:11 -05:00
jared merged commit 86b8411354 into main 2026-11-26 23:20:14 -05:00
jared deleted branch modem-ping-evidence 2026-11-26 23:20:25 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/gandalf#70