Skip to content

[implementation] data: R02 - rebuild selected legacy live days: plan, retire, import, verify (ADR-0074 A2) #520

Closed

Description

@NeoNix-Lab

Parent

SCOPE.md Part D (DG-R), atom R02, registered by governance issue #518; design gate #515 (ADR-0074 Amendment 2, PR #516, A2.2, A2.4 to A2.7); requires R01. Branch from implement/fid; the pull request targets implement/fid, never main. Hand-off notes: HANDOFF_516_astra.md (not versioned).

Authority

ADR-0074 Amendment 2 (accepted) and Amendment 1 (archive source, strict parsing, whole-day mapping); ADR-0075 section 3 (two-level key grammar) and its Amendment 1; ADR-0030; ADR-0044 and ADR-0049 unchanged. AGENTS.md governance boundary.

Start gate

Problem

Legacy live days (dt=<day>, many superseded revisions, one valid revision that holds only the day's last batch) read as a few hundred trades; for 2026-10-20 the archive has 1,568,861 trades and the live path published 1,142,059 (operator-reported: 1,141,530 in-day unique IDs, 427,331 absent, 529 rows outside the day). The ordinary importer refuses an occupied day and must keep doing so.

Objective

An operator-run rebuild of explicitly selected, closed UTC days: plan, retire the damaged revision (R01), import the archive day as revision 1 of dt=<day>/seg=000000.000 through the ordinary S13/S14 path, verify.

Design (ADR-0074 A2.2, A2.4, A2.5; no semantic decision beyond it)

  1. Importer variant (application/bybit_archive_import.py or a module beside it; never a --force of the ordinary importer): the invalid revision of the exact key dt=<day> does not occupy the day; any other partition of the day (valid or closed on dt=<day>, any dt=<day>/seg=... other than the one to create) still refuses. The key to create is fixed. Today _partition_exists refuses dt=<day> and dt=<day>/% in any state.
  2. Plan, read-only, with a digest the executor must present; per day: the incumbent live revision (partition UUID, key, revision, state, physical and manifest hashes, coverage identities), the archive file (URL, SHA-256, size, source-observation time, rows), the producing commit, the key to create and the result of the refusals below. A changed incumbent, source or catalog makes the plan stale; the executor never acquires another target or widens the date set.
  3. Refusals (nothing changes for that day): the day is not closed in UTC (its end is less than 24 h before execution); it has live slices, a checkpoint binding to one of its partitions or an open gap record that names it; its live revision is not valid; conservation fails (every record of the incumbent live revision, by (exchange_ts, trade_id), is found with equal venue, instrument, exchange time, side, price and size in the archive file of its own UTC day, and that day is readable after the operation; a difference in a common field refuses the day, no partial acceptance); the archive fails Amendment 1's parsing or differs from the planned hash.
  4. Execution: one day at a time, no lock held across days or during the read and the verification: retire (R01), import, verify (tools/compare_archive_day.py and a strict DataGateway read: count, order, duplicates). Crash between retire and import: rerunning imports. Crash between import and verify: the executor finds the valid key it would create and verifies. Restore (a superseding pass of R01) is documented, not automatic.
  5. CLI and runbook (tools/, docs/engineering/BYBIT_ARCHIVE_IMPORT_RUNBOOK.md): plan, execute --plan <digest>, verify; resource and time bounds; the operator steps on the server are the operator's.
  6. The rebuilt rows carry null receive_ts and sequence (as the archive); the loss of the sequence of the rows the incumbent serves today is declared and accepted; old bytes, manifests, reports and admissions stay.

Mutation boundary

The importer variant, the plan and executor modules, tools/ CLI, the runbook, the tests and their CI job. Nothing else.

Forbidden: A10 repair and any atomic replacement (ADR-0074 A2.8), seal_partition, S13/S14 and the live publication, checkpoint files and gap evidence, healthy historical days, live slices, other datasets, deletion or retention, trade-v1, the ordering key, TradeKeyV1, dataset identities, the J02 wire, schemas and migrations, governance files and ADRs.

Acceptance criteria

On a disposable PostgreSQL, with the real importer, S13/S14, R01 and the DataGateway:

  1. A retired day is imported under dt=<day>/seg=000000.000; the pilot day 2026-10-20 (a fixture of the same shape, with the real counts proven by the operator run) reads strictly as exactly 1,568,861 archive records, in order, without duplicates, equal field by field to the archive (null receive_ts and sequence expected); non-target days and the live checkpoint are byte-identical.
  2. Each refusal of design 3 leaves catalog, files and checkpoint unchanged: valid or closed incumbent, a live slice, a checkpoint binding, an open day, a stale plan, a differing common field, a malformed or different archive file, a row of the incumbent not present in the archive file of its own day.
  3. Crash between retire and import, and between import and verify, are recovered by rerunning; the restore returns the day to valid.
  4. A neighbouring day whose legacy coverage crossed midnight reads correctly after its own retirement (no overlap conflict in the gateway).
  5. The ordinary importer still refuses an occupied day, including a retired one when run without the rebuild.
  6. Mutation checks: each refusal and each ordering rule has a test that fails when it is weakened (retire before import, closed-day limit, conservation, key fixed, other partitions still refuse, plan digest).

Verification

python tools/run_tests.py; the new PostgreSQL integration (own CI job and database); python tools/check_markdown_links.py; git diff --check; python tools/workflow.py preflight --base implement/fid.

Out of scope

R01; the atomic replacement; running the rebuild on the server (the operator, from a reviewed plan, starting with 2026-10-20); the 31-date inventory as an execution plan; consolidation of slices; automatic repair of live gaps; retention or deletion of retired or superseded revisions; O02/O03.

Risks

  • Between retire and import the day is uncovered by design (a strict read refuses); one day at a time, closed days without consumers.
  • The ID comparison for 2026-10-20 is operator-reported, not a field-equality proof; criterion 1 is where it is proved.

Atomicity check

One responsibility (the operator-run rebuild of selected days over the existing writer and importer); justified by SCOPE.md Part D R02; its dependency on R01 is explicit; no semantic decision beyond ADR-0074 A2; observable criteria; reviewable without unrelated changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions