Fix snapshot events being dropped after trigger lifecycle hooks #3434
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a trigger mutates state in
__on_workflow_fulfilled__(e.g.,ChatMessageTriggerappending the assistant message tochat_history), the snapshottable list pushes aWorkflowExecutionSnapshottedEventonto_workflow_event_inner_queue. Previously, these events were dropped because the inner queue was not drained after the trigger hook. This fix adds draining of the inner queue after__on_workflow_fulfilled__to ensure snapshot events are forwarded to the outer queue and observable by stream consumers (when usingall_workflow_event_filter).Note: Draining after
__on_workflow_initiated__is not needed because those snapshot events are already processed by the main event loop before it exits.Review & Testing Checklist for Human
__on_workflow_fulfilled__doesn't introduce event ordering issues - snapshot events should appear before the fulfilled event__on_workflow_initiated__is correct - the test assertssnapshot_events[0]contains just the user message, which could be brittle if event ordering changesChatMessageTriggerand verify both snapshot events (user message and assistant message) are visible when streaming withall_workflow_event_filterTest Plan:
Notes
The default
workflow_event_filterintentionally excludes snapshot events - consumers must useall_workflow_event_filteror a custom filter to observe them.