loginowskid commited on
Commit
aeb50d3
·
1 Parent(s): ea7eed8

Capture validator stdout/stderr; surface tail in error response

Browse files
Files changed (1) hide show
  1. tools/hf_space/runner.py +18 -2
tools/hf_space/runner.py CHANGED
@@ -208,13 +208,29 @@ def run(
208
  "--no-use-kit",
209
  ]
210
  out(f" $ {shlex.join(cmd)}")
211
- rc = subprocess.call(cmd)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  results_path = out_dir / "results.json"
213
  if rc != 0 and not results_path.exists():
214
  return RunResult(
215
  dataset=dataset, profile=profile, version=version,
216
  status="error",
217
- summary=f"validator exited {rc}; no results.json produced",
 
218
  results_json={}, report_path=out_dir, pr_url=None,
219
  )
220
  results_json = json.loads(results_path.read_text(encoding="utf-8"))
 
208
  "--no-use-kit",
209
  ]
210
  out(f" $ {shlex.join(cmd)}")
211
+ # Capture stdout+stderr to a file so we can ship the tail back
212
+ # in the response when the validator crashes. Streaming the
213
+ # SSE run log from outside the Space is unreliable (gradio's
214
+ # queue eats stderr, the HF /logs/run endpoint replays
215
+ # inconsistently). This is the only way the GitHub-Actions-
216
+ # side caller can see WHY the validator failed.
217
+ log_path = out_dir / "validator.log"
218
+ with log_path.open("wb") as logf:
219
+ rc = subprocess.call(cmd, stdout=logf, stderr=subprocess.STDOUT)
220
+ log_tail = ""
221
+ if log_path.exists():
222
+ try:
223
+ log_tail = log_path.read_text(encoding="utf-8", errors="replace")
224
+ log_tail = "\n".join(log_tail.splitlines()[-100:])
225
+ except OSError:
226
+ pass
227
  results_path = out_dir / "results.json"
228
  if rc != 0 and not results_path.exists():
229
  return RunResult(
230
  dataset=dataset, profile=profile, version=version,
231
  status="error",
232
+ summary=(f"validator exited {rc}; no results.json produced\n\n"
233
+ f"--- validator log tail ---\n{log_tail}"),
234
  results_json={}, report_path=out_dir, pr_url=None,
235
  )
236
  results_json = json.loads(results_path.read_text(encoding="utf-8"))