rohitg00/ai-engineering-from-scratch · error · EventStreamError

persisted events need a non-empty id

Error message

persisted events need a non-empty id

What it means

Error "persisted events need a non-empty id" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at certifications/claude/lessons/12-claude-agent-sdk-and-hooks/code/main.py:68

    messages: list[str] = []
    preview_parts: list[str] = []
    actionable: set[str] = set()
    pending: set[str] = set()
    seen: set[str] = set()
    last_event_id: str | None = None

    for event in events:
        if not isinstance(event, dict) or not isinstance(event.get("type"), str):
            raise EventStreamError("every event needs a type")
        event_type = event["type"]
        if event_type in {"event_start", "event_delta"}:
            if event_type == "event_delta" and isinstance(event.get("text"), str):
                preview_parts.append(event["text"])
            continue

        event_id = event.get("id")
        if not isinstance(event_id, str) or not event_id:
            raise EventStreamError("persisted events need a non-empty id")
        if event_id in seen:
            continue
        seen.add(event_id)
        last_event_id = event_id

        if event_type == "session.status_running":
            status = "running"
            stop_reason = None
        elif event_type == "agent.message":
            content = event.get("content", [])
            if not isinstance(content, list):
                raise EventStreamError("agent.message content must be a list")
            messages.append(
                "".join(
                    str(block.get("text", ""))
                    for block in content
                    if isinstance(block, dict) and block.get("type") == "text"
                )

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at certifications/claude/lessons/12-claude-agent-sdk-and-hooks/code/main.py:68 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/8c7d282a80efdea9. Report an issue: GitHub.