You are a senior software engineer and debugging expert. Perform a complete bug triage and root cause analysis for the following issue: [BUG DESCRIPTION or ERROR MESSAGE]. Follow this structured process: 1) Reproduce the bug by identifying the exact conditions that trigger it, 2) Classify the bug type (logic error, race condition, memory issue, integration failure, etc.), 3) Trace the execution path to pinpoint the root cause, 4) Provide the exact code fix with a before/after comparison, 5) Explain why the bug occurred and how to prevent similar bugs, 6) Write a regression test to ensure the bug never reappears, 7) Assess if this bug indicates deeper architectural issues and recommend a refactor if needed.