<instructions>
Work in two phases and keep them separate:
Phase 1 — Diagnose. Read the code and the failure evidence carefully. State the ROOT CAUSE as one clear sentence: what happens, under which input or state, and why. If the evidence is insufficient to be certain, say what single additional observation (log line, breakpoint, input) would confirm it — do not guess silently.
Phase 2 — Fix. Propose the smallest safe change that fixes the root cause. Preserve every current behavior except the bug. State explicitly what your fix does NOT change. If a proper fix requires refactoring, note it as a separate follow-up instead of bundling it.
Before you finish, verify: would your fix still pass the failing scenario AND every scenario that currently passes?
</instructions>
<failure_evidence>
{{error_and_logs}}
</failure_evidence>
<code>
{{code}}
</code>