Skip to content

Stage 3 — Swap _append_metadata to the lookup enricher #24

Closed

Description

@Polichinel

Stage 3 — Swap _append_metadata to the lookup enricher

Part of the FAO global delivery plan — umbrella: #20. Hard-gated on Stage 2 (#23): zero unexplained differences. This is the ONLY behavioral code change in the entire delivery plan.

Why this exists

After Stages 0–2, the lookup enricher is built, tested, and characterized against real production output. This stage makes it live: _append_metadata() (views_postprocessing/unfao/managers/unfao.py:140-163) stops calling the runtime mapper and calls the enricher. Everything upstream (_read) and downstream (_validate, _save) is untouched — the validation gate (unfao.py:188-221) keeps guarding exactly as before, and because the enricher surfaces unknown gids as nulls (pinned by a Stage-1 test), the fail-loud guarantee survives the swap.

Spec

  1. The swap — _append_metadata uses the Stage-1 enricher. The mapper import (get_default_mapper, unfao.py:19,41) goes away from the manager; with it goes the import-time loading of 774 MB of shapefiles (register C-02's trigger in this code path).
  2. mapping.py stays in the repo, inert. Not deleted, not selectable by config — one live truth (umbrella: deletion is a separate decision after one verified production cycle).
  3. Delete the dead commented-out config blocks unfao.py:80-107 (two alternative AppwriteConfig blocks). This is D-09's only "do now" exception: they are a mis-uncomment hazard during exactly this kind of high-stakes week, and removing comments is zero-risk.
  4. Re-run africa_me_legacy on the production machine — same procedure as Stage 0.

Verification (definition of done)

  • Full test suite green (the boundary-contract tests in tests/test_integration.py now exercise the enricher path)
  • Production africa_me run green end to end
  • Output schema (columns, dtypes, index) identical to the Stage-0 baseline_schema.md — byte-for-byte on the schema, values differing only per the Stage-2 explained classes
  • Runtime and memory recorded and compared to the Stage-0 numbers (expect enrichment to collapse from minutes/hours to seconds)
  • Revert path documented below, verified to be a single commit
  • Umbrella [UMBRELLA] FAO global delivery: lookup-based enrichment (ADR-011) + global coverage #20 updated — this unblocks Stage 4 (views-models, #LINK_G)

Revert path

This change must land as one commit touching only unfao.py (method body + dead-block deletion) so that git revert <sha> restores the mapper path instantly. If anything looks wrong in the verification run, revert first, diagnose second.

Explicitly NOT in this issue

  • No region change (that is Stage 4, views-models)
  • No deletion of mapping.py, shapefiles, or geopandas from dependencies (post-cycle decision)
  • No store/Appwrite changes, no multi-store DeliveryProfile (register C-33, deferred per D-09)
  • No fixes to the pipeline-core read path (C-26..C-29, deferred)

Activity

  1. Polichinel commented on Jun 26, 2026

    @Polichinel
    CollaboratorAuthor

    Smoke-test result — enrichment verified (with one benign caveat)

    Ran the africa_me_legacy smoke test from views-models (postprocessors/un_fao). Because the full delivery is blocked on forecast-path config (below), I verified the #24 enrichment in isolation via a historical-only path (_read_historical_data → _append_metadata, no forecast, no upload):

    • GaulLookupEnricher loaded 64742 cells from gaul_lookup.parquet (version=land_gaul@f74d3b2b).
    • Datafactory fetched africa_me_legacy actuals: 5,729,070 rows (13,110 cells × 437 months).
    • GAUL metadata joined correctly → country_iso_a3, admin0/1/2_gaul*, coords. Spot-check correct (ZAF → Western Cape → South Africa → Overberg). Exit 0.

    ✅ The geopandas-mapper → GaulLookupEnricher swap produces correct output.

    One benign coverage caveat

    2,185 rows = exactly 5 cells have no GAUL-lookup match (enricher warns "will fail validation"). Mapped to coords they are remote islands / offshore ocean:
    62356 = Marion Island / Prince Edward Is. (−46.75, +37.75); the other 4 are offshore Madagascar/Namibia. These are the "land cells GAUL doesn't cover" (cf. #127's 82-globally note). Not an enrichment bug — an artifact of the old africa_me_legacy region. It self-resolves under land_gaul (that region excludes uncovered cells upstream). A full africa_me_legacy delivery would fail completeness validation on these 5 until they're excluded — please confirm the un_fao validation excludes GAUL-uncovered cells.

    Forecast-path findings (NOT #24 — found en route)

    1. APPWRITE_PROD_FORECASTS_COLLECTION_ID='forecasts_metadata' is wrong — that collection doesn't exist in the live Appwrite. The README value is not canonical; please correct it.
    2. The forecast download is ensemble-name-filtered ({category: forecast, name: <ensemble>}); the configured ensemble (rusty_bucket) produces no forecast, so the delivery's forecast half can't run until a real-forecast ensemble is referenced or one is delivered.
    3. Prereq gap: the un_fao postprocessor dir was missing 7 required scaffold dirs (artifacts, notebooks, reports, data/{generated,processed,raw}) — PostprocessorPathManager fails without them. Created on the views-models side.

    Recommendation

    Closeable as enrichment-verified, provided the validation excludes the GAUL-uncovered cells (cleanest under land_gaul, views-models#127). Suggest a fail-loud startup check for credentials + collection existence, and a dry-run/skip-upload flag (there's none today). Full evidence in views-models reports/un_fao_delivery_{prerun,postrun}_postmortem.md.

  2. Polichinel commented on Jun 26, 2026

    @Polichinel
    CollaboratorAuthor

    Done and verified. The _append_metadata swap to GaulLookupEnricher is live on development; the un_fao africa_me_legacy smoke test (post-run postmortem, 2026-06-26) confirmed correct enrichment of 5.7M real actuals (64,742 cells, sample assignments correct). One benign coverage caveat: 5 sub-Antarctic ocean cells have no GAUL match — these are the GAUL-uncovered cells excluded by construction under land_gaul (S4/C-30), not an enrichment bug. Closing — this unblocks views-models#127 (the land_gaul go-global flip).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions