# Datasets_ReingestDataset

`POST /v1/accounts/{account}/datasets/{dataset}:reingest`

Upload only (MCAP): commits a new meta/ingest.toml and ingests the
unchanged recordings again under it, publishing the upload's next
generation. Returns once the work is admitted; the ingest
takes minutes and is read with GetReingest. A config identical to the
published one runs nothing and returns that publication, SUCCEEDED,
with unchanged set.

A config that declares `[episodes] spans` re-cuts the recordings at those
windows. Episode ids follow position, so a re-cut renumbers every episode
of the upload: it is FAILED_PRECONDITION, naming the counts, while any
episode holds a person ruling, a person issue or note, a reach result, an
edit or a split child.

FAILED_PRECONDITION on a mixture, a non-MCAP upload, a merged dataset
(unless validate_only: below) and an upload merged into one (naming it;
its GetReingest and GetIngestReport still answer); INVALID_ARGUMENT when
the config does not parse.

With time_sync_patch the config is a patch of the upload's time sync, and
the server keeps every other table of the published meta/ingest.toml.

A merged dataset has one time sync, which every upload it holds
is to be processed to. ingest_config is the strict time sync patch of
time_sync_patch (any other table is INVALID_ARGUMENT), composed onto each
upload's own published meta/ingest.toml, and membership_revision is
required (ABORTED when the dataset's uploads changed since it was read, in
GetDataset's sync_preparation). The answer is
ReingestDatasetResponse.merged_sync.

With validate_only the call is the pre-check: it reads each upload's
published time sync, one at a time, and says which uploads already hold
the patch, which would be re-processed and which cannot be, and why. It
writes nothing and starts nothing.

Without validate_only the call applies it. In one transaction it stores
the patch as the dataset's time sync (replacing an earlier one), stores
each upload's composed config and standing, and records one
DATASET_UPDATED on the dataset (path time_sync). It dispatches nothing
itself: a background driver admits the uploads that wait as ordinary
corrective re-ingests, the least recently touched first (an apply's
recordings start in membership order; one that met an outage or a refusal
goes to the back), at most four per merged dataset running at once
(QDS_MERGED_SYNC_MAX_RUNNING), each fenced on the head it
was composed at. An upload that already holds the patch is never
dispatched, and the same patch applied again dispatches nothing new. A
failed upload is tried again by the driver up to three times;
`members` applies again to the listed uploads only (the same patch as the
dataset's current time sync), which is Try again for an upload that failed
or could not take it. Progress is read from GetDataset's sync_preparation
and each upload's GetReingest.

Every upload appended to the dataset afterwards (MergeDatasets with
merge_target) is brought to its time sync too: see
MergeDatasetsResponse.reprocessed_uploads.

While uploads are still waiting, claimed or re-processing for the time
sync, the dataset's uploads cannot change: a Remove, a version, a version
preview's publication and the solver are FAILED_PRECONDITION naming the
dataset and the number of recordings. They count the recordings waiting,
claimed, re-processing, failed in a way the driver will retry, and BLOCKED
only until another re-ingest of them ends (waiting_on_operation_id set);
leftovers (failed for good, blocked for what they hold, NOT_APPLICABLE) do
not hold the dataset up. An append or merge into it is accepted and queued
instead (MergeDatasetsResponse.joining_uploads): the recording joins once
the time sync has settled. With cancel_merged_sync the time sync is
withdrawn, and with it the waiting; recordings already re-processing keep
fencing the dataset while an attempt runs or awaits publication, not between
a failed attempt and the re-arm of its re-ingest's own next attempt (up to
three, within minutes). They are then told as "N recordings are still
re-processing; wait for them to finish before removing recordings, running
the solver or creating a version" (a pose move is told as one). An append is
queued meanwhile, and the queue waits for that window too, for ten minutes
at most after the failed attempt.

- Base URL: `https://api.qualia.dev`
- Authentication: an API key in the `X-API-Key` header

## Parameters

- `account` (path, string, required): The account id.
- `dataset` (path, string, required): The dataset id.

## Request body

Required: `application/json` `qualia.v1.ReingestDatasetRequest`

## Responses

- `200` OK: `application/json` `qualia.v1.ReingestDatasetResponse`
- `default` Default error response: `application/json` `google.rpc.Status`

## Schemas

```yaml
qualia.v1.ReingestDatasetRequest:
  required:
    - name
  type: object
  properties:
    name:
      type: string
      description: accounts/{account}/datasets/{dataset}
    ingestConfig:
      type: string
      description: |-
        Required unless resume_reingest is set. The complete meta/ingest.toml
        (schema = 1). It replaces the published
        file: a table the published file declared and this one leaves out is
        dropped. Declaring [episodes] spans re-cuts the upload (see
        ReingestDataset). With merged_settings_context, time_sync_patch or
        validate_only (a merged dataset) this is
        instead a strict clock/alignment patch: only schema, clock and
        channels.<topic>.align are
        accepted. Omitted clock keeps it; empty [clock] resets clock/grid/source
        overrides to automatic. In a nonempty clock table, a supplied fixed_hz or
        row_clock_topic replaces the grid, and source changes only if supplied.
        Explicit align = "nearest" resets alignment; omitted topics keep theirs.
        Unknown/unrouted topics and every other key are refused. The server
        composes onto the exact captured head, retaining episode boundaries,
        rig, camera settings and per-channel timestamp offsets.
    mergedSettingsContext:
      allOf:
        - $ref: "#/components/schemas/qualia.v1.MergedSettingsContext"
      description: |-
        Explicitly confirmed MCAP clock/alignment edit of one merged member.
        Other config tables and episode boundaries must remain unchanged. Older
        callers without this context retain the existing member re-cut rules.
    requestId:
      type: string
      description: |-
        UUID retry key, required with merged_settings_context. A replay retains
        its original operation and membership scope, never today's membership.
    resumeReingest:
      type: string
      description: |-
        Resume this exact completed corrective publication. No ingest_config,
        request_id or merged_settings_context may accompany this operation.
    timeSyncPatch:
      type: boolean
      description: |-
        Treat ingest_config as a patch of the upload's time sync instead of the
        whole file, so editing the time sync cannot drop what the upload's
        published meta/ingest.toml holds besides it: camera stamp offsets, the rig
        and its calibration, camera settings, state and action topics and episode
        boundaries. Only schema, [clock] and [channels.<topic>] align are
        accepted; any other key, or a topic that is not a routed state or action
        channel of the upload, is INVALID_ARGUMENT. The patch is applied to the
        file published when the request is read: FAILED_PRECONDITION for a
        non-MCAP upload, ABORTED when the upload is published again meanwhile
        (read it and retry). Not allowed with merged_settings_context or
        resume_reingest. A server that does not know this field replaces the
        whole file with ingest_config.
    validateOnly:
      type: boolean
      description: |-
        Merged datasets only: ingest_config is the time sync every upload the
        dataset holds is to be processed to. It is then always the strict time
        sync patch of time_sync_patch (set or not), composed onto each upload's own
        published meta/ingest.toml. The answer is ReingestDatasetResponse.merged_sync.
        With validate_only nothing is written or started (the pre-check); without
        it the patch is applied (see ReingestDataset). INVALID_ARGUMENT on an
        upload or a mixture, and with resume_reingest, request_id or
        merged_settings_context.

        Old servers: one that does not know this field ignores it and re-ingests
        the upload named, whatever its kind, replacing its whole meta/ingest.toml
        with ingest_config. A client that may reach an older server checks that it
        knows the field (for example, that GetDataset of the merged dataset carries
        sync_preparation) before it sends a pre-check.
    members:
      type: array
      items:
        type: string
      description: |-
        Merged only: the uploads (accounts/{account}/datasets/{dataset}) the call
        is about, each of which the dataset must hold (NOT_FOUND otherwise). Empty
        means every upload it holds. With validate_only they are the ones checked.
        Without it they are Try again: the patch must be the dataset's current time
        sync (INVALID_ARGUMENT otherwise), and only these uploads are composed
        again and, if they can take it, set to wait for the driver; the others are
        left as they are.
    membershipRevision:
      type: string
      description: |-
        Required for a merged dataset: the membership_revision of GetDataset's
        sync_preparation. ABORTED when the dataset's uploads have changed since:
        read it again and confirm again.
    cancelMergedSync:
      type: boolean
      description: |-
        Merged only: Cancel. Withdraw the dataset's time sync: it is no longer the
        dataset's (as when another time sync replaces it), so sync_preparation shows
        no target, nothing that waits is re-processed, the driver dispatches
        nothing again for it, and a recording appended later is not re-processed.
        A recording already re-processing finishes and publishes (a re-ingest
        cannot be stopped once the worker has it); if it fails in a way that may be
        retried, the driver does not dispatch it again, but its re-ingest's own
        attempts, up to three, still run. While an attempt runs or awaits
        publication, that recording fences the dataset (an append, a Remove, a
        version and the solver are FAILED_PRECONDITION); between a failed attempt
        and the re-arm of the next nothing does. A recording that already holds the
        time sync keeps it. Applying a time sync again
        starts a fresh one: the recordings that hold it read CURRENT, and one that
        still runs joins its running re-ingest. One DATASET_UPDATED (path
        time_sync) records "Time sync change cancelled for N recordings" ("Time sync
        change cancelled" when none was to be brought to it). Cancelling again
        changes and records nothing. Cancel does not look at whether anything waits
        or runs: on a dataset whose time sync is finished it still withdraws the
        time sync (appended recordings are then not re-processed, and the folded
        ingest report compares stamp offsets again). Needs membership_revision.
        INVALID_ARGUMENT with ingest_config, members, validate_only,
        time_sync_patch, request_id, resume_reingest or merged_settings_context,
        and on a dataset that is not merged; FAILED_PRECONDITION on one that never
        had a time sync. The answer is ReingestDatasetResponse.merged_sync (no
        target), cancelled_members and running_members. An older server ignores
        this field and answers the missing ingest_config.
  description: Request for Datasets.ReingestDataset.
qualia.v1.MergedSettingsContext:
  required:
    - mergedDataset
    - members
    - membershipRevision
    - etag
  type: object
  properties:
    mergedDataset:
      type: string
      description: The merged dataset whose membership was confirmed.
    members:
      type: array
      items:
        type: string
      description: Every upload it held, in merge order, including the selected upload.
    membershipRevision:
      type: string
      description: Opaque merge/undo epoch from GetDataset; never recapture it on retry.
    etag:
      type: string
      description: The dataset's editable etag; a member edit sends the selected upload's.
    sourceCommit:
      type: string
      description: |-
        The selected upload's exact paired head. Empty on the merged dataset's
        context, which is used only to fence global label edits.
  description: |-
    No longer answered: a merged dataset is not corrected through its uploads.
    One an older client still sends is checked:
    every resource in the caller's account/workspace, the exact ordered
    membership, the selected upload's etag and its published head. A stale
    context is ABORTED.
qualia.v1.ReingestDatasetResponse:
  type: object
  properties:
    reingest:
      allOf:
        - $ref: "#/components/schemas/qualia.v1.Reingest"
      description: |-
        The re-ingest it admitted (QUEUED), or with unchanged set, the
        publication that already carries the config (SUCCEEDED). Unset for a
        merged dataset.
    mergedSync:
      readOnly: true
      allOf:
        - $ref: "#/components/schemas/qualia.v1.MergedSyncPreparation"
      description: |-
        A merged dataset's time sync (pre-check, apply or Cancel): one answer per
        upload checked or applied to, and after a Cancel as GetDataset reads it (no
        target). Set only then.
    cancelledMembers:
      readOnly: true
      type: integer
      description: |-
        Cancel only (cancel_merged_sync): how many recordings were to be brought to
        the time sync and no longer are: waiting, blocked only by another job,
        claimed to be composed again (or by a replica that died), or failed in a way
        the driver would have retried and their re-ingest's own attempts will not.
        A recording blocked by an earlier time sync's re-ingest of it that still
        runs is in this count and in running_members; one blocked by a tool center
        point move or another re-ingest is in this one only.
      format: int32
    runningMembers:
      readOnly: true
      type: integer
      description: |-
        Cancel only: how many recordings still run, across all of the dataset's
        time syncs (an operation is one): recordings whose attempt runs or awaits
        publication, ones whose attempt failed within the last ten minutes in a way
        that its own waiter may still re-arm (up to three attempts), and
        recordings the driver had claimed and not yet started when the Cancel
        landed. Those whose attempt runs finish. Only an attempt that runs or awaits
        publication fences a Remove, a version or the solver, so this can be above 0
        while nothing does (an append is queued then, and the queue waits for
        them). A repeated Cancel
        counts them the same way (the number falls as recordings end). A claim the
        Cancel meets before its re-ingest has started is counted but may not start:
        the driver puts it back, its admission is refused or not answered, or its
        replica died.
      format: int32
  description: Response for Datasets.ReingestDataset.
qualia.v1.Reingest:
  type: object
  properties:
    name:
      type: string
      description: accounts/{account}/datasets/{dataset}/reingests/{reingest}
    state:
      readOnly: true
      enum:
        - STATE_UNSPECIFIED
        - QUEUED
        - PREPARING
        - PUBLISHING
        - SUCCEEDED
        - FAILED
      type: string
      description: Where the work stands.
      format: enum
    unchanged:
      readOnly: true
      type: boolean
      description: |-
        The posted config was the published one: nothing ran, and this names
        the publication that already carries it.
    failureReason:
      readOnly: true
      type: string
      description: Why it failed; empty unless FAILED.
    progress:
      readOnly: true
      type: object
      description: |-
        While PREPARING: the live step, the same open set of fields the upload
        feed reports (step, detail, counters).
    episodeCount:
      readOnly: true
      type: string
      description: "Once SUCCEEDED: episodes in the published generation."
    frameCount:
      readOnly: true
      type: string
      description: "Once SUCCEEDED: frames in the published generation."
    poseAttempt:
      readOnly: true
      type: integer
      description: Attempt currently preparing a pose move, or zero when cancellation is unavailable.
      format: int32
    publicationFailure:
      readOnly: true
      type: string
      description: Most recent safe publication failure while publishing, if any.
    recutResult:
      readOnly: true
      allOf:
        - $ref: "#/components/schemas/qualia.v1.ReingestRecutResult"
      description: |-
        Present only when a verified re-cut result committed atomically with
        this successful publication. Absence is not an empty/clean result.
  description: |-
    One re-ingest of an upload under a new meta/ingest.toml
    (Datasets.ReingestDataset).
qualia.v1.ReingestRecutResult:
  type: object
  properties:
    notCarriedCount:
      readOnly: true
      type: string
      description: |-
        Exact number of old original takes with state not carried. Zero means
        the verified publication lost no state; no such take is listed.
    publicationCommit:
      readOnly: true
      type: string
      description: Immutable publication commit, used to bind every page of the result.
  description: Summary of state not carried by one verified, finalized re-cut publication.
qualia.v1.MergedSyncPreparation:
  type: object
  properties:
    membershipRevision:
      readOnly: true
      type: string
      description: |-
        Opaque ordered-membership epoch the answer was made at (the same value as
        MergedPosePreparation.membership_revision). Send it back to pre-check or
        apply.
    target:
      readOnly: true
      type: string
      description: |-
        The patch, in canonical form: schema, then [clock] (row_clock_topic,
        fixed_hz, source), then one [channels.<topic>] with its align for each
        aligned topic in byte order of the topic, as the server applies it. Floats
        always carry their point. Empty in GetDataset while the dataset has no time
        sync: none has been applied, or it was withdrawn by a Cancel.
    currentMembers:
      readOnly: true
      type: integer
      description: Of the uploads counted, how many already hold the patch.
      format: int32
    totalMembers:
      readOnly: true
      type: integer
      description: |-
        Number of uploads that can hold a time sync: all the dataset holds, or
        those named in ReingestDatasetRequest.members, except the ones that are not
        ROS recordings (NOT_APPLICABLE), which are counted in
        not_applicable_members. So "current_members of total_members" can reach
        "N of N" whatever else the dataset holds.
      format: int32
    members:
      readOnly: true
      type: array
      items:
        $ref: "#/components/schemas/qualia.v1.MemberSyncPreparation"
      description: |-
        One answer per upload checked or applied to, in membership order. In
        GetDataset, the uploads that do not hold the patch yet, and none while the
        dataset has no target. Uploads that are NOT_APPLICABLE are listed here too,
        though they are not counted in total_members.
    notApplicableMembers:
      readOnly: true
      type: integer
      description: |-
        Of the uploads counted by the answer, how many are not ROS recordings (for
        example LeRobot uploads) and so have no time sync to change. They are in
        neither current_members nor total_members; a client can say "3 recordings
        have no time sync". An older server counts them in total_members and leaves
        this 0.
      format: int32
    joining:
      readOnly: true
      type: array
      items:
        $ref: "#/components/schemas/qualia.v1.JoiningUpload"
      description: |-
        Uploads appended to the dataset while its uploads re-processed, which have
        not joined it yet (MergeDatasetsResponse.joining_uploads): "N recordings
        will join after the current re-processing". Set by GetDataset, an apply
        and the answer to a Cancel (read with the members, in the same query); empty
        in a pre-check. They are not members:
        they are in none of the counts above.
  description: |-
    A merged dataset's time sync and where each of its uploads stands against it
    (ReingestDatasetRequest, Dataset.sync_preparation). After a pre-check it is
    derived from what the uploads publish and nothing is stored. After an apply
    or a Cancel, and in GetDataset, it is read from what the apply stored and from
    the uploads' re-ingests (after a Cancel, with no target).
qualia.v1.MemberSyncPreparation:
  type: object
  properties:
    upload:
      readOnly: true
      type: string
      description: "The upload resource: accounts/{account}/datasets/{dataset}."
    displayName:
      readOnly: true
      type: string
      description: The upload's display name.
    state:
      readOnly: true
      enum:
        - STATE_UNSPECIFIED
        - CURRENT
        - WAITING
        - RUNNING
        - BLOCKED
        - FAILED
        - NOT_APPLICABLE
      type: string
      description: The upload's state against the patch.
      format: enum
    reason:
      readOnly: true
      type: string
      description: |-
        A plain phrase that follows the display name ("has no /joint_states to
        clock rows by"); empty when there is nothing to say.
    skippedTopics:
      readOnly: true
      type: array
      items:
        type: string
      description: |-
        Channels the patch aligns that this upload does not route. They are
        skipped for this upload, which keeps what it has, and named here.
    operationId:
      readOnly: true
      type: string
      description: |-
        UUID polled at this upload's reingests/{operation_id} resource (GetReingest)
        once the driver has admitted its re-process; empty before, and in a
        pre-check.
    publishing:
      readOnly: true
      type: boolean
      description: "While RUNNING: the work is done and the new generation is being published."
    waitingOnOperationId:
      readOnly: true
      type: string
      description: |-
        While BLOCKED only because another re-ingest or tool center point move of
        this upload is still running: that operation's UUID (the upload's
        reingests/{operation_id}). The upload then moves by itself when it ends, so
        it is not a leftover and needs no Try again, and it holds the dataset's
        uploads fixed until it has. Empty for every other upload, including a BLOCKED
        one that does need action. Clients should read this, not the reason text, to
        tell the two apart.
  description: One upload's answer in a merged dataset's time sync.
qualia.v1.JoiningUpload:
  type: object
  properties:
    upload:
      readOnly: true
      type: string
      description: "The upload resource: accounts/{account}/datasets/{dataset}."
    displayName:
      readOnly: true
      type: string
      description: The upload's display name.
    actionNeeded:
      readOnly: true
      type: boolean
      description: |-
        The upload could not join (it became incompatible with the dataset, or the
        dataset or the recording is gone) and stays standalone; reason says why. A
        person appends it again once the reason is gone.
    reason:
      readOnly: true
      type: string
      description: Why, when action_needed; empty otherwise.
  description: An upload waiting to join a merged dataset (MergedSyncPreparation.joining).
google.rpc.Status:
  oneOf:
    - $ref: "#/components/schemas/ApiError"
    - $ref: "#/components/schemas/GatewayError"
  description: "The body of a failed call: one of the two shapes below."
ApiError:
  title: API error
  type: object
  required:
    - code
    - message
    - retryable
    - details
  properties:
    code:
      type: string
      description: The gRPC code name in upper case, e.g. `NOT_FOUND`.
    message:
      type: string
    retryable:
      type: boolean
      description: Whether the same call may succeed if retried.
    details:
      type: array
      items:
        type: object
      description: "Empty, except when a dataset copy or move is refused: then one `google.rpc.ErrorInfo` with the refusal's `reason` code, its `domain` and, in `metadata`, the datasets it names."
  description: A refusal from the API itself.
GatewayError:
  title: Gateway error
  type: object
  required:
    - detail
  properties:
    detail:
      type: string
      description: What went wrong.
  description: A refusal from the gateway before the call reaches the API, for example `401` bad or missing API key, `403` key lacks the scope or environment closed, `413` body too large.
```
