Repository navigation
CI: Retry S3 result upload when a competing write is in flight - #112786
Conversation
|
Workflow [PR], commit [f9d7173] Summary: ✅ AI ReviewSummaryThis PR correctly broadens the lost-race classification so Findings
Final VerdictStatus: Minimum required actions:
|
| # Lost optimistic-lock race. Set to true s.t. the caller re-reads the current version and retries. | ||
| no_strict = True |
There was a problem hiding this comment.
I think it was an error that we didn't set it before
| error_code = e.response.get("Error", {}).get("Code") | ||
| if error_code == "PreconditionFailed" and attempt < max_retries - 1: | ||
| if ( | ||
| error_code in ("PreconditionFailed", "ConditionalRequestConflict") |
There was a problem hiding this comment.
ConditionalRequestConflict only helps once EventFeed.to_s3 is doing a conditional write, but the first-write path still is not. When from_s3 returns NoSuchKey, _etag stays empty, so to_s3 sends a plain put_object without either IfMatch or IfNoneMatch; I instrumented the current code locally and the first write goes out with only Bucket/Key/Body/content headers. Two concurrent creators therefore both read "missing", both upload unconditionally, and the later one overwrites the earlier event, so this new retry branch never fires for the empty-feed case.
That also means the new test in ci/tests/test_event.py is modeling a 409 that S3 will not emit on this path today. Can we make the create case conditional too (for example IfNoneMatch="*", then retry PreconditionFailed/ConditionalRequestConflict the same way) so EventFeed.update is actually atomic for a brand-new feed?
There was a problem hiding this comment.
The first write has always been unconditional, and this PR only fixes error-code classification on writes that are already conditional. Fix is out of the scope. The test point is fair and fixed.
| or "ConditionalRequestConflict" in stderr | ||
| ): | ||
| # Lost optimistic-lock race. Set to true s.t. the caller re-reads the current version and retries. | ||
| no_strict = True |
There was a problem hiding this comment.
This only becomes a retry signal for callers that check the boolean. copy_file_to_s3_with_version now returns False here, but ci/praktika/native_jobs.py:1125 still ignores the result of _ResultS3.copy_result_to_s3_with_version, so in CLI-only environments a competing final-report write can now be silently dropped instead of being retried or surfacing as an exception. Can we either make that caller retry/fail explicitly, or keep propagating a distinct failure until every direct caller handles False?
There was a problem hiding this comment.
This caller already ignores False on lost races. Fixing it properly is outside of the scope of this PR
| @@ -275,8 +275,13 @@ def run_command_with_retries( | |||
| print("ERROR: Invalid AWS CLI command or CLI client version:") | |||
| print(f" | awc error: {stderr}") | |||
There was a problem hiding this comment.
probably aws should be here
leshikus
left a comment
There was a problem hiding this comment.
The last change potentially affects developers too much
| # random delay (0-2s) to reduce contention and minimize race conditions | ||
| # when multiple concurrent jobs attempt to update the workflow report | ||
| time.sleep(random.uniform(0, 2)) | ||
| else: |
There was a problem hiding this comment.
do you think this should stop CI to succeed?
There was a problem hiding this comment.
The last attempt already raises for unexpected errors (no_strict=False). This closes the gap where retry exhaustion by lost races would fall through and return a status that never reached S3. It takes 49 consecutive failed cycles to get here, so it only fires when something is genuinely broken
There was a problem hiding this comment.
This is a pre-existing issue though. Happy to remove the condition
| else: | ||
| raise RuntimeError(f"Failed to upload workflow result after {MAX_ATTEMPTS} attempts") |
copy_file_to_s3_with_versionretries a lost race only onPreconditionFailed(the competing write already committed, so our read is stale). But S3 rejects a conditional write withConditionalRequestConflictwhen the competing write is still in flight (same lost race, caught one moment earlier). Map it to the same retry path instead of killing the job.Example of this firing.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Version info
26.8.1.696(included in26.8and later)