Skip to content

feat(session): optimize session manager initialization#1829

Merged
Unshure merged 3 commits intomainfrom
agent-tasks/1828
Mar 9, 2026
Merged

feat(session): optimize session manager initialization#1829
Unshure merged 3 commits intomainfrom
agent-tasks/1828

Conversation

@Unshure
Copy link
Member

@Unshure Unshure commented Mar 6, 2026

Motivation

When a new session is created in RepositorySessionManager.__init__, we know with certainty that no agents can exist in the session yet. The subsequent read_agent() and read_multi_agent() calls in initialize(), initialize_bidi_agent(), and initialize_multi_agent() will always return None, making them unnecessary API calls.

This optimization eliminates redundant S3 GetObject calls (for S3-backed sessions) or filesystem I/O operations (for file-backed sessions), reducing latency and API costs.

Resolves: #1828

Public API Changes

No public API changes. This is an internal optimization that maintains backward compatibility.

The internal _is_new_session flag is used to track session creation state:

# Internally, the session manager now tracks whether the session was newly created
manager = RepositorySessionManager(session_id="new-session", session_repository=repo)
# manager._is_new_session == True (session didn't exist, was created)

manager = RepositorySessionManager(session_id="existing-session", session_repository=repo)
# manager._is_new_session == False (session already existed)

When _is_new_session is True, the initialize(), initialize_bidi_agent(), and initialize_multi_agent() methods skip their respective read calls since no agents can pre-exist in a newly created session.

Use Cases

  • S3-backed sessions: Eliminates unnecessary S3 GetObject requests when initializing agents in new sessions
  • File-backed sessions: Reduces filesystem I/O operations when initializing agents in new sessions
  • High-throughput applications: Reduces latency when creating many new sessions with agents

Documentation PR

No documentation updates required - this is an internal optimization with no public API changes.

Skip redundant read_agent/read_multi_agent calls when session is newly created.

When a new session is created in RepositorySessionManager.__init__, we know
with certainty that no agents can exist in the session yet. The subsequent
read_agent() and read_multi_agent() calls in initialize(), initialize_bidi_agent(),
and initialize_multi_agent() will always return None, making them unnecessary
API calls.

Changes:
- Add _is_new_session flag to track whether session was newly created
- Skip read_agent() in initialize() and initialize_bidi_agent() for new sessions
- Skip read_multi_agent() in initialize_multi_agent() for new sessions
- Add comprehensive unit tests for the optimization behavior

This eliminates redundant S3 GetObject calls (for S3-backed sessions) or
filesystem I/O operations (for file-backed sessions).
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Assessment: Request Changes

This PR implements a clean internal optimization to skip unnecessary read operations when initializing agents in newly created sessions. The logic is sound and the implementation follows repository patterns well.

Review Summary
  • Critical: The test_output.log file is a debug artifact that must be removed before merging
  • Documentation: The PR description is missing a "Documentation PR" section - please add one with a justification explaining why docs updates are not required (e.g., "No documentation updates needed - internal optimization with no public API changes")
  • Tests: Comprehensive test coverage for the new optimization including both new and existing session scenarios

Nice work on the optimization - the approach of tracking session creation state to avoid redundant I/O is well-designed.

@github-actions github-actions bot added size/m and removed size/m labels Mar 6, 2026
@Unshure Unshure marked this pull request as ready for review March 6, 2026 20:32
@strands-agents strands-agents deleted a comment from github-actions bot Mar 6, 2026
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Issue: Missing "Documentation PR" section in PR description

Per repository guidelines, all PRs should include a "Documentation PR" section with either:

Suggestion: Add a section to the PR description like:

## Documentation PR

No documentation updates required - this is an internal optimization with no public API changes.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Assessment: Request Changes

The previous issue (test_output.log debug artifact) has been resolved. The implementation is clean and well-tested.

Review Summary
  • Code Quality: Clean implementation following repository patterns
  • Tests: Comprehensive coverage (100% per Codecov) including new/existing session scenarios
  • Logic: Sound optimization - new sessions cannot have pre-existing agents
  • ⚠️ Documentation: Missing "Documentation PR" section in PR description

One remaining item: Please add a "Documentation PR" section to the PR description with a justification (e.g., "No documentation updates required - internal optimization with no public API changes").

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Assessment: Request Changes

The code and tests look great. The previous issue (test_output.log) has been resolved.

Outstanding item: Please add a "Documentation PR" section to the PR description as requested in the previous review comment. A simple justification is sufficient:

## Documentation PR

No documentation updates required - this is an internal optimization with no public API changes.

Once added, happy to approve!

@Unshure
Copy link
Member Author

Unshure commented Mar 6, 2026

/strands review

@Unshure Unshure merged commit 32d703c into main Mar 9, 2026
65 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Optimize session manager initialization

3 participants