You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sb...@apache.org on 2026/09/23 14:56:18 UTC
(tooling-trusted-releases) branch sbp updated: Avoid a potential race condition when recording workflow metadata
This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch sbp
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/sbp by this push:
new 4b2533b8 Avoid a potential race condition when recording workflow metadata
4b2533b8 is described below
commit 4b2533b81ef13b44314a206d9005f966a942a9a0
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Wed Sep 23 15:54:41 2026 +0100
Avoid a potential race condition when recording workflow metadata
---
atr/ssh.py | 7 ++-----
atr/storage/writers/revision.py | 8 ++++++++
tests/unit/test_create_revision.py | 27 +++++++++++++++++++++++++--
3 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/atr/ssh.py b/atr/ssh.py
index ca658887..6ae5cd2d 100644
--- a/atr/ssh.py
+++ b/atr/ssh.py
@@ -36,7 +36,6 @@ import asyncssh.kex as kex
import asyncssh.mac as mac
import ssh_audit.builtin_policies as builtin_policies
-import atr.attestable as attestable
import atr.config as config
import atr.db as db
import atr.ldap as ldap
@@ -697,6 +696,7 @@ async def _step_07b_process_validated_rsync_write(
raise datatypes.FailedError(f"rsync upload failed with exit status {exit_status} for {for_revision}")
try:
+ github_payload = server._get_github_payload(process)
result = await wacp.revision.create_revision_with_quarantine(
project_key,
version_key,
@@ -704,16 +704,13 @@ async def _step_07b_process_validated_rsync_write(
allowed_phases=frozenset({sql.ReleasePhase.RELEASE_CANDIDATE_DRAFT}),
description=description,
modify=modify,
+ github_payload=github_payload,
)
if isinstance(result, sql.Quarantined):
log.info(f"rsync upload quarantined for release {release_key}")
message = f"\nATR: Upload received for {project_key} {version_key}. Archive validation in progress.\n"
else:
- github_payload = server._get_github_payload(process)
if github_payload is not None:
- await attestable.github_tp_payload_write(
- project_key, version_key, result.safe_number, github_payload
- )
await wacp.release.set_commit_hash(project_key, version_key, github_payload.sha)
log.info(f"rsync upload successful for revision {result.number}")
host = config.get().APP_HOST
diff --git a/atr/storage/writers/revision.py b/atr/storage/writers/revision.py
index 55f408cb..32960bf8 100644
--- a/atr/storage/writers/revision.py
+++ b/atr/storage/writers/revision.py
@@ -50,6 +50,8 @@ import atr.util as util
if TYPE_CHECKING:
from collections.abc import Awaitable, Callable
+ import atr.models.github as github
+
_QUARANTINE_TOKEN_ALPHABET: Final[str] = "qpzry9x8gf2tvdw0s3jn54khce6mua7b"
_QUARANTINE_TOKEN_LENGTH: Final[int] = 24
@@ -155,6 +157,7 @@ async def _commit_new_revision(
path_provenance: dict[safe.RelPath, atr.models.attestable.ProvenanceV2] | None = None,
extracted_swhids: dict[str, str] | None = None,
sha3_hashes: dict[str, str] | None = None,
+ github_payload: github.TrustedPublisherPayload | None = None,
) -> sql.Revision:
try:
# This is the only place where models.Revision is constructed
@@ -233,6 +236,9 @@ async def _commit_new_revision(
sha3_hashes=sha3_hashes,
)
+ if github_payload is not None:
+ await attestable.github_tp_payload_write(project_key, version_key, new_revision.safe_number, github_payload)
+
if attestable.can_write_file_state_rows(previous_attestable, new_revision.parent_key):
for row in attestable.compute_file_state_rows(
release_key,
@@ -459,6 +465,7 @@ class CommitteeParticipant(FoundationCommitter):
| None = None,
clone_from: safe.RevisionNumber | None = None,
expected_revision: safe.RevisionNumber | None = None,
+ github_payload: github.TrustedPublisherPayload | None = None,
) -> sql.Revision | sql.Quarantined:
"""Create a new revision, quarantining archives that require validation."""
async with db.session() as data:
@@ -640,6 +647,7 @@ class CommitteeParticipant(FoundationCommitter):
version_key=version_key,
path_provenance=path_provenance,
sha3_hashes=sha3_hashes,
+ github_payload=github_payload,
)
async def set_tag(
diff --git a/tests/unit/test_create_revision.py b/tests/unit/test_create_revision.py
index 4f27fb0b..f30f6e9e 100644
--- a/tests/unit/test_create_revision.py
+++ b/tests/unit/test_create_revision.py
@@ -22,6 +22,7 @@ import unittest.mock as mock
import pytest
+import atr.models.github as github
import atr.models.safe as safe
import atr.models.sql as sql
import atr.storage.datatypes as datatypes
@@ -203,7 +204,8 @@ async def test_clone_from_older_revision_skips_merge_without_intervening_change(
@pytest.mark.asyncio
-async def test_commit_new_revision_writes_audit_entry(tmp_path: pathlib.Path):
+@pytest.mark.parametrize("has_github_payload", [False, True])
+async def test_commit_new_revision_writes_metadata_before_checks(tmp_path: pathlib.Path, has_github_payload: bool):
base_dir = safe.StatePath(tmp_path)
temp_dir = tmp_path / "interim"
temp_dir.mkdir()
@@ -212,11 +214,12 @@ async def test_commit_new_revision_writes_audit_entry(tmp_path: pathlib.Path):
sha3_hashes = await revision.attestable.compute_sha3_hashes(path_hashes, None, safe.StatePath(temp_dir))
release_key = sql.release_key("proj", "1.0")
release = mock.MagicMock()
- release.phase = sql.ReleasePhase.RELEASE_PREVIEW
+ release.phase = sql.ReleasePhase.RELEASE_CANDIDATE_DRAFT
release.release_policy = None
release.project.release_policy = None
release.activity_at = datetime.datetime(2026, 1, 1, tzinfo=datetime.UTC)
safe_data = MockSafeData(parent_key=None)
+ github_payload = mock.Mock(spec=github.TrustedPublisherPayload) if has_github_payload else None
calls: list[object] = []
safe_data.commit.side_effect = lambda: calls.append("commit")
@@ -224,9 +227,21 @@ async def test_commit_new_revision_writes_audit_entry(tmp_path: pathlib.Path):
mock.patch.object(revision.sql, "Revision", side_effect=_make_fake_revision),
mock.patch.object(revision.attestable, "write_files_data", new_callable=mock.AsyncMock) as write_files_data,
mock.patch.object(revision.attestable, "compute_file_state_rows", return_value=[]),
+ mock.patch.object(
+ revision.attestable,
+ "github_tp_payload_write",
+ new_callable=mock.AsyncMock,
+ side_effect=lambda *args: calls.append(("payload", args)),
+ ),
mock.patch.object(revision.paths, "get_archives_dir", return_value=base_dir / "archives"),
mock.patch.object(revision.paths, "release_directory", return_value=base_dir / "rev" / "00006"),
mock.patch.object(revision.storage, "audit", side_effect=lambda **kwargs: calls.append(kwargs)),
+ mock.patch.object(
+ revision.tasks,
+ "draft_checks",
+ new_callable=mock.AsyncMock,
+ side_effect=lambda *args, **kwargs: calls.append("checks"),
+ ),
mock.patch.object(revision.util, "chmod_directories"),
):
await revision._commit_new_revision(
@@ -243,10 +258,17 @@ async def test_commit_new_revision_writes_audit_entry(tmp_path: pathlib.Path):
temp_dir=str(temp_dir),
version_key=safe.VersionKey("1.0"),
sha3_hashes=sha3_hashes,
+ github_payload=github_payload,
)
assert write_files_data.await_args.kwargs["sha3_hashes"] == sha3_hashes
+ expected_payload_calls = (
+ [("payload", (safe.ProjectKey("proj"), safe.VersionKey("1.0"), safe.RevisionNumber("00006"), github_payload))]
+ if has_github_payload
+ else []
+ )
assert calls == [
+ *expected_payload_calls,
"commit",
{
"action": "revision_create",
@@ -257,6 +279,7 @@ async def test_commit_new_revision_writes_audit_entry(tmp_path: pathlib.Path):
"description": "Upload of 2 files through web interface",
"was_quarantined": False,
},
+ "checks",
]
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org