xihaian251 opened a new pull request, #1000:
URL: https://github.com/apache/burr/pull/1000

   Fixes #999.
   
   `Application.astream_result` calls `post_end_stream` from its error path, 
but the
   callback is only meaningful after `pre_start_stream` has run. That ordering 
does not
   hold in two cases:
   
   * the halt action is **not streaming** — the `if not next_action.streaming` 
branch
     delegates to `_astep` and returns early on success, so `pre_start_stream` 
never runs;
   * input processing fails before the streaming phase.
   
   Hooks that keep per-stream state cannot pair the callback. 
`LocalTrackingClient` and
   `S3TrackingClient` index `self.stream_state[app_id, action, partition_key]`, 
which only
   `pre_start_stream` populates, so `post_end_stream` raises `KeyError` from 
inside the
   `except` block and replaces the exception the application raised:
   
       tracked=False: ValueError: original failure
       tracked=True:  KeyError: ('<app_id>', 'fail', None)
   
   Net effect: attaching a tracker changes which exception the caller sees.
   
   ## Changes
   
   * track whether `pre_start_stream` completed, and only call 
`post_end_stream` from the
     error path when it did;
   * add a core test that a failing non-streaming action does not fire 
`post_end_stream`
     without `pre_start_stream`;
   * add a tracking test that a failing action keeps its original exception with
     `LocalTrackingClient` attached.
   
   ## Semantics of the guard
   
   `stream_started` is set only after the `pre_start_stream` hook call returns, 
so a hook
   that raises during initialization is not followed by `post_end_stream`. The 
alternative
   (set it before the call, so every adapter is paired even on partial 
initialization) is
   also defensible; I picked "post only for a completed pre" because it 
guarantees the
   error path can never mask the original exception. Happy to switch if you 
prefer the
   other contract.
   
   ## How I tested this
   
   * new tests: `2 passed`
   * `tests/core/test_application.py`: `143 passed` (142 before)
   * `tests/tracking/test_local_tracking_client.py`: `18 passed` (17 before)
   * black 23.11.0 `--line-length=100`, isort 5.12.0 (`--profile black`), 
flake8 6.1.0:
     clean on the three changed files
   * verified that both new tests fail on `8bfd7268` without the source change
   
   Not run: the full pre-commit suite (frontend lint needs npm), and the whole 
`tests/`
   tree. Linux / Python 3.9–3.12 not tested (local environment: Windows 11, 
Python 3.13.1).
   
   ## Notes
   
   * `S3TrackingClient.post_end_stream` has the same lookup; it is covered by 
the same fix.
   * `stream_result` (sync) does not call `post_end_stream` from its error 
path, so it never
     had this masking problem — the async twin was the outlier.
   * This is independent of #979 / #980 / #995: the code path is untouched by 
those PRs.
   


-- 
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]

Reply via email to