Skip to content

[Task] B3 — BAFU ingestion and LCIA reconciliation #59

Closed

Description

@DavidVFitzGerald

Delivery phase

Phase 2 — backend and real integration (B3)

Goal

Deliver one complete reproducible Airflow/PySpark BAFU ingestion and LCIA reconciliation implementation, including required private audit artifacts and a ready synthetic candidate, in one issue and one PR. Work uninterrupted across sessions with incremental commits; do not split the milestone.

Context and authority

Roadmap B3; PRD §4; specification §§1–5, 8–9.2 and 11; ADR0005 after approved merge (#55/PR #56). Read AGENTS.md, engineering role, current PRD/specification, shared B1 contracts and applicable ADRs. The maintainer has supplied three ZIPs in the primary checkout's ignored data/private/bafu-2026-v1/incoming/{xml,scores,schema}/. Raw schema/data govern their actual contents; none of docs/reference/ or archive folders is authorized by this task. Full-data import completeness is not assumed from archive arrival.

Requirements and constraints

Use isolated backend worktree/container resources and an explicit read-only input mount. Preserve original ZIP bytes/filenames, checksums and private provenance; no licensed contents, raw audit rows or production secrets enter Git/public CI/logs. All tooling/resolution/extraction runs in guarded containers. Preserve one uv workspace/lock honoring Airflow constraints; keep ETL out of API runtime. Airflow metadata/database/logs are separate from application data, UI private to localhost/SSH, and no Docker socket is exposed. Spark entry point is portable and reads bounded per-file data without collecting the entire corpus on the driver.

Acceptance criteria

  • AC1 — Inventory/hash the three supplied archives privately, inspect actual member formats/schema and record counts. Safe extraction rejects traversal/unexpected links/resource abuse, retains originals and source paths, and never asserts the approximate ~11,947 count as an oracle. Supply strict versioned Pydantic manifest/rule contracts with maintained release/license/date fields; do not guess source publication date or legal permission.
  • AC2 — Implement maintainer CLI prepare/run/report and one manually triggered idempotent Airflow DAG covering frozen revision/manifest registration, immutable raw archival, Spark parsing, staging, reconciliation, harmonization, readiness and candidate artifact production. Retries/repeated inputs do not silently mutate existing revisions. CLI run triggers/monitors the DAG; portable Spark jobs can also run directly for focused testing. None of these operations publishes data.
  • AC3 — Secure tag/attribute-based XML parsing disables DTD/entities/network, tolerates child order/boolean spelling/optional metadata, retains original attributes/children/text/exchange ordinal and isolates per-file errors. Preserve malformed numeric source text and all duplicate records in shared revision-scoped stg_bafu_* tables. Duplicate process IDs/unknown groups/nonfinite amounts produce deterministic critical gates.
  • AC4 — Classify outputGroup=0 as Reference, signed inputGroup=5 as Technosphere and inputGroup=4/outputGroup=4 as Ecosphere Input/Output; do not classify by amount sign. Exactly one validated reference output supplies process headers; multiple outputs are retained in staging but excluded/reported. Missing references emit staging ERROR and use approved mappings or explicitly isolated deterministic fallback with affected-cell warning; unresolved cases block candidate load.
  • AC5 — Stable versioned UUIDv5 flow identity honors release/type/compartment/unit meaning, ignores display name and sign, and isolates unresolved references. Aggregate exact amounts only by canonical process/flow/type in Spark or deterministic SQL, retain present-zero after cancellation, one provenance constituent per exchange and staged ERROR/resolved WARNING audit trail; incompatible units/meaning block rather than sum.
  • AC6 — Extract BAFU_2026 v1 by sheet name, forward-fill row-1 methods within E:AY and retain row-2 indicator units/source order/default IPCC2021 GWP100. Preserve original A:AY cell values/types and coordinates. Conservatively reconcile by verified name/geography/category/subcategory/unit candidate; never by row number/fuzzy guessed joins. Duplicate/ambiguous/unmatched/excluded rows remain staged and audited; XML-only processes remain visible with N/A scores.
  • AC7 — Each eligible process/indicator has valid/missing/unresolved_basis status; finite zero remains valid zero. Score conversion/aliases occur only through explicitly approved scoped rules with verified source/target quantity AND unit, exact direction/factor/evidence and original/converted amounts. Unverified bases produce N/A, not guessed factors. Confirm actual schema/source evidence before approving any supplied-data conversion.
  • AC8 — Generate all §5.8 reports even after failed import: run.json, validation_issues.csv, lcia_workbook_issues.csv, lcia_header_issues.csv, process_match_report.csv, score_basis_report.csv, excluded_processes.csv, aggregation_report.csv, release_manifest.json and summary.md. Full-original-row audit includes every flagged source row including resolved anomalies, stable original_A through original_AY columns, complete metadata/candidate IDs/basis evidence and deterministic UTF-8 CSV quoting. XML-only/header-only defects get their separate reports; no fabricated worksheet rows.
  • AC9 — Quality gates/count reconciliation mark a candidate ready only with valid references/identities/amounts/provenance and no unresolved critical issue. Produce checksummed promotion artifact with self-contained provenance, versions, rule hashes and reports; no required link depends exclusively on staging that remains local.
  • AC10 — Focused synthetic unit/Postgres/Spark/Airflow DAG/task integration tests cover critical scientific behavior, secure malformed XML isolation, exact duplicate aggregation, missing reference fallback/mapping, multi-output/unknown groups, workbook ambiguity/source order, quantity conversion direction and CSV full-row round-trip on both success and failure. No proprietary fixtures in public CI. Run a private input inventory/representative import against supplied archives and report actual results/blockers; full-data release validation remains R2 and is not a prerequisite to implementing safe synthetic behavior.
  • AC11 — Document exact prepare/run/report commands, private mounts, retained artifacts and rule-approval process; record schema findings, data anomalies and unresolved source questions, counts and hashes privately without exposing raw data in public issue/PR. Frozen-lock/Ruff/MyPy/targeted integration gates and independent QA pass at the delivered SHA.

Out of scope and follow-ups

B4 owns transfer/promotion, explicit publish and rollback. I1 owns real frontend connection. R1/R2 own production resources/deployment, licensing/source-date signoff and full private corpus release validation; successful synthetic or representative import is not full BAFU readiness. No silent conversion, interactive normalization, future cross-provider mapping, uploads or computed LCIA methods. Any unresolved required behavior remains within this issue unless the maintainer authorizes scope change.

Verification plan

Use B1 backend quality/frozen-lock/unit/Postgres targets and add documented make backend-test-etl and make backend-test-airflow (planned until implemented). Inside guarded isolated containers: uv lock --check, frozen ETL sync under the committed Airflow constraints, make backend-format-check backend-lint backend-typecheck backend-test-unit backend-test-integration backend-test-etl backend-test-airflow. ETL integration runs one miniature deterministic XML+workbook workload through portable Spark and the DAG, compares semantic counts/precision/provenance and validates audit CSV round-trip. Add container-backed make import accepting an explicit manifest; document prepare/run/report invocations and record the actual representative private run. Airflow UI/metadata isolation and no socket mount are inspected from resolved Compose configuration. Broader full corpus runs are opt-in/private and release-gated, not mandatory on each PR.

Dependencies and readiness

BLOCKED until B1 contracts/migrations and ADR0005 acceptance are delivered and container ETL dependencies resolve. Link B1 issue/PR after publication. B2 may run independently after B1; avoid simultaneous shared-lock edits. Supplied archive availability is confirmed by coordinator, but manifest metadata and conversion evidence remain explicit verification gates; unknown basis must safely yield N/A. B4 consumes this candidate/artifact interface. PM records READY only after actual dependency/container checks; do not claim imported full data from placement alone.

Published dependencies: B1 #57; sibling B2 #58; B4 #60 consumes this candidate.

Activity

  1. added
    task
    blocked
    on Nov 14, 2026
  2. DavidVFitzGerald commented on Nov 15, 2026

    @DavidVFitzGerald
    OwnerAuthor

    PM: READY — B3 / Phase 2

    B1 #57 / PR #61 is delivered at d3a23893faea5668cdf35bc34a3750f55193dea0 with independent exact-SHA QA PASS. I verified the final head, hosted backend-quality and frontend quality SUCCESS, and QA's combined API/Airflow/PySpark compatibility evidence under the official Airflow constraints. Accepted ADR0005 permits B3 implementation independently of sibling B2 completion. The B1 foundation, rootless tooling and single-lock dependency readiness gates are satisfied; actual Spark/Airflow runtime and ingestion evidence remain B3 deliverables.

    All #59 acceptance criteria remain unchanged and ready. Authority: PRD §4; specification §§1–5, 8–9.2 and 11; accepted ADR0005. Proceed in isolated /tmp/lca-diff-b3, branch feat/b3-ingestion, from the delivered B1 SHA. B2 and B3 may implement concurrently with coordinated ownership of root pyproject/uv.lock/Compose/Make/CI edits. Before opening the one B3 PR, integrate delivered B2 code as directed by the coordinator so its stacked base is feat/b2-read-api; retain one B3 issue/PR. Stacked development does not authorize any merge or publication.

    I confirmed all three original private ZIP files are present in their xml/scores/schema intake directories. Coordinator's read-only preliminary inventory reports 11,947 XML datasets, one workbook and three schema HTML documents, no XML parse/duplicate-dataset-ID failures and exactly one reference output per supplied process. These are attributed intake observations, not proven ingestion/reconciliation/readiness. Preserve original bytes/checksums and explicit read-only mounts; put extraction, provenance and full audit evidence in private storage only.

    Important scientific handoff: the source references include non-unit quantities. Neither matched labels nor agreeing units prove workbook quantity basis. Use only verified approved source/target quantity-and-unit rules; unverified scores must remain missing/unresolved_basis N/A. No guessed quantity multiplier, conversion direction, fuzzy/row-order match or claim of complete full-data validation is permitted. Safe synthetic behavior and the required representative private run can proceed with that conservative policy; license/date approval and full-data release remain R2 gates.

    Implement prepare/run/report, the portable bounded Spark path, private Airflow orchestration, staging/harmonization/reconciliation and every required §5.8 audit artifact including complete original flagged A:AY rows on failure and resolved anomalies. Introduce the planned B3 container targets with the component, keep tests focused on scientific/security/report invariants, and preserve frontend mocks/contracts. B4 #60 consumes B3 artifacts and B2 API visibility; I1 retains Phase 1/B2/B4 gates. Independent QA must verify the delivered B3 SHA. No production action is authorized.

  3. removed
    blocked
    on Nov 15, 2026
  4. DavidVFitzGerald commented on Nov 15, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Engineering: READY FOR QA

    Issue #59 / PR #72, branch feat/b3-ingestion, delivered SHA 9f8a0a5c40abc10d5b502a0d5df708f0d730bc75, isolated worktree /tmp/lca-diff-b3. Stacked base: QA-passed B2 c49aa58d905fef5767e552460673431da5c8a154 / PR #70. No authored frontend change, no merge to main and no production/publication operation.

    AC1–AC11 are implemented: bounded immutable intake and strict manifest/rules; actual Airflow/Spark prepare/run/report path; source-preserving staging and exact SQL NUMERIC/provenance; reference/group/exclusion gates; conservative workbook matching and approved basis rules; all ten private reports on success/failure; complete original A:AY resolved/failed audits; coherent checksummed candidate artifact; focused real integration/CI; operator/verification documentation. Final independent QA and hosted checks remain pending at this SHA.

    Validation evidence is in docs/engineering/b3-verification.md and docs/engineering/b3-ingestion.md. Guarded local project: COMPOSE_PROJECT_NAME=lca-diff-b3 FRONTEND_PORT=5191, read-only source mount. Separate destructive regression project: lca-diff-b3-checks, port variable 5192. All tools run in containers.

    • Frozen single workspace resolves 174 packages under official Airflow constraints; actual Airflow3.4/PySpark4.3/Java17 runtime works.
    • Combined formatter/Ruff passed 49 maintained Python files; strict MyPy passed 37 source files.
    • Foundation regression: 14 passed in 7.15s. Invented source-security and real Spark/Postgres golden/failed-audit checks: 2 passed in 23.58s, including resolved row override audit and reusable payload verification regressions.
    • Real CLI → Airflow DAG → Spark/Postgres/report/artifact synthetic test: 1 passed in 33.95s. The final Airflow task now calls the same full payload verifier. All four hosted checks passed at 63da158; final-SHA jobs remain required.
    • Combined lean API build passed with 53 packages and explicit absence assertions for Airflow/PySpark.

    The required representative private-input validation is complete. Its findings, source inventory, identifiers, counts, checksums and audit contents are retained locally and omitted from this public handoff. No provider rows or score payloads are committed or used in public CI. Full-data release validation remains R2.

    Next: independent QA at the delivered SHA, final hosted checks, then coordinator handoff in B1 → B2 → B3 merge order. Keep #59 open. Stop after B3; B4 operations are not started.

  5. DavidVFitzGerald commented on Nov 15, 2026

    @DavidVFitzGerald
    OwnerAuthor

    QA: PASS

    Reviewed final SHA: 9e8fcc2aedf6ac3f20bd9629946a8e56863f26db, PR #72, stacked on B2. Independent QA used an isolated rootless ETL/PostgreSQL/Airflow project. No application/tests/criteria were edited by QA; no merge, publication or B4 implementation occurred.

    • AC1 PASS: strict manifest/rule contracts and bounded safe archive extraction inspected and exercised. Required private intake/archive/schema evidence was independently verified; observations and identifiers remain private.
    • AC2 PASS: prepare/run/report implementation and manual retry-safe DAG inspected. The real maintainer CLI triggered and monitored the actual Airflow tasks through Spark extraction, candidate construction and final artifact validation. Repeated completed runs are reused without publication; interrupted final artifact metadata can be rebuilt safely.
    • AC3 PASS: secure XML parsing rejects unsafe DTD/entity input and excessive structure; original metadata/numeric text/ordinals remain staged. Malformed/unknown source conditions are gated, and duplicate exchange records remain retained.
    • AC4 PASS: synthetic signed technosphere, reference, environmental, missing/manual/fallback reference and multi-output cases pass. Reference/readiness gates and affected-cell warnings are present; classification never depends on amount sign.
    • AC5 PASS: deterministic versioned identities preserve type/compartment/unit/release meaning; exact PostgreSQL NUMERIC aggregation preserves cancellation to present zero and one provenance constituent per original exchange. No interactive normalization is introduced.
    • AC6 PASS: named-sheet OOXML extraction retains original numeric lexemes/types/coordinates and source indicator order. Matching is conservative; ambiguous/duplicate/unmatched rows are audited. Approved explicit mappings retain original-candidate/rule evidence rather than silently discarding the resolved anomaly.
    • AC7 PASS: synthetic approved conversion direction and exact factor application pass; unverified bases remain categorical N/A. No real conversion rule or source publication date was invented.
    • AC8 PASS: all required report contracts inspected; synthetic success/failure checks verify complete original A:AY CSV round-trip, resolved mapping evidence, exclusions and separate header/XML-only reporting. Required private representative audit evidence was independently verified without publishing provider content or processing metadata.
    • AC9 PASS: semantic readiness/provenance checks, repeatable-read revision-locked export and self-contained portable source references inspected/exercised. Every manifest-listed payload is verified by path, size, checksum and table row count. Corrupt payload reuse is rejected; final Airflow verification uses the same complete verifier.
    • AC10 PASS: frozen/static checks, 12 unit cases, 5 inherited database scenarios, one real Spark/PostgreSQL golden-and-failure scenario and one actual Airflow/CLI scenario pass. The Airflow case completed in 56.88 seconds. Required representative validation and retained artifacts were independently checked privately. This does not establish full-data or release readiness.
    • AC11 PASS: operator and verification documents cover the commands, private read-only mounts, approved-rule policy, artifact/retry behavior and remaining gates. Public documentation/handoff redaction was reviewed. Working tree is clean, no private artifacts are tracked, and all four final-head hosted checks pass.

    Commands executed in the isolated guarded ETL environment included:

    uv sync --frozen --all-packages
    uv lock --check
    make backend-format-check backend-lint backend-typecheck
    make backend-test-unit backend-test-integration backend-test-etl
    uv run --frozen --package lca-etl python scripts/wait_etl_services.py
    make backend-test-airflow

    Ruff checked 49 formatted files; strict MyPy checked 37 source files. Source intake is mounted read-only, capabilities are dropped, no-new-privileges is enabled, Airflow metadata is separate and its UI binds localhost. No Docker socket is mounted. The lean API build/dependency check and API parity checks pass in hosted CI.

    Two independently reproduced defects were fixed before handoff: a resolved explicit row mapping could be omitted from the full-original-row audit; completed-run reuse could accept missing/corrupt artifact payloads. Focused synthetic regression assertions cover the corrected behavior. No knowingly failing check was waived.

    Executable checks ran against code candidate 9f8a0a5; final 9e8fcc2 changes only public documentation redaction. Independent diffs confirm runtime, tests, dependencies, migrations, tooling and workflows are byte-identical. Unchanged local suites were not redundantly rerun for that documentation-only update. Diff whitespace checks pass.

    Final-head hosted checks: backend-quality, api-quality, etl-quality, frontend quality.

    Next action: maintainer review of stacked PRs #61 → #70 → #72, with explicit merge authorization. Stop after B3 as requested. B4 remains unimplemented; real frontend integration and production/licensing/full-release gates remain outstanding.

  6. DavidVFitzGerald commented on Nov 15, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator: READY FOR REVIEW — stopped after B3

    B3 issue #59 / PR #72 is delivered on feat/b3-ingestion at 9e8fcc2aedf6ac3f20bd9629946a8e56863f26db.

    Independent exact-SHA QA PASS verifies all eleven criteria. Final-head quality, backend-quality, api-quality and etl-quality checks are SUCCESS. The engineering checkout is clean. Detailed private evidence remains local; public evidence uses synthetic checks.

    Maintainer merge order: PR #61 (B1) → PR #70 (B2) → PR #72 (B3). These are stacked branches: after merging each predecessor, ensure the next PR targets main and completes any required updated checks before merging. No implementation PR has been merged by the coordinator.

    The maintainer requested a stop after the current B task. B3 implementation is complete and work stops here. B4 issue #60 remains open and unimplemented; frontend integration and production/full-release gates remain separate. Leave #59 open until approved merge and closure verification.

  7. DavidVFitzGerald commented on Nov 15, 2026

    @DavidVFitzGerald
    OwnerAuthor

    Coordinator: delivery to main verified

    The maintainer merged recovery PR #82 into main at 9b0ebbaf07130ed0a8e8c964a1aca4f2e30b53ac. Its delivered head cc69f1e030d5e439433f34dc59ce2c419cef9828 had independent QA PASS and all four required hosted checks passing.

    Verified that main contains the recovery commit and that API/shared/schema/ETL/runtime/test/lock/tooling/workflow files match independently QA-passed B3 9e8fcc2aedf6ac3f20bd9629946a8e56863f26db. Thus B2 #58, B3 #59 and recovery #81 are delivered and ready for closure. B1 #57 was already closed after its verified main merge.

    This closure does not claim real frontend integration, full-data release, production deployment or publication. The maintainer has now authorized resuming the remaining backend milestone B4 #60 in its own issue/PR and isolated worktree.

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

    task

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions