OpenAIConverseConverter restores an empty history when one blob or text payload fails to parse
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 src/bedrock_agentcore/memory/integrations/strands/converters/openai.py 中的 OpenAIConverseConverter.events_to_messages(L159-L186)開始,並閱讀 session_manager.py L795-L814,了解為什麼例外逸出會清空歷史記錄。執行 issue 中以 mock 的 MemoryClient 進行的重現,確認三種失敗形狀,然後在 AgentCoreMemoryConverter 中照搬 #749 的處理方式:跳過壞 payload,並且只記錄 event id。當一個無法解析的 event 被跳過且有效歷史仍能返回時即完成;在現有 converter 測試旁邊加入覆蓋。
由索引模型根據 Issue 內容生成。
描述
Hi team, hope you're doing well!
This is a follow up from #743, where @kimnamu spotted it while testing #749. Thank you, @kimnamu!
Describe the bug
With converter=OpenAIConverseConverter, one stored event that the converter can't parse makes AgentCoreMemorySessionManager.list_messages return [], so the restored agent starts with no history, valid messages included. Three shapes trigger it on current main:
- a dict blob, the shape in
create_blob_event's docstring example (client.py L589 to L596) - the blob
"[3, 4]" - deeply nested conversational text
#749 fixes the same kind of gap in AgentCoreMemoryConverter but doesn't touch converters/openai.py, so the branch behaves the same as main here.
To Reproduce
list_messagespasses every listed event toself.converter.events_to_messagesand catches any exception by logging it and returning[](session_manager.py L795 to L814).- In
OpenAIConverseConverter.events_to_messages(converters/openai.py L159 to L186):- a dict blob reaches
json.loads(payload_item["blob"]), which raisesTypeError, and the blobexceptonly catches(json.JSONDecodeError, ValueError) "[3, 4]"passes the list of length 2 check, thenjson.loads(blob_data[0])gets3and raisesTypeError- deeply nested text makes
json.loads(conv["content"]["text"])raiseRecursionError, which the conversationalexcept (json.JSONDecodeError, KeyError, ValueError)doesn't catch
- a dict blob reaches
- The exception escapes
events_to_messages,list_messagesreturns[], and the agent starts with an empty history.
Minimal repro
Mocked MemoryClient, no AWS needed. Tested on main at 8467c9a (1.27.0) with strands-agents 1.56.0:
import json
from unittest.mock import patch
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig
from bedrock_agentcore.memory.integrations.strands.converters.openai import OpenAIConverseConverter
from bedrock_agentcore.memory.integrations.strands.session_manager import AgentCoreMemorySessionManager
def stored(role, text):
return {"payload": [{"conversational": {"role": role.upper(), "content": {"text": json.dumps({"role": role, "content": text})}}}]}
config = AgentCoreMemoryConfig(memory_id="mem", session_id="sess", actor_id="actor")
with patch("bedrock_agentcore.memory.integrations.strands.session_manager.MemoryClient") as client, patch("boto3.Session"):
client.return_value.list_events.return_value = []
manager = AgentCoreMemorySessionManager(config, converter=OpenAIConverseConverter)
history = [stored("assistant", "hi there"), stored("user", "hello")]
odd = {
"dict blob": {"payload": [{"blob": {"note": "x"}}]},
"blob [3, 4]": {"payload": [{"blob": "[3, 4]"}]},
"deeply nested text": {"payload": [{"conversational": {"role": "USER", "content": {"text": "[" * 100000 + "]" * 100000}}}]},
}
manager.memory_client.list_events.return_value = history
print("valid events only:", len(manager.list_messages("sess", "agent")))
for name, event in odd.items():
manager.memory_client.list_events.return_value = [event] + history
print(f"plus one {name}:", len(manager.list_messages("sess", "agent")))
Output:
valid events only: 2
Failed to list messages from AgentCore Memory: the JSON object must be str, bytes or bytearray, not dict
plus one dict blob: 0
Failed to list messages from AgentCore Memory: the JSON object must be str, bytes or bytearray, not int
plus one blob [3, 4]: 0
Failed to list messages from AgentCore Memory: maximum recursion depth exceeded while decoding a JSON array from a unicode string
plus one deeply nested text: 0
Expected behavior
The one payload that can't be parsed gets skipped with a log line, and the rest of the history is restored, the same way the converter already skips a conversational payload that isn't JSON.
Related: blob content in the ERROR log
The blob except logs the whole payload: logger.error("Failed to parse blob payload: %s", payload_item) (converters/openai.py L177). Once TypeError is caught there, dict blobs land on that line and their content goes into the ERROR log. #749 switched the matching line in AgentCoreMemoryConverter to log only the event id, logger.error("Failed to parse blob content in event %s", event.get("eventId")), and the same would work here.
Environment
- bedrock-agentcore: main at 8467c9a (1.27.0)
- strands-agents: 1.56.0
- Python 3.10, macOS
Additional context
A possible fix: catch TypeError and RecursionError in both branches, log only the event id, and continue, mirroring #749. Does that sound right to you, or would you rather handle it differently? I'm happy to send a PR, or fold it into #749 if you'd prefer both converters in one place. Thanks so much!
- 主要語言
- Python
- 星號
- 786
- 分支
- 163
- 平均合併
- 4 小時
- 30 天內合併 PR
- 22
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
aws/bedrock-agentcore-sdk-python 的其他 Issue
-
bug high-severity
難度 2/5 1-3 小時 新手友好度 72/100
aws/bedrock-agentcore-sdk-python#752 ·
維護者通常 1 天內回覆
-
delete_all_long_term_memories_in_namespace deletes only the first 10 records可能已有人在做 @Fire162 於 18 天前認領。 未關閉bug high-severity
難度 2/5 1-3 小時 新手友好度 75/100
aws/bedrock-agentcore-sdk-python#727 ·
維護者通常 1 天內回覆
-
MPP: credential is always sent in Authorization, ignoring header="Payment-Authorization" in the challenge可能已有人在做 @abhiramshaji-cyber 於 24 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 68/100
aws/bedrock-agentcore-sdk-python#702 ·
維護者通常 1 天內回覆
-
[Bug] update_message fails with parameter validation error when SessionMessage.message_id is a Strands positional integer index可能已有人在做 @citizen204 於 144 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 68/100
aws/bedrock-agentcore-sdk-python#556 ·
維護者通常 1 天內回覆
-
CodeInterpreter should not require a region argument可能已有人在做 @citizen204 於 159 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 68/100
aws/bedrock-agentcore-sdk-python#511 ·
維護者通常 1 天內回覆
查看 aws/bedrock-agentcore-sdk-python 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 88/100
snap-stanford/Biomni#380 ·
-
難度 2/5 1-3 小時 新手友好度 74/100
microsoft/playwright-python#3361 ·
維護者通常 1 天內回覆
-
documentation priority: low size: S status: needs triage
難度 2/5 1-3 小時 新手友好度 74/100
cubrid-lab/sqlalchemy-cubrid#1397 ·
維護者通常 1 天內回覆
-
documentation priority: low size: S status: needs triage
難度 2/5 1-3 小時 新手友好度 72/100
cubrid-lab/pycubrid#1307 ·
維護者通常 1 天內回覆
-
[Bug]: Installer hides SSL certificate errors as bare URLError, and the suggested fix can't work未關閉bug
難度 2/5 1-3 小時 新手友好度 80/100
ShaftHQ/chaosengine-harness#143 ·
維護者通常 1 天內回覆