Skip to content

[sdk/python] Add FlameSessionContext for custom session IDs (RFE350)#351

Merged
k82cn merged 4 commits into
xflops:mainfrom
k82cn:rfe350-flame-session-context
Feb 9, 2026
Merged

[sdk/python] Add FlameSessionContext for custom session IDs (RFE350)#351
k82cn merged 4 commits into
xflops:mainfrom
k82cn:rfe350-flame-session-context

Conversation

@k82cn
Copy link
Copy Markdown
Contributor

@k82cn k82cn commented Feb 8, 2026

Summary

This PR introduces FlameSessionContext, a new feature that allows users to specify custom session IDs when creating services via Runner.service(). This enables better traceability, deterministic testing, and external system integration.

Changes

  • SDK Implementation: Added FlameSessionContext dataclass with session_id and application_name fields
  • Detection Logic: RunnerService.init() now checks for _flame_session_context attribute on execution objects
  • Design Document: Added RFE350 design document with full specification
  • E2E Tests: Added 13 new tests covering all usage patterns

Testing

  • Added 13 new E2E tests for FlameSessionContext
  • All existing tests remain passing (backward compatible)

k82cn and others added 3 commits February 8, 2026 21:46
Introduces FlameSessionContext dataclass that allows users to specify custom
session IDs for Runner.service(). The context can be attached to execution
objects (classes, instances, or functions) via the _flame_session_context
attribute.

Features:
- FlameSessionContext with session_id and application_name fields
- Validation for session_id (type, length, non-empty)
- Detection logic in RunnerService.__init__()
- Backward compatible - auto-generates session ID if not specified

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Design document for FlameSessionContext feature that enables custom session IDs
in Runner.service(). Includes motivation, function specification, implementation
details, and use cases for all supported execution object types.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
E2E tests for FlameSessionContext feature covering:
- Custom session ID with class, instance, and function
- Session ID auto-generation when not specified
- Backward compatibility without context
- Invalid context type handling (ignored with warning)
- Validation tests (empty, too long, invalid types)
- Dynamic class creation with context

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @k82cn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the flamepy Python SDK by providing users with greater control over session creation. It introduces FlameSessionContext, allowing the explicit definition of session IDs and optional application names when launching services. This change significantly improves the ability to trace, debug, and integrate Flame services with external monitoring and logging systems, moving beyond automatically generated, opaque session identifiers.

Highlights

  • Custom Session IDs: Introduced FlameSessionContext dataclass, allowing users to specify custom session IDs and application metadata for services created via Runner.service().
  • Integration with RunnerService: The RunnerService.__init__() method has been updated to detect and utilize the _flame_session_context attribute on execution objects, prioritizing user-defined session IDs.
  • Backward Compatibility: The feature is opt-in and fully backward compatible; services without an explicit _flame_session_context will continue to receive auto-generated session IDs.
  • Input Validation: Added validation logic within FlameSessionContext for session_id to ensure it is a non-empty string and within a maximum length of 128 characters.
  • Documentation and Testing: A new design document (RFE350-flame-session-context/FS.md) has been added, and 13 new end-to-end tests were implemented to cover various usage patterns and edge cases of FlameSessionContext.
Changelog
  • docs/designs/RFE350-flame-session-context/FS.md
    • Added a new design document detailing the FlameSessionContext feature, its motivation, specification, and usage examples.
  • e2e/tests/test_runner.py
    • Added 13 new end-to-end tests to thoroughly verify the functionality and edge cases of FlameSessionContext with classes, instances, functions, and validation scenarios.
  • sdk/python/src/flamepy/runner/init.py
    • Modified to export the newly introduced FlameSessionContext dataclass, making it accessible to users.
  • sdk/python/src/flamepy/runner/runner.py
    • Updated the RunnerService initialization logic to detect and parse the _flame_session_context attribute from execution objects, using the specified session_id if available, otherwise falling back to the default auto-generation.
    • Updated the docstring for the execution_object parameter in RunnerService.__init__ to reflect the new _flame_session_context functionality.
  • sdk/python/src/flamepy/runner/types.py
    • Introduced the FlameSessionContext dataclass, defining session_id and application_name fields, along with __post_init__ validation for input integrity.
Activity
  • A new feature (RFE350) has been implemented to allow custom session IDs for better traceability and integration.
  • A detailed design document has been created and added to the docs/designs directory, outlining the motivation, specification, and implementation details.
  • The core Python SDK components (runner.py, types.py, __init__.py) have been updated to support this feature, including new data structures and logic for session ID handling.
  • Extensive end-to-end tests have been added to validate the new functionality and ensure backward compatibility with existing services.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces FlameSessionContext to allow custom session IDs, which is a great feature for improving traceability and testing. The implementation is solid, with a comprehensive design document and extensive end-to-end tests covering various use cases. The changes are backward compatible and well-integrated into the existing Runner.service() flow. I've added a couple of minor suggestions to improve validation consistency in the new FlameSessionContext and fix a small typo in the design document. Overall, this is an excellent contribution.

## 5. References

### Related Documents
- [RFE280 - Simplify the Python API of Flame](../FRE280-runner/RFE280-runner.md)
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.

medium

There's a minor typo in the link to the related document. It seems FRE280 should be RFE280 to align with the naming convention of other RFEs.

Suggested change
- [RFE280 - Simplify the Python API of Flame](../FRE280-runner/RFE280-runner.md)
- [RFE280 - Simplify the Python API of Flame](../RFE280-runner/RFE280-runner.md)

Comment on lines +67 to +68
if self.application_name is not None and not isinstance(self.application_name, str):
raise ValueError(f"application_name must be a string, got {type(self.application_name)}")
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.

medium

The validation for application_name only checks its type. For consistency with session_id and to prevent potentially undesirable values, it would be beneficial to also validate that application_name is not an empty string and enforce a maximum length. This would make the context object more robust.

        if self.application_name is not None:
            if not isinstance(self.application_name, str):
                raise ValueError(f"application_name must be a string, got {type(self.application_name)}")
            if len(self.application_name) == 0:
                raise ValueError("application_name cannot be empty string")
            if len(self.application_name) > 128:
                raise ValueError(f"application_name too long ({len(self.application_name)} chars, max 128)")

Rename FlameSessionContext to SessionContext and _flame_session_context to
_session_context for consistency and simplicity.

No functional changes - pure rename.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@k82cn k82cn merged commit 0b3a0b6 into xflops:main Feb 9, 2026
5 checks passed
@k82cn k82cn deleted the rfe350-flame-session-context branch February 12, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant