Skip to content

[Core] Support publishing Submission job events using ray event recorder - #61099

Merged
sampan-s-nayak merged 51 commits into
masterfrom
job_events_missing_fields_3
Oct 26, 2026
Merged

sampan-s-nayak merged 51 commits into
masterfrom
job_events_missing_fields_3

Conversation

@sampan-s-nayak

@sampan-s-nayak sampan-s-nayak commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

this pr migrates submission job events to go through the events recorder framework (proto changes have already been merged). Uses the python event recorder bindings to emit these events from the python frontend (breaks the JobInfo object emitted by the export event framework into definition and lifecycle events).

Events are emitted when:

  1. RAY_ENABLE_RAY_EVENT is true (needed for enabling the underlying c++ event recorder)
  2. RAY_ENABLE_PYTHON_RAY_EVENT_TYPES contains SUBMISSION_JOB_DEFINITION_EVENT_TYPE and SUBMISSION_JOB_LIFECYCLE_EVENT_TYPE

note: when the ray event recorder path is enabled the old event export path is disabled

@sampan-s-nayak
sampan-s-nayak requested review from a team, edoakes and jjyao as code owners February 17, 2026 07:30

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request successfully integrates the Ray event recorder framework into the job submission system, enabling the emission of job definition and lifecycle events. The implementation follows the existing pattern for actor and node events, using a priority-based approach where the new framework takes precedence when enabled. The addition of an end-to-end test ensures the correctness of event emission and capture. I have provided a few suggestions to improve the efficiency of protobuf timestamp handling and to ensure robust initialization of the event recorder.

