Cogneris
Environmental Compliance & Inspection

Intent · Every environmental obligation current and evidenced — zero reportable exceedances at Woodbine (UTS).

Operating tolerance: issues closed in ≤ 5 days · no repeat findings · every permit condition met.

← Documentsdocs/INSPECTION-AREA-FIRST-proposal.md3,193 words

Inspections should be walked area by area, not category by category

What this is. A review of the inspection process as it is actually built — in apps/esg-field (the RN field app) and in app/ (the console) — and a recommendation for restructuring it around the place the inspector is standing in rather than the section of the form.

Status. Written 2026-08-04 by Claude Opus 5 (Claude Code), reviewed and revised 2026-08-05 by Codex (codex-cli), from a code read of feat/rn-app-parity.

Slices 1 to 7 of §6 were implemented on 2026-08-05 by Claude Opus 5 (Claude Code, session d44cfa8b) — see WORKLIST E16 for exactly what landed and what was verified. The location-bound events, the dual-read fold and the area-by-area walk all exist; the walk is live for Eglinton and every other site still takes the untouched section walk.

Slice 8 is NOT done, deliberately. The report cannot print an area-by-area record: ReportArea's status vocabulary has no way to say UNANSWERED, so printing the form would mean back-filling a tick nobody gave or inventing a section verdict the form has no field for. makeReport refuses for such a record rather than rendering an empty form. §4.4 is therefore implemented as the fold's aggregation rule but NOT yet as printed output.


1. The finding: "area" means three different things in this codebase

WhereWhat "area" meansCardinality
packages/esg-inspection-template/src/index.ts · apps/esg-field/data/inspection-schema.tsthe source form's free-text inspection-area field, while the checklist itself is typed as Section1 string plus 9 sections (8 inspection bands + general)
packages/esg-events-inspection/src/index.ts · AreaId"one of the 8 inspection areas of the tri-state form" — a form section8
apps/esg-field/lib/store/events.ts · areaIdusually a form-section id; investigation observations also mint an arbitrary id into the same fieldopen string
apps/esg-field/data/sites.ts · app/lib/sitePlans.tsa place, named SiteLocation on device and Zone in the console10–15 per registered site
the source ONxpress fixturefree text: "Area(s) of inspection (if applicable)"1 string

The collision is not cosmetic. It is already producing incomparable fixture numbers on the console:

  • app/lib/projects.ts · areasClean uses "6/10", "7/10" and "12/15" for the three plan-backed projects, matching place counts, but "5/8" and "7/8" for Woodbine and Don Yard, matching the eight inspection bands. Scarborough is "6/6" without a plan or a six-band template in this repo, so its denominator cannot be established from code. One field is rendered under one label on /projects and /projects/[id] despite incompatible meanings.
  • The Lakeshore registers do not agree: app/lib/sitePlans.ts has 15 zones, including separate z-101 through z-105; apps/esg-field/data/sites.ts has 10 locations and omits those five ids. areasClean says 12/15. The device file's claim that the ids match the console is false for this site.

So before any UX change: "area" must be reserved for the place when speaking to an inspector, and the form grouping must be called a section or category. Published event names cannot simply be renamed; adapters and new types must make the distinction explicit without reinterpreting old records.


2. What the walk does today

apps/esg-field/screens/inspect/TaskFlow.tsx — the inspection walk:

  • Renders SECTIONS.map(...) — a flat list of 9 form sections, one card each (TaskFlow.tsx:1144).
  • Progress is done of SECTIONS.length sections recorded (TaskFlow.tsx:1133).
  • A section can commit only when every item in it has an answer (TaskFlow.tsx:1156–1160, 1322). Spill has 8 items, Waste 7 and Erosion 6; the whole template has 34, not 41.
  • Whole-section attestation is absent from this screen, despite the local event type retaining a section-affirmation method. The current screen requires all 34 items to be answered by hand.
  • The append is one AreaInspected event at inspection × section grain. Its exceptions preserve item-level fail/N/A answers; omitted items inherit the section pass in the report fold. Neither the section event nor its item exceptions identify a physical location.
  • Later events for the same section supersede the earlier projection because useAreaState and the report fold key maps only by areaId.

apps/esg-field/screens/capture/CaptureFlow.tsx — standalone NCR capture:

  • Step 1 asks for site and category (CATEGORIES is SECTIONS minus general).
  • RaiseNcrInput.areaId is the category id, not a place (CaptureFlow.tsx:147).
  • The visible site and category both start blank (CaptureFlow.tsx:132–133). Although the component accepts an origin and host site fallback, no raise-from-walk path renders CaptureFlow; the only live render is from the app shell. The real defect is therefore stronger than a duplicate question: inline capture from a walk is not wired at all.

app/inspections/page.tsx — the console capture mirror groups records through byCat and uses the same category-shaped capture fixtures. It is not a persisted inspection read surface.

apps/esg-field/lib/report/html.ts — the device report fold keys AreaInspected, issues and photos by areaId, then emits model.areas. The canonical pipeline in lib/report/inspectionIR.ts maps those results back onto the eight ordered form sections and their individual rows. The printed record is section-shaped, as the pinned ONxpress fixture requires.


3. Why category-first is the wrong iteration order

  1. It does not match the body. An inspector walks a route once. Category-first asks them either to revisit places for each section or to remember multiple section buffers while moving. The code records no physical-place coverage.
  2. The place grain is missing. Item exceptions identify which regulatory check failed, but not where. "Erosion deficient" plus ero-2 still does not say which bank or control installation was observed.
  3. N/A is ambiguous. An item may be inapplicable at one place and required at another. A single site-level answer cannot express that distinction.
  4. Physical coverage is unprovable. 9 of 9 sections recorded says nothing about whether the inspector reached Taylor-Massey Creek. A location-first walk can represent covered and not reached separately — but only for a site with a governed location register.
  5. The location register is disconnected. data/sites.ts is re-exported by data/index.ts, but no screen imports its values or lookup functions. The device event vocabulary and the published inspection event vocabulary carry GPS/geo context in some payloads, but neither carries the register keys locationId or assetId.

4. The recommendation

Make a location-bound item response addressable by (locationId, sectionId, checkId), not merely (locationId, checkId). The template owns section and check identity; the site register owns place and asset identity. Keeping sectionId explicit avoids assuming check ids are globally unique forever and matches the canonical CheckRef shape.

This is not a request to mutate old AreaInspected events or change their meaning. It requires an additive location-bound event shape and a projection that understands both generations.

4.1 Applicability must be governed data, not inferred from prose

SiteLocation.binds in apps/esg-field/data/sites.ts is useful display copy:

z-eg-msf        "air quality · fugitive dust"
z-eg-humber     "watercourse · dewatering discharge"
z-ol-parliament "archaeology Stage 3–4"
z-yard          "skips · oil store · wash-down"

It is not a compliance rule and cannot safely generate a checklist. Adding only sections: SectionId[] is also too coarse: it repeats every item in a section at every bound location, and a missed or mistaken section binding can silently remove a required check from the walk.

The governed shape must be versioned against both the site register and template and bind check ids, with an explicit home for checks that apply site-wide:

export type ApplicabilityMap = {
  readonly siteRegisterVersion: string;
  readonly templateVersion: string;
  readonly locations: Readonly<Record<LocationId, readonly CheckRef[]>>;
  readonly siteWide: readonly CheckRef[];
};

Validation is a release gate, not UI polish:

  • every required template check appears in at least one location or in siteWide;
  • every referenced location, section and check exists in the pinned versions;
  • deliberate multi-location checks are allowed and visible, not deduplicated;
  • removing the last binding for a required check fails validation;
  • applicability and N/A policy are approved domain data, not keywords guessed from binds.

Without those rules, location-first can produce a cleaner-looking but legally incomplete inspection.

4.2 The walk, restructured — with a fallback

registered site ─▶ route (locations) ─▶ location checks ─▶ review ─▶ sign
unregistered site ────────────────────▶ legacy section walk ────────┘
  1. Registered-site route. One card per location: label, display binds, answered/required count and covered/not-reached status. The register order is the default route. Corridor kmAlong can inform order only after ids are explicitly joined to the corridor geometry; the current SiteLocation rows do not themselves contain kmAlong. GPS may suggest a nearby location but must not assert one.
  2. At a location. Show the check-level applicability set. Record a tri-state answer at that location. A location can be not reached with a reason; that is coverage, not N/A. N/A remains an item verdict and must obey the template's policy.
  3. Site-wide checks. Present once in a deliberate stage. They cannot disappear merely because no physical location claimed them.
  4. No-register fallback. Three of the six projects — Woodbine, Don Yard and Scarborough — have no entry in either location register. They retain the current section-first walk until a governed register and applicability map exist. Location-first must not invent zones or block an inspection.
  5. Inline NCR capture. A non-pass can open capture pre-bound to inspection, site, location, section and item, with assets at that location offered but never silently selected. Return to the same check after raising.
  6. Off-route capture stays. Standalone capture may record GPS and an explicit unplaced state. It must not fabricate a register id from proximity.
  7. Review has both views. Location grouping proves the route; section grouping previews the legal form.

4.3 Append-only storage and old inspections

The SQLite log can physically store additive JSON payload fields, but that alone does not make the change safe:

  • SCHEMA_VERSION is 1 and rowToEvent trusts stored JSON after validating only the event type and schema number. Compile-time optional fields are not runtime migration or validation.
  • Current folds use Map<areaId, ...> and latest-event-wins semantics. Writing the same section once per location would overwrite all but the last location in useAreaState, ReviewInspection and both report folds.
  • AreaInspected.exceptions stores departures from a section verdict; it cannot losslessly represent multiple independently answered location/check rows.
  • The device-local vocabulary and @esg/events-inspection already differ. A change must update sync/ingest adapters and contract tests, not only a screen type.
  • Signed historical inspections must remain byte-for-byte interpretable. They must never be backfilled with guessed location ids.

Use an additive location-response event (or an equivalently explicit versioned payload) and a dual-read fold:

Stream generationProjection rule
legacy AreaInspected without location bindingpreserve current site/section semantics and current report output; show location coverage as unavailable
new location-bound check responseskey by location + section + check; compute physical coverage and canonical item marks under the approved aggregation policy
mixed stream during an interrupted upgradekeep generations distinct; do not let a new location response silently overwrite a legacy section attestation

Before rollout, fixture-test legacy, new and mixed streams through Task review, signature eligibility, HTML, canonical IR and sync serialization. An append-only store makes old facts durable; it does not make a changed fold automatically backward-compatible.

4.4 The signed report preserves the ONxpress form

The pinned acceptance fixture requires eight ordered section bands and one tri-state mark per checklist item. It does not define a section-level verdict. Therefore “worst location wins” at section level is insufficient and can destroy the legally required per-item result.

The canonical fold must aggregate each check across its applicable locations:

  • any deficient applicable observation makes that item deficient;
  • an item is satisfactory only when every required applicable occurrence is answered and none is deficient;
  • N/A is emitted only under the approved N/A policy; it is not a substitute for an unvisited location;
  • any missing required location/check occurrence leaves the item unanswered and blocks a complete signature/report claim.

The existing eight bands, item order, tri-state controls, evidence binding, inspection-details area string and signatures remain intact. A location index may be a separately identified appendix or companion view only after the golden structural and visual tests establish that it does not break the required form.

4.5 Completeness, restated honestly

TodayProposed for a registered site
9 of 9 sections recordedlocations covered/not reached and required check occurrences answered/outstanding
section commits after all 34 form items are answered site-widelocation completes only when its governed applicable checks are answered
no physical coverage statelocation coverage is explicit; N/A remains a check verdict
signing is section-completeness drivensigning requires physical coverage plus a complete canonical per-item projection

5. Console changes that follow

  1. Split areasClean. Replace it with typed, separately labelled fixture fields such as locationsCovered and checksClean; do not mechanically turn "5/8" into either one without a source.
  2. Reconcile Lakeshore. Choose and version an authoritative register; preserve aliases/mapping if existing records already reference either id set.
  3. Make /inspections an honest surface. Its current category-grouped capture demo is not an inspection record view. A new read view can group new records by location and preview the canonical section projection, while clearly labelling legacy records as having no location coverage.
  4. Persist before plotting claims. app/lib/sitePlans.ts contains seeded plotted records. atZone(plan.plotted, z.id) cannot become a real inspection count until sync/ingest and a console read model carry the new binding.
  5. Keep no-plan projects usable. The console must show section-only legacy coverage for Woodbine, Don Yard and Scarborough rather than an empty map that implies no inspection occurred.

6. Sequencing — cheapest safe releases, not a chain of prerequisite tickets

The original ordering treated optional fields as sufficient migration and put the location UI before a proven fold. That is backwards: the cheapest correct order proves semantics and compatibility before changing the walk.

The CDT rule in AGENTS.md forbids a PR whose tickets depend on unfinished work or become prerequisites for other developers. The rows below are release slices, not tickets to bundle into one PR. A CDT PR should select one vertical, backward-compatible slice that is useful and releasable by itself; if it needs an unfinished row, it is not ready for CDT selection.

#Independently releasable sliceWhy it can stand alone
1Correct terminology and split misleading areasClean fixtures/labels; document unknown denominatorsRemoves a present correctness defect without changing stored events
2Reconcile/version the three existing registers and add validation, without changing the walkMakes fixture drift fail visibly; no consumer is forced to adopt it
3Define and approve versioned check-level applicability for one pilot registered site, including siteWide and completeness validationProduces governed data and tests; does not suppress checks in the live walk
4Add the location-bound event contract, runtime decoding, sync serialization and dual-read projection behind tests; legacy rendering remains the defaultThe storage/report seam is backward-compatible and useful before navigation changes
5Enable a location-first vertical slice for the pilot site: route, responses, review, inline NCR binding and canonical report projection; all other sites use the legacy pathOne site works end to end without blocking sites or developers lacking registers
6Extend the vertical slice one governed site at a timeEach site addition is data plus validation and can ship independently
7Add console ingestion/read views for location-bound records while retaining legacy section-only renderingOld and new records remain readable; no plan is fabricated
8Add a location appendix/plan visualization only after golden report and aggregation tests passPresentation cannot precede the legal-output gate

Do not make a broad AreaId rename the first change. The published name, local event name, voice routing, reports and historical rows are coupled; terminology can improve at UI and adapter boundaries without a repository-wide foundational rename.


7. What is NOT true today, stated plainly

  • The location register is not consumed by a device screen. It is a seeded vocabulary re-exported from data/index.ts, not part of the working walk.
  • The two location registers do not fully match. Lakeshore is 15 console zones versus 10 device locations.
  • No event payload anywhere in the device-local store or the packages under packages/esg-events-* carries locationId or assetId. Some inspection payloads carry GPS/geo context and locationLabel; those are provenance, not foreign keys into the site register.
  • The device walk is not built on the published inspection vocabulary. It uses a separate local event union with different payload shapes.
  • (locationId, checkId) is not sufficient as stated. Section/template identity, applicability version and legacy semantics also matter.
  • SiteLocation.binds is not an applicability map. It is prose, and no code establishes that it covers every regulatory check.
  • Three of six projects have no location register or plan. A universal location-first launch would strand Woodbine, Don Yard and Scarborough.
  • Inline NCR capture from a walk is not wired. CaptureFlow has origin-shaped props but is rendered from the app shell, not from TaskFlow.
  • The current report cannot fold repeated section results by location. Its maps key by areaId, so later same-section events replace earlier ones.
  • A worst-section roll-up does not preserve the ONxpress requirement. The golden fixture requires a tri-state mark for each of 34 items in eight ordered bands.
  • A TypeScript optional field is not a migration. Runtime decoding, mixed streams, projections, sync and signed historical records require explicit compatibility tests.
  • The source form is section-organised, with only a free-text "Area(s) of inspection". Location-first is a deliberate capture change; the canonical signed output must remain section- and item-shaped.
  • The console inspection fixtures are not persisted inspection records. A plan view cannot claim real coverage until delivery and a read model exist.
  • None of this proposal is implemented.

  • WORKLIST.md — E16, E8, E7, E9, E11
  • SPATIAL-MODEL-purpose-and-views.md — the distinction between a register and its views
  • ../reference/Test_Aecon_Report_Structure.md — pinned signed-report structure
  • apps/esg-field/screens/inspect/TaskFlow.tsx — the walk as built
  • apps/esg-field/screens/capture/CaptureFlow.tsx — standalone capture as built
  • apps/esg-field/lib/store/events.ts · apps/esg-field/lib/report/html.ts — local event shape and fold
  • apps/esg-field/data/sites.ts · app/lib/sitePlans.ts — the two registers
  • packages/esg-events-inspection/src/index.ts — the canonical inspection vocabulary
  • packages/esg-inspection-template/src/index.ts — the 9-section, 34-item form

Review pass

Reviewed and revised 2026-08-05 by Codex (codex-cli).

  • Corrected the template total from 41 to 34 items and distinguished section commits from item exceptions.
  • Corrected the capture claim: the walk-to-capture path is absent, not merely repetitive.
  • Confirmed the mixed areasClean denominators, the 15-versus-10 Lakeshore drift and the unused device register.
  • Narrowed the event claim to register ids while acknowledging existing GPS/geo fields.
  • Replaced unsafe sections[] derivation with governed, versioned check-level applicability and validation.
  • Added a section-first fallback for the three projects with no location register.
  • Added explicit append-only, dual-read and mixed-stream migration requirements.
  • Replaced section-level worst-case roll-up with the per-item aggregation the ONxpress fixture requires.
  • Reordered delivery into independently releasable vertical slices consistent with the CDT PR rule.