Skip to content

gate: the count check reads the xsources against its own SExtractor catalog, and no check reads another job - #693

Merged
rusholme merged 2 commits into
mainfrom
gate-xsources-fraction
Dec 4, 2026
Merged

rusholme merged 2 commits into
mainfrom
gate-xsources-fraction

Conversation

@RussLaher

@RussLaher RussLaher commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Implements rapid_docs decision-gate-xsources-fraction (Caltech-IPAC/rapid_docs#254: decisions.md, the quality gate section of foundation.md, and difference.md).

Change.

  • rapidpipe/foundation/gate.py:
    • Check 3 holds a set when n_xsources_snr_gt20 (kept positive xsources with PSF-fit S/N > 20) is above [gate] snr_gt20_fraction_max (0.32) times n_xsources_read_positive (positive SExtractor rows before the edge cut and prefilter).
    • Check 3 is skipped, so the set passes, when that catalog read fewer than snr_gt20_min_read (100) rows.
    • The run-median count and min_epochs are removed. judge no longer takes a median or epoch count, and decide_all reads only the set's own difference job (two statements).
  • rapidpipe/science/difference/metrics.py (xsource_counts) and rapidpipe/stages/difference.py: the difference job records the two counts.
  • foundation-thin.toml [gate]: adds snr_gt20_fraction_max = 0.32 and snr_gt20_min_read = 100, and removes snr_gt20_factor and min_epochs. A run body that still carries the removed keys is ignored, not refused.

Reason. The packets come from the xsources, so the count should describe that catalog, and no check should depend on the run's history. The old check 3 had these weak points:

  • One median per run: check 3's median mixes all filters and SCAs. A run mixing a crowded and a sparse field, or filters with very different depths, could hold good epochs or let bad ones through.
  • The median includes the epoch itself: in a short run a bad epoch pulls its own threshold up.

Consequences:

  • Early epochs: usable fraction, registration, core and ring now judge a run's first epochs too, which were previously sent unjudged.
  • Older jobs: difference jobs published before this change carry neither new count, so check 3 holds nothing on them.

Testing. All run locally (Python 3.14, PostgreSQL 17):

  • tests/unit/test_gate.py, test_quality_metrics.py, test_difference_stage.py, test_dependency_direction.py and test_ported_from.py: 183 passed.
  • tests/db and tests/cli against a fresh schema.sql: 211 passed. test_publish_pool was not run, as it needs pgbouncer.
  • Full tests/unit: 1414 passed, 1 failed. The failure is test_run_job_workdir, which also fails on the unmodified baseline on macOS.
  • check-public-safety.sh: clean.

0.32 is read on 3,794 recorded difference jobs (runs 264 to 306, replayed read-only from each job's manifest and xsources.parquet): the fraction is at most 0.288 but for two epochs, at 0.352 and 0.401, whose n_sources_snr_gt20 was 13 and 33 times their run's median. At the first draft's 0.5 the check held nothing. 100 is the ruling's value; no recorded catalog read fewer than 291 rows.

🤖 Generated with Claude Code

…atalog, and no check reads another job

A packet set is held when its difference's n_xsources_snr_gt20 (kept positive
xsources with PSF-fit S/N above 20) is above [gate] snr_gt20_fraction_max
(0.5) times n_xsources_read_positive (positive SExtractor rows before the edge
cut and prefilter), judged only when that catalog read at least
snr_gt20_min_read (100) rows. snr_gt20_factor (the run-median count) and
min_epochs are retired, so every check applies from a run's first difference;
decide_all reads two statements and no run median. The difference stage
records the two counts (metrics.xsource_counts). Implements rapid_docs
decision-gate-xsources-fraction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RussLaher

RussLaher commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator Author

My plan for later is to store n_xsources_snr_gt20 and n_xsources_read_positive from the gate test in the database, so these quantities can be easily analyzed for tuning the snr_gt20_fraction_max threshold.

…ferences

Replayed on runs 264 to 306 (read-only, from each job's manifest and
xsources.parquet): the fraction is at most 0.288 but for two epochs, at
0.352 and 0.401, whose n_sources_snr_gt20 was 13 and 33 times their run's
median. At 0.5 the check held nothing. The 100-row floor stays the
ruling's: no recorded catalog read fewer than 291 rows. The runbook's two
descriptions of the gate now state the new rule.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@rusholme
rusholme merged commit ebc7f7c into main Dec 4, 2026
5 checks passed
@rusholme
rusholme deleted the gate-xsources-fraction branch December 4, 2026 19:39
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