Skip to content

Clarify partial=None semantics for on_event_callback replacements #8063

Open

Description

@Bruce-Yii

Following the discussion in #7455, I checked how Runner.on_event_callback handles a replacement Event whose partial field is explicitly set to None.

This is a contract question, not a proposed behavior change.

What happens today

In Runner._get_output_event, fields present in the replacement event's model_fields_set are copied onto the original event. An explicit partial=None therefore replaces an original partial=True.

The Runner then uses the resulting event's partial value to decide whether to append it to the session. Since None is not True, the fragment is treated as non-partial.

Reproduction

With an SSE fake model that emits a fragment (partial=True) followed by its completed response (partial=None), use an on_event_callback plugin that replaces the fragment:

async def on_event_callback(*, invocation_context, event):
    if event.partial is True:
        return event.model_copy(update={"partial": None})
    return None

A real Runner + in-memory session reproduction produced:

EMITTED partials: [None, None]
PERSISTED count: 2 partials: [None, None]

The characterization run used baseline 75fc853. The current main branch's runners.py blob is unchanged from that baseline (84a6b25e79d58538d906ab3bf84f506c6e828782).

Existing behavior to preserve

The Runner tests already cover intentional overrides in both directions:

  • partial=True → False: the transformed event is persisted (test_callback_downgraded_partial_event_is_persisted).
  • partial=False → True: the transformed event is not persisted (test_callback_upgraded_partial_event_is_not_persisted).

This issue is not proposing to remove either behavior.

Question for the callback owners

For an on_event_callback replacement, should an explicit partial=None:

  1. be treated as unset and inherit the source event's partial value, with False remaining the explicit final marker; or
  2. remain an intentional override, as it does today?

In the follow-up on #7455, the maintainer leaned toward the first option and suggested asking the callback owners to decide this together with the after_model_callback behavior.

Could the callback owners confirm the intended contract before any runtime change is made?

Scope

This issue is limited to Event.partial on Runner.on_event_callback replacements.

  • #8005 covers the separate after_model_callback path.
  • #7184 / #7185 fixed persistence classification using the effective post-callback event. This issue is about the meaning of an explicit None on that effective event.

No runtime fix is proposed until the callback contract is confirmed.

Activity

  1. added
    core[Component] This issue is related to the core interface and implementation
    on Nov 17, 2026
  2. llalitkumarrr commented on Nov 17, 2026

    @llalitkumarrr
    Collaborator

    Hello @Bruce-Yii,

    Thank you for raising this issue. Setting partial=None in the callback can simply be omitted in which case partial from the original event is preserved and won't cause this problem, so passing partial=None is more like an error in the callback implementation.

    However just to error proof this, we can go with Option 1 where the original event's partial is not overwritten when partial=None is set on the replacement event in the callback. You are welcome to pursue this approach, though please keep in mind that the PR will still go through review and the reviewer may decide whether or not to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

core[Component] This issue is related to the core interface and implementation

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions