Skip to content

feat(agentic): add trajectory and training observability - #555

Merged
xiaoliang0601 merged 4 commits into
redai-studio:mainfrom
xiaoliang0601:codex/agentic-observability-ea979372
Nov 9, 2026
Merged

xiaoliang0601 merged 4 commits into
redai-studio:mainfrom
xiaoliang0601:codex/agentic-observability-ea979372

Conversation

@xiaoliang0601

Copy link
Copy Markdown
Contributor

What

Add optional Agentic observability from source merge ea979372716677e08a0e83835001214ada280821, whose code change is identical to a7fc3cca843b0dcb23d83abc2cc6e6330904d064.

--dump-agentic-obs joins prompt, group and session inventories, exported trajectories, stage outcomes and per-sample training scalars. Collection is disabled by default. Includes English/Chinese documentation and colocated / asynchronous example launchers.

Why

Follow an individual exported context from its original prompt through generation, reward, selection, transfer and optimizer application. Stable identities and explicit terminal outcomes make dropped, failed and trained exports distinguishable.

Relates to #526, which includes the same observability source alongside hybrid DCS changes. This PR scopes the observability feature independently on current main.

How

  • Carry sample_export_id through SessionShard exports, TransferQueue columns and actor observations; preserve opaque int64 identities in JSON records.
  • Queue bounded background writes for trajectories, stage events, run outcomes and training scalars. Replace inline media with digests, with optional content-addressed sidecars.
  • Resolve conflicts with current main while retaining partial generation on context exhaustion, router retry ownership, Score Centering fields, pre-shifted SFT labels, nonfinite-gradient skips, peak-memory accounting and fault-event lifecycle.
  • Retain SFT reader options and rebuild provenance when an observation reader encounters an offsets-only cache, preserving physical JSONL row identities across blank lines.
  • Place CPU regressions under tests/cpu/, isolate the CUDA snapshot test, and adapt checkpoint, entrypoint and normalized-message fixtures to current main.

Testing

  • pre-commit run --all-files passes
  • Tests pass (pytest tests/)
  • New tests added (if applicable)
  • Documentation updated (if applicable)

Focused local regression across 24 modules: 623 passed, 14 skipped with GPUs hidden. Coverage includes observability producers/writers, Agentic runtime and protocol behavior, startup/failure outcomes, checkpoint annotation, CPU optimizer/Gloo behavior, source-row provenance, TransferQueue iteration and HTTP timing.

The skipped entries comprise 13 unavailable Megatron imports (including module-level skips) and one CUDA snapshot test. The full suite and multi-node GPU integration were not run because this local environment lacks the Megatron training stack and NVIDIA GPUs; these skips are not counted as regression coverage.

Both launchers pass bash -n and DRY_RUN=1. Changed Python files pass duplicate-definition and Ruff F811 checks; all tracked files pass the sensitive-content scan.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • CI/CD or build changes

Screenshots / Logs

Local focused result: 623 passed, 14 skipped. The added cache/provenance regression prevents original JSONL row identifiers from being lost when cached offsets are available. Existing media assertions verify sidecar contents and that media writes leave the event loop free.

# ⭐ Feature

- Join prompt, group, session, trajectory, stage and training records through
  stable export identities, with observation collection disabled by default.
- Record run outcomes, backend timing, selection and transfer events, and
  per-sample training scalars through bounded background writers.
- Add optional media capture and colocated / asynchronous example launchers.

# 🐛 Bug Fix

- Preserve current context exhaustion, Score Centering, SFT, fault events,
  optimizer skip and memory reporting behavior when replaying the source.
- Rebuild source-row metadata when an observation reader encounters an
  offsets-only cache, preserving original JSONL row identities.

# ✅ Tests

- Carry source observability regressions into the CPU suite and isolate the
  CUDA snapshot test; adapt moved checkpoint and entrypoint fixtures.

# 📝 Documentation

- Document observation streams, identifiers and configuration in English
  and Chinese.

