Skip to content

Commit c28ae0e

Browse files
Andrey Cheptsovclaude
andcommitted
Show failed creations in dstack preset
`list_agent_sessions` dropped any session whose status was not `running`, `interrupted` or `success`, so a creation that failed disappeared from the listing entirely. `_STATUS_DISPLAY` already had a red `failed` entry that nothing could reach. A failure is an outcome worth showing. One session here spent six hours and seven trials establishing that a constraint was unreachable on the available hardware, then correctly declined to save a preset. Its trials, learnings and final report are all on disk, but the only way back to them was to already know the preset id. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 3fedd27 commit c28ae0e

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/dstack/_internal/cli/services/presets/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def list_agent_sessions() -> list[dict[str, Any]]:
424424
path = session.path
425425
manifest = session.read_manifest()
426426
status = manifest.get("status")
427-
if status not in ("running", "interrupted", "success"):
427+
if status not in ("running", "interrupted", "success", "failed"):
428428
continue
429429
if status == "running" and not session_process_alive(manifest):
430430
status = "interrupted"

src/tests/_internal/cli/services/presets/test_create.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,22 @@ def test_load_agent_session_reads_any_status(self, tmp_path, monkeypatch):
833833
with pytest.raises(CLIError, match="Unknown preset"):
834834
load_agent_session("nope0000")
835835

836+
def test_lists_a_failed_session(self, tmp_path, monkeypatch):
837+
from dstack._internal.cli.services.presets.session import list_agent_sessions
838+
839+
# A creation that failed is an outcome worth showing: without this the run
840+
# disappears from `dstack preset` and only its id can reach it.
841+
self._session(tmp_path, "dead0000", "failed", "[t] boom\n")
842+
self._session(tmp_path, "beef0000", "success", "[t] saved preset\n")
843+
monkeypatch.setattr(
844+
"dstack._internal.cli.services.presets.session.get_presets_dir",
845+
lambda: tmp_path,
846+
)
847+
848+
listed = {entry["id"]: entry["status"] for entry in list_agent_sessions()}
849+
850+
assert listed == {"dead0000": "failed", "beef0000": "success"}
851+
836852
def test_print_session_log_dumps_log_verbatim(self, tmp_path, monkeypatch, capsys):
837853
session = self._session(
838854
tmp_path, "abcd0000", "success", "[t] trial 1 done\n[t] saved preset\n"

0 commit comments

Comments
 (0)