Skip to content

[Collect One 6/90] Protos: forms (P01) - #2701

Open
gino-m wants to merge 2 commits into
review/c1/w01-build-scaffoldingfrom
review/c1/p01-protos-forms
Open

gino-m wants to merge 2 commits into
review/c1/w01-build-scaffoldingfrom
review/c1/p01-protos-forms

Conversation

@gino-m

@gino-m gino-m commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Collect One review series: P01 Protos: forms (6/90)

Tracking issue: #2629 · Stacked on: #2698 · Reviewer: @rfontanarosa
FYI: @gino-m @shobhitagarwal1612

Context

Collect One is the Kotlin Multiplatform successor to Ground: a single shared codebase for the web
console, the mobile app (Android, iOS, browser), and a Spanner-backed user-data service. Forms use
ProtoForms, a lossless proto3 encoding of ODK XForms. Product and architecture background:
docs/product/prd.md, docs/technical/client/architecture.md (the docs slices have not merged yet, so
these are paths in the wip/baobab tree, not links).

This PR is one slice of the wip/baobab tree. It only adds the files listed below. It is stacked on #2698
(W01 Build system, CI workflows, and tooling): review only this diff; it merges after #2698.

This slice is the ProtoForms schema itself: the openforis.collectone.v1.forms package, plus the README
for the whole shared/protos/ directory. It contains no Kotlin and no Gradle module.

What's in this PR

  • shared/protos/README.md: overview of all proto packages (forms, survey, data, library, sync), the
    "data tables are current state, forms are events" mental model, and the mutation conventions of the gRPC
    services (client-generated UUIDs, sparse delete mask and sparse upsert, soft deletes). Only the
    forms/ part describes files in this PR.
  • shared/protos/forms/types.proto: DataType enum (16 values, scalars to geo types, binary, message,
    select one/multiple), GeoPoint, GeoTrace, GeoShape, and the TypedValue oneof used for literals.
  • shared/protos/forms/form_def.proto: the form definition. FormDef holds a ModelDef and a ViewDef.
    • Model: PrimaryInstance / RecordSchema / FieldDefinition, SecondaryInstance, FieldBinding
      (relevant, calculate, constraint, required, read-only, preload, entity_saveto), ForeignAttribute,
      TranslationCatalog / LanguageTranslation / LocalizedString / MediaRef, ActionDef with
      EventType and ActionType, EntityDeclaration / EntityPropertyMapping / EntitySyncMetadata,
      SubmissionConfig.
    • View: ViewComponent (oneof of ControlDef, GroupDef, RepeatDef), ControlType, LabelDef /
      OutputFragment, ChoiceItem, ItemsetDef, RangeConfig, GeoConfig, IntentConfig.
  • shared/protos/forms/record_instance.proto: a submission. RecordInstance (form id and version,
    RecordMetadata, root RecordNode, optional AuditLog), with FieldValue as a oneof of scalar, list,
    nested node, and repeat list.
  • shared/protos/forms/audit_log.proto: AuditConfig, AuditEvent, AuditLog for client audit logging.

Where it fits

This is the bottom layer: these messages are the wire and storage format for form definitions and
submissions, shared by the mobile app, the web console, and the server. The package depends only on
google.protobuf (Timestamp, Any) and google.type (Date, TimeOfDay). Per the README, Kotlin
classes are generated from these files by Square Wire in the shared/core build, which arrives with K01.

Not in this PR

  • shared/protos/survey/* (SurveyDef, ACLs, organizations, SurveyService) → P02 Protos: survey, ACL, organization
  • shared/protos/data/*, library/*, sync/*, earthengine/*, userdata/* → P03 Protos: data, library, sync, Earth Engine, user data
  • shared/core/build.gradle.kts (the module that compiles these protos) and the textproto codec → K01 Core 1/7: core.forms.serialization.textproto, core.forms.media (MediaCapture, FormStateModels)
  • XForms XML import and export of FormDef → K02 Core 2/7: serialization, xpath.ast (FormDefXmlDeserializer, FormDefXmlSerializer)
  • ProtoFieldCoverageTest, which the custom_extensions comments refer to → K06 Core 6/7: mutation, sampling (DefaultSamplingEngine, SurveyMutations)
  • docs/technical/model/forms/*, the long-form description of this model → D03 Docs: technical 2/2: forms, survey

Suggested reading order

  1. shared/protos/README.md: the "Core Mental Model" and "Packages" sections; the gRPC sections describe P02 and P03.
  2. shared/protos/forms/types.proto
  3. shared/protos/forms/record_instance.proto
  4. shared/protos/forms/audit_log.proto
  5. shared/protos/forms/form_def.proto: FormDef at the bottom first, then ModelDef, then ViewDef and its components.

Focus areas

  • XForms coverage. Most messages cite the ODK XForms spec section they come from (Primary Instance,
    Secondary Instances, Bindings and Bind Attributes, Body Elements, Events and Actions, Entities,
    Submission, Metadata, Data Types, Audit Attributes). Check that the fields are enough to round-trip a
    form; ForeignAttribute exists to keep <bind> attributes from namespaces the model does not cover.
  • id and sort_order on repeated items. FieldDefinition, SecondaryInstance, FieldBinding,
    ActionDef, ChoiceItem, ViewComponent, RecordNode and others carry a stable id "for sparse
    mutation addressing" and often a sort_order. These support the delete / upsert merge described in
    the README, where keyed repeated items are matched by ID and ordered by sort_order. Note the documented
    defaults (for example id defaults to field_path on FieldBinding).
  • Reflection-free records. RecordInstance stores answers as map<string, FieldValue> instead of a
    generated message per form, so every runtime reads submissions with ordinary generated accessors.
  • google.protobuf.Any custom_extensions on FormDef, ModelDef, FieldBinding, ControlDef: the
    comments say the client codecs (ProtoJSON, textproto) drop these for now. Is keeping the fields right?
  • Field numbering. SecondaryInstance reserves field 3 and the name inline_data; inline rows are now
    repeated RecordNode rows = 6.
  • Device identifiers. RecordMetadata keeps subscriber_id, sim_serial, phone_number from the
    XForms metadata set, with notes that modern mobile OSs restrict them.
  • Encryption. SubmissionConfig.base64_rsa_public_key is kept for round-trip only; the comment says
    Collect One does not encrypt submissions and relies on transport security.
  • README accuracy (small things found while reading, not changed here):
    • It names the control tree types ControlNode, GroupNode, RepeatNode; the proto defines
      ControlDef, GroupDef, RepeatDef.
    • It lists TranslationCatalog under types.proto; it is defined in form_def.proto.
    • Its relative links to survey/, data/, library/, sync/, ../core/ and ../../docs/technical/model/
      resolve only once P02, P03, K01 and D03 land.

Safe to skim

  • The Apache license headers.
  • The gRPC and mutation sections of the README until P02 and P03 are up for review.
  • Enum value lists (DataType, ControlType, PreloadType, EventType, ActionType) and the simple
    config messages (RangeConfig, GeoConfig, MediaRef).

Size

Source Tests Data Files
1521 0 0 5

Testing

bash scripts/buf-format.sh --check: PASS. buf build (proto compilation): PASS. bash scripts/ktfmt.sh --check and bash scripts/license-check.sh --check: PASS. No Gradle module is in this slice, so no jvmTest or detekt tasks ran.
CI: Check (ktfmt, buf format check through scripts/buf-format.sh --check, license headers), as far as the
modules in this PR's tree exist. This slice adds no Gradle module, so the protos are first compiled when
shared/core lands in K01.
No deviations from the frozen tree. No currency amounts appear in these files.

@gino-m gino-m added the collect-one Tickets related to Collect One label Nov 27, 2026
@gino-m
gino-m requested a review from rfontanarosa November 27, 2026 19:20
@gino-m gino-m self-assigned this Nov 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the core Protocol Buffer schemas and gRPC service definitions for Collect One, including documentation, form definitions, record instances, audit logs, and shared types. The review feedback points out documentation mismatches in the README regarding message names and file locations. Additionally, it suggests marking several numeric fields as optional (such as max_pixels, accuracy thresholds, and GPS intervals) to distinguish between unset values and explicit zero defaults in proto3.

Comment thread shared/protos/README.md Resolved
Comment thread shared/protos/README.md Resolved
// Dataset.
string entity_saveto = 11;

// Maximum long-edge pixel dimension for image attachments. Images exceeding

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since max_pixels is a numeric field, in proto3 it defaults to 0 when unset. However, 0 is an invalid pixel dimension for image downsampling, and typically represents 'no limit'. Marking this field as optional allows the client and server to explicitly distinguish between 'unset (no limit)' and an explicitly set value.

Suggested change
// Maximum long-edge pixel dimension for image attachments. Images exceeding
optional int32 max_pixels = 12;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✦ Good question; checking with the author and will follow up here.

Comment on lines +672 to +678
double accuracy_threshold_meters = 1;

// Horizontal accuracy threshold in meters above which the UI displays an
// uncertainty warning (e.g., red dialog in ODK Collect).
// Corresponds to XForms `<input unacceptableAccuracyThreshold="...">` and
// XLSForm `warning-accuracy` / `body::unacceptableAccuracyThreshold`.
double warning_threshold_meters = 2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In proto3, numeric fields default to 0.0 when unset. For accuracy_threshold_meters and warning_threshold_meters, a value of 0.0 represents an extremely strict (or impossible) threshold. Marking these fields as optional allows the client to easily distinguish between 'unset (use client/system defaults)' and an explicitly configured threshold.

Suggested change
double accuracy_threshold_meters = 1;
// Horizontal accuracy threshold in meters above which the UI displays an
// uncertainty warning (e.g., red dialog in ODK Collect).
// Corresponds to XForms `<input unacceptableAccuracyThreshold="...">` and
// XLSForm `warning-accuracy` / `body::unacceptableAccuracyThreshold`.
double warning_threshold_meters = 2;
optional double accuracy_threshold_meters = 1;
// Horizontal accuracy threshold in meters above which the UI displays an
// uncertainty warning (e.g., red dialog in ODK Collect).
// Corresponds to XForms `<input unacceptableAccuracyThreshold="...">` and
// XLSForm `warning-accuracy` / `body::unacceptableAccuracyThreshold`.
optional double warning_threshold_meters = 2;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✦ Good question; checking with the author and will follow up here.

Comment on lines +37 to +41
int32 location_min_interval_seconds = 2;

// Maximum acceptable age in seconds for cached GPS readings before requesting
// a fresh location fix from the hardware sensor.
int32 location_max_age_seconds = 3;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In proto3, numeric fields default to 0 when unset. For location_min_interval_seconds and location_max_age_seconds, a value of 0 would mean continuous background GPS tracking and instant cache expiration, which is extremely battery-intensive. Marking these fields as optional allows the client to distinguish between 'unset (use sensible client defaults)' and an explicitly configured value.

Suggested change
int32 location_min_interval_seconds = 2;
// Maximum acceptable age in seconds for cached GPS readings before requesting
// a fresh location fix from the hardware sensor.
int32 location_max_age_seconds = 3;
optional int32 location_min_interval_seconds = 2;
// Maximum acceptable age in seconds for cached GPS readings before requesting
// a fresh location fix from the hardware sensor.
optional int32 location_max_age_seconds = 3;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✦ Good question; checking with the author and will follow up here.

gino-m added a commit that referenced this pull request Nov 27, 2026
…and product docs (#2699, #2701, #2702)

- shared/protos/README.md: ControlDef/GroupDef/RepeatDef names; TranslationCatalog is in form_def.proto (#2701)
- survey_def.proto, organization.proto: FormConceptLinks comment placement; drop stale budget cap wording (#2702)
- docs/product/prd.md, concept-brief.md: Map layer wording, five lifecycle states, general access sliders, Purpose Packs (#2699)
ProtoForms: the XForms data model in proto3.

Sliced from wip/baobab @ db237d5. Tracking: #2629.
@gino-m
gino-m force-pushed the review/c1/p01-protos-forms branch from 85ddc77 to feb3c6e Compare November 28, 2026 01:33

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

collect-one Tickets related to Collect One

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant