Skip to content

Improve typing for wake event payloads #4518

Description

@KyleAMathews

Problem

WakeEvent currently exposes payload?: unknown, so handlers that react to specific wake kinds have to use ad-hoc casts before accessing structured payloads.

This came up in examples/agents-walkthrough, where child-completion wakes carry a payload like:

{
  finished_child: FinishedChild
}

But the handler can only see wake.payload?: unknown, so precise code either repeats casts or uses optional/defensive access:

const finishedChild = (
  wake.payload as { finished_child?: FinishedChild } | undefined
)?.finished_child

That avoids type errors, but it is not ideal: it obscures the contract for child-completion wakes and makes examples less clear.

Desired direction

Provide stronger / discriminated typing for wake events and wake payloads, especially for runtime-generated wake kinds such as child run completion.

Possible approaches:

  • Make WakeEvent a discriminated union for known runtime wake kinds.
  • Export canonical payload types, e.g. FinishedChildWakePayload / ChildRunFinishedWakeEvent.
  • Provide helper/narrowing functions, e.g. isFinishedChildWake(wake) or getFinishedChild(wake).
  • Ensure examples and docs can access structured wake payloads without local casts.

Acceptance criteria

  • Child-completion wake handlers can access finished_child with precise types.
  • Existing generic/custom wake payload use cases remain supported.
  • Examples avoid repeated as { ... } casts for known runtime wake payloads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions