Skip to content

refactor: unify training data and simplify report processing - #446

Merged
BobbyZhouZijian merged 1 commit into
mainfrom
codex/train-data-items
Sep 13, 2026
Merged

BobbyZhouZijian merged 1 commit into
mainfrom
codex/train-data-items

Conversation

@BobbyZhouZijian

Copy link
Copy Markdown
Contributor

Motivation

Processors currently expose different policy and trace sample/batch types, and report assembly adds another chain of public wrappers. Unify the boundary as TrainingBatch.items: tuple[TrainDataItem, ...], so one batch can contain ATIF trajectories, Harbor tasks, or both. This is a maintainer-requested follow-up to #445.

Related: #16 covers broader declarative group rules and introspection; this change preserves recipe-defined readiness rules. Open PR #444 also modifies the CORAL processor and its tests, so those files will need coordination when merging.

Changes

  • Remove PolicySample, TraceSample, and their three batch subclasses. TrainDataItem is TrajectoryItem | TaskItem; trajectories contain ATIF documents exclusively.
  • Capture provider messages, tool calls, observations and multimodal content as ATIF. Preserve original exchanges, feedback and exact rollout tensors in extra.reef; policy backends read that extension, while harness methods read trajectories or recorded exchanges.
  • Migrate all shipped consumers, recipes, tutorials and tests. Preserve masks, log probabilities, top-K capture, teacher candidates, runtime-load spans, advantages and scheduling.
  • Remove ReportSample, the reported processor's Candidate, and BatchUnit, plus the TTTD/CORAL row wrappers. Recipes return training items directly; one private _PendingReport owns buffering and consumption state. Optional grouping(context) supplies collection-group/retry coordinates, and decide_group receives items directly.
  • Preserve complete-step barriers, first-report slot deduplication, reservations, manual/hybrid modes, retention and acknowledgement of selected rows omitted from training output. Add contract tests for these boundaries and update API/developer documentation.

Compatibility and operational impact

This changes Python extension contracts: custom processors and consumers must migrate from the removed types to training items, and grouped report processors must supply grouping(context). Collection groups remain separate from training comparison groups. Old pickled batches containing removed classes are incompatible; service and worker code must be upgraded together. Existing raw records continue to replay through the processors.

Current built-in backends explicitly reject task items until a recipe provides task rollout support. Text-only ATIF does not imply generic tokenization: algorithms requiring captured tokens or log probabilities fail explicitly when they are missing. No new runtime dependency is added.

Verification

  • pre-commit run --all-files: passed.
  • npm run check:docs in docs/site: passed.
  • Changed Python files parse with Python 3.10 syntax.
  • Focused processor/recipe/trainer suites: 182 passed; expanded reported-feedback contract suite: 24 passed.
  • GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null .venv/bin/python -m pytest tests/ -n 4 -q --tb=short --durations=10: 3436 passed, 48 skipped, 1 failed. The failure is test_bridge_catalogs_paired_checkpoint_metrics_and_blocks_before_second_optimizer: the local filesystem reservation blocks the first job. Reproduced on clean main 142e0781.
  • .venv/bin/python -m mypy: the same four existing errors in unchanged lora_transport.py and checkpoint.py; no new errors.
  • Six serialized SFT/SAO/OpenClawRL/TTTD/grouped-PG preparation and multi-epoch scheduling cases match main 142e0781 exactly.
  • JSON-roundtrip and provider/tool/multimodal conversion contracts passed. Five emitted/imported documents validated against Harbor 0.20.0's ATIF schema in an isolated installation.
  • No real GPU training run was performed.

AI assistance

OpenAI Codex implemented the refactor, migrated consumers and documentation, added contract tests, and ran the checks above under maintainer direction. The human contributor remains responsible for reviewing and understanding the changes.

Checklist

  • The change is focused and contains no unrelated cleanup.
  • Tests cover behavior changes, or this pull request does not change behavior.
  • Public interface changes include contract tests, or no public interface changes are present.
  • Affected user and developer documentation is updated, or no documentation update is required.
  • Root README changes update both languages and README.i18n.yaml, or do not affect README content.
  • An accepted RFC is linked, or this change does not require an RFC. (Maintainer-requested interface refactor; no separate RFC linked.)
  • Relevant pre-commit and test checks pass. (Pre-commit passes; existing local pytest/mypy failures are detailed above.)
  • Non-trivial AI assistance is disclosed above, or none was used.

Review and merge

The Merge Oncall is assigned automatically. See the
maintenance model
for review and merge requirements.

@github-actions

Copy link
Copy Markdown

Merge Oncall: @BobbyZhouZijian

The merge oncall will route reviews and keep this pull request moving toward a clear decision.

@github-actions github-actions Bot added area: core Core contracts and scenario lifecycle area: docs User and developer documentation area: examples Examples, recipes, and reference deployments area: harness Harness integration, recipes, and evolution surfaces area: service Service APIs, deployment, and command-line interfaces area: training Training execution, runtimes, algorithms, and pipeline reliability labels Sep 13, 2026
@BobbyZhouZijian
BobbyZhouZijian enabled auto-merge (squash) September 13, 2026 19:31
@BobbyZhouZijian
BobbyZhouZijian merged commit 1fbb922 into main Sep 13, 2026
16 checks passed
BobbyZhouZijian added a commit that referenced this pull request Sep 13, 2026
Resolves the overlap with the ATIF training-data refactor (#446) and the
reported-feedback simplification (#445): main's TrainingBatch/TrajectoryItem
model is kept everywhere, this branch's names stay (CandidateBackend,
CandidatePluginFactory, SupportsReceipt, the runtime module split), main's
edit to the removed reef/runtime/adapters/executor_runtime.py is carried
into reef/train/runtime.py, and the Terminal-Bench example imports the
proxy runtime from reef.inference.http.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
BobbyZhouZijian added a commit that referenced this pull request Sep 14, 2026
main reworked the ground this branch stands on: #432 gave Reef ownership of
inference/training coordination, #446 unified training data as ATIF items, and
#412 moved the scenario and runtime modules. The MLX backend is re-integrated
rather than merely merged.

Conflicts and how they resolved:

- `reef/runtime/adapters/` and `reef/service/deploy/settings.py` are gone on
  main; the deletions are accepted. The MLX kind registers from
  `reef/train/__init__.py`, which is the direction the boundary allows.
- `reef/surface/base.py` and `reef/inference/sglang/chat.py` take main's
  restructured versions; `RecoveryRestorer` is re-added in main's ABC idiom.
- `reef/service/assembly.py` takes main's version: the function this branch had
  changed built a runtime from `ServiceSettings`, which no longer exists.

Re-integration:

- The batch path reads ATIF items. The captured tensors move from a
  `PolicySample`'s attributes to the item's `extra.reef.training`, where the
  openclawrl processor already writes them; the tests use main's own
  `policy_trajectory` helper so both sides agree on that layout.
- `MLXServingRuntime` (new) owns the parameters, the admission gate and the
  served version; `MLXRuntime` keeps candidates, the objective and checkpoints,
  and reaches the engine through it. The factory returns the pair #432's
  contract names. The seam follows the state: three methods needed both halves,
  and all three have the same shape — hold serving, touch the engine, release —
  so serving exposes an explicit `hold`/`release` rather than a context manager,
  because activation deliberately stays held until Reef's commit.
- `MLXInferenceBackend` implements both `InferenceHandler` and
  `InferenceBackend`; a receiver that runs as a separate service splits those,
  an in-process engine does not. The receiver operations that would mean moving
  memory Reef does not own (`offload`, `onload_*`, `unload_adapter`) raise
  instead of pretending, which is what the base class does for
  `load_adapter_files`.
- `assistant_message.py` moves under the MLX backend: main's boundary test
  counts it as an unowned module in `reef/runtime/`, and the MLX backend is its
  only consumer.

One judgement worth flagging: the shipped-config layout test now skips
`results/` directories. A results directory records the deployment a past run
used; migrating it to the current schema would make it a config that was never
executed, which is worse than an old one, because the record's whole value is
that it is what ran.

Verified: 3528 passed, 88 skipped (slime/ray/inference modules excluded — those
dependencies are absent here). mypy clean, ruff 0.14.7, isort 5.13.2,
black 24.3.0, and the Python design and statement policies pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SuEa3FyrkW1xc3sjmAJSEB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core contracts and scenario lifecycle area: docs User and developer documentation area: examples Examples, recipes, and reference deployments area: harness Harness integration, recipes, and evolution surfaces area: service Service APIs, deployment, and command-line interfaces area: training Training execution, runtimes, algorithms, and pipeline reliability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant