Skip to content

Commit d507e04

Browse files
committed
Fix race condition in catalog audit PR allocation and eliminate local METADATA.pb mutations during audit mode
1 parent eba2b45 commit d507e04

2 files changed

Lines changed: 34 additions & 21 deletions

File tree

.ci/autoupdater/catalog_audit.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,41 @@ def export_csv_report(results: List[Dict[str, Any]], output_filepath: str = "cat
126126
def process_single_family(item):
127127
filepath, meta, pipeline, max_prs, pr_counter, base_branch = item
128128

129-
should_create_pr = False
130-
if max_prs > 0:
131-
with pr_lock:
132-
if pr_counter[0] < max_prs:
133-
pr_counter[0] += 1
134-
should_create_pr = True
135-
136129
try:
137-
res = pipeline.process_family(filepath, create_pr=should_create_pr, base_branch=base_branch)
138-
139-
# If we pre-allocated PR slot but family had no update or PR creation failed, release slot
140-
if should_create_pr:
141-
pr_created = res.get("has_update") and res.get("pr_info") and res["pr_info"].get("created")
142-
if not pr_created:
143-
with pr_lock:
144-
pr_counter[0] = max(0, pr_counter[0] - 1)
130+
# Step 1: Run standard pipeline check in-memory without disk mutations
131+
res = pipeline.process_family(filepath, create_pr=False, base_branch=base_branch)
132+
133+
# Step 2: If an update is available, claim PR slot if under max_prs limit
134+
if res.get("has_update") and max_prs > 0:
135+
should_create_pr = False
136+
with pr_lock:
137+
if pr_counter[0] < max_prs:
138+
pr_counter[0] += 1
139+
should_create_pr = True
140+
141+
if should_create_pr:
142+
version_str = res.get("upstream_version") or (res.get("upstream_commit")[:7] if res.get("upstream_commit") else "update")
143+
pr_title = f"🤖 Update upstream font: {meta.name} v{version_str}"
144+
pr_info = pipeline.pr_creator.create_pull_request(
145+
family_name=meta.name,
146+
metadata_filepath=filepath,
147+
updated_pb_content=res.get("updated_pb_content", ""),
148+
pr_title=pr_title,
149+
pr_body=res.get("pr_body", ""),
150+
upstream_version=res.get("upstream_version"),
151+
upstream_commit=res.get("upstream_commit"),
152+
base_branch=base_branch,
153+
)
154+
res["pr_info"] = pr_info
155+
if pr_info and pr_info.get("created"):
156+
res["status"] = "PR_CREATED"
157+
else:
158+
# Release slot if PR creation failed so another family can try
159+
with pr_lock:
160+
pr_counter[0] = max(0, pr_counter[0] - 1)
161+
145162
return res
146163
except Exception as e:
147-
if should_create_pr:
148-
with pr_lock:
149-
pr_counter[0] = max(0, pr_counter[0] - 1)
150164
return {
151165
"family_name": meta.name if meta else Path(filepath).parent.name,
152166
"has_update": False,
@@ -156,6 +170,7 @@ def process_single_family(item):
156170

157171

158172

173+
159174
def run_full_catalog_audit(
160175
fonts_repo_path: str = ".",
161176
max_families: int = 2000,

.ci/autoupdater/orchestrator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,10 @@ def process_family(
140140
upstream_commit=check_result.upstream_commit,
141141
base_branch=base_branch,
142142
)
143-
else:
144-
meta_path.write_text(updated_pb_content, encoding="utf-8")
145-
146143

147144
# Record pipeline completion
148145
status_val = "PR_CREATED" if (pr_info and pr_info.get("created")) else ("PR_READY" if not should_auto_merge else "AUTO_MERGED")
146+
149147
check_id = self.state_store.record_check_result(
150148
family_name=meta.name,
151149
has_update=True,

0 commit comments

Comments
 (0)