Skip to content

fix: do not share session state across requests in m_serve examples - #1481

Open
markstur wants to merge 3 commits into
generative-computing:mainfrom
markstur:issue_1444
Open

fix: do not share session state across requests in m_serve examples#1481
markstur wants to merge 3 commits into
generative-computing:mainfrom
markstur:issue_1444

Conversation

@markstur

Copy link
Copy Markdown
Contributor

Examples are holding the session across requests so that different client would share history. This doesn't significantly affect the examples, but it's a bad pattern if the example influences real implementations.

Assisted-by: IBM Bob

Pull Request

Issue

Fixes #1444

Description

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.

@markstur
markstur requested a review from a team as a code owner July 31, 2026 00:17
@github-actions github-actions Bot added the bug Something isn't working label Jul 31, 2026
Examples are holding the session across requests so that different client
would share history.  This doesn't significantly affect the examples, but
it's a bad pattern if the example influences real implementations.

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
Assisted-by: IBM Bob
Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
@planetf1

planetf1 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

One thing outside this diff's scope, worth a quick follow-up: docs/examples/m_serve/README.md's "Basic Pattern" snippet (line ~115) still shows session = start_session() at module level as the recommended pattern:

from mellea import start_session
...
session = start_session()

def serve(input: list[ChatMessage], ...):
    ...
    result = session.instruct(...)
    return result

That's the exact shared-session pattern this PR is removing from the real examples. Anyone using this README snippet as a starting point for a new example would reintroduce the #1444 bug. Not a blocker for this PR, but worth updating the snippet (move session = start_session() inside serve()) in a follow-up so the docs match the pattern the examples now demonstrate.

Happy to approve once that's done.

…xamples README.md

The examples were fixed, but the README.me for the m serve examples still had
the anti-pattern. It works either way, but we don't want people to learn or copy
the anti-pattern.

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
@markstur

Copy link
Copy Markdown
Contributor Author

One thing outside this diff's scope, worth a quick follow-up: docs/examples/m_serve/README.md's "Basic Pattern" snippet (line ~115) still shows session = start_session() at module level as the recommended pattern:

from mellea import start_session
...
session = start_session()

def serve(input: list[ChatMessage], ...):
    ...
    result = session.instruct(...)
    return result

That's the exact shared-session pattern this PR is removing from the real examples. Anyone using this README snippet as a starting point for a new example would reintroduce the #1444 bug. Not a blocker for this PR, but worth updating the snippet (move session = start_session() inside serve()) in a follow-up so the docs match the pattern the examples now demonstrate.

Happy to approve once that's done.

Done. Thanks for catching that. I feel like I looked at that, but just didn't see it.

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.

Should probably update this since the model was updated to
hf.co/ibm-granite/granite-vision-4.1-4b-GGUF:Q4_K_M

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.

Thank you!
fixed

Signed-off-by: Mark Sturdevant <mark.sturdevant@ibm.com>
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.

m_serve examples share a single module-level ChatContext across all requests

3 participants