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

session emitted an error event

Error message

session emitted an error event

What it means

Error "session emitted an error event" thrown in rohitg00/ai-engineering-from-scratch.

Source

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

            reason = event.get("stop_reason")
            if not isinstance(reason, dict) or reason.get("type") not in {"requires_action", "end_turn"}:
                raise EventStreamError("idle status needs a supported stop_reason")
            stop_reason = reason["type"]
            if stop_reason == "requires_action":
                event_ids = reason.get("event_ids")
                if not isinstance(event_ids, list) or not event_ids or not all(
                    isinstance(item, str) and item in actionable for item in event_ids
                ):
                    raise EventStreamError("requires_action must reference known actionable event IDs")
                pending = set(event_ids)
            else:
                pending.clear()
        elif event_type == "session.status_terminated":
            status = "terminated"
            stop_reason = "terminated"
            pending.clear()
        elif event_type == "session.error":
            raise EventStreamError("session emitted an error event")

    complete = status == "terminated" or (status == "idle" and stop_reason == "end_turn")
    return EventSummary(
        status=status,
        stop_reason=stop_reason,
        messages=messages,
        pending_action_ids=sorted(pending),
        last_event_id=last_event_id,
        preview_text="".join(preview_parts),
        complete=complete,
    )


def validate_policy(policy: dict[str, Any]) -> list[str]:
    errors: list[str] = []
    tools = policy.get("tools")
    if not isinstance(tools, list) or not tools:
        return ["tools must be non-empty"]

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at certifications/claude/lessons/12-claude-agent-sdk-and-hooks/code/main.py:115 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/316f15a43dd88b26. Report an issue: GitHub.