ray icon indicating copy to clipboard operation
ray copied to clipboard

[Dashboard] tail_job_logs() exits successfully when worker node preemption happens with `RAY_LOG_TO_STDERR=1`

Open madiyar-wayve opened this issue 10 months ago • 6 comments

What happened + What you expected to happen

RayJob ends successfully when RAY_LOG_TO_STDERR=1 is set and node preemption kills worker node, even though RayCluster didn't finish execution yet. This is causes a problem because we rely on Ray job cleaning up RayCluster by setting shutdownAfterJobFinishes=True.

As I understand tail_job_logs() exits successfully with no error message when the above happens, which causes the submitter to complete the k8s job successfully. I would expect the tail_job_logs() to run until RayCluster finishes the execution.

We are using KubeRay.

The last logs from submitter pod before it finished running:

2026-01-29 23:51:00.742 INFO cli.py:93 -- Status message: Job is currently running. 
2026-01-29 23:51:00.742 INFO cli.py:91 -- Status for job 'al5tmrnltzh6mtm5brg5-n1-0-dn0-0-dn0-0-tgtxm': RUNNING 
2026-01-29 23:51:00.728 DEBUG sdk.py:502 -- WebSocket closed for job al5tmrnltzh6mtm5brg5-n1-0-dn0-0-dn0-0-tgtxm with close code 1000

I needed to patch Ray to enable debug logs to see that websocket was closed normally, maybe it's worth to make them info log instead of debug?

Versions / Dependencies

Ray 2.53.0 KubeRay 1.5.1

Reproduction script

Set RAY_LOG_TO_STDERR=1 and kill any worker's pod should be enough to reproduce.

Issue Severity

None

madiyar-wayve avatar Feb 02 '26 10:02 madiyar-wayve

Hi @madiyar-wayve , I think you can set the logger level through RAY_LOGGER_LEVEL environment variable:

https://github.com/ray-project/kuberay/blob/fe49c92fe3b1783178da1e005caa600e3554ce17/ray-operator/config/samples/ray-cluster.autoscaler-v2.yaml#L22-L24

machichima avatar Feb 02 '26 11:02 machichima

Thanks @machichima! Will try to use it.

madiyar-wayve avatar Feb 02 '26 11:02 madiyar-wayve

Marking the issue as resolved. Thanks @machichima for the tip! @madiyar-wayve please reopen in case you still have problems.

codope avatar Feb 04 '26 02:02 codope

Hi @codope. Is it possible to re-open the issue please?

The problem here isn't having debug logs enabled, sorry if I didn't explain it properly. The main point of it is that Ray submitter stops running when we set RAY_LOG_TO_STDERR=1 and one of the Ray workers get node preempted. This behavior doesn't happen when we don't set RAY_LOG_TO_STDERR=1.

madiyar-wayve avatar Feb 04 '26 07:02 madiyar-wayve

ok i see. let me reopen. We will take a look. If you're interested in patching, we could help you with that.

codope avatar Feb 04 '26 10:02 codope

We hit this on Ray 2.58 with a plain ray job submit in its default tailing mode, and it ended a 32-node run as a success. The submitter's log (UTC):

06:28:05,494 INFO sdk.py:520 -- WebSocket closed for job raysubmit_... with close code 1000
06:28:05,500 INFO cli.py:92 -- Status for job 'raysubmit_...': RUNNING
06:28:05,500 INFO cli.py:94 -- Status message: Job is currently running.

ray job submit then exited 0, so our launcher, which takes the exit code as the training result, marked the job succeeded and tore down all 32 nodes (256 GPUs) 13.5 minutes after the pods started, before the first training step, with no error from Ray anywhere. The close came within 1.5 s of the start of a burst of very long worker log lines (single lines of up to 841,935 characters). We caught it only by reading the head log; the same close late in a run would end it as a success and lose everything since its last checkpoint.

The path is the same on master (1f273106) and in 2.60.1:

  • tail_job_logs documents a RuntimeError "if the connection closes unexpectedly before the job reaches a terminal state" (sdk.py lines 502-505), but on a close it raises only for code 1006 (lines 521-530).
  • The head relays the agent's stream and returns normally however it ended (job_head.py lines 608-650), so the client sees a 1000 close whatever ended the agent hop.
  • The CLI prints the status after the tail and exits 1 only on FAILED (cli.py lines 98-102 and lines 349-358), so a RUNNING job exits 0.

The fix is in #68695: when the stream ends and the job's status is not terminal, ray job submit and ray job logs --follow log a warning, poll the status every second until it is terminal, and then exit as before, so STOPPED still exits 0. The polling runs in the CLI's sync code, so it avoids the blocking-IO-in-async problem that kept a status check out of #57037. @codope, could you take a look?

savaresejeremy avatar Dec 01 '26 00:12 savaresejeremy