fix(hermes-plugin): an image-only reply left its turn running forever
Live repro (2026-07-27 21:26): "send it one more time" produced a reply that was just the image — no text. Upstream notify-marks every send of a reply's final delivery batch, text and media alike, but only the text path honored the mark; with no text send there was nothing to complete the turn, and the thread sat "Working" until the liveness timeout. The media path now honors the same notify-completion contract, guarded to the still-live turn: in the common text-then-media ordering the text completes the turn first, and re-completing the recent-turn entry the media scopes to would emit a second terminal frame for a turn T3 already folded (its conflict gate rejects those). Two regression tests pin the pair: image-only completes exactly once, text-then-media still emits a single turn.completed. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
77ff1ee304
commit
3d0459539d
2 files changed
+71
No files matched your search
@@ -731,6 +731,21 @@ class T3PlatformAdapter(BasePlatformAdapter):
|
||||
delivery_id_value,
|
||||
exc,
|
||||
)
|
||||
# The same notify-completion contract `send()` honors for text. The
|
||||
# base adapter notify-marks every send of a reply's FINAL delivery
|
||||
# batch (`_mark_notify_metadata`, `gateway/platforms/base.py:5220`) —
|
||||
# text and media alike — and an image-only reply produces no text
|
||||
# send at all, so this is the only place its turn can complete.
|
||||
# Guarded to the still-live turn: the common text-then-media ordering
|
||||
# completes the turn on the text, and re-completing a `_recent_turns`
|
||||
# entry would emit a second `turn.completed` for a turn T3 already
|
||||
# folded.
|
||||
if (
|
||||
turn is not None
|
||||
and bool((metadata or {}).get("notify"))
|
||||
and self._active_turns.get(thread_id) is turn
|
||||
):
|
||||
await self._complete_turn(turn)
|
||||
return SendResult(success=True, message_id=delivery_id_value)
|
||||
|
||||
async def send_image_file(
|
||||
|
||||
@@ -2339,6 +2339,62 @@ class MediaDeliveryTests(unittest.IsolatedAsyncioTestCase):
|
||||
# The completed turn is not resurrected by claiming its media.
|
||||
self.assertNotIn(thread, self.adapter._active_turns)
|
||||
|
||||
async def test_an_image_only_reply_completes_its_turn(self):
|
||||
"""Live repro 2026-07-27 21:26: "send it one more time" → image, no text.
|
||||
|
||||
Upstream notify-marks every send of a reply's final delivery batch —
|
||||
text AND media (`_mark_notify_metadata`, base.py:5220) — but a reply
|
||||
that is only an image produces no text send, so the media send is the
|
||||
only carrier of the completion signal. Without honoring it, the turn
|
||||
sat "Working" until the two-minute liveness timeout.
|
||||
"""
|
||||
thread = "thread-image-only-reply"
|
||||
await self._start_turn(thread, "turn-image-only")
|
||||
frames_before = len(self.connection.messages)
|
||||
|
||||
result = await self.adapter.send_image_file(
|
||||
thread,
|
||||
str(self.chart),
|
||||
caption=None,
|
||||
metadata={"thread_id": thread, "notify": True},
|
||||
)
|
||||
|
||||
self.assertTrue(result.success)
|
||||
frames = self.connection.messages[frames_before:]
|
||||
# `_complete_turn` also republishes connection.status; the contract
|
||||
# here is the ORDER media -> completed, not the exact frame set.
|
||||
types = [frame["type"] for frame in frames]
|
||||
self.assertEqual(types[:2], ["media.deliver", "turn.completed"])
|
||||
self.assertEqual(frames[0]["turnId"], "turn-image-only")
|
||||
self.assertEqual(frames[1]["turnId"], "turn-image-only")
|
||||
self.assertNotIn(thread, self.adapter._active_turns)
|
||||
|
||||
async def test_trailing_media_does_not_recomplete_a_closed_turn(self):
|
||||
"""The text-then-media ordering must emit exactly one turn.completed.
|
||||
|
||||
The text completes the turn; the file's own notify mark must not
|
||||
re-complete the `_recent_turns` entry it scopes to — T3 already
|
||||
folded the turn, and a second terminal frame names a turn its
|
||||
conflict gate would reject.
|
||||
"""
|
||||
thread = "thread-text-then-media"
|
||||
await self._start_turn(thread, "turn-text-media")
|
||||
await self.adapter.send(
|
||||
thread, "Here it is.", metadata={"thread_id": thread, "notify": True}
|
||||
)
|
||||
frames_before = len(self.connection.messages)
|
||||
|
||||
result = await self.adapter.send_image_file(
|
||||
thread,
|
||||
str(self.chart),
|
||||
caption=None,
|
||||
metadata={"thread_id": thread, "notify": True},
|
||||
)
|
||||
|
||||
self.assertTrue(result.success)
|
||||
frames = self.connection.messages[frames_before:]
|
||||
self.assertEqual([frame["type"] for frame in frames], ["media.deliver"])
|
||||
|
||||
async def test_media_long_after_a_turn_closed_does_not_claim_it(self):
|
||||
"""Recency is what bounds the reach-back, so an old turn must not claim.
|
||||
|
||||
|
||||
Reference in new issue
Block a user