Skip to content

Alert diaSourceId packs the xsource's set job and xsid into one long (for the 2026-12-01 review) - #665

Merged
rusholme merged 1 commit into
rebuildfrom
diasourceid-packed/pack
Dec 1, 2026
Merged

rusholme merged 1 commit into
rebuildfrom
diasourceid-packed/pack

Conversation

@rusholme

@rusholme rusholme commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

The alert packet's diaSourceId becomes unique across packets: the xsource's source-set job and its xsid packed into the one 64-bit long, by one function, for the trigger and for every prvDiaSources entry. 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:286 wrote source.sid, and the packet stage fills sid from xsid (XSOURCE_COLUMNS: s.xsid AS sid). xsid numbers 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's prvDiaSources. 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:

quantity value
largest xsid (max(xsid) FROM xsources) 8,012
largest rows in one set (max(count(*)) … GROUP BY job) 8,012
largest job id (max(id) FROM jobs) 161,137
jobs since the recreate (ids 131,976 to 161,137) 29,162, launched 2026-11-14 11:34 to 2026-11-26 04:49 UTC (about 2,500 a day)
difference jobs among them 4,969

Split: xsid in the low 24 bits, the job in the 39 bits above them, the sign bit clear.

  • xsid can 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.
  • The job can reach 549,755,813,887, which is 3.4 million times today's largest id. At the measured rate of about 2,500 jobs a day that lasts about 600,000 years; at 100 times that rate, about 6,000 years.
  • The largest id the split can produce is 2^63 − 1, the largest positive Avro long.

The contract

diaSourceId = job << 24 | xsid            # job * 2**24 + xsid
job  = diaSourceId >> 24
xsid = diaSourceId & (2**24 - 1)          # & 0xFFFFFF
  • param_registry.dia_source_id(job, xsid) packs and dia_source_pair(id) is its inverse; the two sit together beside the field. A job or xsid that is negative, past its width or not an integer is refused (ValueError or TypeError), never wrapped into another pair's id.
  • Source gains source_job, the source set's job. The packet stage's xsource read already selects s.job AS source_job for the trigger and for every member, so each detection carries its own job with no change to the stage's reads. The diaSource record's diaSourceId is a registry getter over (source_job, sid), and the alert's top-level diaSourceId calls the same function.
  • Both diaSourceId doc strings state the split and how to decode it. The two 00.08 .avsc files are regenerated, and only their doc changes (gen_schema --check clean).

Tests, each asserting one contract:

  • test_dia_source_id_tells_apart_one_xsid_in_two_jobs_and_decodes_to_the_pair: one xsid in 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 share xsid 1, 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.
  • The existing packet and alert tests now key or compare by the packed id.

tests/unit locally: 1,375 passed, 2 failed. Both failures are test_measured_with_a_set_falls*, whose temporary-directory cleanup hit an EFS .nfs busy 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:

  • rapid_docs states no versioning rule for the alert schema. Its alert page and its decisions, specification and migration pages were searched.
  • The only written rule is the registry's own header, from dev: "bump VERSION if the change is not backward compatible".
  • This change is backward compatible in Avro's sense. The field's name and type are unchanged, so a 00.08 reader decodes the new packets. The Parsing Canonical Form, which schema registries fingerprint, drops doc, so the schema's fingerprint is unchanged too.
  • The meaning does change, and the description says so: consumers read the id as (job, xsid).

Nothing is registered, built or deployed.

What consumers see change

  • diaSourceId on the alert and on every diaSource is now job << 24 | xsid instead of the bare xsid. It is the same for one detection in every packet that carries it, and distinct between detections.
  • A consumer that joined a packet to its set by (set, diaSourceId) now decodes the set from the id.
  • Unchanged: the packet index's sid column (still the bare xsid, beside its source_job), the external and forced index columns, alert_outbox, every table and the Kafka headers.
  • At today's job ids the values are about 2.7 × 10^12, inside a JavaScript double's exact range. That holds while the job id stays under 2^29 (about 537 million jobs).

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 it job.
  • 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 by sid alone. The old comparison counted any earlier detection with the same xsid as present.
  • Tests: 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

  • The pair is carried on Source (source_job) rather than passed beside it. The registry builds every diaSource from one record, and the stage's read already holds the column.
  • xsid 0 and job 0 are accepted. Both are in range, and neither occurs.
  • read_packets.py and validate_run.py run on a run whose packets were made before this change report a locator mismatch, because those ids are bare xsids. Nothing bridges the two formats (rapid_docs decision-legacy-compatibility).

Improvements seen

  • diaObjectId is the bare xaid. 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 way diaSourceId did. It is seen and not changed here; the card covers the source id only.
  • The alert's diaSourceId doc string says "Identifier for the triggering diaSource". It is now the same value as diaSource.diaSourceId; the doc says how to decode it, not that the two are equal.

Session notes

  • On this host, the unit suite's temporary directories on EFS can fail cleanup with an .nfs busy file (test_measured_with_a_set_falls*, twice in two runs).

What the next task must know

  • This is not merged and not deployed. If the team accepts it, a merge and the next rapid-rebuild revision carry it. Packets already sent keep their bare xsids.

Left

  • The team's review and merge.

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>
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