Repository navigation
fix(memory): pass boto3 session to MemoryClient in AgentCoreMemorySessionManager - #682
Conversation
…sionManager AgentCoreMemorySessionManager.__init__ built its MemoryClient without a boto3 session (MemoryClient then created its clients from a default session), before overwriting the clients from the user-provided session. This discarded the session on the MemoryClient itself. Compute the resolved session first and pass it into MemoryClient(boto3_session=...) so it uses the correct session from the start; the subsequent strands-agents user-agent override still applies. Fixes aws#681. Signed-off-by: avneetbansal-aws <284363899+avneetbansal-aws@users.noreply.github.com>
|
Thanks for turning #681 into a one-line fix and adding a test that pins the session hand-off. I replayed this commit onto current main (99663b0, v1.24.1) and it applies cleanly. The CI/CD Pipeline run on this fork PR is still
The last two rows are the side points in #681. The region attribute and the
|
|
Thanks @kimnamu for replaying the commit and validating it so thoroughly — the before/after tests, the constructor benchmarks, and the full-suite + lint run are all appreciated. Your reading matches mine. The two clients The CI run still showing |
|
Thanks again @kimnamu for replaying the commit and validating it. Is there anything further you need from me to move this forward, or is it just waiting on a maintainer approval/merge at this point? Happy to rebase onto current main if that helps. |
|
Thanks for following up, and for offering to rebase. Nothing is needed from me. I don't have write access here, so my earlier comment was only an independent local check. As far as I can tell the PR is waiting on maintainer approvals, and a rebase isn't needed:
If a rebase does come up later, the default-branch ruleset has |
|
Thanks @kimnamu, that's clear and helpful. Good to have the rebase question settled too, the compare showing main still at Sounds like it's purely waiting on a maintainer approval and the workflow-approval gate at this point. I'll leave the branch as-is so the existing review stays intact. Happy to rebase or rerun any scenario the moment a maintainer needs it. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #682 +/- ##
=======================================
Coverage ? 89.58%
=======================================
Files ? 124
Lines ? 10687
Branches ? 1670
=======================================
Hits ? 9574
Misses ? 728
Partials ? 385
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thank you @jariy17 for approving. Local unit tests and lint pass. The 10 red checks are the pull_request_target fork-checkout refusal in the Secure Integration / Breaking Change workflows, not anything in the diff. Is there a maintainer who can approve the workflow run or merge when convenient? |
|
Thanks @kimnamu, this is a really thorough verification, and the constructor timing is a nice bonus I hadn't expected from a one-line change. The red checks aren't from this change: the Secure Integration jobs refuse to check out fork PR code under Merging this now; it'll be available in the next release. |
Fixes #681.
Problem
`AgentCoreMemorySessionManager.init` constructed its `MemoryClient` without a boto3 session:
```python
self.memory_client = MemoryClient(region_name=region_name) # no session
session = boto_session or boto3.Session(region_name=region_name)
```
Because no session is passed, `MemoryClient.init` builds its `gmcp_client`/`gmdp_client` from a default `boto3.Session()` — so a user-provided `boto_session` (named profile, custom credentials, etc.) is silently discarded on the `MemoryClient` itself. The manager then overwrites those two clients from the correct session, but the `MemoryClient` was still initialized against the wrong one.
Fix
Resolve the session first, then pass it into `MemoryClient`, which already accepts `boto3_session`:
```python
session = boto_session or boto3.Session(region_name=region_name)
self.memory_client = MemoryClient(region_name=region_name, boto3_session=session)
```
The existing `strands-agents` user-agent / `boto_client_config` override that follows is unchanged, so behavior for the overridden clients is identical — the fix just ensures the `MemoryClient` uses the correct session from the start.
Tests