Source merge: ea979372716677e08a0e83835001214ada280821
(cherry picked from commit a7fc3cca843b0dcb23d83abc2cc6e6330904d064)
@rai-studio-bot

rai-studio-bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @xiaoliang0601! 感谢你为 Relax 做出贡献!

📚 Contribution guide / 贡献指南

Describe the problem, your changes, and how you validated them. Keep each PR focused and run pre-commit run --all-files before submitting.

请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 pre-commit run --all-files。

English contribution guide · 中文贡献指南

🛠️ CI commands / CI 指令
Command / 指令 Usage / 用途
/rerun Retry failed CI / 重跑失败的 CI
/rerun <target> Rerun a workflow or check / 重跑指定 workflow 或检查
/cancel <workflow> Cancel an entire workflow / 取消整个 workflow
/help Show commands and targets / 查看指令和 target
/review Request a code review / 请求代码 review

Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access.

在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。

CI usage and targets · CI 用法与 target

🔎 Merge requirements / 合入条件

GitHub:✅ 满足合入条件

Requirement / 条件 Status / 状态
审批人数 ✅ 2/1 · 至少 1 位有仓库 write 或更高权限的人 Approve · 已审批:Yangruipis, SigureMo
团队审批(relax-block-reviewers) ✅ 2/1 · 已审批:Yangruipis, SigureMo
CI ✅ 已通过

@rai-studio-bot

rai-studio-bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: 📝 初步结果已发布 · 深度审查中

审查版本: bbfc670

目标分支: main

已完成本轮范围与 Run 写入修复的常规复核:开始事件及 manifest 均由后台有界队列持有,shutdown 先启动 watchdog 再按序落盘。正在核对同 run 的 shard 重建身份与相关 PR/拆分边界。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已核对本轮 7 文件增量、人工意见与 RunRecorder/BoundedWorker/训练退出调用链;未改动路径复用既有审查证据。
深度审查 🔎 进行中 核查 driver 分配代际是否覆盖 SessionShard 重建,及其 int64/TQ 身份契约。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 Medium severity 规范化 Parquet 负切片的来源行号 ✅ 已解决 —

改进建议(非阻塞)

拆分

🔎 分析中 — 按当前固定版本重新检查拆分边界及依赖。

相关 PR

🔎 分析中 — 核对描述中关联的 PR #526 的重叠实现与合入边界。

提交范围 · 接收 57 · 建议移出 0 · 待确认 0

接收 57 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。

文件结论仓库维护必要性依据替代去向或方案
docs/en/guide/agentic-rollout.md
docs/zh/guide/agentic-rollout.md
接收 双语文档说明可选 Agentic 观测功能及用户可依赖的语义。 PR #555 的 What/Why 与现有 Agentic rollout 用户指南。 沿用已有双语指南位置。
relax/agentic/inventory.py
relax/agentic/observability.py
relax/agentic/pipeline/__init__.py
relax/agentic/pipeline/prepare.py
relax/agentic/pipeline/reward.py
relax/agentic/pipeline/runtime.py
relax/agentic/pipeline/transfer.py
relax/agentic/rollout.py
relax/agentic/runner/ipc.py
relax/agentic/session/service.py
relax/agentic/stage_recorder.py
relax/backends/megatron/actor.py
relax/backends/megatron/data.py
relax/backends/megatron/model.py
relax/distributed/ray/actor_group.py
relax/distributed/ray/placement_group.py
relax/engine/rollout/data_source.py
relax/entrypoints/train.py
relax/utils/agentic_obs/__init__.py
relax/utils/agentic_obs/config.py
relax/utils/agentic_obs/merge.py
relax/utils/agentic_obs/records.py
relax/utils/agentic_obs/run_hooks.py
relax/utils/agentic_obs/source.py
relax/utils/agentic_obs/startup.py
relax/utils/agentic_obs/tracking.py
relax/utils/agentic_obs/train_hooks.py
relax/utils/agentic_obs/writers.py
relax/utils/arguments.py
relax/utils/data/data.py
relax/utils/data/data_utils.py
relax/utils/data/stream_dataloader.py
relax/utils/data/streaming_dataset.py
relax/utils/http_utils.py
relax/utils/metrics/adapters/clearml.py
relax/utils/training/data_fields.py
relax/utils/types.py
relax/utils/utils.py
接收 这些文件实现并接入导出轨迹、阶段事件、训练标量及身份传递,属于 Relax 运行时行为。 PR 描述要求从 SessionShard/TransferQueue 到训练入口的可选观测闭环;路径均在现有 agentic、backend、entrypoint 与 utils 模块中。 可拆为独立模块后由现有调用方接入,但当前目录与对应责任边界一致。
scripts/training/multimodal/run-deepeyes-8gpu-async-obs.sh
scripts/training/multimodal/run-deepeyes-8gpu-colocate-obs.sh
接收 两个启动脚本是面向用户的 colocated/asynchronous Agentic observability 入口。 PR 描述明确新增两种 Deepeyes 观测启动方式,路径位于 scripts/training/multimodal。 可只在文档中给出命令,但可执行脚本能保留实际资源与参数契约。
tests/backends/megatron/test_zero_token_step.py
tests/cpu/backends/megatron/test_checkpoint_rotation.py
tests/cpu/backends/megatron/test_nonfinite_step_skip_cpu.py
tests/cpu/core/test_control_plane_affinity.py
tests/cpu/core/test_training_failure_recovery.py
tests/cpu/entrypoints/test_startup_failure.py
tests/cpu/test_agentic_observability.py
tests/cpu/test_agentic_rollout.py
tests/cpu/utils/data/test_streaming_tq_iterator.py
tests/cpu/utils/test_agentic_obs.py
tests/cpu/utils/test_agentic_obs_isolation.py
tests/cpu/utils/test_agentic_run.py
tests/cpu/utils/test_clearml_observability.py
tests/cpu/utils/test_http_utils.py
tests/test_agentic_observability_cuda.py
接收 测试覆盖新增观测生产者/写入器及受影响的 checkpoint、启动、数据与训练边界,属于持久回归资产。 PR 描述声明新增 CPU 回归并隔离 CUDA 测试;路径位于现有 tests 结构。 可删去重复的纯实现断言,但真实入口、隔离性与 GPU 边界应保留在 tests/ 对应层级。
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@rai-studio-bot rai-studio-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.

审查结论:COMMENT

常规与深度审查已完成。已确认一项 P2 来源身份问题,已附在对应 diff 行;其余已检查的 Agentic 导出、阶段事件、TransferQueue/Megatron 训练字段、生命周期清理和默认关闭路径未发现新的可证实阻塞缺陷。当前头的 GitHub checks 已全部通过;多节点 GPU/完整 Megatron 路径仍以 CI 为准。

审查看板:nyanpasu-review

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

Comment thread relax/utils/data/streaming_dataset.py Outdated
from relax.utils.agentic_obs.source import SourceRow

if self._is_parquet:
start = self.row_slice.start or 0 if self.row_slice is not None else 0

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 severity P2 · 规范化 Parquet 负切片的来源行号

parse_generalized_path 接受 @[负数:] 切片,但这里把负的 row_slice.start 直接加到局部索引。于是 rows.parquet@[-3:] 实际读取物理行 2、3、4,却写出 source_row_id 为 -3、-2、-1,破坏来源身份契约,并可能让观察记录无法与其他读取路径对齐。请使用 slice.indices(len(self._parquet_data))(或等价的规范化边界)后再计算物理行号;同时补一个 Parquet 负切片回归。最小复现:StreamingReader("rows.parquet@[-3:]", with_source=True) 在该头返回 [("2", "-3"), ("3", "-2"), ("4", "-1")]。

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.

已确认修复:4c37b7739d5b2a64f0851ef783cab40be53d6e64 在 Parquet 切片前用 slice.indices(len(_parquet_data))[0] 保存规范化的物理起点,负切片和越界起点现在写出与未切片读取一致的 source_row_id。新增的 Parquet 负切片、批量读取、跨文件 composite 以及 source-disabled 回归已通过(4 tests passed)。

