Repository navigation
fix: run post execute hooks when stream_result fails before streaming - #968
Merged
elijahbenizzy merged 1 commit intoOct 17, 2026
Merged
Conversation
stream_result and astream_result called the pre execute hook before validating halt conditions and fast-forwarding, but only called the post hook on errors raised later. A failure in that early section left the LangfuseBridge root span and its propagate_attributes context attached. The early section now calls the post hook with the exception before re-raising.
elijahbenizzy
approved these changes
Oct 17, 2026
elijahbenizzy
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Checked that the success-path hook order is identical to main and the post hook fires once; the _run_call_var guard makes the except path safe. Thanks for the parametrized repro. Elijah
elijahbenizzy
enabled auto-merge (squash)
October 17, 2026 15:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes #967
stream_resultandastream_resultcall thepre_run_execute_callhook first, then process the control flow parameters, validate the halt conditions and fast-forward withrun(), but only the latertryblock calls the post hook on an error. When anything in that early section raised (an action failing during the fast-forward, or an unknownhalt_aftername),post_run_execute_callnever ran, soLangfuseBridgeleft its root span and its Langfusepropagate_attributescontext attached. Later spans in the same context landed in the failed call's trace with its session and user ids, and the same app's nextrun()emitted norunspan because the app id stayed registered.Changes
Application.stream_resultandApplication.astream_result, the section between the pre hook and the existingtryis wrapped so that an exception callscall_post/acall_postwith that exception and is then re-raised. This matches what a failingrun()already does. The rest of the diff inapplication.pyis the indentation that comes with the wrap.How I tested this
test_langfuse_bridge_stream_result_failure_closes_trace(parametrized over a failing fast-forward and an unknownhalt_aftername) andtest_langfuse_bridge_astream_result_failure_closes_tracetotests/integrations/test_burr_langfuse.py. They use the graph from the issue (a -> b, wherearaises) and check that thestream_resultroot span is ended with an error status, that no span is still current, that the Langfuse attribute context has been exited, and that the same app's nextrun()emits its ownrunroot with no parent. All three fail onmain(thestream_resultspan is never exported) and pass with the change.pytest tests/integrations/test_burr_langfuse.py: 12 passed.pytest tests/core: 396 passed, 4 failed, identical with and without the change. The 4 failures aretest_graphviz_display.py::test_visualize_dot_output, which needs the Graphvizdotexecutable that is not installed on my machine.Notes
The ordering in
stream_resultpredates the Langfuse integration, so any lifecycle hook that pairspre_run_execute_callwithpost_run_execute_call(for example the OpenTelemetry bridge) was also missing its post call on these failures.Checklist