Skip to content

fix(session-manager): eliminate session manager double-folder bug#44

Merged
galuszkm merged 1 commit into
mainfrom
fix/mg/session-manager
May 23, 2026
Merged

fix(session-manager): eliminate session manager double-folder bug#44
galuszkm merged 1 commit into
mainfrom
fix/mg/session-manager

Conversation

@galuszkm
Copy link
Copy Markdown
Member

Description

Problem
The session manager was being resolved twice at boot time, creating orphan
folders:

  1. Once in resolve_infra() (before session_id is known) → random UUID folder
  2. Again in load_session() (with real session_id) → correct folder
    Result: one empty orphan folder per process startup.

Solution
Move session manager resolution from infra/load_session to the leaves (per-agent and per-orchestration builders). A single effective_session_id is computed once in load_session() and threaded down, ensuring all agents in one session share the same session_id and storage backend.

Related Issues

N/A

Type of Change

  • Bug fix
  • Breaking change

YAML / API Impact

Essential Changes

  • Removed ResolvedInfra.session_manager field (pure infra, no I/O)
  • resolve_infra() validates global SM config only (rejects agentcore globally)
  • load_session() computes effective_session_id and threads it down
  • All leaf builders now accept global_session_manager_def + session_id params
  • New helper resolve_leaf_session_manager() implements uniform 4-step chain:
    1. Agent/orch-level def (if set)
    2. Explicit opt-out (if field is explicitly None)
    3. Global def (fallback)
    4. None (no session persistence)
  • build_delegate merges orch session_manager into forked entry_def
  • build_swarm / build_graph resolve leaf SM inline before building

Breaking Changes

  • ResolvedInfra.session_manager removed entirely
  • Function signatures changed: resolve_agents(), build_agent_from_def(), OrchestrationBuilder.__init__(), build_delegate(), build_swarm(), build_graph(), and resolve_orchestrations() no longer accept session_manager= parameter; use keyword-only global_session_manager_def + session_id instead
  • session_manager_override parameter removed from build_agent_from_def()
  • Each agent/orchestration now resolves its own SM instance (not shared across agents); functionally identical for file/S3/AgentCore providers which have no shared in-memory state

Testing

How have you tested the change?

  • I ran uv run just check (lint + type check)
  • I ran uv run just test for overall testing
  • I added or updated tests that prove my fix is effective or my feature works
  • I verified existing examples in examples/ still work

Checklist

  • I have read the CONTRIBUTING document
  • I have updated the documentation accordingly
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Resolve session managers at the leaves (per-agent/per-orchestration) instead of at boot time. A single effective_session_id is computed once in load_session() and threaded down to all leaf builders. This eliminates orphan folders created by early resolution with random UUIDs.

Key changes:
- Removed ResolvedInfra.session_manager field
- resolve_infra() validates SM config only, no I/O
- load_session() computes effective_session_id and threads it down
- All leaf builders now accept global_session_manager_def + session_id
- New resolve_leaf_session_manager() helper implements uniform 4-step chain
- build_delegate merges orch SM into forked entry_def before building

BREAKING CHANGE:
ResolvedInfra.session_manager removed.
Function signatures changed for: resolve_agents(), build_agent_from_def(), OrchestrationBuilder,build_delegate(), build_swarm(), build_graph(), resolve_orchestrations().
All now use keyword-only global_session_manager_def + session_id instead of
session_manager parameter. session_manager_override removed entirely.
Copy link
Copy Markdown

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 fixes a boot-time session manager double-resolution that created an orphan session folder by deferring session manager instantiation to per-agent / per-orchestration “leaf” builders and threading a single effective_session_id through load_session().

Changes:

  • Removed ResolvedInfra.session_manager and changed resolve_infra() to validate (but not construct) global session manager configuration.
  • Added effective_session_id computation in load_session() and passed global_session_manager_def + session_id down into agent/orchestration builders.
  • Introduced a shared resolve_leaf_session_manager() helper to enforce consistent precedence (leaf override → explicit opt-out → global fallback → none), and updated tests/docs accordingly.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
uv.lock Bumps local package version to 0.3.0 in the lockfile.
tests/unit/test_exception_usage.py Removes unnecessary ty: ignore on topological_sort calls.
tests/unit/config/resolvers/test_config.py Updates infra tests for “no session manager construction in resolve_infra” and adds global agentcore rejection test.
tests/unit/config/resolvers/test_agents.py Updates agent resolver tests for new global_session_manager_def + session_id plumbing and leaf resolution behavior.
tests/unit/config/resolvers/orchestrations/test_planner.py Removes unnecessary ty: ignore on topological_sort calls.
tests/unit/config/resolvers/orchestrations/test_builders.py Updates orchestration builder tests for new SM def/session_id wiring; adds additional session-id forwarding assertions.
tests/unit/config/loaders/test_load_session.py Updates load_session() tests to validate effective_session_id derivation and def/session_id threading.
src/strands_compose/config/resolvers/session_manager.py Adds resolve_leaf_session_manager() helper implementing the uniform leaf precedence chain.
src/strands_compose/config/resolvers/orchestrations/planner.py Broadens topological_sort input type to Mapping for better flexibility.
src/strands_compose/config/resolvers/orchestrations/builders.py Moves session manager resolution into leaf builders; threads global_session_manager_def + session_id.
src/strands_compose/config/resolvers/orchestrations/init.py Updates orchestration resolver signature to accept global_session_manager_def + session_id.
src/strands_compose/config/resolvers/config.py Removes ResolvedInfra.session_manager and changes resolve_infra() to SM validation-only.
src/strands_compose/config/resolvers/agents.py Resolves session managers via resolve_leaf_session_manager() and updates resolver signatures.
src/strands_compose/config/loaders/loaders.py Computes effective_session_id and threads it + global SM def into leaf resolvers.
docs/configuration/Chapter_17.md Documents new infra/session behavior and effective_session_id semantics.
docs/configuration/Chapter_07.md Updates guidance to reflect single effective session id per load_session() call.

Comment thread tests/unit/config/resolvers/orchestrations/test_builders.py
@galuszkm galuszkm merged commit ee80d0b into main May 23, 2026
9 checks passed
@galuszkm galuszkm deleted the fix/mg/session-manager branch May 23, 2026 00:40
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.

2 participants