xihaian251 opened a new pull request, #1008:
URL: https://github.com/apache/burr/pull/1008
`stream_result()` and `astream_result()` process the action inputs twice
when the action matched by `halt_after` is not a streaming action: they build
`action_inputs` before branching, then delegate to `_step()` / `_astep()`,
which process the same inputs again. An injected dependency such as `__context`
or `__tracer` is constructed twice per step, and the instance built by the
streaming entry point is discarded.
Fixes #1007
## Changes
- `burr/core/application.py`: move the `_process_inputs()` call into the
streaming branch in both `stream_result()` and `astream_result()`. The
non-streaming path already delegates to a function that processes inputs, so it
now processes them exactly once. The `action_inputs` value was previously
computed and then unused on that path.
- `tests/core/test_stream_input_processing.py`: one parametrised regression
test asserting the `__context` factory runs exactly once for both entry points.
Fails 2/2 on `main`, passes 2/2 here.
Ordering on the streaming path is unchanged: `_process_inputs()` still runs
before `pre_start_stream`, and the generators receive the same `action_inputs`
as before.
## How I tested this
On `main` at `6741dac2`, Python 3.12.14 and 3.13.14 (identical results):
```text
$ pytest tests/core/test_stream_input_processing.py -q
# before
FAILED
tests/core/test_stream_input_processing.py::test_streaming_entry_point_injects_dependency_once[stream_result]
FAILED
tests/core/test_stream_input_processing.py::test_streaming_entry_point_injects_dependency_once[astream_result]
E AssertionError: __context should be injected once per step
E assert 2 == 1
# after
2 passed
```
Full core suite, same environment:
```text
$ pytest tests/core -q
# this branch, before the fix (main + the new test file)
11 failed, 425 passed # 9 pre-existing graphviz failures + the 2 new ones
# this branch, after the fix
9 failed, 427 passed # only the pre-existing graphviz failures remain
```
The 9 remaining failures are all `tests/core/test_graphviz_display.py` and
are unrelated (no graphviz binary in this environment); they fail identically
on unpatched `main`.
`black --line-length=100`, `isort --profile black --line-length=100 -p burr`
and `flake8` (with the repo's `setup.cfg`) pass on both changed files.
## Notes
- **One observable side effect, only on `main` as it stands.** A
missing-required-input error raised through `astream_result()` additionally
emits the standard `astep()` ERROR log line, because the error now surfaces
from `_astep()` rather than from `stream_result()`'s own `_process_inputs()`
call. Exception type, message and hook sequence are unchanged. On top of #980
or #995 the extra line does not appear: both move `_process_inputs()` ahead of
`_astep()`'s `try` block, so nothing is logged. Measured: `main` 0 → 1, `#980`
0 → 0, `#995` (7a58bba5) 0 → 0.
- **Lifecycle hooks are unchanged.** Measured `pre_run_step` /
`post_run_step` / `pre_start_stream` / `post_end_stream` counts before and
after the patch, over both entry points and both the success and missing-input
paths: 4 cases × 4 counters = 16 values, zero differences.
- **Independent of #999 / #1000.** This does not touch the `post_end_stream`
pairing. Applying this patch on top of #1000 leaves #1000's behaviour intact
(`post_end_stream` still fires only for streams that started), and `tests/core`
shows no new failures there.
- **Independent of #979.** This does not change what `pre_run_step`
receives. #980 and #995 address that; the reproduction here still fails on both
of those branches.
- **Applies cleanly on #908 and on the current #995.** #908 changes how
`iterate` / `stream_iterate` pass inputs to subsequent steps and does not
modify these two functions; `git apply` succeeds on `52eef27d` and the new
tests pass there. The same holds on `7a58bba5`, the current head of #995.
## Checklist
- [x] PR has an informative and human-readable title
- [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 — N/A, no new functions
- [ ] Placeholder code is flagged / future TODOs are captured in comments —
N/A
- [ ] Project documentation has been updated if adding/changing
functionality — N/A, this restores the documented behaviour rather than
changing the API
---
<sub>Disclosure: this patch and the accompanying test were prepared with AI
assistance, then reviewed and
verified by me. Every result under "How I tested this" comes from actual
local runs on `6741dac2` with
Python 3.12.14 and 3.13.14, not projections. I can provide the full pytest
output or re-run any step on
request.</sub>
--
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]