Skip to content

Fix Run.logs() returning nothing for a finished run - #4176

Merged
r4victor merged 2 commits into
masterfrom
issue_4175_python_api_logs_finished_run
Aug 20, 2026
Merged

Fix Run.logs() returning nothing for a finished run#4176
r4victor merged 2 commits into
masterfrom
issue_4175_python_api_logs_finished_run

Conversation

@r4victor

@r4victor r4victor commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Fixes #4175

Run.logs() returned an empty iterator for any run in a terminal state, with no error, while dstack logs printed the same run's logs - the CLI passes --replica 0 by default and so never took that path.

  • Fall back to the lowest-numbered replica when replica_num is None and no replica is running, restoring the behaviour _find_job had before Rolling deployment for services #2821 added the running-replica requirement for rolling deployments.
  • Keep preferring a running replica, and pick the lowest-numbered one when several match, so the choice no longer depends on the order of Run.jobs.
  • Let attach() resolve a replica on a DONE run, which makes its existing "read logs from the websocket" branch reachable; a failed or terminated run still returns early before the job is used.
  • Replace return [] with return in the logs() generator, where the value was never visible to the caller.

AI assistance: written with Claude Code.

`logs()` shared job lookup with `attach()`, which resolves `replica_num=None`
to a running replica only. Reading logs must outlive the replica, so it now
falls back to the lowest-numbered replica when none is running.
Restores the pre-rolling-deployment fallback for the whole lookup instead of
wrapping it, and makes the choice deterministic when several replicas match.
@r4victor
r4victor merged commit 99fdc7e into master Aug 20, 2026
27 checks passed
@r4victor
r4victor deleted the issue_4175_python_api_logs_finished_run branch August 20, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Python API Run.logs() returns nothing for a finished run

1 participant