Skip to content

CI: Retry S3 result upload when a competing write is in flight - #112786

Merged
rienath merged 9 commits into
masterfrom
data-race-ci
Aug 3, 2026
Merged

rienath merged 9 commits into
masterfrom
data-race-ci

Conversation

@rienath

@rienath rienath commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

copy_file_to_s3_with_version retries a lost race only on PreconditionFailed (the competing write already committed, so our read is stale). But S3 rejects a conditional write with ConditionalRequestConflict when 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):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Version info

  • Merged into: 26.8.1.696 (included in 26.8 and later)

@rienath
rienath requested review from leshikus and maxknv July 31, 2026 18:21
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f9d7173]

Summary: ✅


AI Review

Summary

This PR correctly broadens the lost-race classification so ConditionalRequestConflict follows the same retry path as PreconditionFailed in EventFeed.update and S3.copy_file_to_s3_with_version, and the added tests cover the helper branches that changed. I still see two current-code contract gaps in the touched optimistic-locking flow, so I cannot approve the PR as-is.

Findings

⚠️ Majors

  • [ci/praktika/event.py:324-327] [dismissed by author -- https://github.com/CI: Retry S3 result upload when a competing write is in flight #112786#discussion_r3693235866] EventFeed.update still promises an atomic optimistic-locking update, but the create path writes without any precondition when from_s3 returned NoSuchKey. Two concurrent first writers both execute unconditional put_object, so the later one can overwrite the earlier event and the new retry branch never gets a chance to fire. Suggested fix: send IfNoneMatch="*" when _etag is empty and treat PreconditionFailed / ConditionalRequestConflict on that create path as the same lost race.
  • [ci/praktika/native_jobs.py:1125-1126] [dismissed by author -- https://github.com/CI: Retry S3 result upload when a competing write is in flight #112786#discussion_r3693423665] The PR reclassifies ConditionalRequestConflict into the "retry me" False return from S3.copy_file_to_s3_with_version, but native_jobs._finish_workflow still ignores that boolean. In CLI-only environments a competing final-report write can therefore drop update_final_report changes silently instead of retrying or surfacing an exception, so the advertised "retry result upload" contract still does not hold for this caller. Suggested fix: retry here the same way update_workflow_results does, or fail loud when the final versioned upload returns False.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Make the first EventFeed write conditional, or narrow the atomicity claim if brand-new feeds are intentionally best-effort.
  2. Handle False from _ResultS3.copy_result_to_s3_with_version in ci/praktika/native_jobs.py by retrying or failing loud.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 31, 2026
Comment thread ci/praktika/s3.py Resolved
Comment thread ci/praktika/s3.py Resolved
Comment thread ci/praktika/s3.py Outdated
Comment on lines +282 to +283
# Lost optimistic-lock race. Set to true s.t. the caller re-reads the current version and retries.
no_strict = True

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was an error that we didn't set it before

Comment thread ci/praktika/event.py
error_code = e.response.get("Error", {}).get("Code")
if error_code == "PreconditionFailed" and attempt < max_retries - 1:
if (
error_code in ("PreconditionFailed", "ConditionalRequestConflict")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ci/praktika/s3.py
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caller already ignores False on lost races. Fixing it properly is outside of the scope of this PR

@leshikus leshikus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Comment thread ci/praktika/s3.py Outdated
@@ -275,8 +275,13 @@ def run_command_with_retries(
print("ERROR: Invalid AWS CLI command or CLI client version:")
print(f" | awc error: {stderr}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably aws should be here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed

@leshikus leshikus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last change potentially affects developers too much

Comment thread ci/praktika/result.py Outdated
# 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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think this should stop CI to succeed?

@rienath rienath Aug 3, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pre-existing issue though. Happy to remove the condition

Comment thread ci/praktika/result.py Outdated
Comment on lines +1523 to +1524
else:
raise RuntimeError(f"Failed to upload workflow result after {MAX_ATTEMPTS} attempts")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else:
raise RuntimeError(f"Failed to upload workflow result after {MAX_ATTEMPTS} attempts")

For the reference of readers: @leshikus asked me privately to remove these lines until @maxknv reviews them. We can add them in a separate PR

@rienath
rienath added this pull request to the merge queue Aug 3, 2026
Merged via the queue into master with commit cc77e19 Aug 3, 2026
180 checks passed
@rienath
rienath deleted the data-race-ci branch August 3, 2026 17:15
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants