Skip to content

ADR 0005: M2 parcel resolution

Intake stores captures with no confident parcel match as needs_match and parcel_id = NULL. Review actions can return or reject them, but accept requires a matched parcel, so the office cannot finish the capture entirely in the browser. Parcel search and the parcel identity constraints already exist.

One resolution endpoint with one parcel source

Section titled “One resolution endpoint with one parcel source”

POST /v1/captures/:id/resolve-parcel accepts exactly one of:

{ "parcelId": "uuid" }
{
"parcel": {
"mapLot": "014-022-003",
"address": "12 Elm Street",
"ownerName": "Synthetic Owner"
},
"expectedStatus": "needs_match"
}

Both or neither source is a 422 validation_failed. Existing parcels must belong to the capture’s tenant and town; a mismatch is 422 parcel_not_found rather than a leak. New map/lot and address are required; owner is optional.

Alternative considered: separate match and create endpoints. Rejected because the operation and audit event are the same.

The endpoint does not rematch in_review or terminal captures. A stale expectedStatus returns 409 capture_status_conflict; any other status returns 409 invalid_transition. Rematching would need its own decision about replacing an existing audit-backed match and is deferred.

Parcel creation and matching are one atomic batch

Section titled “Parcel creation and matching are one atomic batch”

CaptureRepository.assignParcel runs one D1 batch:

  1. When creating, insert the parcel only if the capture is still needs_match.
  2. Update the capture: set parcel_id, set status in_review, guarded by needs_match.
  3. Insert the event only if the update changed a row (changes() = 1).

A stale status makes steps 1 and 2 no-ops, so no parcel or event remains. A duplicate map/lot raises the parcel unique constraint; the adapter translates it to DuplicateParcelError and the core returns 409 parcel_exists. The batch is transactional, so a failed duplicate insert rolls back the whole operation.

Alternative considered: create the parcel first, then update the capture. Rejected because a failed match would leave an orphan parcel.

The route uses requireSession and requireSameOrigin; active reviewer and admin roles may resolve. API keys cannot resolve parcels. The event is capture.parcel_matched with actorType user, the reviewer id and name, needs_match as the previous status, and in_review as the result.

A panel renders only for needs_match captures. Existing-parcel mode searches by map/lot, address, or owner within the capture’s town. Create mode prefills map/lot and address from the submitted payload and accepts an optional owner. Success replaces the cached detail, invalidates capture lists, removes the panel, and shows the parcel event; accept becomes available because the capture is now in_review.

  • No schema or migration change.
  • A reviewer can complete the M2 path: login → resolve parcel → accept or return → audit trail.
  • Parcel creation currently exists only through resolution. Admin create/edit/import remains future work and should reuse the core creation rules.
  • Rematching, parcel deletion, and parcel merge are not supported.
  • Parcel search is bounded at 50 results until parcel/admin paging work.
  • SameSite=Lax plus the same-origin check protect the cookie-authenticated write; CSRF tokens remain a hardening item.