Skip to content

feat: propagate RunContextWrapper to session history read/write paths#2690

Draft
HuxleyHu98 wants to merge 14 commits intoopenai:mainfrom
HuxleyHu98:session-wrapper-history-paths
Draft

feat: propagate RunContextWrapper to session history read/write paths#2690
HuxleyHu98 wants to merge 14 commits intoopenai:mainfrom
HuxleyHu98:session-wrapper-history-paths

Conversation

@HuxleyHu98
Copy link

Summary

This PR adds backward-compatible RunContextWrapper propagation to the main session history read/write paths.

Specifically, it:

  • adds optional wrapper support to:
    • Session.get_items(...)
    • Session.add_items(...)
  • propagates the current runner RunContextWrapper through:
    • prepare_input_with_session(...)
    • save_result_to_session(...)
    • save_resumed_turn_items(...)
  • updates both sync and streamed runner flows to pass the current wrapper
  • preserves compatibility for existing custom session implementations by falling back to the old call signatures when a session method does not accept wrapper

Why

Issue #2072 is about making runtime context available to session implementations.

The earlier approach in #2488 added optional parameters at the interface level, but it did not actually propagate context from the runner side. This patch focuses on the runner-side propagation path so session implementations that support it can actually receive RunContextWrapper during session history reads/writes.

At the same time, this keeps older custom session implementations working unchanged.

Scope

This PR intentionally keeps the scope narrow.

Included:

  • session history read/write paths:
    • get_items
    • add_items
  • sync and streamed runner flows
  • backward-compatible dispatch for legacy session implementations

Not included:

  • pop_item
  • clear_session
  • broader session lifecycle expansion outside the main history read/write paths

I kept those out on purpose to make the initial change small, testable, and compatibility-focused.

Compatibility

Backward compatibility is handled in the internal dispatch layer.

If a session implementation supports the optional wrapper parameter, the runner passes the current RunContextWrapper.

If it does not, the runner falls back to the existing call shape, so older custom session implementations continue to work without modification.

Tests

Added coverage for:

  • new-style custom session implementations that accept wrapper
    • verifies get_items / add_items receive the current RunContextWrapper
    • verifies the wrapper exposes the original run context
  • legacy custom session implementations with the old method signatures
    • verifies they still work in:
      • Runner.run
      • Runner.run_sync
      • Runner.run_streamed

Ran:

  • tests/test_session.py
  • tests/test_agent_runner_streamed.py
  • tests/test_soft_cancel.py
  • tests/test_hitl_session_scenario.py
  • tests/extensions/memory/test_encrypt_session.py
  • tests/memory/test_openai_responses_compaction_session.py

Result:

  • 146 passed

Static checks:

  • pyright0 errors
  • ruff checkpassed

@HuxleyHu98 HuxleyHu98 changed the title Pass RunContextWrapper to session history read/write paths without breaking existing sessions Propagate RunContextWrapper to session history read/write paths Mar 17, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53f1c4779f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@HuxleyHu98 HuxleyHu98 changed the title Propagate RunContextWrapper to session history read/write paths feat: propagate RunContextWrapper to session history read/write paths Mar 17, 2026
@seratch seratch assigned seratch and unassigned seratch Mar 17, 2026
@seratch seratch marked this pull request as draft March 17, 2026 01:58
@HuxleyHu98 HuxleyHu98 marked this pull request as ready for review March 17, 2026 02:59
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78e39d7b91

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33cc084153

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@github-actions github-actions bot added the enhancement New feature or request label Mar 17, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56794b32ad

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d06a2fe9d3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@HuxleyHu98 HuxleyHu98 force-pushed the session-wrapper-history-paths branch from 4c26f31 to 6f96adb Compare March 17, 2026 12:33
@HuxleyHu98
Copy link
Author

I’ve addressed the review feedback and resolved the outdated Codex conversations. Local checks are passing on my side. Could a maintainer please enable/approve the PR checks when convenient? Thanks!

@seratch seratch marked this pull request as draft March 17, 2026 22:45
@HuxleyHu98 HuxleyHu98 force-pushed the session-wrapper-history-paths branch from 168e211 to 3cee188 Compare March 18, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature:sessions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants