Steps to reproduce
from dstack.api import Client
c = Client.from_config()
r = c.runs.get("<a run that has finished>")
print(len(b"".join(r.logs()))) # 0
print(len(b"".join(r.logs(replica_num=0)))) # the actual logs
Actual behaviour
logs() yields nothing for any terminal run - no exception, no warning. dstack logs <same run> prints the logs in full.
_find_job matches on replica_num alone when it is given, but when it is None it matches only a submission whose status is RUNNING:
|
def _find_job(self, replica_num: Optional[int], job_num: int) -> Optional[Job]: |
|
for j in self._run.jobs: |
|
if ( |
|
replica_num is not None |
|
and j.job_spec.replica_num == replica_num |
|
or replica_num is None |
|
and j.job_submissions[-1].status == JobStatus.RUNNING |
|
) and j.job_spec.job_num == job_num: |
|
return j |
|
return None |
Once a run is terminal nothing is RUNNING, so _find_job returns None and logs() returns an empty generator. The CLI is unaffected because its --replica argparse default is 0, so it never passes None.
Expected behaviour
logs() with default arguments should return the logs of a finished run, as the CLI does - fall back to replica 0 when no submission is running, or raise instead of yielding nothing.
dstack version
master at 2517069, server run from source.
Steps to reproduce
Actual behaviour
logs()yields nothing for any terminal run - no exception, no warning.dstack logs <same run>prints the logs in full._find_jobmatches onreplica_numalone when it is given, but when it isNoneit matches only a submission whose status isRUNNING:dstack/src/dstack/api/_public/runs.py
Lines 420 to 429 in 2517069
Once a run is terminal nothing is
RUNNING, so_find_jobreturnsNoneandlogs()returns an empty generator. The CLI is unaffected because its--replicaargparse default is0, so it never passesNone.Expected behaviour
logs()with default arguments should return the logs of a finished run, as the CLI does - fall back to replica 0 when no submission is running, or raise instead of yielding nothing.dstack version
master at 2517069, server run from source.