Repository navigation
Alert diaSourceId packs the xsource's set job and xsid into one long (for the 2026-12-01 review) - #665
Merged
Conversation
The packet's diaSourceId was the bare xsid, numbered from 1 within each source set, so it repeated between packets and within one packet's prvDiaSources. param_registry.dia_source_id(job, xsid) packs the pair as job << 24 | xsid (39 job bits, 24 xsid bits, sign bit clear) and refuses a value past its width; dia_source_pair() is the inverse. Every diaSource (trigger and previous detections) and the alert's top-level id use it, each with its own set's job, which Source now carries as source_job. The two doc strings state the split and the decoding; the 00.08 .avsc files are regenerated (doc only). The check scripts compare the packed id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The alert packet's
diaSourceIdbecomes unique across packets: the xsource's source-set job and itsxsidpacked into the one 64-bitlong, by one function, for the trigger and for everyprvDiaSourcesentry. No table, no index column, no Kafka header and no Avro type changes.Left open for the team's meeting of 2026-12-01 21:00 UTC. This changes what consumers receive, and it sets aside Russ's proposal of 2026-11-24 to draw the id from database sequences. That proposal needs a schema change: a sequence, plus a column or a redefinition of
xsid. Its ids also cannot be taken back to the source set without a lookup. The pair packed here is the database's own key,UNIQUE (job, xsid), so it needs no schema change and decodes with no lookup. Companion docs PR: Caltech-IPAC/rapid_docs#248.The failure seen
assemble.py:286wrotesource.sid, and the packet stage fillssidfromxsid(XSOURCE_COLUMNS:s.xsid AS sid).xsidnumbers a set's kept xsources from 1, so it is unique only within its job. The same id therefore appeared in many packets, and within one packet'sprvDiaSources. Azalee and Jacob reported this in #pipeline on 2026-11-24, and it is on Azalee's before-2026-12-08 list. Two detections collide whenever their sets numbered them alike, since every set numbers from 1.The split, measured
One read-only transaction (
SET TRANSACTION READ ONLY, SELECT only) through the pooler (RAPID_PARAMETER_PATH=/rapid/rebuild), on 2026-12-01 at 00:40 UTC:xsid(max(xsid) FROM xsources)max(count(*)) … GROUP BY job)max(id) FROM jobs)Split: xsid in the low 24 bits, the job in the 39 bits above them, the sign bit clear.
xsidcan reach 16,777,215, which is 2,094 times the largest set measured. Sets are uncapped (max_sources = -1), so the headroom is a multiple of today's maximum rather than a rate.long.The contract
param_registry.dia_source_id(job, xsid)packs anddia_source_pair(id)is its inverse; the two sit together beside the field. A job orxsidthat is negative, past its width or not an integer is refused (ValueErrororTypeError), never wrapped into another pair's id.Sourcegainssource_job, the source set's job. The packet stage's xsource read already selectss.job AS source_jobfor the trigger and for every member, so each detection carries its own job with no change to the stage's reads. ThediaSourcerecord'sdiaSourceIdis a registry getter over(source_job, sid), and the alert's top-leveldiaSourceIdcalls the same function.diaSourceIddoc strings state the split and how to decode it. The two 00.08.avscfiles are regenerated, and only theirdocchanges (gen_schema --checkclean).Tests, each asserting one contract:
test_dia_source_id_tells_apart_one_xsid_in_two_jobs_and_decodes_to_the_pair: onexsidin two jobs gives two ids, each decoding to its(job, xsid); the widest pair is 2^63 − 1.test_dia_source_id_refuses_a_job_or_xsid_past_its_width: a value past the width, negative or not an integer is refused.test_each_detection_s_id_packs_its_own_set_s_job_with_its_xsid(packet stage,write_set): the trigger and two previous detections sharexsid1, each in a set of its own. The three ids are distinct, and each decodes to its own detection's job, matched by its epoch. A pack called with the trigger's job for every entry fails this test; that was checked by mutating the getter, which produced one id for all three.tests/unitlocally: 1,375 passed, 2 failed. Both failures aretest_measured_with_a_set_falls*, whose temporary-directory cleanup hit an EFS.nfsbusy file (OSError: [Errno 16]) on this host. They do not touch this change; CI runs them on local disk.The version question
No step: the schema stays 00.08. The rule applied:
dev: "bump VERSION if the change is not backward compatible".doc, so the schema's fingerprint is unchanged too.(job, xsid).Nothing is registered, built or deployed.
What consumers see change
diaSourceIdon the alert and on everydiaSourceis nowjob << 24 | xsidinstead of the barexsid. It is the same for one detection in every packet that carries it, and distinct between detections.(set, diaSourceId)now decodes the set from the id.sidcolumn (still the barexsid, beside itssource_job), theexternalandforcedindex columns,alert_outbox, every table and the Kafka headers.Files
rapidpipe/science/alerts/param_registry.py: the split,dia_source_id,dia_source_pair, and the two doc strings.rapidpipe/science/alerts/records.py:Source.source_job. It is exempt from strict reads, because a strict read names itjob.rapidpipe/science/alerts/assemble.py: the alert's top-level id.rapidpipe/science/alerts/schema/00/08/rapid.v00_08.{alert,diaSource}.avsc: regenerated, doc only.rapidpipe/stages/packet.py: one docstring sentence.scripts/read_packets.py,scripts/validate_run.py: the locator check compares the packed id with the index row's(source_job, sid).scripts/completeness.py: the history check matches previous detections by(job, sid)rather than bysidalone. The old comparison counted any earlier detection with the samexsidas present.tests/unit/test_alerts_science.py,tests/unit/test_packet.py,tests/unit/test_completeness.py,tests/db/test_packet_inputs.py.Divergences and choices
Source(source_job) rather than passed beside it. The registry builds everydiaSourcefrom one record, and the stage's read already holds the column.xsid0 and job 0 are accepted. Both are in range, and neither occurs.read_packets.pyandvalidate_run.pyrun on a run whose packets were made before this change report a locator mismatch, because those ids are barexsids. Nothing bridges the two formats (rapid_docs decision-legacy-compatibility).Improvements seen
diaObjectIdis the barexaid. The database keys an xobject by (dataset, field,xaid, job) (UNIQUE (dataset, field, xaid, job), rapid_docs alerts page), so the object id can repeat between fields and jobs, the same waydiaSourceIddid. It is seen and not changed here; the card covers the source id only.diaSourceIddoc string says "Identifier for the triggering diaSource". It is now the same value asdiaSource.diaSourceId; the doc says how to decode it, not that the two are equal.Session notes
.nfsbusy file (test_measured_with_a_set_falls*, twice in two runs).What the next task must know
rapid-rebuildrevision carry it. Packets already sent keep their barexsids.Left