HKUDS/Vibe-Trading · error · ValueError

unknown delivery status {raw_status!r}

Error message

unknown delivery status {raw_status!r}

What it means

Raised by ScheduledRun delivery from_dict (agent/src/scheduled_research/models.py:279) when the delivery 'status' field is not one of the recognized DeliveryStatus enum values. from_dict maps the raw value through DeliveryStatus(raw_status) and any unknown string or wrong type fails the enum lookup, re-raising as ValueError with the offending value.

Source

Thrown at agent/src/scheduled_research/models.py:279

            data: A raw dict as produced by :meth:`to_dict`, or ``None`` for a
                record written before delivery existed.

        Returns:
            The reconstructed :class:`DeliveryRecord`.

        Raises:
            TypeError: If a present field has the wrong type.
            ValueError: If ``status`` is not a recognized value.
        """
        if not data:
            return cls()
        if not isinstance(data, dict):
            raise TypeError("'delivery' must be an object or null")
        raw_status = data.get("status", DeliveryStatus.NONE.value)
        try:
            status = DeliveryStatus(raw_status)
        except ValueError as exc:
            raise ValueError(f"unknown delivery status {raw_status!r}") from exc
        for name in ("session_id", "key", "error", "provider_message_id"):
            value = data.get(name)
            if value is not None and not isinstance(value, str):
                raise TypeError(f"'delivery.{name}' must be a string or null")
        updated_at = data.get("updated_at")
        if updated_at is not None and not isinstance(updated_at, int):
            raise TypeError("'delivery.updated_at' must be an integer (epoch ms) or null")
        attempts = data.get("attempts", 0)
        if isinstance(attempts, bool) or not isinstance(attempts, int) or attempts < 0:
            raise TypeError("'delivery.attempts' must be a non-negative integer")
        return cls(
            status=status,
            session_id=data.get("session_id"),
            key=data.get("key"),
            error=data.get("error"),
            attempts=attempts,
            updated_at=updated_at,
            provider_message_id=data.get("provider_message_id"),

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Use exact enum values (check DeliveryStatus members, e.g. 'none', lowercase forms)
  2. Normalize case and mapping in your writer before persisting
  3. Align reader/writer versions so both know the same status set
  4. Reset the field to the default by omitting 'status' from the stored delivery object

Example fix

// before
delivery = {"status": "SENT", "session_id": sid}

// after
delivery = {"status": "sent", "session_id": sid}  # exact enum value
Defensive patterns

Strategy: validation

Validate before calling

from agent.src.scheduled_research.models import DeliveryStatus

def valid_status(value):
    try:
        DeliveryStatus(value)
        return True
    except ValueError:
        return False

Type guard

from agent.src.scheduled_research.models import DeliveryStatus

def coerce_status(raw):
    """Return a valid DeliveryStatus or the NONE default."""
    try:
        return DeliveryStatus(raw)
    except ValueError:
        return DeliveryStatus.NONE

Try / catch

try:
    delivery = DeliveryInfo.from_dict(raw)
except ValueError as exc:
    if "unknown delivery status" in str(exc):
        raw = dict(raw); raw["status"] = DeliveryStatus.NONE.value
        delivery = DeliveryInfo.from_dict(raw)
    else:
        raise

Prevention

When it happens

Trigger: Passing delivery = {"status": "SENT"} (wrong case), {"status": "delivered"}, {"status": 1}, or a newly added status from a newer version being read by an older version. Default when status is absent is DeliveryStatus.NONE, which always succeeds.

Common situations: Version skew where a newer writer persists a status the reader's enum doesn't know; hand-edited store files; case mismatches from mapping provider states (e.g. 'sent'/'queued') to internal statuses without normalizing.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/40d40c4b04ef8131. Report an issue: GitHub.