Spaces:
Running on Zero
Running on Zero
fix(app): print the bootstrap summary last and exit 1 on any failure
Browse filesThe Space API keeps only the last 2000 characters of output. A failed
bootstrap now prints its traceback first, then "[ams] model bootstrap
failed:" with the short per-root summary as the very last lines, then
raises SystemExit(1) so no second traceback follows. Any exception takes
this path, not only ModelStoreError, so a bug or an OS error while
linking checkpoints also ends with a readable last line.
- app.py +10 -5
- tests/test_preload_repos.py +20 -10
app.py
CHANGED
|
@@ -87,6 +87,7 @@ print(f"[ams] sys.path patched (vendor exists: {_VENDORED_ACE_STEP.exists()})",
|
|
| 87 |
import hashlib
|
| 88 |
import random
|
| 89 |
import shutil # noqa: F401 (reserved for future cleanup paths)
|
|
|
|
| 90 |
|
| 91 |
import gradio as gr
|
| 92 |
|
|
@@ -136,16 +137,20 @@ def _symlink_ace_step_checkpoints() -> None:
|
|
| 136 |
def _bootstrap_spaces_cache() -> None:
|
| 137 |
"""On HF Spaces, make the pinned model snapshots available before the UI starts.
|
| 138 |
|
| 139 |
-
No-op locally.
|
| 140 |
-
|
| 141 |
-
the
|
|
|
|
| 142 |
"""
|
| 143 |
if not os.getenv("SPACE_ID"):
|
| 144 |
return
|
| 145 |
try:
|
| 146 |
_symlink_ace_step_checkpoints()
|
| 147 |
-
except
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
|
| 151 |
def _warm_demucs_on_spaces() -> None:
|
|
|
|
| 87 |
import hashlib
|
| 88 |
import random
|
| 89 |
import shutil # noqa: F401 (reserved for future cleanup paths)
|
| 90 |
+
import traceback
|
| 91 |
|
| 92 |
import gradio as gr
|
| 93 |
|
|
|
|
| 137 |
def _bootstrap_spaces_cache() -> None:
|
| 138 |
"""On HF Spaces, make the pinned model snapshots available before the UI starts.
|
| 139 |
|
| 140 |
+
No-op locally. Any failure (a required repo that cannot be found or
|
| 141 |
+
downloaded, or anything else) prints the traceback, then the short summary
|
| 142 |
+
as the very last lines, and exits with status 1 without a second
|
| 143 |
+
traceback: the Space API keeps only the last 2000 characters of the log.
|
| 144 |
"""
|
| 145 |
if not os.getenv("SPACE_ID"):
|
| 146 |
return
|
| 147 |
try:
|
| 148 |
_symlink_ace_step_checkpoints()
|
| 149 |
+
except Exception as e:
|
| 150 |
+
traceback.print_exc()
|
| 151 |
+
summary = str(e) if isinstance(e, model_store.ModelStoreError) else f"{type(e).__name__}: {e}"
|
| 152 |
+
print(f"[ams] model bootstrap failed:\n{summary}", file=_sys.stderr, flush=True)
|
| 153 |
+
raise SystemExit(1) from None
|
| 154 |
|
| 155 |
|
| 156 |
def _warm_demucs_on_spaces() -> None:
|
tests/test_preload_repos.py
CHANGED
|
@@ -106,21 +106,31 @@ def test_bootstrap_delegates_to_model_store_on_spaces(monkeypatch, fake_startup,
|
|
| 106 |
assert [c[0] for c in fake_startup.calls] == [tmp_path / "vendor" / "ace-step" / "checkpoints"]
|
| 107 |
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
monkeypatch.setenv("SPACE_ID", "test/test")
|
| 117 |
|
| 118 |
with pytest.raises(SystemExit) as exc:
|
| 119 |
app._bootstrap_spaces_cache()
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
assert
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
|
| 126 |
# --- README front matter (read by HF Spaces at build time) ------------------------
|
|
|
|
| 106 |
assert [c[0] for c in fake_startup.calls] == [tmp_path / "vendor" / "ace-step" / "checkpoints"]
|
| 107 |
|
| 108 |
|
| 109 |
+
@pytest.mark.parametrize("kind", ["model_store", "other"])
|
| 110 |
+
def test_bootstrap_failure_prints_traceback_then_summary_last_and_exits_1(
|
| 111 |
+
monkeypatch, fake_startup, capsys, kind
|
| 112 |
+
):
|
| 113 |
+
if kind == "model_store":
|
| 114 |
+
summary = (
|
| 115 |
+
"could not get o/xl@" + "a" * 40 + " (1 files, 0.00 GB): no cache root is usable\n /r: denied"
|
| 116 |
+
)
|
| 117 |
+
fake_startup.error = model_store.ModelStoreError(summary)
|
| 118 |
+
else: # a bug or an OS error outside the resolver ends the same way
|
| 119 |
+
summary = "OSError: [Errno 30] Read-only file system: 'checkpoints'"
|
| 120 |
+
fake_startup.error = OSError(30, "Read-only file system", "checkpoints")
|
| 121 |
monkeypatch.setenv("SPACE_ID", "test/test")
|
| 122 |
|
| 123 |
with pytest.raises(SystemExit) as exc:
|
| 124 |
app._bootstrap_spaces_cache()
|
| 125 |
|
| 126 |
+
assert exc.value.code == 1
|
| 127 |
+
err = capsys.readouterr().err
|
| 128 |
+
assert "Traceback (most recent call last)" in err
|
| 129 |
+
assert err.index("Traceback") < err.rindex("[ams] model bootstrap failed:")
|
| 130 |
+
# The Space API keeps the last 2000 characters: the summary must be the last thing printed.
|
| 131 |
+
assert err.rstrip().endswith(summary.splitlines()[-1])
|
| 132 |
+
assert err.rstrip()[-2000:].count("[ams] model bootstrap failed:") == 1
|
| 133 |
+
assert summary.splitlines()[0] in err.rstrip()[-2000:]
|
| 134 |
|
| 135 |
|
| 136 |
# --- README front matter (read by HF Spaces at build time) ------------------------
|