From 2c2c19dd2f07ccace719d851f07ed67dbcf8e39e Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Thu, 19 Nov 2026 20:24:22 -0500 Subject: [PATCH] fix(moves): probe a host again before a relay instead of reusing a failure A failed ssh probe is cached for five seconds, and relays.connect asked ssh.ready, which answers that cached failure. A finish made within five seconds of any failed probe of the target, such as one the source's letter collection makes under load, therefore answered target_unreachable with the target up, and the move stayed at its checklist. Only a finish with something to report connects, so the gate saw it in test_what_the_source_took_after_its_export_is_skipped_by_the_target. relays.connect now uses ssh.reach, which uses a cached ready answer but starts (or joins) a fresh probe instead of answering a cached failure. Reads that only observe a host keep the five-second failure cache. The regression fails a probe, brings the target back, and requires the next finish to go active; it fails without the change. --- apps/albedo/src/albedo/transfer/relays.gleam | 2 +- apps/albedo/src/albedo/workspace/ssh.gleam | 40 ++++++++++++++++++-- e2e/move_checklist_test.py | 32 +++++++++++++++- robot-docs/workspaces.md | 8 ++++ 4 files changed, 76 insertions(+), 6 deletions(-) diff --git a/apps/albedo/src/albedo/transfer/relays.gleam b/apps/albedo/src/albedo/transfer/relays.gleam index a7535ddd0..5ba356253 100644 --- a/apps/albedo/src/albedo/transfer/relays.gleam +++ b/apps/albedo/src/albedo/transfer/relays.gleam @@ -119,7 +119,7 @@ pub fn connect( ) -> Result(Relay, Trouble) { waiting("connecting to " <> host <> " over ssh") use found <- result.try( - ssh.ready(ssh_target, ssh_ms) + ssh.reach(ssh_target, ssh_ms) |> result.map_error(fn(failure) { case failure { hosts.Unsupported(_) -> diff --git a/apps/albedo/src/albedo/workspace/ssh.gleam b/apps/albedo/src/albedo/workspace/ssh.gleam index 4476e4a98..2c95049b1 100644 --- a/apps/albedo/src/albedo/workspace/ssh.gleam +++ b/apps/albedo/src/albedo/workspace/ssh.gleam @@ -73,6 +73,20 @@ pub fn ready(target: String, wait_ms: Int) -> Result(Host, Failure) { } } +/// The host for a connection about to be made: a recent ready answer, or +/// what a probe started (or joined) now finds. Unlike `ready`, a failure +/// cached in the last few seconds is not answered again: a move or a finish +/// that connects now must not be refused for a host that came back since. +pub fn reach(target: String, wait_ms: Int) -> Result(Host, Failure) { + case + actor_call.try_call(server(), wait_ms, Reach(target, _)) + |> result.replace_error(Nil) + { + Ok(answer) -> decoded(answer) + Error(Nil) -> Error(Warming) + } +} + /// Bring an original snapshot into the daemon's archive before the old /// remote run directory is removed. The helper verifies its digest on disk. pub fn fetch_snapshot( @@ -354,6 +368,8 @@ const call_ms = 5000 type Message { Probe(target: String, reply: Subject(String)) + /// As `Probe`, but a cached failure is probed again. + Reach(target: String, reply: Subject(String)) Peek(target: String, reply: Subject(Result(String, Nil))) Observe(target: String, refresh: Bool, reply: Subject(Result(String, Bool))) Step(target: String, reply: Subject(String)) @@ -440,6 +456,18 @@ fn handle(state: State, message: Message) -> actor.Next(State, Message) { } Error(Nil) -> actor.continue(start(state, target, Some(reply))) } + Reach(target, reply) -> + case fresh(state, target) { + Ok(answer) -> + case is_ready(answer) { + True -> { + process.send(reply, answer) + actor.continue(state) + } + False -> actor.continue(start(state, target, Some(reply))) + } + Error(Nil) -> actor.continue(start(state, target, Some(reply))) + } Peek(target, reply) -> case fresh(state, target) { Ok(answer) -> { @@ -537,13 +565,17 @@ fn start( } fn ttl(answer: String) -> Int { - let state = json.parse(answer, decode.at(["state"], decode.string)) - case state { - Ok("ready") -> ready_ms - _ -> failed_ms + case is_ready(answer) { + True -> ready_ms + False -> failed_ms } } +/// Whether a probe's answer found the host ready. +fn is_ready(answer: String) -> Bool { + json.parse(answer, decode.at(["state"], decode.string)) == Ok("ready") +} + /// The probe's answer is its last line. A step line before it is passed on /// to the cache as it arrives. fn run(target: String, server: Subject(Message)) -> String { diff --git a/e2e/move_checklist_test.py b/e2e/move_checklist_test.py index eaebfb4c6..f35bc90e4 100644 --- a/e2e/move_checklist_test.py +++ b/e2e/move_checklist_test.py @@ -376,7 +376,8 @@ class MoveChecklistTests(unittest.TestCase): status, accepted = self.deliver(self.app.base, hook, secret, "late-event") self.assertEqual(status, 202) self.app.idle(self.session) - self.assertEqual(self.finish(transfer)["state"], "active") + finished = self.finish(transfer) + self.assertEqual(finished["state"], "active", finished) target_intake = f"http://127.0.0.1:{self.target.connection['webhook_port']}" status, again = self.deliver(target_intake, hook, secret, "late-event") @@ -396,6 +397,35 @@ class MoveChecklistTests(unittest.TestCase): self.assertEqual(status, 202) self.assertNotEqual(fresh["delivery_id"], accepted["delivery_id"]) + def test_a_finish_just_after_the_target_came_back_reaches_it(self): + """A probe that failed seconds before finish, as one the source's + letter collection makes under load, must not refuse finish once the + target is back: finish probes again instead of answering the cached + failure.""" + hook, secret = self.hook() + transfer, _move = self.to_checklist() + # Something to report, so finish connects to the target. + status, _ = self.deliver(self.app.base, hook, secret, "late-event") + self.assertEqual(status, 202) + self.app.idle(self.session) + self.down.touch() + with self.app.api("/hosts/vassago/probe", {}) as response: + observation = json.load(response) + observation = wait_for( + lambda: (host := self.host_state("vassago")) != "probing" and host, + 15, + "the probe never answered", + ) + self.assertEqual(observation, "unreachable") + self.down.unlink() + finished = self.finish(transfer) + self.assertEqual(finished["state"], "active", finished) + + def host_state(self, target): + with self.app.api(f"/hosts?target={target}") as response: + [host] = json.load(response)["items"] + return host["state"] + def test_a_checklist_left_for_later_survives_a_restart_and_finishes(self): self.schedule("recurring", "nightly digest", 86400, 86400) transfer, move = self.to_checklist() diff --git a/robot-docs/workspaces.md b/robot-docs/workspaces.md index e4f8fbdf3..3cde2bd49 100644 --- a/robot-docs/workspaces.md +++ b/robot-docs/workspaces.md @@ -24,6 +24,14 @@ fail when the host or directory is unavailable. unreachable host returns an error, not a missing-folder result. The remote probe and gather retain their separate time bounds. +[`ssh`](../apps/albedo/src/albedo/workspace/ssh.gleam) caches each host's probe +answer: a ready host for a minute and a failure for five seconds, so repeated +reads of an unreachable host do not each wait on ssh. `ssh.ready` answers that +cached failure. A relay to another daemon, which a move, its finish, and letter +forwarding open, connects through `ssh.reach` instead: a cached failure starts a +new probe, so an action taken after the host came back is not refused on an +answer from before. + `location.label` and `location.to_json` show a remote host's alias, with `user@` only when it differs from the user ssh config picks for it. The SDK formats without reading anything: the caller passes that lookup. `locations.label` and -- knotmirror 0.0.1