Registry stack documentation: machine-readable Markdown.
Index of all pages: https://docs.registrystack.org/dev/llms.txt
Full corpus: https://docs.registrystack.org/dev/llms-full.txt

# Adapter job packs

> What the maintained KoboToolbox and ODK Central job packs read, how they authenticate, page, and map items, the limits you must size for, and how to fork the KoboToolbox pack for a wide form.

If you ingest survey submissions into a registry with the Registry Adapter, a job pack is the reviewed,
reusable description of how to read the source.
Each maintained job pack acquires submissions one page per route run and returns the item contract
`{items: [{key, revision, value}], next}`.
No pack carries compiled knowledge, writes, or a delete or patch endpoint.
This page describes the two maintained packs: KoboToolbox and ODK Central.
[Ingestion job sources](../../configure/adapter-ingestion-jobs/) describes the generic source types,
and [Operate the Adapter](../../operate/adapter/) runs a job over a pack.

## KoboToolbox pack

The maintained KoboToolbox pack has synthetic fixture coverage.
No run record is published, so `testedVersions` is unverified until your own pilot repeats a run
against your server.
Treat any compatibility with a production deployment or a server upgrade as unproved.

### What the route reads

The route reads the v2 submissions listing, `GET /api/v2/assets/{uid}/data/`, one page per run.
The v2 API renamed the v1 `submissions` path to `data`.
The reply envelope is `{count, next, previous, results}`; the route reads `results` only and never
follows the reply's `next` URL.

