Skip to content

fix(prefect): address roborev review on #286#287

Merged
jqnatividad merged 1 commit into
mainfrom
roborev-2160-fixes
May 16, 2026
Merged

fix(prefect): address roborev review on #286#287
jqnatividad merged 1 commit into
mainfrom
roborev-2160-fixes

Conversation

@jqnatividad

Copy link
Copy Markdown
Collaborator

Summary

Addresses roborev review #2160 on the just-merged PR #286 (commit 6cdb76f). Two of the three findings are fixed; the third is a documented false-positive skip.

Fixes

Medium — caching.py: contradictory comment blocks.
The pre-existing "Composed cache policies" comment block explained WHY we compose CacheKeyFnPolicy with TASK_SOURCE. The new block right below said we deliberately do NOT compose. Consolidated into a single block that explains both the empirical hazard with + TASK_SOURCE (Prefect 3.7's CompoundCachePolicy.compute_key dropping None contributions and collapsing to a TASK_SOURCE-only key) and the trade-off.

Medium — file_persistence.py: OOM risk on multi-GB files.
persist_file reads the full file into RAM before handing it to the Prefect block (Prefect 3's LocalFileSystem.write_path / read_path are bytes-in / bytes-out, no streaming variant), so on multi-GB CSV ingestions a single task completion could OOM the worker. Added DATAPUSHER_PLUS_MAX_PERSIST_FILE_MB (default 512 MiB). Files above the cap skip persistence with a debug log and fall back to pre-caching same-run-only behaviour (cross-run cache hits would surface a clear FileNotFoundError instead of OOM). Set env var to 0 to disable the cap entirely.

Skipped (false positive)

Low — analyze_task csv_path_key "double-write". Reviewer claimed analyze_task's ctx.tmp is the same file validate_task already persisted, so persisting under …:analyze:csv is wasted. This is incorrect: AnalysisStage transforms ctx.tmp via context.update_tmp(...) at three sites in stages/analysis.py (line 180 qsv_safenames_csv, line 526 qsv_slice_csv, line 563 qsv_applydp_csv). The analyze:csv slot holds genuinely different bytes from validate:csv and is needed so a cross-run cache hit on AnalyzeResult has a real key to restore from. Logged in the roborev close comment.

Tests

Two new cases in tests/test_file_persistence.py:

  • test_persist_skips_files_above_size_cap — file above cap returns None, never reaches the block.
  • test_persist_cap_zero_disables_size_gate — cap=0 disables the gate.

Verified in the dpp-test ckan-dev container: 62/62 unit tests pass (60 prior + 2 new).

Test plan

  • ci.yml (DataPusher+ Integration CI) — quick-dir matrix still green (the size cap is well above the test files; no behaviour change for normal-sized inputs).

🤖 Generated with Claude Code

Roborev #2160 raised three findings on PR #286 / commit 6cdb76f. Two
are addressed here; the third is a documented false-positive skip.

**Medium — caching.py: contradictory TASK_SOURCE-rationale comment
blocks (lines 157-171 vs 173-188).** The pre-existing "Composed cache
policies" block explained WHY we compose `CacheKeyFnPolicy` with
`TASK_SOURCE`. The new block immediately below said we deliberately
do NOT compose. Consolidated into a single block under
"Cache policies" that explains both the empirical hazard with
`+ TASK_SOURCE` and the trade-off (no auto-invalidation on task body
changes; 24h TTL bounds the staleness window).

**Medium — file_persistence.py OOM risk on multi-GB files.**
`persist_file` reads the full file into RAM before handing it to the
Prefect block API. Prefect 3's `LocalFileSystem.write_path` /
`read_path` are bytes-in / bytes-out (no streaming variant), so on a
multi-GB CSV ingestion a single task completion could OOM the worker.
Added `DATAPUSHER_PLUS_MAX_PERSIST_FILE_MB` (default 512 MiB); files
above the cap skip persistence with a debug log and fall back to the
pre-caching same-run-only behaviour (cross-run cache hits surface a
clear `FileNotFoundError` from the downstream stage rather than OOM).
Set the env var to `0` to disable the cap entirely. Two new tests
in `test_file_persistence.py` cover the cap-trips-and-skips path
and the cap=0-disabled-and-persists path.

**Low — analyze_task csv_path_key double-write (skipped, false
positive).** Reviewer claimed `analyze_task`'s `ctx.tmp` is the same
file `validate_task` already persisted, making the analyze-stage
persist a wasted duplicate. This is incorrect: `AnalysisStage`
transforms `ctx.tmp` via `context.update_tmp(...)` at three sites
in `stages/analysis.py` (lines 180 `qsv_safenames_csv`,
526 `qsv_slice_csv`, 563 `qsv_applydp_csv`). The analyze:csv slot
holds genuinely different bytes from validate:csv and is needed
so a cross-run cache hit on `AnalyzeResult` has a real key to
restore from. Logged this in the roborev close comment.

Verified in `dpp-test`: 62/62 pass (60 prior + 2 new size-cap tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jqnatividad jqnatividad merged commit 7e40b20 into main May 16, 2026
1 check passed
@jqnatividad jqnatividad deleted the roborev-2160-fixes branch May 16, 2026 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant