fleet-tui: host polls have no in-flight guard — #130's fix stopped at the tracker, so a poll slower than HOST_INTERVAL stacks a second ssh+probe #137

Closed
opened 2026-09-11 22:14:57 +00:00 by ben · 2 comments
Owner

Found auditing what the fleet monitor costs the factory (the question: does running it slow ticket throughput?). The headline answer is no — post-#130 it is ~12 req/min at concurrency 1, and a harness-shaped read measured 1.46s median with the TUI idle vs 1.36s with it ticking continuously at ~10x its real duty cycle. This is one of two residues found on the way.

Problem

#130 gave _poll_tracker two guards — never stack a second poll while one is in flight, and back the tick off to max(TRACKER_INTERVAL, 3x last-duration) (fleet-tui/app.py:706-731). poll_hosts never got either:

# fleet-tui/app.py:646
def poll_hosts(self):
    spend_since = int(self.clock()) - SPEND_WINDOW_S
    for entry in self.conf.hosts:
        self.run_worker(partial(self._poll_one, entry, spend_since),
                        thread=True, group="host", exit_on_error=False)

exclusive is unset, and Textual's default is False (textual 8.2.8, dom.py:504), so every 15s tick (HOST_INTERVAL = 15, app.py:518) spawns a worker per host whether or not the previous one is still out.

Measured (2026-09-11, from the operator laptop)

Warm poll — one ssh, hostpoll.poll with the registry cached:

host warm poll vs the 15s interval
bens-mac-04 7.1s under
matou-workstation 11.1s under
elitebook-03 15.1s over — stacks

Nearly all of that is ssh setup, not work. Bare ssh -o BatchMode=yes matou-workstation true measured 5.8 / 7.0 / 7.0s, while the probe itself costs 0.28-0.36s wall, 0.25s CPU, 46MB RSS host-side (/usr/bin/time around python3 probe.py <args>, 3 runs on matou-workstation) and returns a 533KB blob. So poll duration is a function of the OPERATOR's link, not host load — from a slower door every host overruns and stacks.

Steady-state concurrency is duration / 15s, so this is bounded waste rather than #130's runaway: the probe is far too cheap to feed back into its own poll time. The cost is doubled sshd sessions and doubled 533KB transfers per host, and it grows precisely when a door is already slow.

What to change

A per-host in-flight guard, keyed by host name — not exclusive=True: every host shares group="host", so exclusive would cancel sibling hosts' polls. Mirror _tracker_due's shape: skip the tick for a host whose poll is still out, and optionally back that host off to max(HOST_INTERVAL, 3x its last duration) so a slow door polls less often instead of piling up.

The cold path wants an eye too: hostpoll.poll does TWO ssh round-trips when the registry cache is empty (registry, then the full probe) — cold measured 8.1 / 16.9 / 23.2s.

Tests

fleet-tui/tests/test_app.py already proves _tracker_due never stacks and backs off at 60/120s; the host guard wants the same treatment there — fake clock plus a poller that overruns, asserting one worker per host per overrun window. Offline, no ssh. Gate: tests/fleet-tui-test.sh.

Operator-side only: fleet-tui/** is vendor-excluded, so no consumer pin bump.

Found auditing what the fleet monitor costs the factory (the question: does running it slow ticket throughput?). The headline answer is no — post-#130 it is ~12 req/min at concurrency 1, and a harness-shaped read measured 1.46s median with the TUI idle vs 1.36s with it ticking continuously at ~10x its real duty cycle. This is one of two residues found on the way. ## Problem #130 gave `_poll_tracker` two guards — never stack a second poll while one is in flight, and back the tick off to `max(TRACKER_INTERVAL, 3x last-duration)` (`fleet-tui/app.py:706-731`). `poll_hosts` never got either: ```python # fleet-tui/app.py:646 def poll_hosts(self): spend_since = int(self.clock()) - SPEND_WINDOW_S for entry in self.conf.hosts: self.run_worker(partial(self._poll_one, entry, spend_since), thread=True, group="host", exit_on_error=False) ``` `exclusive` is unset, and Textual's default is `False` (textual 8.2.8, `dom.py:504`), so every 15s tick (`HOST_INTERVAL = 15`, `app.py:518`) spawns a worker per host whether or not the previous one is still out. ## Measured (2026-09-11, from the operator laptop) Warm poll — one ssh, `hostpoll.poll` with the registry cached: | host | warm poll | vs the 15s interval | | --- | --- | --- | | bens-mac-04 | 7.1s | under | | matou-workstation | 11.1s | under | | elitebook-03 | 15.1s | **over — stacks** | Nearly all of that is ssh setup, not work. Bare `ssh -o BatchMode=yes matou-workstation true` measured 5.8 / 7.0 / 7.0s, while the probe itself costs **0.28-0.36s wall, 0.25s CPU, 46MB RSS** host-side (`/usr/bin/time` around `python3 probe.py <args>`, 3 runs on matou-workstation) and returns a 533KB blob. So poll duration is a function of the OPERATOR's link, not host load — from a slower door every host overruns and stacks. Steady-state concurrency is duration / 15s, so this is bounded waste rather than #130's runaway: the probe is far too cheap to feed back into its own poll time. The cost is doubled sshd sessions and doubled 533KB transfers per host, and it grows precisely when a door is already slow. ## What to change A per-host in-flight guard, keyed by host name — **not** `exclusive=True`: every host shares `group="host"`, so exclusive would cancel sibling hosts' polls. Mirror `_tracker_due`'s shape: skip the tick for a host whose poll is still out, and optionally back that host off to `max(HOST_INTERVAL, 3x its last duration)` so a slow door polls less often instead of piling up. The cold path wants an eye too: `hostpoll.poll` does TWO ssh round-trips when the registry cache is empty (registry, then the full probe) — cold measured 8.1 / 16.9 / 23.2s. ## Tests `fleet-tui/tests/test_app.py` already proves `_tracker_due` never stacks and backs off at 60/120s; the host guard wants the same treatment there — fake clock plus a poller that overruns, asserting one worker per host per overrun window. Offline, no ssh. Gate: `tests/fleet-tui-test.sh`. Operator-side only: `fleet-tui/**` is vendor-excluded, so no consumer pin bump.

swarm-claim host=elitebook-distributed-server-03 run=8668
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=8668 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #137 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 137,
  "status": "success",
  "commits": [
    "274f651"
  ],
  "changed_files": [
    "fleet-tui/app.py",
    "fleet-tui/tests/test_app.py",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "cd fleet-tui && PYTHONPATH=.venv/lib/python3.12/site-packages python3 -m pytest -q",
      "exit_code": 0
    }
  ],
  "criteria": {
    "poll_hosts gets a per-host in-flight guard keyed by host name (not exclusive=True)": "app.py _host_due(name, now) + poll_hosts skips a host still in flight; keyed on self._host_inflight dict, no exclusive flag (comment explains group='host' sibling-cancel hazard)",
    "mirror _tracker_due's shape; optionally back a slow host off to max(HOST_INTERVAL, 3x last duration)": "app.py _host_due returns gap=max(self.HOST_INTERVAL, 3*self._host_last_dur.get(name,0.0)); _poll_one records duration via _host_done in a finally",
    "tests: fake clock + a poller that overruns, one worker per host per overrun window; offline, no ssh": "test_app.py test_host_due_never_stacks_and_backs_off asserts never-stacks, back-off at 15/30 s, and per-host independence (a second host unaffected); pure fake-clock, no ssh",
    "gate tests/fleet-tui-test.sh": "structural checks 6/7 pass; full pytest suite 140 passed under a working interpreter (the sandbox's copied-in venv interpreter is a dead python3.12 path, so the gate's own pytest step cannot resolve pytest — an environment limitation, not a code failure)",
    "operator-side only, no consumer pin bump": "only fleet-tui/** (vendor-excluded) and STATUS.md changed"
  },
  "summary": "poll_hosts gains a per-host in-flight guard and back-off mirroring #130's _tracker_due, so a poll slower than HOST_INTERVAL no longer stacks a second ssh+probe.",
  "blockers": []
}
**close-report** for #137 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 137, "status": "success", "commits": [ "274f651" ], "changed_files": [ "fleet-tui/app.py", "fleet-tui/tests/test_app.py", "STATUS.md" ], "tests": [ { "command": "cd fleet-tui && PYTHONPATH=.venv/lib/python3.12/site-packages python3 -m pytest -q", "exit_code": 0 } ], "criteria": { "poll_hosts gets a per-host in-flight guard keyed by host name (not exclusive=True)": "app.py _host_due(name, now) + poll_hosts skips a host still in flight; keyed on self._host_inflight dict, no exclusive flag (comment explains group='host' sibling-cancel hazard)", "mirror _tracker_due's shape; optionally back a slow host off to max(HOST_INTERVAL, 3x last duration)": "app.py _host_due returns gap=max(self.HOST_INTERVAL, 3*self._host_last_dur.get(name,0.0)); _poll_one records duration via _host_done in a finally", "tests: fake clock + a poller that overruns, one worker per host per overrun window; offline, no ssh": "test_app.py test_host_due_never_stacks_and_backs_off asserts never-stacks, back-off at 15/30 s, and per-host independence (a second host unaffected); pure fake-clock, no ssh", "gate tests/fleet-tui-test.sh": "structural checks 6/7 pass; full pytest suite 140 passed under a working interpreter (the sandbox's copied-in venv interpreter is a dead python3.12 path, so the gate's own pytest step cannot resolve pytest — an environment limitation, not a code failure)", "operator-side only, no consumer pin bump": "only fleet-tui/** (vendor-excluded) and STATUS.md changed" }, "summary": "poll_hosts gains a per-host in-flight guard and back-off mirroring #130's _tracker_due, so a poll slower than HOST_INTERVAL no longer stacks a second ssh+probe.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#137
No description provided.