afxx 1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
afxx/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env python3
2
+ """Implementation modules for the AF development workflow CLI."""
afxx/afx/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env python3
2
+ """AFX replay and platform API integration."""
afxx/afx/launcher.py ADDED
@@ -0,0 +1,144 @@
1
+ """Launch the official AFX CLI; no upload, heartbeat or retest implementation."""
2
+
3
+ import os
4
+ from pathlib import Path
5
+ import subprocess
6
+ import time
7
+
8
+ from afxx import common as w
9
+ from afxx import config
10
+ from afxx.environment import runtime
11
+ from afxx.afx import replay
12
+
13
+
14
+ def process_identity(pid):
15
+ """Linux process start time protects against PID reuse."""
16
+ try:
17
+ fields = Path(f"/proc/{int(pid)}/stat").read_text().rsplit(")", 1)[1].split()
18
+ return None if fields[0] == "Z" else fields[19]
19
+ except (OSError, ValueError, IndexError):
20
+ return None
21
+
22
+
23
+ def ensure_started(c, package):
24
+ settings = config.platform_settings(c)
25
+ token = settings.get("client_token_file")
26
+ w.require_code(
27
+ bool(token),
28
+ "CONFIG_INVALID",
29
+ "fill platform.client_token_file (remote AFX client token)",
30
+ )
31
+ home = Path(c["remote"]["state_dir"]).parent / "afx-client"
32
+ home.mkdir(parents=True, exist_ok=True, mode=0o700)
33
+ with w.lock(home / "launch.lock"):
34
+ env = runtime.environment(c)
35
+ env["AUTOFUSEX_HOME"] = str(home)
36
+ devices = c["replay"]["devices"]
37
+ if devices == "auto":
38
+ count = replay.visible_device_count(
39
+ w.capture(replay.device_command(runtime.python(c)), env=env, timeout=60)
40
+ )
41
+ devices = [f"npu:{i}" for i in range(count)]
42
+ (home / "results").mkdir(exist_ok=True, mode=0o700)
43
+ base = [runtime.python(c), "-m", "afx", "platform", "client"]
44
+ options = [
45
+ "--endpoint",
46
+ settings["url"],
47
+ "--token-file",
48
+ token,
49
+ "--results",
50
+ str(home / "results/results.sqlite"),
51
+ ]
52
+ for device in devices:
53
+ options.extend(["--device", device])
54
+ argv = base + ["run", *options, "--retest"]
55
+ expected = {
56
+ "argv": argv,
57
+ "package": package,
58
+ "environment": {
59
+ k: env.get(k)
60
+ for k in (
61
+ "VIRTUAL_ENV",
62
+ "ASCEND_HOME_PATH",
63
+ "LD_LIBRARY_PATH",
64
+ "PYTHONPATH",
65
+ "ASCEND_RT_VISIBLE_DEVICES",
66
+ "ASCEND_VISIBLE_DEVICES",
67
+ )
68
+ },
69
+ }
70
+ record_path = home / "launch.json"
71
+ marker_path = home / "platform-client.json"
72
+ record = w.read(record_path) if record_path.exists() else {}
73
+ active = record and process_identity(record["pid"]) == record["start_time"]
74
+ if active:
75
+ w.require_code(
76
+ all(record["expected"].get(key) == expected[key] for key in ("argv", "environment")),
77
+ "PLATFORM_CLIENT_MISMATCH",
78
+ f"running AFX client uses another environment or command; see {record_path}",
79
+ )
80
+ w.require_code(
81
+ marker_path.exists()
82
+ and w.read(marker_path).get("pid") == record["pid"],
83
+ "PLATFORM_CLIENT_START_FAILED",
84
+ f"AFX startup not confirmed; see {home / 'client.log'}",
85
+ )
86
+ return {
87
+ "pid": record["pid"],
88
+ "reused": True,
89
+ "log": str(home / "client.log"),
90
+ }
91
+ # Do not duplicate an independently started client in the same AFX home.
92
+ if marker_path.exists():
93
+ marker = w.read(marker_path)
94
+ w.require_code(
95
+ not process_identity(marker.get("pid", 0)),
96
+ "PLATFORM_CLIENT_UNTRACKED",
97
+ f"AFX client already running without matching launch evidence; see {marker_path}",
98
+ )
99
+ # Official one-shot command checks authentication before launching the resident process.
100
+ try:
101
+ w.capture(base + ["once", *options], env=env, cwd=home, timeout=90)
102
+ except Exception as error:
103
+ raise w.WorkflowError(
104
+ "PLATFORM_CLIENT_START_FAILED",
105
+ "AFX client preflight failed; check endpoint and client token permissions",
106
+ ) from error
107
+ with (home / "client.log").open("ab") as log:
108
+ process = subprocess.Popen(
109
+ argv,
110
+ env=env,
111
+ cwd=home,
112
+ stdin=subprocess.DEVNULL,
113
+ stdout=log,
114
+ stderr=subprocess.STDOUT,
115
+ start_new_session=True,
116
+ )
117
+ start_time = process_identity(process.pid)
118
+ w.require_code(
119
+ start_time is not None,
120
+ "PLATFORM_CLIENT_START_FAILED",
121
+ f"AFX exited during startup; see {home / 'client.log'}",
122
+ )
123
+ w.write(
124
+ record_path,
125
+ {"pid": process.pid, "start_time": start_time, "expected": expected},
126
+ )
127
+ deadline = time.monotonic() + 30
128
+ while time.monotonic() < deadline:
129
+ w.require_code(
130
+ process.poll() is None,
131
+ "PLATFORM_CLIENT_START_FAILED",
132
+ f"AFX exited during startup; see {home / 'client.log'}",
133
+ )
134
+ if marker_path.exists() and w.read(marker_path).get("pid") == process.pid:
135
+ return {
136
+ "pid": process.pid,
137
+ "reused": False,
138
+ "log": str(home / "client.log"),
139
+ }
140
+ time.sleep(0.2)
141
+ raise w.WorkflowError(
142
+ "PLATFORM_CLIENT_START_FAILED",
143
+ f"AFX startup not confirmed; see {home / 'client.log'}",
144
+ )
afxx/afx/platform.py ADDED
@@ -0,0 +1,485 @@
1
+ """AFX issue protocol and remote verification submission."""
2
+
3
+ import sys
4
+ from afxx import common as workflow_common
5
+ from afxx import config as workflow_config
6
+ from afxx.environment import runtime as workflow_runtime
7
+
8
+ import contextlib
9
+ import json
10
+ from pathlib import Path
11
+ import re
12
+ import threading
13
+ import time
14
+ import urllib.error
15
+ import urllib.parse
16
+ import urllib.request
17
+ import uuid
18
+
19
+
20
+ class NoRedirect(urllib.request.HTTPRedirectHandler):
21
+ def redirect_request(self, req, fp, code, msg, headers, newurl):
22
+ return None
23
+
24
+
25
+ def call(c, method, path, body=None, *, remote=False):
26
+ p = workflow_config.platform_settings(c)
27
+ try:
28
+ token = (
29
+ Path(p["remote_token_file" if remote else "token_file"]).read_text().strip()
30
+ )
31
+ except OSError:
32
+ raise workflow_common.WorkflowError(
33
+ "PLATFORM_CREDENTIAL_MISSING", "无法读取平台凭据文件"
34
+ ) from None
35
+ workflow_common.require(
36
+ token and not any(ch.isspace() for ch in token), "invalid platform token file"
37
+ )
38
+ headers = {"Authorization": "Bearer " + token, "Content-Type": "application/json"}
39
+ request = urllib.request.Request(
40
+ p["url"].rstrip("/") + path,
41
+ data=json.dumps(body).encode() if body is not None else None,
42
+ headers=headers,
43
+ method=method,
44
+ )
45
+ try:
46
+ with urllib.request.build_opener(NoRedirect()).open(
47
+ request, timeout=30
48
+ ) as response:
49
+ value = json.load(response)
50
+ except urllib.error.HTTPError as error:
51
+ # Return only a validated protocol code, never arbitrary response text or headers.
52
+ try:
53
+ code = json.load(error).get("error", {}).get("code", "")
54
+ except (ValueError, AttributeError):
55
+ code = ""
56
+ code = (
57
+ code
58
+ if isinstance(code, str) and re.fullmatch(r"[a-z_]{1,64}", code)
59
+ else "http_error"
60
+ )
61
+ raise workflow_common.WorkflowError(
62
+ "PLATFORM_" + code.upper(), f"平台请求失败,HTTP {error.code} ({code})"
63
+ ) from None
64
+ except (OSError, ValueError):
65
+ raise workflow_common.WorkflowError(
66
+ "PLATFORM_UNAVAILABLE", "平台连接或响应异常;重试同一请求"
67
+ ) from None
68
+ if (
69
+ not isinstance(value, dict)
70
+ or value.get("schema_version") != 1
71
+ or value.get("ok") is not True
72
+ or "data" not in value
73
+ ):
74
+ raise workflow_common.WorkflowError(
75
+ "PLATFORM_RESPONSE_INVALID", "平台未返回成功的 JSON 响应"
76
+ )
77
+ return value["data"]
78
+
79
+
80
+ NUMBERED_ISSUE = re.compile(r"[FAP][0-9]{1,9}")
81
+
82
+
83
+ def validate_issue_id(value):
84
+ workflow_common.require(
85
+ isinstance(value, str) and NUMBERED_ISSUE.fullmatch(value),
86
+ "issue ID must be an F, A or P followed by 1 to 9 digits",
87
+ )
88
+ return value
89
+
90
+
91
+ def record_path(c, issue_id):
92
+ return (
93
+ Path(c["local"]["state_dir"])
94
+ / "issues"
95
+ / (validate_issue_id(issue_id) + ".json")
96
+ )
97
+
98
+
99
+ def claimed(c, issue_id):
100
+ value = workflow_common.read(record_path(c, issue_id))
101
+ workflow_common.require(
102
+ value["platform_url"] == workflow_config.platform_settings(c)["url"]
103
+ and value["agent_id"] == c["platform"]["agent_id"],
104
+ "issue belongs to another platform or agent",
105
+ )
106
+ return value
107
+
108
+
109
+ def claim(c, request_key, *, issue_id=None):
110
+ p = workflow_config.platform_settings(c)
111
+ body = {"agent_id": p["agent_id"], "request_key": request_key}
112
+ if issue_id is not None:
113
+ body["issue_id"] = validate_issue_id(issue_id)
114
+ value = call(c, "POST", "/api/issues/claim", body)
115
+ if value is None:
116
+ return None
117
+ workflow_common.require(
118
+ isinstance(value, dict)
119
+ and value.get("lease_id")
120
+ and isinstance(value.get("lease_expires_at"), int)
121
+ and isinstance(value.get("repro"), dict),
122
+ "invalid issue claim response",
123
+ )
124
+ selected = validate_issue_id(value.get("issue_id"))
125
+ workflow_common.require(
126
+ issue_id is None or selected == issue_id, "issue identity mismatch"
127
+ )
128
+ value.update(
129
+ id=selected,
130
+ expires=value["lease_expires_at"] / 1000,
131
+ request_id=request_key,
132
+ platform_url=p["url"],
133
+ agent_id=p["agent_id"],
134
+ )
135
+ path = record_path(c, selected)
136
+ with workflow_common.lock(path.with_suffix(".lock")):
137
+ if path.exists():
138
+ prior = workflow_common.read(path)
139
+ workflow_common.require(
140
+ prior["expires"] <= value["expires"]
141
+ or prior["lease_id"] == value["lease_id"],
142
+ "stale claim retry; newer lease exists locally",
143
+ )
144
+ workflow_common.write(path, value)
145
+ return value
146
+
147
+
148
+ def summarize(c, issue_id, summary_file, request_id):
149
+ validate_issue_id(issue_id)
150
+ workflow_common.require(isinstance(request_id, str) and re.fullmatch(r"[A-Za-z0-9_.-]{1,128}", request_id),
151
+ "summarize requires a valid request-id")
152
+ try:
153
+ knowledge = workflow_config.read_config(summary_file)
154
+ except (OSError, ValueError, TypeError) as error:
155
+ raise workflow_common.WorkflowError("SUMMARY_INVALID", f"cannot read summary YAML: {error}") from error
156
+ required = {"kind", "title", "symptom", "root_cause", "solution"}
157
+ optional = {"keywords", "ops", "dtypes", "backends", "graph_pattern", "applicability", "version_range", "fix_ref", "body_md"}
158
+ workflow_common.require_code(
159
+ isinstance(knowledge, dict)
160
+ and all(isinstance(knowledge.get(k), str) and knowledge[k].strip() for k in required)
161
+ and set(knowledge) <= required | optional,
162
+ "SUMMARY_INVALID", "summary must contain kind/title/symptom/root_cause/solution and only supported knowledge fields",
163
+ )
164
+ lease = claimed(c, issue_id)
165
+ body = {"request_key": request_id, "lease_id": lease["lease_id"], "knowledge": knowledge}
166
+ context = {"platform_url": workflow_config.platform_settings(c)["url"], "agent_id": c["platform"]["agent_id"]}
167
+ path = record_path(c, issue_id).with_suffix("") / "summaries" / (workflow_common.digest(request_id) + ".json")
168
+ with workflow_common.lock(path.with_suffix(".lock")):
169
+ state = workflow_common.read(path) if path.exists() else {}
170
+ if state:
171
+ workflow_common.require_code(state["body"] == body and state["context"] == context,
172
+ "REQUEST_CONFLICT", "summary request-id already binds another summary, lease or platform")
173
+ if state["state"] == "submitted":
174
+ return state["response"]
175
+ else:
176
+ state = {"state": "prepared", "issue_id": issue_id, "context": context, "body": body}
177
+ workflow_common.write(path, state)
178
+ # Let the platform enforce summarizing, lease and knowledge permission.
179
+ # Do not pre-check state: a lost successful response must remain retryable after resolved.
180
+ value = call(c, "POST", f"/api/issues/{issue_id}/knowledge", state["body"])
181
+ workflow_common.require_code(
182
+ isinstance(value, dict) and value.get("issue_id") == issue_id
183
+ and value.get("status") == "resolved" and isinstance(value.get("knowledge_id"), str)
184
+ and re.fullmatch(r"K[0-9]{1,9}", value["knowledge_id"]),
185
+ "PLATFORM_RESPONSE_INVALID", "invalid summary publication response",
186
+ )
187
+ state.update(state="submitted", response=value)
188
+ workflow_common.write(path, state)
189
+ return value
190
+
191
+
192
+ def numbered_seeds(c, issue_id, repro):
193
+ if not repro["truncated"]:
194
+ return list(
195
+ dict.fromkeys(
196
+ case["case_key"]
197
+ for case in repro["cases"]
198
+ if case["case_source"] == "nnsmith"
199
+ )
200
+ )
201
+ # The paginated endpoint omits case_source. AFX reserves short E/F keys for nnsmith.
202
+ seeds = {}
203
+ cursor = 0
204
+ while True:
205
+ page = call(
206
+ c, "GET", f"/api/issues/{issue_id}/cases?role=affected&after={cursor}"
207
+ )
208
+ for case in page["cases"]:
209
+ key = case["case_key"]
210
+ if not case["stale"] and re.fullmatch(r"[EF][0-9A-Z]{26}", key):
211
+ seeds[key] = None
212
+ following = page["next_cursor"]
213
+ if following is None:
214
+ return list(seeds)
215
+ workflow_common.require_code(
216
+ type(following) is int and following > cursor,
217
+ "PLATFORM_RESPONSE_INVALID",
218
+ "invalid issue cases cursor",
219
+ )
220
+ cursor = following
221
+
222
+
223
+ def preview(c, issue_id, *, full=False):
224
+ validate_issue_id(issue_id)
225
+ receipt = claimed(c, issue_id)
226
+ if not full:
227
+ cases = receipt["repro"]["cases"]
228
+ summary = receipt.get("log_summary") or next(
229
+ (case["log_summary"] for case in cases if case.get("log_summary")),
230
+ receipt.get("title"),
231
+ )
232
+ return {
233
+ "issue_id": issue_id,
234
+ "failure_summary": summary,
235
+ "seeds": numbered_seeds(c, issue_id, receipt["repro"]),
236
+ }
237
+ return {
238
+ "issue_id": issue_id,
239
+ "snapshot": receipt["repro"],
240
+ "related_knowledge": receipt.get("related_knowledge", []),
241
+ }
242
+
243
+
244
+ def renew(c, lease, *, remote=False):
245
+ body = {"lease_id": lease["lease_id"], "request_key": uuid.uuid4().hex}
246
+ return call(
247
+ c,
248
+ "POST",
249
+ "/api/issues" + "/" + validate_issue_id(lease["id"]) + "/renew",
250
+ body,
251
+ remote=remote,
252
+ )
253
+
254
+
255
+ @contextlib.contextmanager
256
+ def deployment_lease(c, job):
257
+ request = workflow_common.read(job / "request.json")
258
+ lease = request.get("issue")
259
+ if not lease:
260
+ yield
261
+ return
262
+ workflow_config.platform_settings(c)
263
+ renew(c, lease, remote=True)
264
+ stopped = threading.Event()
265
+
266
+ def keep_alive():
267
+ while not stopped.wait(30):
268
+ try:
269
+ renew(c, lease, remote=True)
270
+ except Exception:
271
+ print("平台租约续期失败,提交前将再次检查", flush=True)
272
+
273
+ thread = threading.Thread(target=keep_alive, daemon=True)
274
+ thread.start()
275
+ try:
276
+ yield
277
+ finally:
278
+ stopped.set()
279
+ thread.join(timeout=35)
280
+
281
+
282
+ def submit_issue_round(c, path, state, lease, package):
283
+ issue_id = lease["id"]
284
+ # Match the version representation advertised by AFX platform clients.
285
+ candidate = {
286
+ "lease_id": lease["lease_id"],
287
+ "fix_version": re.sub(r"[^A-Za-z0-9_.+-]", "_", package["version"])[:64],
288
+ "fix_sha256": package["sha256"],
289
+ }
290
+ if not state:
291
+ state = {
292
+ "state": "prepared",
293
+ "issue_id": issue_id,
294
+ "body": dict(candidate, request_key=uuid.uuid4().hex),
295
+ }
296
+ workflow_common.write(path, state)
297
+ workflow_common.require(
298
+ all(state["body"].get(k) == v for k, v in candidate.items()),
299
+ "prepared verification belongs to another lease or AF package",
300
+ )
301
+ from afxx.afx import launcher
302
+
303
+ launcher.ensure_started(c, package)
304
+ result = call(
305
+ c, "POST", f"/api/issues/{issue_id}/verify", state["body"], remote=True
306
+ )
307
+ workflow_common.require_code(
308
+ isinstance(result, dict)
309
+ and result.get("issue_id") == issue_id
310
+ and type(result.get("round_no")) is int
311
+ and result["round_no"] > 0,
312
+ "PLATFORM_RESPONSE_INVALID",
313
+ "invalid numbered issue verification response",
314
+ )
315
+ state.update(state="submitted", round_no=result["round_no"], response=result)
316
+ workflow_common.write(path, state)
317
+ return state
318
+
319
+
320
+ def verify(c, job, lease=None):
321
+ linked = workflow_common.read(job / "request.json").get("issue")
322
+ if linked and lease:
323
+ workflow_common.require(
324
+ linked == lease, "deployment belongs to a different issue or lease"
325
+ )
326
+ lease = lease or linked
327
+ workflow_common.require(
328
+ lease, "issue verify requires --issue-id or an issue-linked deployment"
329
+ )
330
+ issue_id = validate_issue_id(lease["id"])
331
+ path = job / "platform.json"
332
+ with workflow_common.lock(job / "platform.lock"):
333
+ state = workflow_common.read(path) if path.exists() else {}
334
+ workflow_common.require(
335
+ not state or state.get("issue_id") == issue_id,
336
+ "deployment already linked to another issue",
337
+ )
338
+ if state.get("state") == "submitted":
339
+ workflow_common.require(
340
+ state["body"]["lease_id"] == lease["lease_id"],
341
+ "submission belongs to another lease",
342
+ )
343
+ return state
344
+ # Capture the selected binary afresh, including retries of an uncertain POST.
345
+ code = "import json; from autofusex.fuzz.client.environment import collect; print(json.dumps(collect()))"
346
+ package = workflow_runtime.af_identity(
347
+ json.loads(
348
+ workflow_common.capture(
349
+ [workflow_runtime.python(c), "-c", code],
350
+ env=workflow_runtime.environment(c),
351
+ ).splitlines()[-1]
352
+ )
353
+ )
354
+ deployment = workflow_runtime.current_deployment(c, job / "result.json")
355
+ workflow_common.require(
356
+ package["sha256"] == deployment["runtime"]["pyautofuse"]["sha256"],
357
+ "installed AF differs from this deployment",
358
+ )
359
+ return submit_issue_round(c, path, state, lease, package)
360
+
361
+
362
+ def issue_detail(c, issue_id):
363
+ validate_issue_id(issue_id)
364
+ value = call(c, "GET", f"/api/issues/{issue_id}")
365
+ workflow_common.require_code(
366
+ isinstance(value, dict) and value.get("issue_id") == issue_id,
367
+ "PLATFORM_RESPONSE_INVALID", "issue identity mismatch",
368
+ )
369
+ return value
370
+
371
+
372
+ def issue_tasks(c, issue_id, round_no):
373
+ validate_issue_id(issue_id)
374
+ workflow_common.require(type(round_no) is int and 1 <= round_no <= 999999,
375
+ "round number must be between 1 and 999999")
376
+ value = call(c, "GET", f"/api/issues/{issue_id}/rounds/{round_no}/tasks")
377
+ workflow_common.require_code(isinstance(value, list) and all(isinstance(task, dict) for task in value),
378
+ "PLATFORM_RESPONSE_INVALID", "invalid round tasks response")
379
+ return {"issue_id": issue_id, "round_no": round_no, "tasks": value}
380
+
381
+
382
+ def regression_preview(c, issue_id):
383
+ validate_issue_id(issue_id)
384
+ value = call(c, "GET", "/api/regression/preview?" + urllib.parse.urlencode({"issue_id": issue_id}))
385
+ workflow_common.require_code(
386
+ isinstance(value, dict) and value.get("issue_id") == issue_id,
387
+ "PLATFORM_RESPONSE_INVALID", "regression preview identity mismatch",
388
+ )
389
+ return value
390
+
391
+
392
+ def execution_detail(c, exec_uuid):
393
+ # AFX ingestion accepts opaque execution IDs, not only canonical UUIDs.
394
+ workflow_common.require(isinstance(exec_uuid, str) and re.fullmatch(r"[A-Za-z0-9_-]{8,64}", exec_uuid),
395
+ "execution UUID must contain 8 to 64 letters, digits, underscores or hyphens")
396
+ value = call(c, "GET", "/api/executions/" + exec_uuid)
397
+ workflow_common.require_code(
398
+ isinstance(value, dict) and value.get("exec_uuid") == exec_uuid,
399
+ "PLATFORM_RESPONSE_INVALID", "execution identity mismatch",
400
+ )
401
+ return value
402
+
403
+
404
+ def poll(c, issue_id, round_no):
405
+ validate_issue_id(issue_id)
406
+ workflow_common.require(
407
+ type(round_no) is int and round_no > 0, "round number must be positive"
408
+ )
409
+ detail = issue_detail(c, issue_id)
410
+ rounds = detail["rounds"]
411
+ verification = next((r for r in rounds if r["round_no"] == round_no), None)
412
+ workflow_common.require(
413
+ verification and verification["kind"] == "verify",
414
+ "verification round not found",
415
+ )
416
+ regression = next(
417
+ (r for r in rounds if r["round_no"] == round_no + 1 and r["kind"] == "regress"),
418
+ None,
419
+ )
420
+ if regression:
421
+ workflow_common.require(
422
+ all(
423
+ regression[k] == verification[k] for k in ("fix_version", "fix_sha256")
424
+ ),
425
+ "regression candidate differs from verification",
426
+ )
427
+ last = regression or verification
428
+ terminal = last["finished_at"] is not None
429
+ return {
430
+ "issue_id": issue_id,
431
+ "status": detail["status"],
432
+ "round_no": round_no,
433
+ "verification": verification,
434
+ "regression": regression,
435
+ "terminal": terminal,
436
+ "outcome": last["outcome"] if terminal else None,
437
+ }
438
+
439
+
440
+ def wait(c, issue_id, round_no, timeout):
441
+ deadline = time.monotonic() + timeout
442
+ lease = claimed(c, issue_id)
443
+ previous = None
444
+ while True:
445
+ result = poll(c, issue_id, round_no)
446
+ if result["terminal"]:
447
+ if result["outcome"] != "passed":
448
+ raise workflow_common.WorkflowError(
449
+ "PLATFORM_VERIFICATION_FAILED", "平台复测未通过", result
450
+ )
451
+ return result
452
+ if time.monotonic() >= deadline:
453
+ raise workflow_common.WorkflowError(
454
+ "PLATFORM_WAIT_TIMEOUT", "等待超时,可继续查询同一验证轮次",
455
+ {"issue_id": issue_id, "round_no": round_no, "event": "timeout"}
456
+ )
457
+ renew(c, lease)
458
+ if previous is not None and result['status'] != previous:
459
+ print(f"{issue_id}: {result['status']}", file=sys.stderr, flush=True)
460
+ previous = result['status']
461
+ time.sleep(min(30, max(0, deadline - time.monotonic())))
462
+
463
+
464
+ def retry_remote(job, lease=None):
465
+ job = Path(job)
466
+ try:
467
+ c = workflow_config.validate_config(
468
+ workflow_config.read_config(job / "config.yaml")
469
+ )
470
+ with (
471
+ workflow_common.lock(workflow_runtime.venv_lock(c), shared=True),
472
+ workflow_common.lock(
473
+ workflow_runtime.registry(c).with_suffix(".lock"), shared=True
474
+ ),
475
+ ):
476
+ value = verify(c, job, lease)
477
+ return {"state": "success", "verification": value}
478
+ except workflow_common.WorkflowError as error:
479
+ return {"state": "failed", "error_code": error.code, "error": str(error)}
480
+ except Exception as error:
481
+ return {
482
+ "state": "failed",
483
+ "error_code": "PLATFORM_VERIFY_FAILED",
484
+ "error": str(error),
485
+ }