e762a5a473
With the selective prompt-cache copy (#57046), un-marked messages on the decorated api_messages list share their nested content parts with the persistent conversation history — the per-message copy in conversation_loop is shallow and decoration now deep-copies only the marked messages. try_shrink_image_parts_in_messages previously wrote the re-encoded image INTO the aliased part/source dicts, so an image-too-large retry on an Anthropic route would silently replace the original image bytes in agent.messages (and persist the degraded copy). Replace the in-place writes with copy-on-write: rebuild the content list with fresh part/source/image_url dicts and reassign msg['content'] — a top-level write on the per-call copy that never reaches history. Adds two regression tests simulating the aliasing; both fail against the old in-place implementation (mutation-verified).