The read order is pinned rather than left to the server default.
Every send carries `sort={"_id":1}` and `limit=100` (the documented default page size).
Past the first run it also carries the keyset filter `query={"_id":{"$gt":<afterId>}}`, built from the
job cursor.
The `sort` and MongoDB-syntax `query` parameters are documented in the
[KoboToolbox API documentation](https://support.kobotoolbox.org/api.html), and `_id` is the integer
submission id the server sorts on by default.
A submission only ever gains a larger `_id` than every earlier one, so the keyset neither skips nor
repeats rows when submissions arrive between runs, where a `start` offset would shift.

The resumption cursor is the pack's own `{afterId}` object:

- A page with submissions, full or short, hands out the `_id` of its last submission.
- An empty page hands the incoming cursor back unchanged, so the `ongoing` scan holds its place at the
  tail and the next pass reads only what arrived since.
- A first run over a form with no submissions hands out no cursor, because there is no position to
  keep.

A reply whose `_id` values do not climb past the cursor (a server that ignored `sort` or `query`) fails
the run rather than hand out a position that would skip or repeat submissions.
The route declares `nextRecovery: key-deduplicated` as the documented fallback.

The asset a job reads is a deployment value.
A source route carries no template parameters, so the runtime configuration binds the `kobo-api`
endpoint's `baseUrl` to the data URL of your own asset (origin plus base path), and the pack sends
`path: /`, which lands on the documented trailing slash.
The [`kobotoolbox-job` example](https://github.com/registrystack/registry-stack/tree/main/products/adapter/examples/kobotoolbox-job)
shows the binding in `job-runtime.example.yaml`.

{/* Evidence: products/adapter/packs/kobotoolbox/pack.yaml nextRecovery, edits, maximumResponseBytes;
    crates/registry-adapter/tests/job_pack_replay.rs
    kobotoolbox_first_run_reads_a_full_page_from_the_start,
    kobotoolbox_continuation_reads_after_the_last_id,
    kobotoolbox_tail_pass_picks_up_new_submissions_and_holds_the_tail,
    kobotoolbox_empty_page_keeps_the_position,
    kobotoolbox_reply_reaching_back_past_the_cursor_is_refused. */}

### Authentication

KoboToolbox authenticates API requests with an API token over `Authorization: Token <token>`, or with
Basic auth over TLS.
An endpoint declares one kind, so the pack declares `static-authorization` with `scheme: Token`, and
the runtime configuration binds the personal API token through `tokenRef`.

The API token cannot sign in to the Kobo web UI, but it is not read-only: it carries the account's API
rights, so bind the token of an account restricted to the form.
A Kobo password also signs in to the web UI, so a leaked password is a full account login.
A deployment that must use Basic swaps the endpoint kind to `basic` and binds `usernameRef` and
`passwordRef`; both sides of the kind match move together.
The endpoint declares no request or response header allowlists, because the documented read consumes no
header the engine would copy.

A refused credential never reaches the route: the engine's authentication plan raises the
uncatchable `credential.rejected` on a 401 under a static kind.

{/* Evidence: products/adapter/packs/kobotoolbox/pack.yaml static-authorization;
    crates/registry-adapter/tests/job_pack_replay.rs
    kobotoolbox_refused_credential_raises_credential_rejected. */}

### Item mapping

- `key` is the submission's `_id`, as text, scoped to one configured asset.
- `revision` is the submission's `_uuid`.
  Edits keep `_id` and `meta/rootUuid` stable while changing `_uuid`.
  A job does not switch its identity selector after delivery; existing effects need reconciliation
  before an identity migration.
- `value` is the submission object with its slash-separated group and repeat names nested into
  objects.
  `_validation_status` passes through only inside `value`, read-only.

Kobo returns group answers as flat names such as `household/household_size`.
The item value carries them as `household: {household_size: ...}`, so a job projection addresses them
as `household.household_size`, because the projection grammar has no escape for a slash inside a member
name.
Rows of a repeat group arrive with their full names (`household/member/member_name`); each row drops
its repeat's own name before nesting.

A submission without an integer `_id` or without `_uuid` fails the page rather than producing a weaker
item.
So does a name that is both an answer and a group (`household` and `household/x` in one submission),
because nesting would have to drop one of them.
The route shapes one submission per script call (a `split` over `results`), so a wide form never shares
one script budget with the whole page.

{/* Evidence: crates/registry-adapter/tests/job_pack_replay.rs
    kobotoolbox_name_that_is_both_a_leaf_and_a_group_is_refused;
    products/adapter/packs/kobotoolbox/scripts/shape-item.rhai. */}

### Limits to plan for

The maintained pack rests on these observations from a controlled run with synthetic data.
Verify each against your own server and form before you rely on it:

- Submission `_id` values were unique, and an authenticated edit kept the same `_id`.
  Deduplication and identity continuity across server upgrades are unproved.
- Real submissions carried `_uuid`, and edits changed it.
  The pack still refuses a submission missing it.
- Edited submissions retained `meta/rootUuid`.
  Legacy submissions and every historical form version were not tested.
  The maintained asset-scoped key remains `_id`.
- A source edit stayed behind the saved keyset tail.
  A rescan found it; an ordinary tail read did not.
  Keep `edits: rescan` and the bounded reconciliation interval.
  Deletion history is not a poll-only change feed.
- A fixed `limit=100` returned pages of 100 and 1, followed by an empty tail.
  A 30,000-item deployment and bulk-cap behaviour were not exercised.
  Size the response bound and the rescan cost for each form (see
  [Wide forms](#wide-forms)).
- `sort={"_id":1}` and the `$gt` keyset filter returned exactly the expected ascending continuation.
  This was not a concurrent-writer or server-upgrade test.
- Group answers used slash-separated names, including a numeric answer encoded as a string.
  Group and repeat nesting and ambiguous-name refusal have synthetic replay coverage; not every repeat
  or legacy form shape was exercised against a server.
- The `Token` authentication the pack declares has synthetic replay coverage only.

A direct registration job does not establish the separate Coordinator workflow, automatic corrections,
or approval authority for the ingestion service.
A service-initiated Proposal also needs a review policy compatible with that actor: a policy requiring
a human initiator refused a separate fixture before task creation.
Do not relax a production review policy to copy a synthetic run.

{/* TODO[evidence]: the limits above are observations from a run whose record is not published;
    only the replay fixtures and refusal tests are in the repository. */}

### Wide forms

The pack fixes the page at `limit=100` and the endpoint at 1 MiB (`maximumResponseBytes: 1048576`).
A form whose submissions average more than about 10 KB (many questions, repeat groups, attachments,
geolocation) makes a full page exceed that bound.
The send then fails with the same page on every pass, and the position never moves.
Neither the runtime nor the job can change the pack's page size, and the runtime may only lower the
response bound.
The fix is a pack of your own for that form, pinned in place of the maintained one:

1. Copy `pack.yaml` and its `scripts/` directory to a directory you own.
   Give the copy a new `id` (or `version`) so nobody mistakes it for the maintained pack.
2. In the copy, lower `limit` (for example to `"25"`), or raise the endpoint's `maximumResponseBytes`
   (the ceiling is 16 MiB, 16777216), or both.
   A lower `limit` also lowers the rescan cost per page.
3. If you raised `maximumResponseBytes`, raise `profile.maximumResponseBytes` and
   `profile.maximumPageBytes` in the job to match.
   The profile is never tighter than the endpoint.
   If you lowered `limit` alone, nothing else needs to change.
4. Recompute the pack digest with `shasum -a 256 pack.yaml`.
   Put it in `source.pack.digest` of your job file and in `pack.digest` of `project.yaml`.
   Update `id` or `version` in both places if you changed them.
5. Run `adapterctl job check` with your pack.
   The check refuses a stale digest and names the field.

The maintained pack and its digest stay unchanged, so you can still compare your copy with it.

{/* Evidence: products/adapter/packs/kobotoolbox/pack.yaml maximumResponseBytes, limit;
    crates/registry-adapter-core/src/pack.rs. */}

{/* TODO[evidence]: no test names the 16 MiB endpoint ceiling, the 10 KB average figure, or the stale
    digest refusal of adapterctl job check. */}

### Fixtures

The pack carries five synthetic fixture suites, with `documented` provenance and an unverified
upstream version:

- A first run reading the first 100 of 130 submissions.
- The continuation, reading the remaining 30 and holding the tail.
- A later pass picking up two new submissions.
- The empty pages (at the tail and on a first run).
- A 401 suite expecting the `credential.rejected` class.

Every name and value in them is made up.
The maintained facade fixture shape has a profile operation per entry, which a job route does not
have, so these files keep the stable envelope and carry a provisional job entry shape, marked in each
header.
The repository's replay test compiles the pack's route through the job compiler and replays every
fixture entry.
It checks the exact request the route sends (path and query) and the item page or problem class that
comes back.
The same test holds the refusal cases: a reply reaching back past the cursor, and a name that is both an
answer and a group.

{/* Evidence: crates/registry-adapter/tests/job_pack_replay.rs replay_entry,
    kobotoolbox_first_run_reads_a_full_page_from_the_start. */}

## ODK Central pack

No ODK Central server has been reached with this pack.
Every upstream shape is synthesised from the published documentation, every fixture is synthetic with
`documented` provenance, and `testedVersions` is empty.
The Central documentation names feature versions (`$orderby` since v2024.1, which this pack needs) but
pins no server version the pack was run against.
Treat the pack as unproved until a controlled deployment answers the questions in
[Behaviour to confirm](#behaviour-to-confirm).

### What the routes read

Two source routes share one `odk-odata` HTTP endpoint.
Both pin the read order rather than leave it to Central's default (newest first), both use `$top=100`,
and neither follows the reply's `@odata.nextLink`: Central's `$skiptoken` pages in its default
newest-first order, so it cannot resume an ascending scan.
Neither route uses `$expand` or `$select`.

- `odk-submissions` reads the Submissions entity set of one form's OData service,
  `GET /v1/projects/{projectId}/forms/{xmlFormId}.svc/Submissions`, one page per run.
  Every send carries `$orderby=__system/submissionDate asc`; past the first run it also carries
  `$filter=__system/submissionDate ge <cursor date>`.
  Both `__system/submissionDate` filtering and `$orderby` are documented for the Submissions entity
  set.
- `odk-repeats` reads one repeat entity set.
  Central exposes each repeat as its own entity set (for example `Submissions.household.member`), so
  the deployment binds the endpoint base path to that set.
  Every send carries `$orderby=$root/Submissions/__system/submissionDate asc` (repeat rows in their
  parent submission's order, with the `$root/` prefix the documentation gives for repeat filters) and
  `$skip` from the cursor's offset.

The `odk-submissions` cursor is `{submissionDate, seen}`: the date of the last row read, as Central
rendered it, and every id the reply carried at that date.
The filter's bound is inclusive (`ge`), so the next reply starts with the rows at the cursor date
again; those the cursor lists as seen are dropped, and the rest are new.
The inclusive bound with a seen list, instead of a strict `gt`, covers submissions that share one
rendered millisecond: Central stores the timestamp more finely than it renders it, so a strict filter
on the rendered value could skip a row.

Both routes hold their place at the tail of the `ongoing` scan:

- A page with rows hands out the position after its last row (`{submissionDate, seen}` or
  `{offset}`).
- An empty page hands the incoming cursor back unchanged, so the next pass reads only what arrived
  since.
- A first run over a form with nothing to read hands out no cursor.

`odk-submissions` refuses a reply that is out of submission-date order or reaches back before the
cursor date (a server that ignored `$orderby` or `$filter`).
It also refuses more than 40 ids at one rendered date: the cursor would outgrow its 2 KiB bound, and a
page of nothing but seen rows would never move on.
Each of these refusals ends the pass with the `script` error class and leaves the position unchanged,
so the next pass fails the same way until the cause is gone; the pack has no runtime setting that
skips it.
A bulk server-side import can cause the 40-id refusal.
The pack carries the limit, so a deployment that must read past such a date forks the pack (raise the
`40` in the pack's `shape-page.rhai` script, within the cursor's 2 KiB bound) and repins its digest in
the job and project files.

The `odk-repeats` offset is a position in a list that can change.
A deleted repeat row, or a parent submission that arrives late with an older submission date, shifts
the rows after it by one, and the shifted row is skipped until the next rescan (`edits: rescan`, every
3600 seconds) reads it again.
An added row only reads one row again, which `key-deduplicated` absorbs.

The project, form, and entity set a job reads are deployment values.
A source route carries no template parameters, so the runtime configuration binds the `odk-odata`
endpoint's `baseUrl` to the entity-set URL of your own form (origin plus base path), and the pack sends
`path: /`.
A job on the `odk-repeats` route binds it to the repeat entity set's URL instead.
The [`odk-central-job` example](https://github.com/registrystack/registry-stack/tree/main/products/adapter/examples/odk-central-job)
shows the binding in `job-runtime.example.yaml`.

{/* Evidence: products/adapter/packs/odk-central/pack.yaml maximumResponseBytes;
    crates/registry-adapter/tests/job_pack_replay.rs
    odk_central_first_run_reads_a_full_page_in_submission_order,
    odk_central_continuation_filters_past_the_last_submission,
    odk_central_tail_pass_picks_up_new_submissions_and_holds_the_tail,
    odk_central_empty_page_keeps_the_position,
    odk_central_reply_reaching_back_before_the_cursor_date_is_refused,
    odk_central_repeat_route_bound_to_the_submissions_set_is_refused;
    products/adapter/packs/odk-central/scripts/shape-page.rhai. */}

{/* TODO[evidence]: no test names the 40-id refusal or the 3600 second rescan interval. */}

### Authentication

Central accepts Basic auth over HTTPS (its own documentation calls it "allowed, but strongly
discouraged" because every request re-verifies the password) and bearer session tokens minted by
`POST /v1/sessions`, which expire by default after 24 hours.
An endpoint declares one kind, so the pack declares `basic`.

The session-token alternative needs a credential kind that owns the session exchange: mint once, carry
`Authorization: Bearer`, and mint again on expiry.
A `static-authorization` pin carries one static value, and a 24-hour session token is not static.
So Basic over mandatory TLS is what the pack supports, and the session-token credential is an engine
capability to ask for, not a pack edit.

Central answers 401 without a `WWW-Authenticate` challenge.
The engine's authentication plan raises the uncatchable `credential.rejected` before any route step sees
it.

{/* Evidence: crates/registry-adapter/tests/job_pack_replay.rs
    odk_central_refused_credential_raises_credential_rejected. */}

### Item mapping

- `key` is the entity's `__id` (the documented OData key; Central's field table maps it to the
  submission `instanceId`).
- `revision` is `__system/updatedAt`, or `__system/submissionDate` while the submission was never
  edited.
  Central leaves `updatedAt` null when a submission is first created, so the fallback keeps an unedited
  submission's revision stable and an edit changes it.
- `value` is the entity object exactly as the page returned it.
- `odk-repeats` keys are the repeat row's own `__id`.
  Central derives it from the parent instance and the row's place in it, and gives the parent's
  instance id under `__Submissions-id` (`__Submissions-<group>-id` for a repeat nested in a group).
  The route requires one such member, so a binding to the Submissions set fails instead of passing
  submissions off as repeat rows, and `value` carries it unchanged.
  A repeat row carries no `__system`, so its item carries no revision.

A page whose entities lack the mapped members fails rather than producing weaker items.
The `key` and `revision` mappings rest on documentation, not on a probe.

{/* Evidence: crates/registry-adapter/tests/job_pack_replay.rs
    odk_central_repeat_rows_key_on_their_own_id;
    products/adapter/packs/odk-central/scripts/shape-repeats.rhai. */}

### Behaviour to confirm

Confirm each of these against a controlled deployment before you rely on the pack:

1. `__id` is the submission instance UUID, unique and stable, on your Central version.
2. `__system/updatedAt` changes on every edit on your Central version.
3. Your Central honours both `$orderby` and a `ge` filter on `__system/submissionDate`.
   Check how many submissions share one rendered millisecond at your submission rate (the pack refuses
   more than 40), and that a submission's `submissionDate` stays fixed across edits.
4. Central accepts the `$root/Submissions/__system/submissionDate` ordering on a repeat set, the order is
   stable for rows of one parent, and the `__id` and `__Submissions-id` members read as described.
   New submissions append at the end, but an edit that adds or removes a repeat row in an older
   submission shifts every later row by one: an added row reads one row again, and a removed row skips
   one until the periodic rescan.
5. The session-token credential: what a session-owning credential kind needs, and whether Central's
   default 24-hour expiry fits your job cadence.

### Fixtures

The pack carries six synthetic fixture suites, with `documented` provenance and an unverified upstream
version:

- A first run reading the first 100 of 130 submissions (two of them edited, the rest with a null
  `updatedAt`).
- The continuation, which drops a boundary submission sharing its millisecond with the next one and
  holds the tail.
- A later pass picking up two new submissions.
- The empty pages (at the tail and on a first run).
- A 401 suite expecting the `credential.rejected` class.
- One repeat-table suite.

Every name and value in them is made up.
The repository's replay test compiles the pack's routes through the job compiler and replays every
fixture entry, and it holds the refusal cases: a reply reaching back before the cursor date, and a
repeat route bound to the Submissions set.

## Next

- [operate the adapter](../../operate/adapter/)
- [ingestion job sources](../../configure/adapter-ingestion-jobs/)
- [govstack consultation and write](../../configure/adapter-consultation/)