Skip to content

refactor(ogc): clarify module boundaries - #346

Merged
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:refactor/ogc-module-boundaries
Aug 2, 2026
Merged

refactor(ogc): clarify module boundaries#346
thodson-usgs merged 1 commit into
DOI-USGS:mainfrom
thodson-usgs:refactor/ogc-module-boundaries

Conversation

@thodson-usgs

Copy link
Copy Markdown
Collaborator

Summary

Structural refactoring of the OGC chunking module to clarify responsibilities and reduce coupling. No behavioral changes — all existing tests pass (one test updated to reflect the live-view simplification in item 3).

Includes the perf commit from #345 as the base.

Changes

1. Extract combining.py from planning.py (item 2)

Moves response/frame recombination helpers (_combine_chunk_frames, _combine_chunk_responses, _merge_response, _lowest_remaining, _safe_elapsed, _QUOTA_HEADER) into a dedicated combining.py. planning.py re-exports them for backwards compatibility.

Rationale: planning.py was conflating "what to split" with "how to reassemble" — two concerns with different reasons to change.

2. Move _Fetch/_Finalize/_passthrough_result into chunking.py (item 3)

These type aliases define ChunkedCall's contract, not anything about interruptions. They lived in interruptions.py only to break a circular import. Now they're in chunking.py where they belong.

3. Simplify ChunkInterrupted by dropping snapshot copies (item 5)

ChunkInterrupted.__init__ used to .copy() the partial frame at raise time so exc.partial_frame was a frozen snapshot separate from exc.call.partial_frame (the live view). The distinction was subtle and unlikely to be used by callers (the primary pattern is exc.call.resume()), and cost a full-frame copy proportional to completed data.

Now partial_frame and partial_response are properties that delegate to self.call — same as the live view, no memory copy. Pickle still works (snapshots at serialize time).

4. Unify error classification into shared _classify_transient helper (item 6)

_classify_chunk_error (chain-walk) and _retryable (top-level only) shared ~80% of their logic. Created a shared _classify_transient(exc) that classifies a single exception, so adding a new transient type only needs one update.

Deferred to follow-up PRs

  • Extract gather_paginated primitive — unifying ChunkedCall._run and wateruse._fan_out (invasive; needs careful testing of the retry/interruption model)
  • Split engine.py — separating request construction, pagination, and argument normalization (~750-line module with 3 concerns)

thodson-usgs added a commit to thodson-usgs/dataretrieval-python that referenced this pull request Jul 23, 2026
…tate

Revert the live-view change (item 3 of DOI-USGS#346): restore exc.partial_frame /
exc.partial_response as raise-time snapshots rather than properties that
delegate to exc.call.

Snapshot is the better contract for an exception — a record of the failure
moment, not a live handle:

- In a resume loop each interruption stays a faithful record of what it saw.
  Live-view aliased every exception to the one shared call, so after a second
  failure exc1.partial_frame and exc2.partial_frame returned the same (later)
  state.
- After a successful resume, live-view's .partial_frame returned the COMPLETE
  result — a field named "partial" that no longer was.
- Exception payloads shouldn't mutate after you catch them (cf.
  CalledProcessError.output).

Removing the delegation also drops the properties and the _pickled_* /
__getstate__ snapshot machinery it required: partial_frame/partial_response
are plain instance attributes again, pickled by the base __getstate__
(net -21 lines in interruptions.py).

No behavior change versus released main — this PR is unmerged, so live-view
never shipped. DOI-USGS#346 is now a true no-behavioral-change refactor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extract response and frame recombination into combining.py and colocate the private fetch/finalize contracts with ChunkedCall.

Centralize transient classification while preserving retry, resumability, exception snapshot, deduplication, nested GeoJSON, and response metadata contracts. Add regression coverage for those behaviors.

Align Ruff 0.16.1 across CI, pre-commit, and test metadata, and apply its Markdown code-fence formatting.
@thodson-usgs
thodson-usgs force-pushed the refactor/ogc-module-boundaries branch from 6101a34 to f8e4efd Compare August 2, 2026 13:00
@thodson-usgs
thodson-usgs marked this pull request as ready for review August 2, 2026 13:11
@thodson-usgs
thodson-usgs merged commit 09b5665 into DOI-USGS:main Aug 2, 2026
9 checks passed
@thodson-usgs
thodson-usgs deleted the refactor/ogc-module-boundaries branch August 2, 2026 13:12
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