Repository navigation
fix(gateway): preserve email attachment boundaries - #72674
HeyBobChan wants to merge 1 commit into
Conversation
Related: #65522 preserves all busy-session media events in FIFO order. This PR instead makes boundary preservation Email-specific while retaining album behavior elsewhere; the policy difference needs maintainer selection or consolidation, not a duplicate label. |
|
Thanks — I compared #65522 closely. This PR deliberately scopes FIFO media preservation behind an adapter capability because the sweeper review on #65522 correctly identified Telegram photo-burst/album merging as an established contract. The tests here cover both sides explicitly:
Current |
eb4bf14 to
85da555
Compare
|
Rebased cleanly onto current This boundary fix is the remaining blocker for safely enabling email attachment intake in a downstream production Hermes deployment; we will wait for an official release rather than pin a fork. Could a maintainer please make the queued-media policy decision and, if accepted, include it in a |
85da555 to
a478106
Compare
|
Rebased cleanly onto current Fresh verification on the rebased head:
All passed. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating Email's complete-message semantics without changing the default album behavior. The premise is confirmed on current main: Email images become PHOTO events at plugins/platforms/email/adapter.py:856-864, and busy-session merging at gateway/platforms/base.py:5694-5700 / gateway/platforms/base.py:2460-2485 folds later media into the first event.
Problems
- The added tests do not invoke the two runner paths changed by this PR: the direct active-agent PHOTO route (
gateway/run.py:14021-14026) and pending-agent-sentinel route (gateway/run.py:14069-14077). Helper-only tests would not catch a future bypass of the boundary-preserving queue contract.
Suggested changes
- Add active-Email-session regressions through
GatewayRunner._handle_messagefor those paths, asserting distinct RFC Message-IDs,SessionSourcevalues, media, and FIFO order. - Salvage the queue restoration against the current SessionState queue API (
gateway/run.py:7330-7365), introduced after this PR's base.
Automated hermes-sweeper review.
| @@ -11579,9 +11609,7 @@ async def _handle_message(self, event: MessageEvent) -> Optional[str]: | |||
|
|
|||
| if event.message_type == MessageType.PHOTO: | |||
| logger.debug("PRIORITY photo follow-up for session %s — queueing without interrupt", _quick_key) | |||
There was a problem hiding this comment.
Please add an end-to-end active-session Email regression through _handle_message here (including the pending-agent sentinel). The added tests cover _queue_or_replace_pending_event and the base fallback, but do not execute this direct priority path.
What does this PR do?
Preserves native message boundaries for adapters such as Email whose media-bearing events are already complete messages.
Before this change, two emails arriving from the same sender while a turn was busy could be merged into one pending event. The merged event retained the first email's Message-ID and source while appending the later email's text and attachments. A downstream hook therefore could not determine which attachment belonged to which RFC message.
This adds a generic, default-off adapter capability:
Email opts in. Busy-session queueing then uses the existing FIFO instead of album merging. Telegram and every other adapter retain their current default media-burst behavior.
The fix also closes sibling bypasses in the base-adapter fallback, the direct running-agent PHOTO/sentinel paths, and the recursion-depth reset. The latter had a broader FIFO bug: after five or more queued events it could merge/reorder media or overwrite text while resetting recursion depth.
Email now also binds its RFC Message-ID onto
SessionSource, matching theMessageEvent.Related Issue
No matching issue or PR was found after searching open and closed results for email attachment merging and busy-session media queues.
Type of Change
Changes Made
SessionSource.message_idfor Email.How to Test
Result: 134 tests passed; Ruff and
git diff --checkpassed on macOS.The full repository suite was also started through
scripts/run_tests.sh, but this minimal local dev environment lacks the optionalacppackage and produced unrelated existing credential-test failures. The affected gateway suites above are clean.Checklist
Code
pytest tests/ -qin a complete all-extras environmentDocumentation & Housekeeping
cli-config.yaml.example— N/A; no user configuration keyCONTRIBUTING.md/AGENTS.md— N/A; existing generic architecture retained