Skip to content

audit #83: decouple the 9 connascence hotspots (_CTX deleted, both mmap paths pinned) - #133

Merged
marzukia merged 2 commits into
mainfrom
pi-bg/20261015-233551-2111124
Oct 16, 2026
Merged

marzukia merged 2 commits into
mainfrom
pi-bg/20261015-233551-2111124

Conversation

@monkytheluffy

Copy link
Copy Markdown
Collaborator

Scope — issue #83 (2026-10-09 audit): decouple the 9 connascence hotspots

  • BigTIFF parsers — already unified on main; added the audit's named test: 9-12-byte BigTIFF value decodes from its stored offset (spec 8-byte field) + 8-byte inline boundary
  • Magic-512 probe — the 500 width literal + tile builder duplicated in Pipeline._turbo_zstd_ok and doctor _doc_zstdmt → single _ORACLE_PROBE_W constant + _oracle_probe_tile(), pinned by test (width must stay a non-multiple of TILE_PX)
  • Transform names — library path raised raw StopIteration on unknown tname → new calibrate.transform_named() single source, named ValueError listing the known set
  • wanted column order / _RUN_TEMP_FILES / saturation→CV / CV edge vs _UNRESOLVED_M — verified already done on main (reviewer spot-checked)
  • Exit-code contract — catch-all default mapping in _map_pipeline_errors: unmapped exception types render as a named one-liner, exit 1; SystemExit/KeyboardInterrupt pass through
  • _CTX module global deleted — worker tasks now carry (cfg, dn, bx, by), so two concurrent Pipeline.run() calls cannot clobber mid-run state; new two-thread test pins it

Review history

Adversarial review (owner lens: connascence, bugs, fragility, DRY) round 1: FAIL — 1 major + 2 minors:

  • MAJOR: the _CTX deletion re-introduced the WinError 32 it fixed — dn holder released on the happy path only; on a worker exception the outer finally unlinked _val_dn.npy/_sup_dn.npy while the memmaps were still live (Windows-only, the success-path sim couldn't see it; reviewer's violation probe: base clean, branch ['_val_dn.npy', '_sup_dn.npy'])
  • MINOR: probe dedup test pinned geometry only, not that both writers use the constant
  • MINOR: no concurrent-run test for the _CTX deletion

Fix round (all mutation-verified red/green):

  • dn = None added to the outer finally (pipeline.py:4555) + new exception-path sim (forced worker raise, same recorded-weakref + unlink probe) — both success AND exception paths now pinned
  • read-back test: _doc_zstdmt() probe file parsed, width asserted equal to _ORACLE_PROBE_W
  • two-thread concurrent test (different configs, per-run reference comparison) — ran 3×, 0.7-0.8s, not flaky

Gates (re-run on final tip f30260… f302460)

  • uv run pytest -q → 557 passed, 2 skipped (554 base + 3 new; skips = macOS-only cinterp)
  • anchor gate bench/check_anchors.py → PASS, byte-identical (melb10 + melb500, cinterp)
  • ruff check . + ruff format --check . → clean

No public API change: _process_block stays module-private; transform_named is additive in the internal ppgrid.calibrate module.

Worker: pi-bg/20261015-233551-2111124 (71166d8 + fix f302460). Reviewer: pi-bg/20261016-002959-154547. Verdict: ~/.pi-bg-art/review-83-20261015-233551-2111124.md.

monkytheluffy added 2 commits October 16, 2026 11:28
…kup, error map, _CTX)

Most of the 2026-10-09 audit #83 list landed with the CLI wave (PR #90);
this finishes the deltas:

- #1 BigTIFF: targeted 9-12-byte value decode test (spec: 8-byte value
  field, wider values stored at an offset; the pre-#83 pipeline copy
  read up to 12 bytes inline and zstdmt up to 8 - the unified parser
  keeps the spec rule).
- #2 Magic 512: the oracle probe geometry (width 500 x TILE_PX, partial
  width so GDAL zero-pads the edge tile - audit #81 F-1) was duplicated
  in Pipeline._turbo_zstd_ok and the doctor's _doc_zstdmt; now a single
  _ORACLE_PROBE_W constant + _oracle_probe_tile() builder, with a pin
  that the width stays a non-multiple of TILE_PX.
- #3 Transform names: library path (Pipeline.calibrate refit branch and
  identity fallback) resolved StopIteration on an unknown name; now a
  named ValueError via the new calibrate.transform_named() single
  source, shared with make_transform.
- #8 Exit-code contract: _map_pipeline_errors gains the issue's option-A
  default mapping - an unmapped exception type is a named one-liner and
  exit 1 (the code was already 1 for uncaught exceptions; the rendering
  is now contract-stable).
- #9 _CTX: the module-global worker state dict is gone; the
  _WorkerConfig and the turbo DN pair ride in each _process_block task
  tuple (cfg, dn, bx, by). The DN holder is released after the block
  pool so the final run-temp unlink still precedes no held mmap
  (Windows WinError 32, pinned by the os_portability sim).
…udit #83 review)

- pipeline.py: the (val_dn, sup_dn) holder tuple rode the task args and was
  released only by the happy-path dn = None after the block pool. A worker
  raising (or Ctrl-C) inside the pool left the memmaps live when the
  finally's _remove_run_temps() unlinked them -> WinError 32 on real
  Windows, masking the real error. The finally now releases dn too.
- tests: exception-path sim (forced _process_block failure) in
  test_os_portability.py pins the invariant on both paths; mutation-
  verified (fails with the one-liner reverted).
- tests: _doc_zstdmt probe read-back pins the on-disk width to
  _ORACLE_PROBE_W, so a third probe writer reverting to a literal width
  is caught; mutation-verified (width=400 -> fail).
- tests: two concurrent Pipeline.run() calls with different configs must
  each match their single-run reference (the _CTX-deletion hazard).
@marzukia
marzukia merged commit d45f484 into main Oct 16, 2026
11 checks passed
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.

2 participants