Skip to content

feat: preserve Context subtype and enforce input==output context type - #1582

Open
AngeloDanducci wants to merge 3 commits into
generative-computing:mainfrom
AngeloDanducci:ad-1522
Open

feat: preserve Context subtype and enforce input==output context type#1582
AngeloDanducci wants to merge 3 commits into
generative-computing:mainfrom
AngeloDanducci:ad-1522

Conversation

@AngeloDanducci

Copy link
Copy Markdown
Contributor

Pull Request

Issue

Fixes #1522

Description

preserve Context subtype and enforce input==output context type

Testing

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

Attribution

  • AI coding assistants used

Adding a new component, requirement, sampling strategy, or tool?

If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.

  • Component
  • Requirement
  • Sampling Strategy
  • Tool

NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.

Signed-off-by: AngeloDanducci <angelo.danducci.ii@ibm.com>
@AngeloDanducci
AngeloDanducci requested a review from a team as a code owner August 25, 2026 15:31
@github-actions github-actions Bot added the enhancement New feature or request label Aug 25, 2026

@jakelorocco jakelorocco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good; I have a few concerns / thoughts that I think would be worth addressing in this PR so that we can get a better surface for the context typing.

Comment on lines +831 to +834
checked_ctx = _enforce_context_type(
context, new_ctx, allow_context_type_change=allow_context_type_change
)
return result, checked_ctx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know that SamplingResults don't currently keep track of their context type, but could we also check that the context types of the sampling results are accurate as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be addressed in the new changeset.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is somewhat out of scope but I think it should be a part of this PR as well to ensure everything works smoothly. Can you please add some tests that check that the context functions that return self actually work when subclassing? ie do we need additional checks to make sure a context type always returns its own type for those functions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good for the functional api. I wonder if there's a way we should allow changing context types for sessions? right now, sessions default to preventing context type changes. I guess we wouldn't be able to get correct static typing but maybe there should be a flag for overriding this at the session level as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And on that same note, can we type the context (and backend I guess) of a given context at this point too? So that you can access the context type of a given session?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be handled now - made MelleaSession context type generic.

…verride

Signed-off-by: AngeloDanducci <angelo.danducci.ii@ibm.com>
Signed-off-by: AngeloDanducci <angelo.danducci.ii@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add context typing so that functions return the type of context passed into them

2 participants