Skip to content

fix: Populate context_view in COMPONENT_PRE_EXECUTE payload#941

Open
araujof wants to merge 1 commit intogenerative-computing:mainfrom
araujof:fix/940_plugins
Open

fix: Populate context_view in COMPONENT_PRE_EXECUTE payload#941
araujof wants to merge 1 commit intogenerative-computing:mainfrom
araujof:fix/940_plugins

Conversation

@araujof
Copy link
Copy Markdown
Contributor

@araujof araujof commented Apr 26, 2026

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

Summary

  • Fix COMPONENT_PRE_EXECUTE delivering None for payload.context_view by passing context.as_list() when constructing the payload in aact()
  • Add tests verifying the field is populated for both non-empty and empty contexts

Changes

mellea/stdlib/functional.py

  • Added context_view=context.as_list() to the ComponentPreExecutePayload constructor in aact()

test/plugins/test_hook_call_sites.py

  • test_component_pre_execute_payload_has_context_view — non-empty context produces a populated list
  • test_component_pre_execute_empty_context_gives_empty_list — fresh context gives [], not None

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Test plan

  • uv run pytest test/plugins/test_hook_call_sites.py -v -k component_pre_execute — all tests pass
  • uv run pytest test/plugins/test_all_payloads.py -v — no regression
  • uv run ruff check / ruff format — clean

Attribution

  • AI coding assistants used

Related

Part of #920.

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
@araujof araujof requested a review from a team as a code owner April 26, 2026 13:34
@github-actions github-actions Bot added the bug Something isn't working label Apr 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

The PR description has been updated. Please fill out the template for your PR to be reviewed.

@araujof
Copy link
Copy Markdown
Contributor Author

araujof commented Apr 26, 2026

cc: @nrfulton @jakelorocco

@psschwei
Copy link
Copy Markdown
Member

I also had a fix for this in #921 - we can merge either PR, doesn't matter to me.
For comparison, I had gone with using context.view_for_generation() rather than .as_list() (which I would still recommend doing)
This PR has the better tests.

@araujof
Copy link
Copy Markdown
Contributor Author

araujof commented Apr 27, 2026

I also had a fix for this in #921 - we can merge either PR, doesn't matter to me. For comparison, I had gone with using context.view_for_generation() rather than .as_list() (which I would still recommend doing) This PR has the better tests.

Thanks @psschwei . I wasn't sure what method to use, and decided to go with as_list as it would show non empty views for stateless SimpleContext.

backend = _MockBackend()
ctx = SimpleContext.from_previous(SimpleContext(), CBlock("prior turn"))
action = Instruction("Context view test")
await aact(action, ctx, backend, strategy=None)

If the correct behavior is to return an empty view in this case, we could change it to use .view_for_generation(). In this case, we would need to update unit test test_component_pre_execute_payload_has_context_view to reflect that SimpleContext.view_for_generation() always returns [] (by design, it's stateless, no history sent to the model).

@jakelorocco any thoughts? Happy to merge #921 into this PR if view_for_generation() is right approach here.

I could be wrong, but if we are using view_for_generation, couldn't one just use the generation hook? Maybe, at the component hook, one would want to have the complete context? I defer to the Mellea experts on this one :)

@psschwei
Copy link
Copy Markdown
Member

psschwei commented Apr 27, 2026

My thought with using view_for_generation was just to mirror what the model sees, but I don't have super strong opinions here and will defer to you and @jakelorocco

Copy link
Copy Markdown
Contributor

@planetf1 planetf1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no notable issues noted - defer to jake on approval

Copy link
Copy Markdown
Contributor

@jakelorocco jakelorocco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer context.view_for_generation. My reasoning is that that view is what the generation will see (same as Paul's logic).

If we need additional information to do something in the hook, I think we should modify the hook to pass along the full context and let the user call the necessary functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(plugins): COMPONENT_PRE_EXECUTE payload has empty context_view

4 participants