Skip to content

chore: automates session tracing context#591

Merged
garrett4wade merged 2 commits intomainfrom
rchardx/session
Nov 18, 2025
Merged

chore: automates session tracing context#591
garrett4wade merged 2 commits intomainfrom
rchardx/session

Conversation

@rchardx
Copy link
Copy Markdown
Collaborator

@rchardx rchardx commented Nov 17, 2025

Description

Removes manual session identifiers from phase scopes so they resolve from contextvars. Introduces a decorator to register sessions per sample when a task is active and applies it to rollout workflows to streamline tracing. Refreshes profiling guidance and tests to match the new implicit session workflow.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not
    work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Checklist

  • I have read the Contributing Guide
  • I have run formatting tools (pre-commit or manual)
  • I have run relevant unit tests and they pass
  • I have added tests for new functionality
  • I have updated documentation if needed
  • My branch is up to date with main
  • This PR introduces breaking changes (if yes, fill out details below)
  • If this PR changes documentation, I have built and previewed it locally with
    jb build docs
  • No critical issues raised by AI reviewers (/gemini review)

Breaking Change Details (if applicable):

Additional Context


Need help? Check the Contributing Guide or ask in
GitHub Discussions!

@rchardx rchardx requested a review from Copilot November 17, 2025 13:08
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @rchardx, 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 refactors the performance tracing mechanism to automate the management of session identifiers. By leveraging Python's contextvars, it eliminates the need for manual session_id passing in tracing functions and context managers. This change simplifies the API for developers, making it easier to integrate session tracing into workflows, particularly for individual samples within a larger task, without altering core functionality.

Highlights

  • Automated Session Tracing Context: Manual session identifiers have been removed from phase scopes, allowing them to resolve implicitly from contextvars.
  • New session_context Decorator: A new decorator, session_context, has been introduced to automatically register sessions per sample when a task is active, streamlining tracing workflows.
  • Simplified Tracing API: The trace_session_phase and atrace_session_phase context managers no longer require explicit session_id arguments, fetching it automatically from the context.
  • Updated Rollout Workflows: Rollout workflows (rlvr.py, vision_rlvr.py) now utilize the session_context decorator on their _collect_samples methods, simplifying session management.
  • Documentation and Test Refresh: Profiling guidance and tests have been updated to align with the new implicit session workflow, ensuring clarity and correctness.
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 a significant improvement to the session tracing mechanism by automating context management with contextvars. The new @session_context decorator and the updated trace_session_phase/atrace_session_phase functions greatly simplify the tracing API, removing the need for manual session ID propagation. The changes are well-implemented across the tracer utility, workflow files, and documentation. My review includes a couple of minor suggestions to improve code clarity in the updated tests by removing redundant try...finally blocks.

Comment thread areal/tests/test_perf_tracer.py Outdated
Comment thread areal/tests/test_perf_tracer.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR streamlines session tracing by automating context management for session identifiers. The changes eliminate manual session registration code in workflow methods, replacing it with a new @session_context() decorator that automatically handles session creation and context population from the active task. This reduces boilerplate and makes the tracing API more intuitive.

  • Introduced session_context() decorator to automatically register sessions per sample invocation
  • Simplified atrace_session_phase() and trace_session_phase() APIs to no longer require explicit session_id parameters
  • Updated rollout workflows (RLVRWorkflow and VisionRLVRWorkflow) to use the new decorator-based approach

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
areal/utils/perf_tracer.py Added session_context() decorator factory and updated phase tracing context managers to automatically retrieve session_id from context
areal/workflow/rlvr.py Applied @session_context() decorator to _collect_samples method and removed manual session registration code
areal/workflow/vision_rlvr.py Applied @session_context() decorator to _collect_samples method and removed manual session registration code
areal/tests/test_perf_tracer.py Updated tests to use new API where phase context managers no longer require session_id parameter
docs/best_practices/perf_profiling.md Refreshed documentation with examples of the new decorator-based workflow and updated API signatures

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/best_practices/perf_profiling.md Outdated
Comment thread areal/tests/test_perf_tracer.py Outdated
Comment thread areal/tests/test_perf_tracer.py Outdated
Comment thread docs/best_practices/perf_profiling.md Outdated
Comment thread docs/best_practices/perf_profiling.md
Removes manual session identifiers from phase scopes so they resolve from contextvars.
Introduces a decorator to register sessions per sample when a task is active and applies it to rollout workflows to streamline tracing.
Refreshes profiling guidance and tests to match the new implicit session workflow.
@rchardx
Copy link
Copy Markdown
Collaborator Author

rchardx commented Nov 17, 2025

/gemini review

@rchardx rchardx requested a review from Copilot November 17, 2025 15:41
@rchardx rchardx added the safe-to-test Ready to run unit-tests in a PR. label Nov 17, 2025
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 is a well-executed refactoring that automates session tracing context using contextvars. The introduction of the @session_context decorator is a significant improvement, as it removes boilerplate code from workflows and makes the tracing mechanism more implicit and easier to use. The changes are applied consistently, and the updates to tests and documentation are thorough and clear. Overall, this is a great enhancement to the codebase's maintainability. I have a couple of minor suggestions to improve docstring consistency.

Comment thread areal/utils/perf_tracer.py
Comment thread areal/utils/perf_tracer.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@rchardx rchardx added safe-to-test Ready to run unit-tests in a PR. and removed safe-to-test Ready to run unit-tests in a PR. labels Nov 18, 2025
Copy link
Copy Markdown
Collaborator

@garrett4wade garrett4wade left a comment

Choose a reason for hiding this comment

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

LGTM

@garrett4wade garrett4wade merged commit fa5f3c6 into main Nov 18, 2025
7 checks passed
@garrett4wade garrett4wade deleted the rchardx/session branch November 18, 2025 03:11
Bruce-rl-hw pushed a commit to Bruce-rl-hw/AReaL-vllm that referenced this pull request Dec 4, 2025
* chore: automates session tracing context

Removes manual session identifiers from phase scopes so they resolve from contextvars.
Introduces a decorator to register sessions per sample when a task is active and applies it to rollout workflows to streamline tracing.
Refreshes profiling guidance and tests to match the new implicit session workflow.

* Apply suggestions from code review

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
leandermaben pushed a commit to leandermaben/AReaL that referenced this pull request Mar 24, 2026
* chore: automates session tracing context

Removes manual session identifiers from phase scopes so they resolve from contextvars.
Introduces a decorator to register sessions per sample when a task is active and applies it to rollout workflows to streamline tracing.
Refreshes profiling guidance and tests to match the new implicit session workflow.

* Apply suggestions from code review

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-test Ready to run unit-tests in a PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants