From 37f2ff728744ece020d5acf22d0ccb1f30735055 Mon Sep 17 00:00:00 2001 From: Fahad Farrukh Date: Sat, 13 Jun 2026 00:30:49 -0400 Subject: [PATCH] fix(payments): T06 cap memory polling at the documented 5-minute ceiling The polling loop waiting for AgentCore Memory to reach ACTIVE used `while True:` with no upper bound. The inline print told users "usually 30-90s" but the README at line 163 already documents a 5-minute practical ceiling and tells operators to "call get_memory once to inspect failureReason" if it stays CREATING beyond that. The script never enforces the ceiling. A genuinely stuck memory polls forever, and the original test run at 150s was already past the "usually" range without any signal that something might be unusual. Add MAX_WAIT_SECONDS = 300 (matching the README's ceiling). When the elapsed time crosses it, raise TimeoutError with the exact get-memory command from the README so the operator has the next step in front of them. The message also points at CloudWatch logs in the bedrock-agentcore log group. The existing FAILED-state RuntimeError path is unchanged; the existing finally-block memory cleanup still runs on either exit. Update the inline waiting message to mention the ceiling so users have a calibrated expectation rather than "30-90s" optimism. Verified: - Mocked-clock tests covering stuck/FAILED/happy-path scenarios all pass. - Live AWS happy-path: real memory creation in us-west-2 reached ACTIVE at 150s through the patched loop, then cleaned up normally. --- .../research_agent_with_memory.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/01-features/08-agents-that-transact/00-getting-started/06-research-agent-with-payment-memory/research_agent_with_memory.py b/01-features/08-agents-that-transact/00-getting-started/06-research-agent-with-payment-memory/research_agent_with_memory.py index 563e43b51..1e8b9dbda 100644 --- a/01-features/08-agents-that-transact/00-getting-started/06-research-agent-with-payment-memory/research_agent_with_memory.py +++ b/01-features/08-agents-that-transact/00-getting-started/06-research-agent-with-payment-memory/research_agent_with_memory.py @@ -197,8 +197,12 @@ def main() -> None: try: # Wait for memory to become ACTIVE. CreateMemory returns immediately # with status=CREATING; downstream record ops require ACTIVE. + # README documents ~30-90s typical, 5 minutes as the practical ceiling. + # If we exceed the ceiling, surface it so the user can investigate + # rather than wait indefinitely. + MAX_WAIT_SECONDS = 300 print( - "\n Waiting for memory to become ACTIVE (usually 30-90s)...", + f"\n Waiting for memory to become ACTIVE (usually 30-90s, ceiling {MAX_WAIT_SECONDS}s)...", flush=True, ) elapsed = 0 @@ -210,6 +214,13 @@ def main() -> None: if status == "FAILED": reason = memory_ctl.get_memory(memoryId=memory_id)["memory"].get("failureReason", "unknown") raise RuntimeError(f"Memory creation failed: {reason}") + if elapsed >= MAX_WAIT_SECONDS: + raise TimeoutError( + f"Memory {memory_id} stayed in {status} for {elapsed}s — exceeded the " + f"{MAX_WAIT_SECONDS}s ceiling. Inspect failureReason via " + f"`aws bedrock-agentcore-control get-memory --memory-id {memory_id}` " + f"and check CloudWatch logs in the bedrock-agentcore log group." + ) print( f" status={status}, elapsed={elapsed}s, polling again in 10s...", flush=True,