xihaian251 commented on PR #1033:
URL: https://github.com/apache/burr/pull/1033#issuecomment-6708064467
Hi maintainers — this is a follow-up to #1027 (early close), already merged
as
36e3ff30. I found two gaps in the streaming containers' `finally` and would
appreciate a review.
1. A *successful* streaming step can be persisted as `failed`.
`sys.exc_info()[1]`
inside `StreamingResultContainer.__iter__` /
`AsyncStreamingResultContainer.__aiter__`
reads thread state, so if the caller is inside an `except` block while
consuming
the stream, that unrelated exception becomes the step's `exception=`.
`PersisterHook` then writes `failed`, and resume re-runs the action. With
a
non-idempotent action the side effect happens twice (SQLite repro:
`count` 1 -> 2).
`stream_iterate` marks every step in the chain failed the same way.
2. A hook raising a plain `Exception` from that same `finally` replaces the
action's real exception and truncates `post_end_stream` / execute-method
post.
Truncating `post_end_stream` is not just a missing log line:
`LocalTrackingClient`
releases its per-stream state only there, so the entry leaks and the
tracking
log gets an `initialize_stream` with no matching `end_stream`. I measured
both
directions on a successful step with one failing `post_run_step` hook.
The patch records the iterator's own exception via its `except` clauses,
keeps the
step's error when a hook fails (hook `BaseException` still propagates), and
lets
the remaining lifecycle callbacks run. `close()` / `aclose()` are untouched
— four
regression cases pin #1027's early-stop contract.
On the async close race we discussed last time: I can now reproduce it
deterministically. Hold `aclose()` inside the action's cleanup, let the
iterator's
`GeneratorExit` handler park on `asyncio.wait([_close_future])`, then cancel
that
finalizer task. `main` reports the caller's `CancelledError` to
`post_run_step`;
with the patch it reports `GeneratorExit`, which is what `aclose`'s own
docstring
and #1027 promise. Persisted status is `failed` on both, cleanup runs once,
no
unhandled task exceptions. It is pinned by a new test — so this is a
contract fix,
not a behaviour regression, and I have written it up as a behaviour change
anyway.
Verification on `36e3ff30` (all re-run this round, no inherited numbers):
the 30
regression cases go 19 failed/11 passed -> 30 passed on **3.10.22, 3.11.16,
3.12.14
and 3.13.14**; `tests/core` goes 473 -> 503 passed on both 3.10.22 and
3.13.14; the
full suite's failure list is identical before and after (15 pre-existing
environment
failures) with exactly +30 passed; 16 mutation targets all killed; pinned
black/isort/flake8 + ASF header pass; `git apply --check` on a clean
36e3ff30 tree
passes, and applying the patch file itself and re-running gives 30 passed on
all
four versions.
Three things I want to flag rather than hide:
* I could not run CI's exact `pytest tests` command locally — 8 optional
integration
extras aren't installed. The PR body states exactly which files were
excluded.
* I am deliberately not fixing four pre-existing issues in this PR: a failing
`post_run_step` still blocks later `post_run_step` hooks in
`lifecycle/internal.py`; cancelling the consumer *during* reporting still
skips
`post_end_stream`; a persister error still changes the caller-visible
exception;
and — found while checking coverage — `stream_result` halting at a
**non-streaming** action dispatches `post_run_step` twice when a hook
fails, the
second time with the hook's own exception as the step's, so the tracker
records
the step twice with the second entry marked failed. All four behave
identically
on `main` and with the patch. I have a minimal repro for the last one and
can
file them as separate issues if you agree with the direction.
* #1000 / #1016 ("only end a stream that was actually started") guard the
outer
error path in `astream_result` so a stream that never started is not
ended; this
PR makes sure a stream that *did* start is not skipped. Same pairing
contract,
opposite side, no textual overlap. #1032 (`_astep` cancellation) and #897
(execute-hook wrappers) are also untouched; I'll rebase if they land first.
The contributor used WorkBuddy AI (Tencent Hunyuan Hy) for analysis and
drafting;
all code, reproductions and verification were reviewed locally, and the
disclosure
is in the PR body. Happy to add a `Generated-by:` commit trailer per the ASF
generative tooling guidance if you'd like one.
--
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]