Repository navigation
Description
Summary
evaluateWritePreconditions (emulator/s3_conditional.go) returns 412 PreconditionFailed for a
lost race and 404 NoSuchKey for If-Match against an absent key. Both are correct and match AWS.
The gap is that S3 has a third outcome the emulator cannot produce: 409 Conflict. It is not a
cosmetic difference in status code — it selects a different recovery path in the caller, and a
caller that treats it as a synonym for 412 is wrong in a way no test against substrate can reveal.
This follows on from #397, which made 412 reachable. Filing it separately because 409 is a distinct
behavior rather than a missed case of the same one.
What AWS documents
From How to prevent object overwrites with conditional writes, under Conditional write behavior:
You can also receive a
409 Conflictresponse in the case of concurrent requests if a delete
request to an object succeeds before a conditional write operation on that object completes. When
using conditional writes withPutObject, uploads may be retried after receiving a409 Conflict
error. When usingCompleteMultipartUpload, the entire multipart upload must be re-initiated with
CreateMultipartUploadto upload the object again after receiving a409 Conflicterror.
And in the scenarios section, for a delete landing during an in-flight multipart upload:
This scenario will result in a
409 Conflictresponse for anIf-None-Matchheader and a
404 Not Foundresponse for anIf-Matchheader.
So the caller contract is three-way, and the arms are not interchangeable:
| response | meaning | correct recovery |
|---|---|---|
412 PreconditionFailed |
another writer won the race | re-read state, recompute, retry the CAS |
409 Conflict on PutObject |
a delete interleaved | retry the PUT as-is |
409 Conflict on CompleteMultipartUpload |
a delete interleaved | abandon the upload ID; re-do CreateMultipartUpload and every UploadPart |
404 NoSuchKey on If-Match |
object gone | re-upload rather than retry the CAS |
A CAS loop that retries a CompleteMultipartUpload 409 by re-sending Complete with the same upload
ID will spin until it gives up, because that upload ID can no longer complete. That is the bug this
would catch, and it is invisible today: substrate can only produce 412, so the loop looks correct.
Why it matters here
ObjectFS is evaluating S3 conditional writes as a coordination primitive (objectfs#169) — per-key
CAS for leader election and metadata updates, in place of a replicated log. Verified against
substrate v0.85.0 already, and all of it passes: exactly one of 32 concurrent If-None-Match: *
PUTs wins, a stale-ETag write gets PreconditionFailed, If-Match on an absent key gets
NoSuchKey, and 8 workers running a CAS increment loop converge to exactly 8 with no lost updates.
Substrate's per-key striped mutex, and the comment explaining why check-then-Put would invert the
exactly-one-winner property, is exactly the fidelity that made those results worth trusting.
What cannot be tested is the failure branch a production caller most needs: distinguishing "I lost a
race, recompute and retry" from "a delete interleaved, and for MPU my upload ID is dead." Since the
CAS loop is the whole mechanism under evaluation, its error taxonomy is the part where a wrong
assumption is most expensive.
Suggested shape
409 arises from a race, not from a state a request can assert, so it cannot be produced by
inspecting the current object the way 412 is. Two options, and the second seems better:
-
Emit 409 when a conditional write finds the key absent and a delete for that key was observed
recently — needs a per-key "recently deleted" window, which is state substrate would have to keep. -
Make it fault-injectable. A FaultController rule that turns a conditional write into
409 Conflictlets a test exercise the branch deterministically without substrate having to model
the race. This matches how the outcome is reached in reality — it is a timing accident, so a test
wanting it should ask for it rather than try to provoke it.
Option 2 also covers the MPU asymmetry cleanly: the rule can target CompleteMultipartUpload
specifically, which is the arm with the expensive recovery.
The error body S3 returns for this is ConditionalRequestConflict, per the
PutObject error list — a
distinct code from PreconditionFailed, which is what an SDK matches on, so it needs to be exact
for errors.As on smithy.APIError to work the way a caller writes it.
Also worth noting
If-None-Match on write correctly rejects any value other than * (matching "The If-None-Match
header expects the * (asterisk) value"), and CompleteMultipartUpload correctly ignores in-progress
uploads when evaluating preconditions — both verified in v0.85.0. Those are the two subtleties I
expected to find missing and did not.
Activity
docs: evaluate conditional writes against Raft, and correct what the …
scttfrdmn commentedon Aug 3, 2026
Labelled
type: bug/area: s3/fidelity, and deliberately left unmilestonedrather than pulled into v0.89.0. Recording the reasoning so the absence is a decision
rather than an oversight.
Agreed on the substance, including your option 2. The three-way taxonomy is real and
the
CompleteMultipartUploadarm is the expensive one: a CAS loop that retries Completewith the same upload ID after a 409 spins until it gives up, and substrate can only
produce 412, so that loop looks correct today. That is a caller-contract gap, not a
cosmetic status-code difference.
Why option 2 is the right shape here, in substrate's own terms. A 409 arises from a
race — a delete landing between the conditional write's evaluation and its completion.
There is no request-inspectable state that implies it, so it cannot be derived the way
412 is. Option 1's "recently deleted" window would make the response depend on when
a request arrives, which is the one thing substrate's determinism guarantee forbids:
same inputs → same outputs, and a replay must reproduce exactly. A
FaultControllerrule is the established way substrate produces an outcome that is real but timing-born —
the test asks for it rather than trying to provoke it, and the seed makes it reproducible.
Why not v0.89.0. That release is the CloudFormation delete/rollback cluster (#518,
#508, #534, #520) — one coupled model, sharing no mechanism with the fault controller.
This belongs with whichever release next touches fault injection; #510 (the shared PRNG
making
Probabilityorder-dependent) is parked for the same reason, and the two arebetter done together: #510 is precisely the kind of determinism defect that would
undermine a new fault rule's reproducibility, so fixing it first is the sensible order.
Two things worth pinning down before implementation, both of which affect what a rule
can express:
PutObjectvsCompleteMultipartUpload)or the condition header (
If-None-MatchvsIf-Match). Your table makes themindependent axes — a delete during MPU is 409 for
If-None-Matchbut 404 forIf-Match— so a rule keyed on operation alone cannot express the documented matrix.CompleteMultipartUploadmust also invalidate the upload ID insubstrate's state. If it does not, a test could retry Complete and succeed, which
would validate the exact broken retry loop this issue exists to catch. I think it
must, and that is the part with real state implications rather than just a response.
Thanks for the detail on the ObjectFS side (objectfs#169) — knowing the CAS loop is the
mechanism under evaluation, rather than an incidental caller, is what makes the error
taxonomy worth getting exactly right rather than approximately.
scttfrdmn commentedon Aug 6, 2026
Picking this up for v0.93.0. Measured it on a live server first, and one result changes the plan I recorded above: option 2 produces the code but not the consequence. It also settles both of the questions I left open.
Option 2 cannot express the bug this issue exists to catch
Armed over the control plane on a running server:
{"service":"s3","operation":"CompleteMultipartUpload", "fault_type":"error","error_code":"ConditionalRequestConflict", "http_status":409,"times":1}The first
CompleteMultipartUploadfailed as asked, andGET /v1/fault/rulesreportedfired: 1:Then the immediate retry with the same upload ID succeeded:
Control, same server: a
CompleteMultipartUploadthat genuinely succeeds and is then retried returnsNoSuchUpload. So the difference is not the SDK or the harness — the faulted upload really was still completable.The cause is where faults run.
InjectFaultis step 4.5 of the request pipeline (emulator/server.go:636), beforeregistry.RouteRequestat step 5, so a fault never reaches the plugin and writes no state. That is deliberate and documented ("no state is written for a request a fault refuses"), and right for what fault injection is — it just means a fault rule cannot invalidate an upload ID. A consumer's broken CAS loop, the one that re-sends Complete with the same ID, would pass against a fault rule exactly as it passes today.So my answer to my own question 2 above is confirmed, and it is load-bearing rather than a detail: the 409 must invalidate the upload ID, and that requirement is what rules out the fault controller as the mechanism.
Question 1: the matrix does not need a header axis
I worried that a rule keyed on operation alone could not express "409 for
If-None-Match, 404 forIf-Match". It does not have to, because those two cells are not the same kind of outcome:If-Matchfails withNoSuchKey. Substrate already produces it today fromevaluateWritePreconditions, reachable by simply deleting the key. Nothing needs seeding.If-None-Match. The API model'sIfMatchdocumentation forPutObject,CopyObjectandCompleteMultipartUploadeach says "If a conflicting operation occurs during the upload S3 returns a 409 ConditionalRequestConflict response", with recovery advice that differs per arm —PutObjectIf-None-Match "retry the upload", If-Match "fetch the object's ETag and retry", Complete "re-initiate the multipart upload withCreateMultipartUpload, and re-upload each part".The user guide's 404-for-
If-Matchline describes the timing where the delete lands before evaluation, which is the determinate case above. So one seeded outcome per operation covers the documented matrix, and the header axis is not needed.What ships
A plugin-level seed — substrate's own documented answer to "a deterministic emulator needs to produce a rare outcome" (the
Fault-awarefidelity level). The seed reaches the plugin, so the multipart arm can kill the upload.POST /v1/s3/conditional-conflictandDELETEthe same, keyedbucket/keyor the"*"wildcard, following the established seed pattern (sqsConsistencySeed/consumeQueueMissinemulator/sqs_control.go): key-scoped consulted before wildcard, an exhausted key-scoped seed falling through so it cannot mask a funded wildcard, and counted in occurrences rather than a duration — the simulated clock advances with wall time, so a duration seed would make assertions wall-clock dependent.putConflicts,copyConflicts,completeConflicts), so a fixture can seed the multipart arm without perturbing plain writes.CompleteMultipartUploadarm additionally calls the existingabortUploadState, so a same-ID retry getsNoSuchUploadinstead of spinning. This deliberately contradicts the 412 arm's "the upload stays open" behaviour, and for a documented reason: Complete's 409 recovery is re-initiating withCreateMultipartUpload, which is only meaningful if the old ID cannot complete.Provenance
The code and the status are documented (the
IfMatch/IfNoneMatchmember docs above, plus the user guide). But there is no shape namedConditionalRequestConflictin the API model, and the code appears in no operation'serrorslist, so no message string is documented anywhere. Perdocs/fidelity.mdthe message will be substrate's own and will say so in the comment beside the literal, and the invalidation of the upload ID is substrate's reading of the documented recovery advice rather than an observed response. Assert on the code and the status.Shipping alongside #510, for the reason recorded above — its shared PRNG is the determinism defect that would otherwise undermine the fault tier this touches — plus two wiring gaps found while probing: a default CLI server builds no
FaultControllerat all, so/v1/fault/rulesanswers 501 (which is why my first probe silently did nothing), and when one exists it is seeded fromtime.Now().UnixNano()with no way for a config file to pin it.feat(s3): a seedable 409 ConditionalRequestConflict on conditional wr…
scttfrdmn commentedon Aug 6, 2026
Shipped in v0.93.0 (#583), as the seed described in the comment above rather than as option 2, for the measured reason: a fault short-circuits at Step 4.5 before the plugin, so it produces the code but leaves the upload ID completable — passing the very loop this issue exists to fail.
What landed.
POST /v1/s3/conditional-conflictseeds how many subsequent conditional writes to a key reportConditionalRequestConflict/409, keyedbucket/keyor by*, with independentputConflicts/copyConflicts/completeConflictscounters;DELETEclears one or all. A conflict is consumed only after the preconditions pass, so a genuine412or404is still reported as itself and does not spend the budget, and an unconditional write is never affected — the code is documented only onIf-Match/If-None-Match.The headline arm. Consuming a seeded
completeConflictscallsabortUploadState, so the upload ID genuinely dies. Verified against the real AWS CLI: the firstcomplete-multipart-uploadreturns409 ConditionalRequestConflict, the retry with the same upload ID returnsNoSuchUpload,ListPartson that ID is gone,ListMultipartUploadsis empty, and the object is a404. Control: a412'd Complete leaves the upload open and completable, which is the pre-existing behaviour and the distinction a caller has to act on.Provenance, per
docs/fidelity.md. The code, the409status and the per-arm recovery advice come from the S3 API model'sIfMatch/IfNoneMatchmember documentation and the conditional-writes user-guide page. No message text is documented anywhere — the model carries noConditionalRequestConflictshape and lists the code in no operation'serrors— so the message is substrate's own and the comment beside the literal says so. Assert on the code and the status. The upload-ID invalidation is substrate's inference from the documented recovery advice, which is only meaningful if the old ID cannot complete; that too is recorded in the code.12 tests in
emulator/s3_conditional_conflict_test.go;docs/services.mddocuments the endpoint, the precedence and fall-through rules, and the multipart asymmetry, and the now-false paragraph claiming409was "deliberately not emulated" is gone.Mutation-tested where the release's assumptions are load-bearing —
abortUploadStatedropped from the Complete arm, the seed consulted beforeevaluateWritePreconditionsinstead of after, the fall-throughcontinueturned into areturn, thecond.any()gate removed, the decrement dropped, and409→412. All CAUGHT.One measured defect found on the way and deliberately not fixed here: #582, the same wildcard-double-consume race in
consumeQueueMissthat this implementation's dedicated seed mutex avoids. It is milestoned v0.94.0.fix(errors): a conflict on a contended key took every write in the pr…
feat(coord): a lease over PutObjectIf where every guarded action re-a…