Skip to content

S4 — Lookup access hygiene: one read per run, no private-name coupling #152

Closed

Description

@Polichinel

Epic: #148 · Depends on S3 · Closes C-66, C-68

Background

The ADR-011 GAUL lookup (data/gaul_lookup.parquet, 888 KB, 64,742 rows) is read three times per contract run:

Site What it does Used by the contract path?
managers/unfao.py:98 self._enricher = GaulLookupEnricher() — eager, unconditional; reads the parquet into pandas at enrichment.py:48 No
managers/unfao.py:460 pq.read_table(_DEFAULT_LOOKUP) → wire_sink.deliver_run yes
managers/unfao.py:612 pq.read_table(_DEFAULT_LOOKUP) → historical.build_historical_table yes

So every run pays three reads of one artifact, one of them into a representation the delivery no longer uses. After S1 deletes _append_metadata, GaulLookupEnricher's only remaining consumer is scripts/build_gaul_lookup.py's tests and the enricher's own suite.

Separately, _DEFAULT_LOOKUP is a private name imported across module boundaries — defined enrichment.py:33, imported managers/unfao.py:18, used at :460 and :612. The leading underscore says "internal"; three modules depend on it. A refactor splitting enrichment.py (#89) is entitled to move or rename it and would break two live call sites silently.

Work

  • Remove self._enricher = GaulLookupEnricher() from __init__ (:98) — the contract path never uses the instance
  • Promote the lookup path to a declared public constant. unfao/product.py is the declared home for delivery declarations (its docstring: "Everything here is a declaration, never an inference") — the artifact a delivery depends on belongs there, not behind an underscore in the enricher
  • Read the table once per run and pass it to both consumers — deliver_run and build_historical_table already take lookup as a parameter (DIP, established by wire/sidecar.py:10-13), so this is threading one value, not a redesign
  • Leave GaulLookupEnricher itself in place — it is still the build/verification path's object and tests/test_enrichment.py (159 lines) covers it. Its retirement is S4 — enrichment.py: numpy/pyarrow keyed gather (drop pandas merge) #89's business.

Acceptance criteria

  • The lookup parquet is read once per delivery run — asserted by test (count reads, or assert the same object reaches both consumers)
  • No underscore-prefixed name is imported across a module boundary: grep -rn "import _\|import .*, _" views_postprocessing/ clean for this case
  • GaulLookupEnricher is not instantiated on the delivery path
  • tests/test_gaul_lookup_fidelity.py (18 tests) still green — it imports the lookup path and must follow the rename

Testing / validation

ruff check . · full suite green · byte-parity e2e green — the sidecar is built from this table, so a threading mistake would show up as changed bytes.

Activity

  1. added
    story
    implementation
    on Jul 31, 2026
  2. added a commit that references this issue on Jul 31, 2026
    5dc4443
  3. Polichinel commented on Jul 31, 2026

    @Polichinel
    CollaboratorAuthor

    Done in PR #162 (merged to development). Three reads per delivery → one; _DEFAULT_LOOKUP → public gaul_lookup.LOOKUP_PATH; the pandas enricher leaves the delivery path entirely. Register C-66 and C-68 closed.

    C-60 deliberately left open: version() still degrades to "unknown" silently — it was moved verbatim, because moving and changing behaviour in one commit is the discipline S5 depends on. Documented at its new home with a pointer to C-60's scope.

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

    implementationstory

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions