Error: 412 Precondition Failed, "condition not met".
Meaning: you sent a write with if_generation_match set, and the object's current generation does not match. Either someone else wrote it first, or it was created/deleted since you read it. The write was rejected to protect you from clobbering.
Common patterns:
- if_generation_match=0 with an existing object: "only write if absent" failed because it is present. You wanted create-or-fail semantics and the object is already there.
- if_generation_match=[N] after a read: another writer beat you. Re-read, get the new generation, re-apply your change, retry.
How to use it right:
1. Read object + generation.
2. Compute new content.
3. Write with if_generation_match=[generation from step 1].
4. On 412, go back to step 1. Bound the retries; infinite retry loops on hot objects starve.
This is optimistic concurrency, not an error to "fix" by removing the precondition. Removing it reintroduces the lost-update race the precondition was preventing.
Agent trap: catching 412 and retrying the SAME bytes with the SAME stale generation. That fails forever. You must re-read first.
Verify: after a successful write, the returned generation increments by one from your read; concurrent writers see 412s, not silent overwrites.