Comment on lines +144 to +147
now = time.time()
transition.timestamp.CopyFrom(
Timestamp(seconds=int(now), nanos=int((now % 1) * 1e9))
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of creating a new Timestamp object and using CopyFrom, you can use the FromMilliseconds method directly on the existing transition.timestamp object. This is more efficient and avoids manual nanosecond calculations which can sometimes suffer from floating-point precision issues.

Suggested change
now = time.time()
transition.timestamp.CopyFrom(
Timestamp(seconds=int(now), nanos=int((now % 1) * 1e9))
)
transition.timestamp.FromMilliseconds(int(time.time() * 1000))

Comment on lines +207 to +223
if ray_constants.RAY_ENABLE_RAY_EVENT:
try:
from ray._raylet import initialize_event_recorder

initialize_event_recorder(
aggregator_address=self._dashboard_agent.ip,
aggregator_port=self._dashboard_agent.grpc_port,
node_ip=self._dashboard_agent.ip,
node_id_hex=self._dashboard_agent.node_id,
max_buffer_size=10000,
)
logger.info("Initialized ray event recorder in JobAgent.")
except Exception:
logger.warning(
"Failed to initialize ray event recorder in JobAgent.",
exc_info=True,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The initialize_event_recorder call is placed within the run method of JobAgent. While this works for initialization, consider if a corresponding shutdown_event_recorder call is needed when the agent or module stops, similar to the implementation in JobSupervisor. This ensures that any buffered events are flushed before the process exits.

@ray-gardener ray-gardener Bot added the community-contribution Contributed by the community label Feb 17, 2026
sampan-s-nayak and others added 7 commits February 18, 2026 10:59
Signed-off-by: sampan <[email protected]>
…ss attribute

Cython cdef class types are immutable — setting EventRecorder._instance
at module scope raises TypeError at runtime. Use a module-level
_event_recorder_instance variable with global declarations instead.

Signed-off-by: sampan <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

rueian pushed a commit that referenced this pull request Sep 2, 2026
Fixes #65608.

## Problem

`JobManager` records the head's GCS address at construction and passes
it to
every detached `JobSupervisor`, which builds its own `GcsClient` from
it:

```python
# job_manager.py
self._gcs_address = gcs_client.address
...
supervisor = self._supervisor_actor_cls.options(...).remote(
    submission_id, entrypoint, metadata or {}, self._gcs_address, self._cluster_id_hex, self._logs_dir,
)

# job_supervisor.py
gcs_client = GcsClient(address=gcs_address, cluster_id=cluster_id_hex)
```

With GCS fault tolerance the head pod can be replaced while a job keeps
running
on a worker. The worker's raylet and CoreWorker reconnect through the
stable head
service, but the supervisor's separately constructed client stays pinned
to the
old address. When the entrypoint exits with code 0,
`put_status(SUCCEEDED)` times
out, the broad exception handler writes `FAILED`, and the job is
reported as
`JOB_SUPERVISOR_ACTOR_DIED` despite having succeeded.

## Fix

Use the GCS client already configured for the worker process hosting the
actor,
which reconnects through the stable head service:

```python
gcs_client = ray._private.worker.global_worker.gcs_client
```

`gcs_address` and `cluster_id_hex` existed only to build that client, so
they are
removed from the supervisor's signature and from the `JobManager` side.
The same
file already uses worker-local state a few lines below
(`ray._private.worker.global_worker.node`), so this follows existing
practice
here. Net -4 lines.

## Not a duplicate

`#65027` also concerns jobs during GCS failover, but patches
`job_manager.py`'s
monitor loop to retry transient gRPC errors. This patches
`job_supervisor.py`'s
client construction. They are complementary: retries in the monitor
cannot help a
supervisor whose own client is pinned to an address nothing is listening
on.

No other open PR references #65608. `gh pr list --search
"job_supervisor"` and
`--search "JobSupervisor gcs"` surfaced only #65006, #47166, #61099 and
#65027,
none of which touch this client construction.

## Testing

Added `test_job_succeeds_when_manager_gcs_address_is_stale` in
`python/ray/dashboard/modules/job/tests/test_job_manager.py`. The full
reported
path needs KubeRay with GCS FT and a head replacement; the essential
condition is
that the address the manager recorded is unusable while the worker's own
client
still works. `_StaleAddressGcsClient` wraps the live client and reports
`127.0.0.1:1`, which is reserved and never bound.

```
python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -k stale -q
```

- on master: `1 failed` — the supervisor cannot persist the terminal
status
- with this change: `1 passed` in 12.70s

Surrounding tests that exercise supervisor construction, job submission,
supervisor logging and the existing failover path:

```
python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -q -p no:randomly \
  -k "stale or network_fault_tolerance or supervisor_log_json or supervisor_logs_saved \
      or submit_no_ray_address or get_all_job_info"

7 passed, 63 deselected in 82.54s
```

Lint, using the repo's own configuration:

```
pre-commit run --files python/ray/dashboard/modules/job/job_supervisor.py \
  python/ray/dashboard/modules/job/job_manager.py \
  python/ray/dashboard/modules/job/tests/test_job_manager.py

ruff / pydoclint / black / Ray docstyle / semgrep / import order: all Passed
```

I did not get a clean full-module run locally: `test_job_manager.py` in
its
entirety stalls on this machine shortly after start (pytest idle at 0%
CPU, no
Ray processes alive) both with and without this change, so it looks
unrelated to
it. Happy to run anything specific a reviewer wants.

Ray installed as `ray[default]` 2.58.0 with `python/ray/setup-dev.py`
symlinks;
tested on macOS (Apple silicon).

## Out of scope

The `except Exception` handler in `JobSupervisor.run` reclassifies a
failure to
*persist* an already-known result as
`JOB_ENTRYPOINT_COMMAND_START_ERROR`. That
is a real second defect, but transient-error handling in this area is
the subject
of #65027, so it is left alone here to avoid a collision.

## AI usage

AI assistance was used for the investigation, the code change, and the
test. I
reviewed every changed line, ran the commands above myself, and can
explain and
defend the change.

Signed-off-by: Roshan Sharma <[email protected]>

@machichima machichima left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing the first pass and leave a few comments

Comment on lines +82 to +99
# Mapping from JobStatus name to SubmissionJobLifecycleEvent.State enum value.
_JOB_STATUS_TO_PROTO_STATE = {
"PENDING": SubmissionJobLifecycleEvent.State.PENDING,
"RUNNING": SubmissionJobLifecycleEvent.State.RUNNING,
"STOPPED": SubmissionJobLifecycleEvent.State.STOPPED,
"SUCCEEDED": SubmissionJobLifecycleEvent.State.SUCCEEDED,
"FAILED": SubmissionJobLifecycleEvent.State.FAILED,
}


def job_status_to_proto_state(
status_name: str,
) -> Optional[int]:
"""Convert a JobStatus name to the proto State enum value.

Returns None if the status name is not recognized.
"""
return _JOB_STATUS_TO_PROTO_STATE.get(status_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking if we can do this here directly and do not need an extra _JOB_STATUS_TO_PROTO_STATE map

value = SubmissionJobLifecycleEvent.State.DESCRIPTOR.values_by_name.get(
    status_name
)
return value.number if value is not None else None

Similar to what we have here:

status_value_descriptor = (
ExportSubmissionJobEventData.JobStatus.DESCRIPTOR.values_by_name.get(
job_info.status.name
)
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg

Comment on lines +358 to +363
agent_info_raw = await self._job_info_client._gcs_client.async_internal_kv_get(
f"{DASHBOARD_AGENT_ADDR_NODE_ID_PREFIX}{driver_node_id}".encode(),
namespace=KV_NAMESPACE_DASHBOARD,
)
if agent_info_raw:
_, _, grpc_port = json.loads(agent_info_raw)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, I think we only need grpc_port here? Are we able to get through ray._private.worker.global_worker.node using node.metrics_agent_port?

node = ray._private.worker.global_worker.node

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entrypoint_num_cpus=job_info.entrypoint_num_cpus,
entrypoint_num_gpus=job_info.entrypoint_num_gpus,
entrypoint_memory=job_info.entrypoint_memory,
entrypoint_resources=job_info.entrypoint_resources,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious, do we need to set session_name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think we should

entrypoint_memory=job_info.entrypoint_memory,
entrypoint_resources=job_info.entrypoint_resources,
)
EventRecorder.emit(builder.build())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log warning if it return false?

@staticmethod
def emit(RayEvent event):
"""Emit a single event. No-op if not initialized.
Args:
event: A RayEvent object (created via InternalEventBuilder.build()).
Returns:
True if the event was successfully queued, False otherwise.
"""
return EventRecorder.emit_batch([event])

)
self._submission_id = submission_id
self._state = state
self._message = message

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw this previous bot review comment: #61099 (comment), I think it's valid. Should we change message to default to "" rather than None and pass it to super().__init__() directly?

Signed-off-by: sampan <[email protected]>
…g_fields_3

Signed-off-by: sampan <[email protected]>

# Conflicts:
#	python/ray/dashboard/modules/job/job_manager.py
#	python/ray/dashboard/modules/job/job_supervisor.py
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…oject#65686)

Fixes ray-project#65608.

## Problem

`JobManager` records the head's GCS address at construction and passes
it to
every detached `JobSupervisor`, which builds its own `GcsClient` from
it:

```python
# job_manager.py
self._gcs_address = gcs_client.address
...
supervisor = self._supervisor_actor_cls.options(...).remote(
    submission_id, entrypoint, metadata or {}, self._gcs_address, self._cluster_id_hex, self._logs_dir,
)

# job_supervisor.py
gcs_client = GcsClient(address=gcs_address, cluster_id=cluster_id_hex)
```

With GCS fault tolerance the head pod can be replaced while a job keeps
running
on a worker. The worker's raylet and CoreWorker reconnect through the
stable head
service, but the supervisor's separately constructed client stays pinned
to the
old address. When the entrypoint exits with code 0,
`put_status(SUCCEEDED)` times
out, the broad exception handler writes `FAILED`, and the job is
reported as
`JOB_SUPERVISOR_ACTOR_DIED` despite having succeeded.

## Fix

Use the GCS client already configured for the worker process hosting the
actor,
which reconnects through the stable head service:

```python
gcs_client = ray._private.worker.global_worker.gcs_client
```

`gcs_address` and `cluster_id_hex` existed only to build that client, so
they are
removed from the supervisor's signature and from the `JobManager` side.
The same
file already uses worker-local state a few lines below
(`ray._private.worker.global_worker.node`), so this follows existing
practice
here. Net -4 lines.

## Not a duplicate

`ray-project#65027` also concerns jobs during GCS failover, but patches
`job_manager.py`'s
monitor loop to retry transient gRPC errors. This patches
`job_supervisor.py`'s
client construction. They are complementary: retries in the monitor
cannot help a
supervisor whose own client is pinned to an address nothing is listening
on.

No other open PR references ray-project#65608. `gh pr list --search
"job_supervisor"` and
`--search "JobSupervisor gcs"` surfaced only ray-project#65006, ray-project#47166, ray-project#61099 and
ray-project#65027,
none of which touch this client construction.

## Testing

Added `test_job_succeeds_when_manager_gcs_address_is_stale` in
`python/ray/dashboard/modules/job/tests/test_job_manager.py`. The full
reported
path needs KubeRay with GCS FT and a head replacement; the essential
condition is
that the address the manager recorded is unusable while the worker's own
client
still works. `_StaleAddressGcsClient` wraps the live client and reports
`127.0.0.1:1`, which is reserved and never bound.

```
python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -k stale -q
```

- on master: `1 failed` — the supervisor cannot persist the terminal
status
- with this change: `1 passed` in 12.70s

Surrounding tests that exercise supervisor construction, job submission,
supervisor logging and the existing failover path:

```
python -m pytest python/ray/dashboard/modules/job/tests/test_job_manager.py -q -p no:randomly \
  -k "stale or network_fault_tolerance or supervisor_log_json or supervisor_logs_saved \
      or submit_no_ray_address or get_all_job_info"

7 passed, 63 deselected in 82.54s
```

Lint, using the repo's own configuration:

```
pre-commit run --files python/ray/dashboard/modules/job/job_supervisor.py \
  python/ray/dashboard/modules/job/job_manager.py \
  python/ray/dashboard/modules/job/tests/test_job_manager.py

ruff / pydoclint / black / Ray docstyle / semgrep / import order: all Passed
```

I did not get a clean full-module run locally: `test_job_manager.py` in
its
entirety stalls on this machine shortly after start (pytest idle at 0%
CPU, no
Ray processes alive) both with and without this change, so it looks
unrelated to
it. Happy to run anything specific a reviewer wants.

Ray installed as `ray[default]` 2.58.0 with `python/ray/setup-dev.py`
symlinks;
tested on macOS (Apple silicon).

## Out of scope

The `except Exception` handler in `JobSupervisor.run` reclassifies a
failure to
*persist* an already-known result as
`JOB_ENTRYPOINT_COMMAND_START_ERROR`. That
is a real second defect, but transient-error handling in this area is
the subject
of ray-project#65027, so it is left alone here to avoid a collision.

## AI usage

AI assistance was used for the investigation, the code change, and the
test. I
reviewed every changed line, ran the commands above myself, and can
explain and
defend the change.

Signed-off-by: Roshan Sharma <[email protected]>

@MengjinYan MengjinYan left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A high level comment: Regarding the PR description, it will be great to include the problem statement, the implementation explanation, how the configs are set to turn on the feature and how the functions are tested.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b7ed61b. Configure here.

// For static information associated with this event, see SubmissionJobDefinitionEvent.
message SubmissionJobLifecycleEvent {
// NOTE: keep in sync with JobStatus in
// python/ray/dashboard/modules/job/common.py.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proto change needs fault-tolerance review

Low Severity

⚠️ This PR modifies one or more .proto files.
Please review the RPC fault-tolerance & idempotency standards guide here:
https://github.com/ray-project/ray/tree/master/doc/source/core/internals/rpc-fault-tolerance.md

Fix in Cursor Fix in Web

Triggered by project rule: Bugbot Rules

Reviewed by Cursor Bugbot for commit b7ed61b. Configure here.

@sampan-s-nayak

Copy link
Copy Markdown
Contributor Author

@MengjinYan thanks, addressed comments + updated description

The dashboard agent exits via os._exit on SIGTERM and is SIGKILLed by the
raylet on normal shutdown, so the atexit hook never runs. The supervisor
keeps its explicit shutdown.

Signed-off-by: sampan <[email protected]>

@MengjinYan MengjinYan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sampan-s-nayak
sampan-s-nayak enabled auto-merge (squash) October 22, 2026 05:32
@github-actions
github-actions Bot disabled auto-merge October 22, 2026 11:35
@sampan-s-nayak
sampan-s-nayak merged commit ed1d83a into master Oct 26, 2026
7 checks passed
@sampan-s-nayak
sampan-s-nayak deleted the job_events_missing_fields_3 branch October 26, 2026 04:36
@win5923

win5923 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Hi @MengjinYan @sampan-s-nayak,
Is it able to cherry-pick this into 2.60?

Edited:
nvm, I think 2.61 is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants