Skip to content

Add Project.move_images_to_batch and 'annotation batch move' - #565

Merged
tonylampada merged 8 commits into
mainfrom
bc/SLM-157
Nov 24, 2026
Merged

tonylampada merged 8 commits into
mainfrom
bc/SLM-157

Conversation

@tonylampada

@tonylampada tonylampada commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A customer's upload script names each annotation batch after a serial number. Upload dedup leaves images already in the project in their old batch, so the serial's batch holds only the new ones (REQ-238). The API regroups them with an API key since 2026-11-24 (roboflow/roboflow#18290, live in production), but the SDK and CLI on PyPI have no call for it.

roboflow annotation batch move -p <project> ...

Which images to move. Exactly one of:
  --image-id ID      this image. Repeat the flag, up to 1,000 ids.
  --tag T            every image of the project that carries this tag.
There is no other selector: no search query, no source batch, no filename.

Where they go. Exactly one of:
  --batch-id ID      this batch. It must exist.
  --batch-name N     the batch with this name, up to 200 characters. Created when there is none.

Only unassigned images move, out of whichever batch each one sits in. An image in a
job, in the dataset or already in the target stays put and is counted as skipped.

$ roboflow annotation batch move -p ws/proj --batch-name serial-0042 --tag serial-0042
Moved 7 image(s) to batch 'serial-0042' (b-new). Skipped 1 already there or not movable.
(output against a local stand-in for the API; the counts are the stand-in's)

Python: project.move_images_to_batch(batch_name="serial-0042", tag="serial-0042")
        returns {"batchId", "batchName", "moved", "skipped"}

What changes:

  • roboflow annotation batch move moves unassigned images into a batch, picked by id or by tag; --json prints the API's answer.
  • Project.move_images_to_batch(...) does the same from Python.
  • Both refuse before any request: over 1,000 ids, or not exactly one selector and one target (CLI exit 1, SDK ValueError).
  • An API refusal keeps the API's message. The CLI adds a hint for a tag past the project's 1,000-image limit and for a 404, which means a key from another workspace or without batch:update.

Tested

  • CLI: by tag, by ids, --json, exit codes 1/2/3 · tests/cli/test_annotation_handler.py, TestBatchMove
  • SDK: one selector, one target; ambiguous arguments refused · tests/test_project_annotation_administration.py
  • HTTP call: path, body, error with its status · tests/adapters/test_annotation_administration.py
  • Hints: a 404 names the key; an unknown tag lot-1000 gets no cap hint · TestBatchMove; both failed before their fix
  • All 12 fail on main's source; suite 1,294 OK; CI 15 of 15 on 9efe3118
  • CLI output against a local stand-in for the API
  • Not run: staging or production; no key for a test workspace here.
Evidence

All runs on 9efe3118c6840674369836e98fd2d6e2ccc20bdd, Python 3.12, 2026-11-24.

Suite

$ uv venv .venv --python 3.12 && uv pip install --python .venv/bin/python -e ".[dev]"
$ .venv/bin/python -m unittest
Ran 1294 tests in 48.752s
OK (skipped=1)

The 12 tests this PR adds

$ .venv/bin/python -m unittest \
    tests.adapters.test_annotation_administration.TestAnnotationJobAdministration.test_move_images_to_batch_contract \
    tests.adapters.test_annotation_administration.TestAnnotationJobAdministration.test_move_images_to_batch_error_raises_with_status \
    tests.cli.test_annotation_handler.TestBatchMove \
    tests.test_project_annotation_administration.TestProjectAnnotationAdministration.test_move_images_to_batch_sends_one_selection_and_one_target \
    tests.test_project_annotation_administration.TestProjectAnnotationAdministration.test_move_images_to_batch_rejects_ambiguous_arguments_before_calling_api
Ran 12 tests in 1.198s
OK

The same 12 with roboflow/ taken from main (b0f4aec), tests from this branch. Output cut to the summary and the distinct causes:

Ran 12 tests in 0.015s
FAILED (errors=14)        (12 tests; the extra 2 are subtests)
  12 AttributeError: roboflow.adapters.rfapi does not have the attribute 'move_images_to_batch'
   2 AttributeError: module 'roboflow.adapters.rfapi' has no attribute 'move_images_to_batch'

The two hint tests with roboflow/ taken from b28014d, the commit before both hint fixes:

FAIL: test_not_found_hint_points_at_the_key_not_the_batch
AssertionError: 'batch:update' not found in "Check the project and --batch-id; 'roboflow annotation batch admin-list' lists batches."
FAIL: test_unknown_tag_with_1000_in_its_name_gets_no_cap_hint
AssertionError: 'hint' unexpectedly found in {'message': 'No images in this project carry the tag "lot-1000"', 'hint': 'A tag moves at most 1000 images; move the rest with --image-id lists.'}
Ran 2 tests in 0.204s
FAILED (failures=2)

CLI against a local stand-in for the API. The stand-in's answers are written by hand from the API's contract, so this shows what the CLI sends and prints, not what the API does. Run with API_URL=http://127.0.0.1:8765 ROBOFLOW_API_KEY=key and an empty HOME; the 404 case uses ROBOFLOW_API_KEY=other. "loading Roboflow …" lines removed.

$ roboflow annotation batch move -p ws/proj --batch-name serial-0042 --tag serial-0042
Moved 7 image(s) to batch 'serial-0042' (b-new). Skipped 1 already there or not movable.
[exit 0]

$ roboflow --json annotation batch move -p ws/proj --batch-id b1 --image-id i1 --image-id i2
{
  "batchId": "b1",
  "batchName": "existing",
  "moved": 2,
  "skipped": 1
}
[exit 0]

$ roboflow --json annotation batch move -p ws/proj --batch-name b --tag big
{"error": {"message": "Tag \"big\" matches more than 1000 images in this project; move them by imageIds in smaller selections", "hint": "A tag moves at most 1000 images; move the rest with --image-id lists."}}
[exit 1]

$ roboflow --json annotation batch move -p ws/proj --batch-name b --tag lot-1000
{"error": {"message": "No images in this project carry the tag \"lot-1000\""}}
[exit 1]

$ roboflow --json annotation batch move -p ws/proj --batch-id b1 --tag t
{"error": {"message": "Not found", "hint": "Check the project, and that the API key is from its workspace with 'batch:update' scope."}}
[exit 3]

$ roboflow annotation batch move -p ws/proj --tag t
Error: Choose the target with exactly one of --batch-name or --batch-id.
  Hint: --batch-name creates the batch if it does not exist; --batch-id must name an existing batch.
[exit 1]

$ roboflow --json annotation batch move -p ws/proj --batch-name b --tag t --image-id i1
{"error": {"message": "Choose the images with exactly one of --image-id or --tag."}}
[exit 1]

Requests the stand-in received (the last two commands sent none):

REQUEST /ws/proj/annotation-batches/move {"tag": "serial-0042", "batchName": "serial-0042"}
REQUEST /ws/proj/annotation-batches/move {"imageIds": ["i1", "i2"], "batchId": "b1"}
REQUEST /ws/proj/annotation-batches/move {"tag": "big", "batchName": "b"}
REQUEST /ws/proj/annotation-batches/move {"tag": "lot-1000", "batchName": "b"}
REQUEST /ws/proj/annotation-batches/move {"tag": "t", "batchId": "b1"}

stub.py:

"""Local stand-in for POST /{workspace}/{project}/annotation-batches/move. Logs each request body."""
import json, sys
from http.server import BaseHTTPRequestHandler, HTTPServer

class H(BaseHTTPRequestHandler):
    def log_message(self, *a): pass
    def _send(self, code, out):
        self.send_response(code); self.send_header("Content-Type", "application/json"); self.end_headers()
        self.wfile.write(json.dumps(out).encode())
    def do_GET(self): self._send(200, {})
    def do_POST(self):
        raw = self.rfile.read(int(self.headers.get("Content-Length") or 0))
        if not self.path.split("?")[0].endswith("/annotation-batches/move"):
            return self._send(200, {})
        body = json.loads(raw)
        sys.stderr.write("REQUEST " + self.path.split("?")[0] + " " + json.dumps(body) + "\n"); sys.stderr.flush()
        if body.get("tag") == "big":
            return self._send(400, {"error": {"message": 'Tag "big" matches more than 1000 images in this project; move them by imageIds in smaller selections', "type": "BadRequestError"}})
        if body.get("tag") == "lot-1000":
            return self._send(400, {"error": {"message": 'No images in this project carry the tag "lot-1000"', "type": "BadRequestError"}})
        if "api_key=other" in self.path:
            return self._send(404, {"error": {"message": "Not found"}})
        moved = len(body.get("imageIds", [])) or 7
        self._send(200, {"batchId": body.get("batchId", "b-new"), "batchName": body.get("batchName", "existing"), "moved": moved, "skipped": 1})

HTTPServer(("127.0.0.1", 8765), H).serve_forever()

Deploy

Ships with the next PyPI release. Docs: roboflow/docs#406, to merge with or after that release.

Your calls

Tony decides: the command lives under annotation batch, not batch, because that group is Batch Processing jobs. On a no: moved before the release.

Reviewer guide

https://stormy-moment-h7np.here.now/

🤖 Generated with Claude Code

tonylampada and others added 8 commits October 22, 2026 14:30
Moves existing images, by IDs or tag, into an annotation batch named or
identified, via POST /{ws}/{proj}/batches/move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches the final SLM-156 contract: path, integer skipped, and the per-call
cap for image IDs and tags, surfaced with a hint in the CLI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus <noreply@anthropic.com>
…ve (REQ-238)

The API answers an unknown --batch-id with a 400 and a 404 only for a key
without batch:update or from another workspace, so the hint names the key.
The docstring and the adapter test now say the same.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
…e limits (REQ-238)

The hint matched any error text containing 1000, so an unknown tag such as
lot-1000 got it. The SDK docstring and CLI help now name the 20000-image
workspace tag cap and the 200-character batch name limit.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
@jarbas-roboflow jarbas-roboflow Bot added the LGTJarb 🤖 Approved by Jarbas automated PR review label Nov 24, 2026
@jarbas-roboflow

Copy link
Copy Markdown

PR Review: Add Project.move_images_to_batch and 'annotation batch move' (REQ-238)

  • Repository: roboflow/roboflow-python
  • PR: #565
  • Branch: bc/SLM-157 → main
  • Author: Tony Lâmpada (tonylampada)
  • Review date: 2026-11-24
  • Head: 9efe3118c6840674369836e98fd2d6e2ccc20bdd
  • Prepared base: b0f4aeca5c7a60d9e225baae5f763a9ae5733cbd
  • Scope: 8 files, +351 / −1; fresh review, no previous artifact.

Generated by Codex via roboflow-review-pr. Review is advisory; verify before merging.

📋 Summary

Adds SDK and CLI access to regroup existing images without uploading them again. Callers select images by IDs or tag and choose a target by batch ID or name. Named batches are reused or created by the API; the client preserves the server's moved/skipped counts.

No correctness, security, or architectural issue requiring changes was identified. The wire contract matches companion API PR #18290, inspected at head ba25b0ac398b2ef511229c5074953a54bf7ade6c. That PR is merged; deployment availability was not verified.

🏗️ Architectural Review

The public Project method validates selection and target arguments before delegating to the shared HTTP adapter. The CLI handler follows the existing annotation commands' direct-adapter pattern. Its placement under annotation batch fits the domain and avoids confusion with Batch Processing.

flowchart LR
    P[Project method] --> A[Shared adapter]
    C[Annotation CLI] --> R[Project resolver]
    R --> A
    A --> E[Move API]
    E --> O[Batch operation]
    O --> S[Source and batch state]
Loading

Dependency direction stays consistent. Batch lookup, creation, authorization, tag resolution, and state mutation remain server responsibilities; the SDK introduces no second source of state. The four-field response is minimal and matches the server transport response. The 1000-image cap matches the companion API's constant; broad-tag rejection remains server-side so the client cannot silently move a partial selection.

No repository-specific docs/review-guidelines.md was present. Reviewed the applicable contributor guidance: Google-style public docstrings, Typer registration, JSON output, noninteractive use, structured errors, and exit codes. The new command calls the quiet HTTP adapter directly rather than a noisy SDK constructor. Correctness, dependency boundaries, error handling, naming, changeability, tests, and API alignment were checked.

🐛 Code Quality Issues

No Critical, Warning, or Minor findings supported by a concrete failure path in the reviewed change.

The adapter omits absent fields, retains API error messages and HTTP status, and uses the existing HTTP wrapper. The CLI distinguishes selection errors from API failures, preserves JSON output, and gives a scope-aware 404 hint. Blank strings and malformed IDs that the CLI does not reject locally are still rejected by the API schema; this does not bypass server validation.

💡 Recommendations

  • Before releasing the SDK, verify that the move endpoint is deployed and smoke-test ID selection, tag selection, reuse of a named batch, and skipped images. A merged API PR alone does not establish deployment.
  • Check the comprehensive CLI reference in roboflow-dev-reference, as required by the contributor documentation policy. This PR updates the quickstart; companion docs PR #406 covers batch and REST documentation, but a comprehensive CLI-reference update was not verified.

These are release/documentation follow-ups, not demonstrated defects in the implementation.

🧪 Tests

The added coverage proves that the SDK delegates both selection/target forms and refuses ambiguous, empty, and over-limit input before calling the adapter. Adapter tests prove the endpoint, authentication parameter, camelCase payload, and preservation of API error status/message. CLI tests prove readable and JSON success output, invalid argument rejection, the image cap, 401/404/400 exit behavior, the permission-oriented 404 hint, and that a tag merely containing 1000 does not receive a false cap hint. These tests exercise observable behavior and do not introduce material test bloat.

Validation: all 54 tests across the three changed test modules pass under Python 3.12 with inherited PYTHONPATH removed (python -m unittest tests.adapters.test_annotation_administration tests.cli.test_annotation_handler tests.test_project_annotation_administration). Ruff passes for all six changed Python files, and git diff --check passes.

Initial environment attempts failed independently of the PR: Python 3.15 tried to build the AVIF dependency without native headers; a subsequent Python 3.12 run inherited Python 3.14 Pillow packages and failed SDK fixture imports. Removing PYTHONPATH resolves the SDK fixture problem. No staging or live mutation tests were performed, and the whole repository suite was not run.

⚖️ Verdict — ✅ Approve

The change is bounded, follows the existing SDK/CLI architecture, and matches the companion API contract. No actionable merge-blocking regression was found; retain the API deployment check before release.


Review timestamp: 2026-11-24 UTC.

@tonylampada tonylampada changed the title Add Project.move_images_to_batch and 'annotation batch move' (REQ-238) Add Project.move_images_to_batch and 'annotation batch move' Nov 24, 2026
@tonylampada
tonylampada marked this pull request as ready for review November 24, 2026 19:10
@tonylampada tonylampada self-assigned this Nov 24, 2026
@tonylampada
tonylampada requested a review from a team November 24, 2026 19:11
@tonylampada
tonylampada merged commit 170a0a1 into main Nov 24, 2026
15 checks passed
This was referenced Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTJarb 🤖 Approved by Jarbas automated PR review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants