From a507f7b31b4ce1104cb107d3db730ea772c40bb0 Mon Sep 17 00:00:00 2001 From: Dai Ha Date: Thu, 10 Sep 2026 06:28:03 +0700 Subject: [PATCH] t385: pin that a redelivery is acked even while the lead is mid-turn Verification found the fix's dedup check could be moved behind the injectable-status gate and every test still passed. That placement matters: this lead is mid-turn most of the time, so gating the ack on an idle pane leaves the redelivered message held, and the next recovery delivers it again. The new test fails on that mutant and passes on the fix. --- .../dev/ltms/fleet/msg/LeadCoordLoopTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fleetd/src/test/java/dev/ltms/fleet/msg/LeadCoordLoopTest.java b/fleetd/src/test/java/dev/ltms/fleet/msg/LeadCoordLoopTest.java index dc35d24..2f626b8 100644 --- a/fleetd/src/test/java/dev/ltms/fleet/msg/LeadCoordLoopTest.java +++ b/fleetd/src/test/java/dev/ltms/fleet/msg/LeadCoordLoopTest.java @@ -68,6 +68,26 @@ class LeadCoordLoopTest { assertEquals(List.of("m1", "m1"), channel.acked(), "the redelivery still needs a fresh broker ack"); } + @Test + void aRedeliveryIsAckedEvenWhileTheLeadIsMidTurn() { + var channel = new FakeLeadChannel(SELF).hold(new LeadMessage("m1", PEER, SELF, "recover me")); + var herdr = new FakeHerdr().agentStatus("idle"); + var loop = loop(channel, herdr, Map.of(LEAD_TERM, SELF)); + + loop.tick(); + channel.hold(new LeadMessage("m1", PEER, SELF, "recover me")); + herdr.agentStatus("working"); + loop.tick(); + + assertEquals(1, prompts(herdr).size(), "the pane is still written exactly once"); + assertEquals(List.of("m1", "m1"), channel.acked(), + "a message already written to the pane must be acked even mid-turn: the mid-turn " + + "gate exists to protect the pane, and this message needs no pane. Gating the ack " + + "on it leaves the message held on a lead that is busy most of the time, and every " + + "recovery redelivers it again — which is the loop this fix exists to stop"); + assertTrue(channel.peek().isEmpty(), "so it is no longer held"); + } + @Test void leavesTheMessageUnackedWhenTheLeadIsMidTurn() { var channel = new FakeLeadChannel(SELF).hold(new LeadMessage("m1", PEER, SELF, "hello"));