Issue Importance: HIGH (P1)
Summary
An audit of data ingestion pipelines, Vertex AI Gemini pipeline, clustering scripts, and unit tests identified bugs affecting ingestion stability, error handling, taxonomy alignment, and test reliability.
Sub-Issues & Sub-Task Importance Ratings
- [CRITICAL - P0] Missing Staging Deduplication in MERGE Scripts:
db/merge_ingest.bq.sql: Staging queries in MERGE scripts lack QUALIFY ROW_NUMBER() OVER (PARTITION BY ...) deduplication, triggering BigQuery MERGE Error 400 when staging duplicate rows.
- Fix: Add
QUALIFY ROW_NUMBER() OVER (...) = 1 windowing to staging SELECT queries.
- [HIGH - P1] Unhandled 5xx HTTP Errors in Ingestion:
upload_over_to_bigquery.py (line 98): Retries HTTP 429 rate-limiting, but hits a break block on any 5xx server error (502/503), aborting execution without retrying.
- Fix: Include 5xx error codes in the retry loop.
- [HIGH - P1] Hardcoded Issue Count Mismatch:
bigquery_issue_scoring.py: Defines EXPECTED_ISSUE_COUNT = 7, but the taxonomy in db/seed.bq.sql and db/issue_anchors.json now has 9 issues, causing pipeline checks to fail.
- Fix: Update
EXPECTED_ISSUE_COUNT = 9.
- [MEDIUM - P2] TOCTOU File Unlink Race Condition:
big_query_to_data.py (line 182): Executes temporary_path.unlink() in a finally block after if temporary_path.exists():, causing FileNotFoundError if unlinked concurrently in Python 3.13.
- Fix: Pass
missing_ok=True: temporary_path.unlink(missing_ok=True).
- [MEDIUM - P2] Test Argument Misalignment:
tests/test_summary_creation_pipeline.py: Test passes PosixPath into min_confidence positional argument due to signature mismatch, failing JSON manifest serialization tests.
- Fix: Align function call arguments in test.
Affected Files
db/merge_ingest.bq.sql
src/mk_tracking/download_knesset_data/upload_over_to_bigquery.py
src/mk_tracking/bigquery_issue_scoring.py
big_query_to_data.py
tests/test_summary_creation_pipeline.py
Issue Importance: HIGH (P1)
Summary
An audit of data ingestion pipelines, Vertex AI Gemini pipeline, clustering scripts, and unit tests identified bugs affecting ingestion stability, error handling, taxonomy alignment, and test reliability.
Sub-Issues & Sub-Task Importance Ratings
db/merge_ingest.bq.sql: Staging queries in MERGE scripts lackQUALIFY ROW_NUMBER() OVER (PARTITION BY ...)deduplication, triggering BigQuery MERGE Error 400 when staging duplicate rows.QUALIFY ROW_NUMBER() OVER (...) = 1windowing to staging SELECT queries.upload_over_to_bigquery.py(line 98): Retries HTTP 429 rate-limiting, but hits abreakblock on any 5xx server error (502/503), aborting execution without retrying.bigquery_issue_scoring.py: DefinesEXPECTED_ISSUE_COUNT = 7, but the taxonomy indb/seed.bq.sqlanddb/issue_anchors.jsonnow has 9 issues, causing pipeline checks to fail.EXPECTED_ISSUE_COUNT = 9.big_query_to_data.py(line 182): Executestemporary_path.unlink()in afinallyblock afterif temporary_path.exists():, causingFileNotFoundErrorif unlinked concurrently in Python 3.13.missing_ok=True:temporary_path.unlink(missing_ok=True).tests/test_summary_creation_pipeline.py: Test passesPosixPathintomin_confidencepositional argument due to signature mismatch, failing JSON manifest serialization tests.Affected Files
db/merge_ingest.bq.sqlsrc/mk_tracking/download_knesset_data/upload_over_to_bigquery.pysrc/mk_tracking/bigquery_issue_scoring.pybig_query_to_data.pytests/test_summary_creation_pipeline.py