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
| Where | What "area" means | Cardinality |
|---|---|---|
packages/esg-inspection-template/src/index.ts · apps/esg-field/data/inspection-schema.ts | the source form's free-text inspection-area field, while the checklist itself is typed as Section | 1 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 section | 8 |
apps/esg-field/lib/store/events.ts · areaId | usually a form-section id; investigation observations also mint an arbitrary id into the same field | open string |
apps/esg-field/data/sites.ts · app/lib/sitePlans.ts | a place, named SiteLocation on device and Zone in the console | 10–15 per registered site |
| the source ONxpress fixture | free 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·areasCleanuses"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/projectsand/projects/[id]despite incompatible meanings.- The Lakeshore registers do not agree:
app/lib/sitePlans.tshas 15 zones, including separatez-101throughz-105;apps/esg-field/data/sites.tshas 10 locations and omits those five ids.areasCleansays12/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-affirmationmethod. The current screen requires all 34 items to be answered by hand. - The append is one
AreaInspectedevent at inspection × section grain. Itsexceptionspreserve 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
useAreaStateand the report fold key maps only byareaId.
apps/esg-field/screens/capture/CaptureFlow.tsx — standalone NCR capture:
- Step 1 asks for site and category (
CATEGORIESisSECTIONSminusgeneral). RaiseNcrInput.areaIdis 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 anoriginand host site fallback, no raise-from-walk path rendersCaptureFlow; 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
- 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.
- The place grain is missing. Item exceptions identify which regulatory check failed, but not where. "Erosion deficient" plus
ero-2still does not say which bank or control installation was observed. - 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.
- Physical coverage is unprovable.
9 of 9 sections recordedsays 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. - The location register is disconnected.
data/sites.tsis re-exported bydata/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 keyslocationIdorassetId.
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 ────────┘
- 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. CorridorkmAlongcan inform order only after ids are explicitly joined to the corridor geometry; the currentSiteLocationrows do not themselves containkmAlong. GPS may suggest a nearby location but must not assert one. - 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.
- Site-wide checks. Present once in a deliberate stage. They cannot disappear merely because no physical location claimed them.
- 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.
- 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.
- Off-route capture stays. Standalone capture may record GPS and an explicit unplaced state. It must not fabricate a register id from proximity.
- 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_VERSIONis 1 androwToEventtrusts 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 inuseAreaState,ReviewInspectionand both report folds. AreaInspected.exceptionsstores departures from a section verdict; it cannot losslessly represent multiple independently answered location/check rows.- The device-local vocabulary and
@esg/events-inspectionalready 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 generation | Projection rule |
|---|---|
legacy AreaInspected without location binding | preserve current site/section semantics and current report output; show location coverage as unavailable |
| new location-bound check responses | key by location + section + check; compute physical coverage and canonical item marks under the approved aggregation policy |
| mixed stream during an interrupted upgrade | keep 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
| Today | Proposed for a registered site |
|---|---|
9 of 9 sections recorded | locations covered/not reached and required check occurrences answered/outstanding |
| section commits after all 34 form items are answered site-wide | location completes only when its governed applicable checks are answered |
| no physical coverage state | location coverage is explicit; N/A remains a check verdict |
| signing is section-completeness driven | signing requires physical coverage plus a complete canonical per-item projection |
5. Console changes that follow
- Split
areasClean. Replace it with typed, separately labelled fixture fields such aslocationsCoveredandchecksClean; do not mechanically turn"5/8"into either one without a source. - Reconcile Lakeshore. Choose and version an authoritative register; preserve aliases/mapping if existing records already reference either id set.
- Make
/inspectionsan 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. - Persist before plotting claims.
app/lib/sitePlans.tscontains 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. - 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 slice | Why it can stand alone |
|---|---|---|
| 1 | Correct terminology and split misleading areasClean fixtures/labels; document unknown denominators | Removes a present correctness defect without changing stored events |
| 2 | Reconcile/version the three existing registers and add validation, without changing the walk | Makes fixture drift fail visibly; no consumer is forced to adopt it |
| 3 | Define and approve versioned check-level applicability for one pilot registered site, including siteWide and completeness validation | Produces governed data and tests; does not suppress checks in the live walk |
| 4 | Add the location-bound event contract, runtime decoding, sync serialization and dual-read projection behind tests; legacy rendering remains the default | The storage/report seam is backward-compatible and useful before navigation changes |
| 5 | Enable 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 path | One site works end to end without blocking sites or developers lacking registers |
| 6 | Extend the vertical slice one governed site at a time | Each site addition is data plus validation and can ship independently |
| 7 | Add console ingestion/read views for location-bound records while retaining legacy section-only rendering | Old and new records remain readable; no plan is fabricated |
| 8 | Add a location appendix/plan visualization only after golden report and aggregation tests pass | Presentation 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-*carrieslocationIdorassetId. Some inspection payloads carry GPS/geo context andlocationLabel; 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.bindsis 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.
CaptureFlowhas origin-shaped props but is rendered from the app shell, not fromTaskFlow. - 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.
Related
- 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 structureapps/esg-field/screens/inspect/TaskFlow.tsx— the walk as builtapps/esg-field/screens/capture/CaptureFlow.tsx— standalone capture as builtapps/esg-field/lib/store/events.ts·apps/esg-field/lib/report/html.ts— local event shape and foldapps/esg-field/data/sites.ts·app/lib/sitePlans.ts— the two registerspackages/esg-events-inspection/src/index.ts— the canonical inspection vocabularypackages/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
areasCleandenominators, 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.