feat: delete (soft) and restore training runs via SDK and CLI - #512
Open
leeclemnet wants to merge 7 commits into
Open
feat: delete (soft) and restore training runs via SDK and CLI#512leeclemnet wants to merge 7 commits into
leeclemnet wants to merge 7 commits into
Conversation
Wires the platform's external v2 trainings delete/restore routes: - rfapi: delete_version_training (POST .../v2/trainings/delete, optional trainingId with sole-run fallback) and restore_version_training (trainingId required — trashed runs are invisible to the sole-run resolver). - SDK: Version.delete_training(training_id=None) and Version.restore_training(training_id), mirroring Version.delete()/ restore() trash semantics: the run and its models hide from listings but stay restorable for 30 days before permanent cleanup. - CLI: `roboflow train delete <project>/<version> [--training-id]` and `roboflow train restore <project>/<version> --training-id`, with actionable hints for in-progress runs, alias-backed models, and multi-run versions. Deletion is soft-only on the public API by design; permanent deletion stays in the web UI's Trash view. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
leeclemnet
force-pushed
the
feat/trainings-delete-restore
branch
from
July 24, 2026 18:36
ae5c422 to
958e8ad
Compare
7 tasks
CI installs unpinned ruff; 0.16.0 (2026-07-23) starts enforcing CPY001 (missing copyright notice) under select = ["ALL"], failing every file. Add the CPY family to the ignore list alongside the other excluded families. Verified with ruff 0.16.0: format, check, and mypy all pass. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…y path - delete_version_training omits trainingId only when None and raises ValueError on blank/whitespace ids, so an empty selector can never fall back to soft-deleting the version's sole run; restore_version_training rejects blank ids likewise. - New `roboflow train list <project>/<version>` enumerates a version's runs (TRAINING_ID / STATUS / MODEL_TYPE / MODELS), and the MULTIPLE_TRAININGS hint on delete now points at it instead of `train results`, which cannot enumerate runs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The platform refactored training deletion to match project/version/workflow:
HTTP DELETE on the resource and restore via the shared workspace trash route.
- delete_version_training now issues
DELETE /{ws}/{proj}/{ver}/v2/trainings/{training_id} (id required) and
returns the shared { deleted, type, ..., trash: true } shape.
- restore_version_training is gone; Training.restore, Version.restore_training,
and 'roboflow train restore' go through restore_trash_item(..., "training", id) —
the same route project/version/workflow restores use.
- Sole-run resolution moves client-side (resolve_version_training_id):
Version.delete_training() and 'roboflow train delete' without --training-id
list the version's runs and only proceed when there is exactly one, keeping
the MULTIPLE_TRAININGS error + 'roboflow train list' hint.
- CLI restore hints now match the trash route's "not found in trash" message.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The v2 trainings list serializes each run's id as `id` (the pre-existing serializeExternalTraining shape, shared with MCP), not `trainingId` — the CLI table rendered an empty TRAINING_ID column and the sole-run resolver's MULTIPLE_TRAININGS message listed "None". Read `id`, correct the docstring, and point the test fixtures at the real payload shape (the old fixtures used the wrong key, which is exactly what masked this). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Review follow-up: a blank --training-id raised a bare ValueError past the CLI's error path, and restore forwarded whitespace ids to the API. - restore_trash_item validates item_id (shared by every trash restore). - train delete/restore map ValueError through output_error with exit code 2 and a --training-id hint. - Tests: structured error + exit code for blank delete/restore, blank Training.restore(), and blank restore_trash_item ids. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
External SDK users have no context for "DNA" or "MMPV" — say what the commands and methods do in product terms instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
leeclemnet
marked this pull request as ready for review
July 27, 2026 17:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds SDK and CLI support for the platform's new training deletion feature (roboflow/roboflow#13869), which is soft-delete-first: deleting a training moves it (and every model it produced) to the workspace Trash for 30 days, hidden from listings but restorable, before permanent cleanup.
rfapi.delete_version_training(...)— thin wrapper forDELETE /{ws}/{project}/{version}/v2/trainings/{training_id}(the platform's entity trash pattern;training_idrequired). Restore goes through the existingrfapi.restore_trash_item(..., "training", id)— the same sharedPOST /{ws}/trash/restoreroute project/version/workflow restores use; there is no bespoke trainings restore route.rfapi.resolve_version_training_id(...)resolves an omitted id to the version's sole run client-side (several runs raiseMULTIPLE_TRAININGSwith the ids listed).Version.delete_training(training_id=None)/Version.restore_training(training_id)— mirror the existingVersion.delete()/Version.restore()trash semantics;Training.delete()/Training.restore()do the same on the run object returned by the trainings APIs.roboflow train delete <project>/<version> [--training-id ...]androboflow train restore <project>/<version> --training-id ..., with actionable hints for the refusal cases (in-flight run → stop/cancel first; run backs the version's registered model; multi-run version needs--training-id; item not in trash →roboflow trash list).roboflow train list <project>/<version>enumerates a version's runs with their ids (reading the API'sidfield) so MMPV training ids are discoverable. Blank/whitespace--training-idvalues fail as structured usage errors (exit code 2) instead of raw tracebacks, andrestore_trash_itemvalidates its id for every trash type.Deletion is soft-only on the public API by design — permanent deletion stays in the web UI's Trash view, consistent with the existing note in
rfapithat permanent trash actions are never exposed to API keys.Related Issue(s): Depends on roboflow/roboflow#13869 (platform endpoints) — merge/deploy that first; until then these calls return 404.
Type of Change
Testing
Test details:
Checklist
Additional Context
Mirrors the existing
cancel_version_training/stop_version_trainingadapter pattern and thetrain cancel/train stopCLI command pattern. The companion MCP PR (roboflow/roboflow-mcp#124) was closed by design: MCP has no trash-lifecycle tools for any entity yet, so trainings won't lead there.🤖 Generated with Claude Code