digit50 opened a new pull request, #968: URL: https://github.com/apache/burr/pull/968
closes https://github.com/apache/burr/issues/967 `stream_result` and `astream_result` call the `pre_run_execute_call` hook first, then process the control flow parameters, validate the halt conditions and fast-forward with `run()`, but only the later `try` block calls the post hook on an error. When anything in that early section raised (an action failing during the fast-forward, or an unknown `halt_after` name), `post_run_execute_call` never ran, so `LangfuseBridge` left its root span and its Langfuse `propagate_attributes` context 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 next `run()` emitted no `run` span because the app id stayed registered. ## Changes - In `Application.stream_result` and `Application.astream_result`, the section between the pre hook and the existing `try` is wrapped so that an exception calls `call_post` / `acall_post` with that exception and is then re-raised. This matches what a failing `run()` already does. The rest of the diff in `application.py` is the indentation that comes with the wrap. - No change to the Langfuse bridge itself. ## How I tested this - Added `test_langfuse_bridge_stream_result_failure_closes_trace` (parametrized over a failing fast-forward and an unknown `halt_after` name) and `test_langfuse_bridge_astream_result_failure_closes_trace` to `tests/integrations/test_burr_langfuse.py`. They use the graph from the issue (`a -> b`, where `a` raises) and check that the `stream_result` root 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 next `run()` emits its own `run` root with no parent. All three fail on `main` (the `stream_result` span 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 are `test_graphviz_display.py::test_visualize_dot_output`, which needs the Graphviz `dot` executable that is not installed on my machine. - The reproduction script from the issue now prints the expected output for all three cases. ## Notes The ordering in `stream_result` predates the Langfuse integration, so any lifecycle hook that pairs `pre_run_execute_call` with `post_run_execute_call` (for example the OpenTelemetry bridge) was also missing its post call on these failures. ## Checklist - [x] PR has an informative and human-readable title (this will be pulled into the release notes) - [x] Changes are limited to a single goal (no scope creep) - [x] Code passed the pre-commit check & code is left cleaner/nicer than when first encountered. - [x] Any _change_ in functionality is tested - [ ] New functions are documented (with a description, list of inputs, and expected output) - [ ] Placeholder code is flagged / future TODOs are captured in comments - [ ] Project documentation has been updated if adding/changing functionality. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
