Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/praisonai/praisonai/bots/_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

logger = logging.getLogger(__name__)

# Constant for permanent error detection
PERMANENT_ERROR_PREFIX = "Permanent error:"


class MessageSender(Protocol):
"""Protocol for message sending implementations."""
Expand Down Expand Up @@ -329,7 +332,7 @@ async def deliver_with_retry(
logger.error(
f"[{platform}] Permanent delivery failure to {channel_id}: {e}"
)
return False, f"Permanent error: {last_error}"
return False, f"{PERMANENT_ERROR_PREFIX} {last_error}"

# Check if we're out of attempts
if attempt >= max_attempts:
Expand Down Expand Up @@ -509,7 +512,7 @@ async def send(
await self.outbox.mark_sent(key)
else:
# Check if permanent error
permanent = error and "Permanent error:" in error
permanent = error and error.startswith(PERMANENT_ERROR_PREFIX)
await self.outbox.mark_failed(key, error or "Unknown error", permanent=permanent)

return success
Expand Down Expand Up @@ -555,7 +558,7 @@ async def sender(target: str, payload: Dict[str, Any]) -> bool:
)

# Preserve permanent failure information
if not success and error and error.startswith("Permanent error:"):
if not success and error and error.startswith(PERMANENT_ERROR_PREFIX):
raise RuntimeError(error)

return success
Expand Down
26 changes: 26 additions & 0 deletions src/praisonai/tests/unit/bots/test_delivery_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Regression tests for durable delivery module wiring."""

import pytest


@pytest.mark.parametrize(
"attr",
["DurableDelivery", "deliver_with_retry", "deliver_chunked", "DurableAdapterMixin"],
)
def test_bots_package_exports_delivery_symbols(attr):
"""PR #2054 removed _delivery.py while exports still referenced it."""
import praisonai.bots as bots

assert hasattr(bots, attr)
assert getattr(bots, attr) is not None


def test_durable_adapter_imports_delivery_class():
from praisonai.bots._durable_adapter import DurableAdapterMixin
from praisonai.bots._delivery import DurableDelivery

mixin = DurableAdapterMixin()
mixin.setup_durable_delivery(outbox_path=None, platform="test")
assert mixin.durable_delivery is None

assert DurableDelivery is not None
Loading