Capture the normalized physical start before slicing Parquet rows so
source_row_id and prompt_id match reads of the same unsliced source.

Cover negative bounds, starts before the file beginning, direct and batch
access, per-file composite datasets, and source-disabled reads.

Validation: 171 CPU tests and all pre-commit hooks pass.
Comment thread .gitleaks.toml Outdated
description = "OBS launcher references the trial env var name, not its value"
condition = "AND"
regexTarget = "match"
regexes = ['''^QS_TRIAL_ID$''']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这个要加到 allowlists 么?我看脚本里也没写这个?

# 🐛 Bug Fix

## Restore the existing Gitleaks config

- Remove the launcher-specific trial ID exception. The launcher accepts its
  observation directory through OBS_DIR.
- Restore the original rule table now that the extra exception is gone.
- Verify all configured pre-commit hooks, including Gitleaks.

@Yangruipis Yangruipis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

审查版本:8613043486c8e9585694f6271ab7db93186ca8d5。

发现两项需要合并前修复的 P2,已附行内评论:

  1. 全局故障恢复重建 SessionShard 后复用 export ID,破坏轨迹、阶段与训练记录的身份关联契约。
  2. Run 开始事件同步写盘,观测存储阻塞时会卡住训练启动,违背观测不等待磁盘的隔离契约。

两项均已有轻量 CPU 复现。当前 head 的 13 项 GitHub checks 均通过;本地所选 CPU 用例 148 通过、7 项因缺依赖失败,另两个模块因缺依赖无法收集。本地未运行 GPU 或多节点集成验证。

Comment thread relax/agentic/observability.py Resolved
Comment thread relax/utils/agentic_obs/run_hooks.py Resolved
# 🐛 Bug Fix

## Preserve export identity through shard recovery

- Reserve a distinct counter range for each shard fleet created by the
  driver and carry it in the observation configuration.
- Keep the shard ordinal and the signed int64 and decimal JSON formats.

## Queue the run start event

- Write the start event on a bounded daemon and drain it before flushing
  the recorded outcome during shutdown.
- Cover shard recorder recreation and blocked JSONL opens in CPU tests.
@xiaoliang0601
xiaoliang0601 merged commit 1285357 into redai-studio:main Nov 9, 2026
14 checks passed
xiaoliang0601 added a commit that referenced this pull request Nov 10, 2026
## What

Store the Agentic training-input loss mask as nonzero token intervals in
train JSONL. Relates to #555.

## Why

Tool observations and model responses often form long runs of the same
mask value. The interval representation keeps the positions needed for
debugging while making those records smaller.

## How

- Encode `loss_mask.ranges` in the background writer as zero-based
`[start, end, value]` triples with an exclusive end. Positions outside
the ranges are zero up to `response_length`.
- Compute `effective_tokens` from the interval lengths and values.
Integer mask weights and all-zero samples can be reconstructed exactly.
- Advertise train schema `4.0.0` through `train_schema_version` in the
manifest. The format guide documents v3 arrays and v4 intervals, and the
regression checks both with the existing DP update merge.

## Testing

- [x] `pre-commit run --all-files` passes
- [ ] Tests pass (`pytest tests/`)
- [x] New tests added (if applicable)
- [x] Documentation updated (if applicable)

The Agentic observability, JSONL writer, and stream-join CPU suites
passed 201 tests. The round-trip test covers integer mask values and
checks the same merged update summary for v3 and v4 records. The CUDA
snapshot test skipped on the local CPU host, and integration tests
require multi-node GPU hardware.

## Type of Change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update
- [ ] Refactoring (no functional changes)
- [x] Performance improvement
- [ ] CI/CD or build changes

## Screenshots / Logs

The 42-token synthetic mask in the round-trip regression takes 126 bytes
as a JSON array and 37 bytes as an interval object, counting the field
value only.
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.

4 participants