breken-ai opened a new pull request, #937: URL: https://github.com/apache/burr/pull/937
Class-based actions can take the injected `__context` (or `__tracer`) as a `run` parameter, but that only works on the sync, non-streaming path. An `async def run(self, state, __context)` action, or a `StreamingAction` / `AsyncStreamingAction` whose `stream_run` takes `__context`, fails when it runs: ``` TypeError: AsyncActionWithContext.run() got an unexpected keyword argument '__context' TypeError: StreamingActionWithContext.stream_run() got an unexpected keyword argument '__context' ``` Inside a class body, Python name-mangles `__context` to `_ClassName__context`. #449 and #452 fixed this for `_run_function` by remapping the injected inputs to the mangled names with `_remap_dunder_parameters`. `_arun_function`, `_run_multi_step_streaming_action` and `_arun_multi_step_streaming_action` still pass `__context=` unchanged. ## Changes - `burr/core/application.py`: add a small `_remap_injected_inputs(method, inputs)` helper that wraps the existing check-and-remap from `_run_function`. Call it in `_run_function` (behavior unchanged), `_arun_function`, and the sync and async multi-step streaming runners, on `stream_run`. - Function-based actions are unaffected. Their `run` takes `**run_kwargs`, so no parameter name ends in `__context` and the inputs pass through unchanged. - `tests/core/test_application.py`: three end-to-end regressions that build an app with a class-based action reading `__context.app_id`. They go through `astep()`, `stream_result()` and `astream_result()`. ## How I tested this - On `main` (`8161159`), the three new tests fail with the `TypeError`s above. - With the fix, they pass. `pytest tests/core`: 403 passed (with the `graphviz` package installed; without it, only the existing graphviz display tests fail, the same as on `main`). - black 23.11.0 (`--line-length=100`), isort 5.12.0 and flake8 6.1.0 at the pre-commit pins are clean on the changed files. `git diff --check` is clean. ## Notes - The sync `run()` path has had the remap since late 2024 (#449 / #452). This change brings the async and streaming class APIs to parity. The single-step internal classes (`SingleStepAction`, `SingleStepStreamingAction`) are documented as not user-facing, so I left them alone to keep the change focused. ## 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 - [x] New functions are documented (with a description, list of inputs, and expected output) (`_remap_injected_inputs` is a private helper with a docstring) - [ ] Placeholder code is flagged / future TODOs are captured in comments (none added) - [ ] Project documentation has been updated if adding/changing functionality (no documented behavior changes; this makes the code match the existing `__context` docs) --- **AI disclosure (per the [ASF Generative Tooling guidance](https://www.apache.org/legal/generative-tooling.html)):** an AI coding tool (Claude Code, Claude Opus 5.5) wrote this change through the `breken-ai` account. The tool found the bug, wrote the fix and the tests, and wrote this description. The commit carries a `Generated-by:` trailer. The diff is a small original change to existing Burr code and includes no third-party material. The red/green runs above are real, and you can re-run them from the diff. If you would rather not take AI-assisted contributions here, say so and I will close this. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
