From 5c756850a39c3e500b973f4119d450b6dedb8d5e Mon Sep 17 00:00:00 2001 From: NeoNix <112125692+NeoNix-Lab@users.noreply.github.com> Date: Tue, 27 Oct 2026 21:11:50 +0100 Subject: [PATCH 1/7] docs(adr): propose ADR-0074 Amendment 3, close live cycles days from the archive (#538) Design only. Proposes retire-and-import for closed days published as live slices in cycles mode (A2.3 reassessment per slice, then the archive day as dt=/seg=000000.000), with the plan, refusals, overlap rule, relation to the continuous session and the open items for the maintainer. Changes no code, governance file or data. Co-Authored-By: Claude Sonnet 5.5 --- ...multi-instrument-bybit-linear-trades-v1.md | 218 +++++++++++++++++- 1 file changed, 217 insertions(+), 1 deletion(-) diff --git a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md index 678d9fe..ee9ee26 100644 --- a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md +++ b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md @@ -2,7 +2,7 @@ **Status:** ACCEPTED (design gate #377, PR #481; accepted by the maintainer 2026-10-19, recorded in issue #377). Amendment 1 (historical source, design gate #487): ACCEPTED 2026-10-20. Amendment 2 (rebuild of damaged legacy live days, design gate #515): -ACCEPTED 2026-10-24. +ACCEPTED 2026-10-24. Amendment 3 (close live `cycles` days from the archive, design gate #538): PROPOSED 2026-10-27. **Date:** 2026-10-19 Design gate #377; evidence issue #378. Amends ADR-0040, ADR-0043 and the applicability of the Bybit `trade-v1` ordering and @@ -489,3 +489,219 @@ operator-reported evidence of A2.1 is accepted as evidence, not as an audit. Not done by this acceptance: the implementation (`R01`, issue #519; `R02`, issue #520); the governance registration of those atoms (issue #518); any change of production data; the choice of the days to rebuild, which comes only from a reviewed plan (A2.4). Cleaning retired or superseded legacy revisions remains the maintainer's retention decision. + +--- + +## Amendment 3 - Close live `cycles` days from the archive + +**Status:** PROPOSED (design gate [#538](https://github.com/NeoNix-Lab/quant-platform/issues/538)) +**Date:** 2026-10-27 + +The accepted ADR and Amendments 1 and 2 remain operative. This amendment is not an implementation, a governance +reconciliation or authority to change production data. It proposes how a closed live day published by the service in `cycles` +mode is closed from the Bybit archive, in the same two steps as Amendment 2 does for the legacy `dt=` days (retire, then +import), and it leaves to the maintainer the choices listed in A3.10. + +### A3.1 Problem and evidence + +[ADR-0075](ADR-0075-live-trades-continuous-session-and-append-only-slices-v1.md) section 3 gives a slice `complete` coverage +over its own window and says that consecutive slices chain by construction. That holds for the continuous session (section 1, +`O02`). The service on `homelab` runs in the default `cycles` mode: each cycle opens a WebSocket, publishes one slice and pauses +before the next. The pause between two slices is not covered: a read that spans it is refused under `strict` coverage +(`LIVE_INGEST_SERVER_DEPLOYMENT.md`), and the steady state reconciles only at start, restart or after a cycle that proved nothing +(`live_ingest_server`, ADR-0043), so the trades of the pause are not recovered either. Issue #504 measured 27.2% of the trades of +2026-10-20 missing against the archive on the publication that preceded the slices. + +Operator-reported read-only catalog queries on `homelab`, 2026-10-26 (`kind='trades'`, `instrument='BTCUSDT'`, state `valid`). +These are supplied operational evidence, not a new independent server audit. + +| Check | Result | +| --- | --- | +| 2026-10-24 slices | 3,327 valid slices, 749,441 rows, 3,326 gaps between consecutive slices, 28,718.2 s uncovered (33.2% of the day), longest gap 299.5 s, shortest 6.03 s. | +| 2026-10-24 gap distribution | 3,324 gaps of at most 30 s; one between 30 and 120 s; one between 120 and 300 s. | +| 2026-10-25 slices | 3,333 gaps, 29,681.6 s uncovered (34.4% of the day), longest gap 31.0 s, shortest 6.05 s. | + +A slice per cycle is 3,327 partitions for a day, not the "about 288" that section 7 of ADR-0075 expects of the continuous +session. The two long gaps of 2026-10-24 are consistent with restarts of the service; that was not checked against its logs. +The share of trades actually lost on these two days is not measured: their archive files are not on the server. #504 is the +only measured loss. + +On 2026-10-26 the maintainer replaced the damaged period by hand, outside the guarantees of Amendment 2 and by explicit +instruction: a catalog dump (`/srv/marketdata/backups/catalog-before-replace-20261026.dump`), then one transaction by an +untracked operator script that deleted the 85,684 `trades` catalog rows of 2026-09-23 and of 2026-09-25 through 2026-10-23, the +day directories renamed (not removed) into `/srv/marketdata/replaced/BTCUSDT-trades-20261026/`, and the 30 days imported with +`tools/import_bybit_archive_day.py` (30 `valid`, none refused). 2026-09-24 had been rebuilt before by R02. The result is +contiguous `valid` coverage from 2026-09-20 through 2026-10-23, checked by SQL. The open long-gap record files in the dataset +root were left in place. That procedure is not a precedent for this amendment (A3.9, item 1). + +Amendment 2 cannot do this for a slice day. The plan of R02 refuses a day that has live slices, and the rebuild import refuses +any partition under `dt=/` other than the legacy key. From 2026-10-24 every live day is a slice day, and the service keeps +publishing in `cycles` mode until `O02` runs against the real provider (a run that has not been performed). + +### A3.2 Decision (proposed) + +Authorize an operator-requested closure of explicitly selected, closed UTC days of +`canonical/trades/bybit/BTCUSDT/trade-v1` whose publication is a family of live slices `dt=/seg=...` (ADR-0075 section 3). +Per selected day, in this order: + +1. **Retire every slice.** For each `valid` slice of the day, record the superseding quality reassessment of A2.3 (`fail` on + completeness, `valid -> invalid` through the existing ADR-0030 seam), with the violation `live_slices_incomplete_day` and the + archive identity that shows it. Nothing is deleted or rewritten: each slice stays the live row of its key, now `invalid`, + with its bytes, manifests and reports. One short transaction per slice, as A2.3; the step is idempotent, so a day that is + partly retired is an honest state (the slices not yet retired are still served) and rerunning completes it. +2. **Import.** Import the whole-day archive file of Amendment 1 as revision 1 of `dt=/seg=000000.000` through S13/S14, with + the importer variant of A2.2 widened by one case: the day's slices, all of them `invalid`, do not occupy the day. A `valid`, + `closed` or `writing` partition of the day, a retired partition that is not a slice of the day, or a slice that already + holds the key `seg=000000.000` still refuses (a window that starts at the day's first instant is a case to refuse, not to + collide with). +3. **Verify.** As A2.2 item 3: full comparison with the archive file, then a strict `DataGateway` read of the day. + +The ordinary importer keeps its refusal of an occupied day; the closure is never a `--force` of it. As in A2.5, retire and import +are not one transaction: between them the day is honestly not served, and the order guarantees that two valid partitions never +cover the same day. + +### A3.3 Plan, preconditions and refusals + +The plan and its digest are those of A2.4. For each day the plan also records: the slices (key, revision, state, physical and +manifest hashes), their rows and distinct trade ids, the covered and uncovered seconds of the day, the measured loss (the +archive's distinct ids that no slice holds), and the open long-gap records that name the day (path, SHA-256, interval). The +measured loss is the number that this amendment lacks today. + +A day is refused, and nothing is changed for it, if any of the following holds: + +- the day is not closed in UTC: its end is less than 24 hours before execution; +- the live checkpoint is bound to a partition of the day; +- a live revision of the day is `writing` or `closed`; +- **conservation fails.** Every record of every `valid` slice, by `(exchange_ts, trade_id)`, must be found with equal venue, + instrument, exchange time, side, price and size in the archive file of its own UTC day, and that day must be readable after + the operation (selected in the same plan, or already `valid`). Any difference in a common field refuses the day; there is no + partial acceptance. The rows lose the live `sequence` and `receive_ts` they carry now (ADR-0040 keeps them as live evidence): + a declared loss of provenance, recoverable from the retained bytes, and not a claim of the original session's continuity; +- a slice crosses a UTC midnight (ADR-0075 Amendment 1, the bridge slice) and the neighbouring day is not selected in the same + plan: both days refuse; +- an overlap exists (A3.6); +- an open long-gap record that names the day is not contained in it (A3.5); +- **there is nothing to repair:** the slices of the day cover it without a pause (the `continuous` case, A3.7). The plan + reports it and the closure does not run; +- the archive file fails Amendment 1's strict parsing, or its hash differs from the plan, or its manifest hash recorded in the + catalog differs from the manifest beside the artifact. + +### A3.4 Readers, concurrency and failure + +- **Coherent reads.** As A2.5: `select_partitions` filters by lifecycle state in one statement, so each reassessment is seen + whole or not at all. +- **Crash and retry.** After a crash between two retirements the day is partly retired; rerunning continues. After a crash + between the last retirement and the import, rerunning imports. After a crash between the import and the verification the + executor finds the valid key and goes to the verification, which is read-only and repeatable. The attempt is identified by + the plan digest. +- **Concurrency.** The closure takes the day lock of the importer (it never waits) and, per slice, the dataset row lock that the + live publication takes, for a short transaction. The service writes slices of the current day, never of a closed one. The + closure of a `cycles` day is about 3,300 such transactions; their total duration and their effect on the publication latency + of the live service are to be measured by the implementation proof, not assumed. +- **Untouched.** The live checkpoint, the long-gap record files, the manifests, the bytes of the retired slices, other days and + other datasets. No deletion, catalog reset or retention is part of the operation + ([ADR-0049](ADR-0049-retention-deletion-authority-v1.md)). + +### A3.5 Open long-gap records and manifests + +The long-gap record files (`coverage-manifest-long-gap-*.json` in the dataset root) are not modified, moved or deleted by the +closure. [ADR-0044](ADR-0044-live-ingest-long-gap-remediation-v1.md) reaches `REPAIR_CUTOVER_COMPLETE` only through A10's +cutover, and this amendment does not amend it. A record whose interval lies inside the day does not block the closure: the +import is certified by S13 over the whole day. A record whose interval is not contained in the day (a gap that crosses a +midnight) blocks the closure of that day until the neighbouring day is in the same plan, because one coverage document names one +partition. The record stays open. The live service keeps loading it and keeps reporting an explicit-gap session state; whether +an archive closure should end that state is a decision of the maintainer (A3.10, item 2). + +On 2026-10-26 the record files named nine of the replaced days and were left in place; the 30 imports certified. Their effect on +the live service and on the gateway after the replacement has not been checked. The open records also name 2026-10-24, the +first day to close: whether that record's interval lies inside the day is read from the file by the plan, not assumed here. + +The manifests of the slices are written beside the artifact (`#510`), so the lost-manifest blocker that stopped R02 on the +legacy days does not apply to slice days. The plan still compares the manifest hash with the catalog and refuses a difference. + +### A3.6 The overlap rule (and a correction of A2.4) + +The `DataGateway` refuses overlapping eligible partitions (`CatalogConflict`) on any read that touches the overlap. The plan of +Amendment 2 does not check it: a legacy day whose predecessor crosses midnight and is blocked cannot be rebuilt, and R02's plan +did not say so (observed on 2026-10-26). The rule, for every closure and every A2 rebuild: after the retirements of the plan, no +`valid` partition outside the plan may have a coverage interval that intersects the UTC interval of a day to import; otherwise +that day refuses. This corrects the plan of R02 as a defect of its implementation, not a change of A2. + +### A3.7 Relation to the continuous session + +The closure is transitional. When the service runs `continuous` (`O02`, `O03`), slices chain without a pause and the plan finds +no uncovered second: it refuses with "nothing to repair". The archive then serves as a verification: the slices of a closed day +are compared with it by the existing O03 evidence tool, and nothing is retired or imported. A day published partly in `cycles` +and partly in `continuous` (the day of the switch) is closed like any other day, because it has pauses. This amendment does not +choose the date of the switch and does not depend on it. + +### A3.8 Exact effect if accepted + +| Authority | Bounded amendment | +| --- | --- | +| ADR-0075 section 7, "taking the day from the Bybit archive" and "the already damaged days" | Section 7 describes that archive day as a **consolidation**, an optimization of reads opened only on a measured cost. This is a **repair** of an incomplete day on its own evidence (A3.1) and lifts the pause only for the explicitly selected, closed slice days. Consolidation of complete days is not opened. | +| This ADR, Amendment 2 (A2.2, A2.4) | Extends retire-and-import to slice families. The refusal "the day has a live slice" is lifted only for the selected day's own slices, which step 1 retires; every other A2 refusal stands; A3.6 is added. | +| ADR-0030 (A16) | No change of meaning. The writer of A2.3 is used per slice. | +| ADR-0044 | Not amended: the long-gap records stay open (A3.5). | +| ADR-0043, ADR-0075 sections 1 to 6 | Unchanged. No reconciliation between cycles is added (A3.9, item 3). | +| ADR-0049 | Unchanged: no deletion; retention of the retired slices stays the maintainer's decision. | +| S13, S14, identity, ordering, key grammar | Unchanged; the import uses them as they are. | + +This proposal does not accept the 2026-10-26 replacement as a procedure, does not complete `O02` or `O03`, and changes no +governance file. Acceptance must be recorded explicitly and followed by a separately authorized implementation issue and a +governance reconciliation that registers its atom in `SCOPE.md`. Production execution follows a reviewed, pinned implementation +and a reviewed date plan. + +### A3.9 Considered and not adopted + +1. **A catalog `DELETE`, as on 2026-10-26.** It removes the days from the catalog, and the quality reports and relocation rows + that cascade from the partitions with them; only a dump remains as evidence. A2.5 forbids deletion and catalog reset. It was + the maintainer's instruction for an exceptional damaged period, not a procedure to repeat per day. +2. **A day-level retirement** (one reassessment for all the slices of a day). It needs a new ADR-0030 target kind. Not adopted. + Its cost is visible: a `cycles` day is about 3,300 reassessments and as many quality reports, which is one more reason to + leave `cycles`. +3. **A bounded REST reconciliation after every cycle.** The recent-trades window returns at most 1,000 trades: about 36 s at the + 27 trades a second of 2026-09-24, about 77 s at the 13 trades a second of the covered time on 2026-10-24. That is enough for + the 3,324 gaps of at most 30 s and not for a restart gap of 299.5 s, and it would turn the loop into the REST poller that + `live_ingest_server` documents it must not become. The continuous session removes the pause itself, and belongs to `O02`. +4. **A scheduled, unattended closure.** Deferred (A3.10, item 3). +5. **An atomic replacement of the slices.** As A2.8. + +### A3.10 Open items for the maintainer + +1. **Instruments.** BTCUSDT only is proposed. Another instrument is a later amendment, and the instruments started through the + multi-instrument unit would go through `continuous` first. +2. **Gap records.** Keep them open (proposed), or amend ADR-0044 so that an archive closure ends the open state. The second + needs a rule for the gaps that cross a midnight, which one coverage document cannot restate. +3. **Trigger.** An operator command (proposed), or a scheduled run after the UTC day closes. A scheduler would produce and + execute its own plan without the reviewed date plan that A2.6 requires; if wanted, it is a separate amendment after + several manual closures verify without a refusal. +4. **Archive availability.** The 24-hour closed-day rule of A2.4 stands. The publication lag of the archive file is not measured + here. The plan records the source-observation time and refuses when the file cannot be fetched; it does not wait. +5. **Retention.** The retired slices, the directories moved aside on 2026-10-26 and the catalog dump: who keeps them and for how + long (ADR-0049). +6. **Complete live days.** A day that the continuous session published without a pause is never replaced (A3.7). Say so + explicitly if a replacement should ever be allowed. + +### A3.11 Required implementation and operational proof + +The runtime proof is required after implementation; this design-only proposal does not claim any of these probes passed. + +1. **Slice-day closure.** The plan, execute, verify and restore of A2 extended to slice families, over a disposable PostgreSQL. + Probes: N slices retired and the day imported; a strict `DataGateway` read returns exactly the archive's records, in order, + without duplicates, with full-field equality (null `receive_ts` and `sequence` expected). Each refusal of A3.3 changes + nothing: an open day, a checkpoint binding, a `writing` or `closed` slice, a differing common field, a differing archive hash, + a bridge slice without its neighbour, a gap record that is not contained, an overlapping valid partition, a day without a + pause, a slice already at `seg=000000.000`. Crashes between two retirements, between retire and import, and between import + and verify are recovered by rerunning; the restore path returns the retired slices to `valid`. Non-target days, the + checkpoint and the gap record files are byte-identical. Mutation checks weaken the conservation and the overlap rules, and + the tests fail. +2. **The overlap guard of A3.6** in the plan of R02, with its own probe. +3. **Operation.** Dry-run, execute and verify on `2026-10-24` first (the first closed slice day); `2026-10-25` and later days + only from a new reviewed plan. The duration of the retirements and their effect on the publication latency of the live + service are measured and reported. + +### A3.12 Acceptance record + +Pending. Not done by this proposal: the acceptance; the governance registration of an atom; the implementation; any change of +production data; the choice of the days; the deployment; the switch of the service to the continuous session. From 29e77b528d3bf895c95af0862a0fb35cefc0e183 Mon Sep 17 00:00:00 2001 From: NeoNix <112125692+NeoNix-Lab@users.noreply.github.com> Date: Tue, 27 Oct 2026 21:19:19 +0100 Subject: [PATCH 2/7] docs(adr): Amendment 3 covers the whole allow-list and runs unattended (#538) Records the maintainer's requirement of 2026-10-27: every instrument of the allow-list, automatic, every day closed. Adds A3.12 (selection by rule, three outcomes, the guards that replace the reviewed date plan, what it does not do) and rewrites the open items on instruments, trigger and gap records. Design only. Co-Authored-By: Claude Sonnet 5.5 --- ...multi-instrument-bybit-linear-trades-v1.md | 96 ++++++++++++++----- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md index ee9ee26..b9b6bb7 100644 --- a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md +++ b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md @@ -2,7 +2,7 @@ **Status:** ACCEPTED (design gate #377, PR #481; accepted by the maintainer 2026-10-19, recorded in issue #377). Amendment 1 (historical source, design gate #487): ACCEPTED 2026-10-20. Amendment 2 (rebuild of damaged legacy live days, design gate #515): -ACCEPTED 2026-10-24. Amendment 3 (close live `cycles` days from the archive, design gate #538): PROPOSED 2026-10-27. +ACCEPTED 2026-10-24. Amendment 3 (close every live day from the archive, unattended, for the whole allow-list; design gate #538): PROPOSED 2026-10-27. **Date:** 2026-10-19 Design gate #377; evidence issue #378. Amends ADR-0040, ADR-0043 and the applicability of the Bybit `trade-v1` ordering and @@ -492,15 +492,17 @@ atoms (issue #518); any change of production data; the choice of the days to reb --- -## Amendment 3 - Close live `cycles` days from the archive +## Amendment 3 - Close every live day from the archive, unattended, for the whole allow-list **Status:** PROPOSED (design gate [#538](https://github.com/NeoNix-Lab/quant-platform/issues/538)) **Date:** 2026-10-27 The accepted ADR and Amendments 1 and 2 remain operative. This amendment is not an implementation, a governance -reconciliation or authority to change production data. It proposes how a closed live day published by the service in `cycles` -mode is closed from the Bybit archive, in the same two steps as Amendment 2 does for the legacy `dt=` days (retire, then -import), and it leaves to the maintainer the choices listed in A3.10. +reconciliation or authority to change production data. The maintainer's requirement (2026-10-27) is that the system serve +**every instrument of the allow-list** (section 1: BTCUSDT, ETHUSDT, SOLUSDT, XRPUSDT, DOGEUSDT), **run by itself** and +**close every day well**, so that no day is repaired by hand again. This amendment proposes how a closed live day is verified +against the Bybit archive and, when it is incomplete, closed from it in the two steps of Amendment 2 (retire, then import), and +how that runs unattended (A3.12). It leaves to the maintainer the choices listed in A3.10. ### A3.1 Problem and evidence @@ -540,9 +542,9 @@ publishing in `cycles` mode until `O02` runs against the real provider (a run th ### A3.2 Decision (proposed) -Authorize an operator-requested closure of explicitly selected, closed UTC days of -`canonical/trades/bybit/BTCUSDT/trade-v1` whose publication is a family of live slices `dt=/seg=...` (ADR-0075 section 3). -Per selected day, in this order: +Authorize the closure of closed UTC days of `canonical/trades/bybit//trade-v1`, for each instrument of the +allow-list, whose publication is a family of live slices `dt=/seg=...` (ADR-0075 section 3). The days are selected by that +rule (A3.12), never from a free list. Per selected day, in this order: 1. **Retire every slice.** For each `valid` slice of the day, record the superseding quality reassessment of A2.3 (`fail` on completeness, `valid -> invalid` through the existing ADR-0030 seam), with the violation `live_slices_incomplete_day` and the @@ -609,8 +611,11 @@ closure. [ADR-0044](ADR-0044-live-ingest-long-gap-remediation-v1.md) reaches `RE cutover, and this amendment does not amend it. A record whose interval lies inside the day does not block the closure: the import is certified by S13 over the whole day. A record whose interval is not contained in the day (a gap that crosses a midnight) blocks the closure of that day until the neighbouring day is in the same plan, because one coverage document names one -partition. The record stays open. The live service keeps loading it and keeps reporting an explicit-gap session state; whether -an archive closure should end that state is a decision of the maintainer (A3.10, item 2). +partition. The record stays open. The live service keeps loading it and keeps reporting an explicit-gap session state. Run +unattended, a record left open would keep that state for good, so item 2 of A3.10 is a decision that the requirement forces: it +is proposed that a record whose whole interval lies inside a day certified `complete` from the archive be superseded by that +coverage. That amends ADR-0044, so it is a separate amendment of it and not part of this one; until it is accepted the records +stay open. On 2026-10-26 the record files named nine of the replaced days and were left in place; the 30 imports certified. Their effect on the live service and on the gateway after the replacement has not been checked. The open records also name 2026-10-24, the @@ -642,15 +647,15 @@ choose the date of the switch and does not depend on it. | ADR-0075 section 7, "taking the day from the Bybit archive" and "the already damaged days" | Section 7 describes that archive day as a **consolidation**, an optimization of reads opened only on a measured cost. This is a **repair** of an incomplete day on its own evidence (A3.1) and lifts the pause only for the explicitly selected, closed slice days. Consolidation of complete days is not opened. | | This ADR, Amendment 2 (A2.2, A2.4) | Extends retire-and-import to slice families. The refusal "the day has a live slice" is lifted only for the selected day's own slices, which step 1 retires; every other A2 refusal stands; A3.6 is added. | | ADR-0030 (A16) | No change of meaning. The writer of A2.3 is used per slice. | -| ADR-0044 | Not amended: the long-gap records stay open (A3.5). | +| ADR-0044 | Not amended here: the supersession of a contained long-gap record is a separate amendment of it (A3.5, A3.10 item 2). | | ADR-0043, ADR-0075 sections 1 to 6 | Unchanged. No reconciliation between cycles is added (A3.9, item 3). | | ADR-0049 | Unchanged: no deletion; retention of the retired slices stays the maintainer's decision. | | S13, S14, identity, ordering, key grammar | Unchanged; the import uses them as they are. | This proposal does not accept the 2026-10-26 replacement as a procedure, does not complete `O02` or `O03`, and changes no governance file. Acceptance must be recorded explicitly and followed by a separately authorized implementation issue and a -governance reconciliation that registers its atom in `SCOPE.md`. Production execution follows a reviewed, pinned implementation -and a reviewed date plan. +governance reconciliation that registers its atoms in `SCOPE.md`. Production execution follows a reviewed, pinned implementation; +the unattended run replaces the reviewed date plan of A2.6 by the guards of A3.12. ### A3.9 Considered and not adopted @@ -664,18 +669,20 @@ and a reviewed date plan. 27 trades a second of 2026-09-24, about 77 s at the 13 trades a second of the covered time on 2026-10-24. That is enough for the 3,324 gaps of at most 30 s and not for a restart gap of 299.5 s, and it would turn the loop into the REST poller that `live_ingest_server` documents it must not become. The continuous session removes the pause itself, and belongs to `O02`. -4. **A scheduled, unattended closure.** Deferred (A3.10, item 3). +4. **An operator-only closure with a reviewed date plan per run.** Not adopted: the maintainer requires an unattended system + (A3.12), and the review of A2.6 is replaced there by refusals that stop the day and signal. 5. **An atomic replacement of the slices.** As A2.8. ### A3.10 Open items for the maintainer -1. **Instruments.** BTCUSDT only is proposed. Another instrument is a later amendment, and the instruments started through the - multi-instrument unit would go through `continuous` first. -2. **Gap records.** Keep them open (proposed), or amend ADR-0044 so that an archive closure ends the open state. The second - needs a rule for the gaps that cross a midnight, which one coverage document cannot restate. -3. **Trigger.** An operator command (proposed), or a scheduled run after the UTC day closes. A scheduler would produce and - execute its own plan without the reviewed date plan that A2.6 requires; if wanted, it is a separate amendment after - several manual closures verify without a refusal. +1. **Instruments.** Every instrument of the allow-list, as the maintainer requires. The rule of A3.12 selects only days that + exist as slice families: an instrument that has no live ingest has none, and nothing happens for it. +2. **Gap records.** Amend ADR-0044, by its own amendment, so that a certified archive coverage of a whole day supersedes an + open record contained in it (proposed; the unattended operation forces the question), or keep the records open and accept + a permanent explicit-gap state. A gap that crosses a midnight needs a rule of its own, which one coverage document cannot + restate. +3. **Trigger.** Unattended, as the maintainer requires: a daily run (A3.12). Still to decide: the hour of the run, the maximum + number of days per run and who receives the failure signals. 4. **Archive availability.** The 24-hour closed-day rule of A2.4 stands. The publication lag of the archive file is not measured here. The plan records the source-observation time and refuses when the file cannot be fetched; it does not wait. 5. **Retention.** The retired slices, the directories moved aside on 2026-10-26 and the catalog dump: who keeps them and for how @@ -701,7 +708,50 @@ The runtime proof is required after implementation; this design-only proposal do only from a new reviewed plan. The duration of the retirements and their effect on the publication latency of the live service are measured and reported. -### A3.12 Acceptance record +4. **The daily run (A3.12).** Over a disposable PostgreSQL and a fake archive source: two instruments, with days in each of the + three outcomes in one run; a refusal on one day does not stop the others; a rerun after a crash completes the day; a stale + plan; an archive file that changes between two runs; the per-run bound; a second run changes nothing; no day outside the + rule changes by a byte; a verification failure restores the retired slices and signals. + +### A3.12 Unattended operation + +The requirement is that no day needs a hand. One run, started by a timer on the server, is the only actor: the A2.4 plan +followed by the A3.2 steps for every selected day, with no operator in between. + +**Selection.** For each instrument of the allow-list, in a fixed order, the run takes the closed UTC days (A2.4) whose live +revisions are slice partitions and that no `valid` archive-sourced `dt=/seg=000000.000` already closes. The selection is +bounded by the data: a day that the rule does not name is never touched, and nothing widens the set. + +**Per day, one of three outcomes**, decided by the plan and recorded: + +1. *Complete.* The slices cover the day without a pause and conserve against the archive: the run only verifies (A3.7), retires + and imports nothing, and records the evidence. +2. *Incomplete and conserved.* The run closes the day (A3.2) and verifies it. +3. *Refused.* Any refusal of A3.3 or A3.6: the day is left exactly as it is, a failure signal names the instrument, the day and + the reason, and the run goes on with the other days and instruments. The next run reconsiders the day; within a run it is + never retried and never forced. + +**What replaces the reviewed plan.** Amendment 2 required a reviewed date plan because its days were damaged and nobody could +read them. Here the review is replaced by what makes the operation safe to run alone: nothing is deleted; the retirement is +reversible by the restore path of A2.3 until the import is verified; the plan binds the archive hash and the incumbent +identities and is refused as stale if either changed; conservation proves that no live record is lost or altered; every refusal +stops that day only; the run is idempotent and takes the day lock without waiting. A run that finds a day retired and not +imported (a crash) completes it; a day whose verification fails is restored to `valid`, signalled and left. + +**Evidence and state.** No new control table (A2.6). The state of a day is read from the catalog: slices `valid`, slices +`invalid` with the archive key `valid`, or refused. The plan, its digest and the verification result are written as report +files in an operator evidence directory and emitted as signals through the existing observability seam; where the verification +of a complete day is kept durably is decided by the implementation issue, within the existing seams. + +**Bounds.** One instrument and one day at a time; a configured maximum number of days per run (a safety bound, not a policy); the +live service is never stopped and never waits for the run beyond the short lock of A3.4. + +**What this does not do.** It does not make the current day complete: a day is closed only after it ends and the archive of the +day is published. While the service runs in `cycles`, the last day or two stay incomplete and a strict read refuses them; only +the continuous session (`O02`) makes a day complete as it happens. The unattended run closes what is behind; it does not replace +the continuous session, and the system the maintainer asks for is the two together. + +### A3.13 Acceptance record Pending. Not done by this proposal: the acceptance; the governance registration of an atom; the implementation; any change of -production data; the choice of the days; the deployment; the switch of the service to the continuous session. +production data; the first run; the deployment; the switch of the service to the continuous session. From d0eae2db2ea2dd22bd0f33ab3e6f6ff044d9e1aa Mon Sep 17 00:00:00 2001 From: NeoNix <112125692+NeoNix-Lab@users.noreply.github.com> Date: Tue, 27 Oct 2026 21:25:22 +0100 Subject: [PATCH 3/7] docs(adr): Amendment 3 runs at 12:00 UTC with replace-or-mark-invalid fallback (#538) The daily run closes the previous day at 12:00 UTC. A slice day is closed when it has ended and the live checkpoint is bound to a later day (replaces the 24-hour margin for slice days). When the import is refused the day is marked invalid with the existing A2.3 reassessment and retried by the next run; a failed verification retires the imported partition too. Design only. Co-Authored-By: Claude Sonnet 5.5 --- ...multi-instrument-bybit-linear-trades-v1.md | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md index b9b6bb7..fe7c2b1 100644 --- a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md +++ b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md @@ -569,10 +569,12 @@ manifest hashes), their rows and distinct trade ids, the covered and uncovered s archive's distinct ids that no slice holds), and the open long-gap records that name the day (path, SHA-256, interval). The measured loss is the number that this amendment lacks today. -A day is refused, and nothing is changed for it, if any of the following holds: +A day is refused if any of the following holds. The first two refuse the whole operation and change nothing. Every other +one refuses the import only, and A3.12 says what is then done with the day: -- the day is not closed in UTC: its end is less than 24 hours before execution; -- the live checkpoint is bound to a partition of the day; +- the day is not closed: it has not ended in UTC, or the live checkpoint is not yet bound to a partition of a later day + (ADR-0042 keeps the key monotonic, so no slice of the day can still arrive). For a slice day this replaces the 24-hour margin + of A2.4; - a live revision of the day is `writing` or `closed`; - **conservation fails.** Every record of every `valid` slice, by `(exchange_ts, trade_id)`, must be found with equal venue, instrument, exchange time, side, price and size in the archive file of its own UTC day, and that day must be readable after @@ -681,10 +683,12 @@ the unattended run replaces the reviewed date plan of A2.6 by the guards of A3.1 open record contained in it (proposed; the unattended operation forces the question), or keep the records open and accept a permanent explicit-gap state. A gap that crosses a midnight needs a rule of its own, which one coverage document cannot restate. -3. **Trigger.** Unattended, as the maintainer requires: a daily run (A3.12). Still to decide: the hour of the run, the maximum - number of days per run and who receives the failure signals. -4. **Archive availability.** The 24-hour closed-day rule of A2.4 stands. The publication lag of the archive file is not measured - here. The plan records the source-observation time and refuses when the file cannot be fetched; it does not wait. +3. **Trigger.** Unattended, as the maintainer requires: a daily run at 12:00 UTC for the previous day (A3.12). Still to + decide: the maximum number of days per run and who receives the failure signals. +4. **Archive availability.** The publication time of the archive file is not measured here, so it is not known whether the file + of the previous day exists at 12:00 UTC. The plan records the source-observation time and never waits: a run that cannot + fetch the file takes the fallback of A3.12 and the next run completes the day. If the file is regularly later than the run, + the hour is the thing to change. 5. **Retention.** The retired slices, the directories moved aside on 2026-10-26 and the catalog dump: who keeps them and for how long (ADR-0049). 6. **Complete live days.** A day that the continuous session published without a pause is never replaced (A3.7). Say so @@ -711,32 +715,48 @@ The runtime proof is required after implementation; this design-only proposal do 4. **The daily run (A3.12).** Over a disposable PostgreSQL and a fake archive source: two instruments, with days in each of the three outcomes in one run; a refusal on one day does not stop the others; a rerun after a crash completes the day; a stale plan; an archive file that changes between two runs; the per-run bound; a second run changes nothing; no day outside the - rule changes by a byte; a verification failure restores the retired slices and signals. + rule changes by a byte. The fallback: an archive absent at the run leaves the day retired and the next run imports it; a + conservation difference, an overlap and a hash change each leave the day retired and signalled; a verification failure + retires the imported partition too and signals; the retired slices can be restored to `valid` by the A2.3 restore path. ### A3.12 Unattended operation The requirement is that no day needs a hand. One run, started by a timer on the server, is the only actor: the A2.4 plan followed by the A3.2 steps for every selected day, with no operator in between. -**Selection.** For each instrument of the allow-list, in a fixed order, the run takes the closed UTC days (A2.4) whose live +**Schedule.** Once a day at 12:00 UTC, for the previous UTC day and for any earlier day still not closed. The hour is a +configuration of the timer, not of the data. + +**Selection.** For each instrument of the allow-list, in a fixed order, the run takes the closed days (A3.3) whose live revisions are slice partitions and that no `valid` archive-sourced `dt=/seg=000000.000` already closes. The selection is bounded by the data: a day that the rule does not name is never touched, and nothing widens the set. -**Per day, one of three outcomes**, decided by the plan and recorded: - -1. *Complete.* The slices cover the day without a pause and conserve against the archive: the run only verifies (A3.7), retires - and imports nothing, and records the evidence. -2. *Incomplete and conserved.* The run closes the day (A3.2) and verifies it. -3. *Refused.* Any refusal of A3.3 or A3.6: the day is left exactly as it is, a failure signal names the instrument, the day and - the reason, and the run goes on with the other days and instruments. The next run reconsiders the day; within a run it is - never retried and never forced. +**Per day.** The run plans the day and then does one of these, decided by the plan and recorded: + +1. *The slices are complete and conserve against the archive.* The run only verifies (A3.7), retires and imports nothing, and + records the evidence. +2. *The slices are incomplete, the archive is fetched and conserved, and nothing overlaps.* The run replaces the day for its + whole length: it retires every slice, imports the archive day and verifies it (A3.2). +3. *Anything else that refuses the import:* the archive cannot be fetched or parsed, its hash changed, a live record differs + from the archive, an overlap, a gap record that is not contained, a bridge slice without its neighbour. The run **marks the + day invalid** with what exists already: it retires every slice with the A2.3 reassessment (`valid -> invalid`), writes + nothing else, and signals. The day is then honestly not served (a strict read refuses it with `NoCoverage`) instead of being + served incomplete or suspect, and the retired slices keep their bytes and can be restored. Because retired slices do not + occupy the day (A3.2), the next run takes the same day again from item 2. +4. *A verification that fails after the import.* The run retires the imported partition as well, so the day is not served, and + signals. +5. *The whole operation refused* (the day is not closed; a slice is `writing` or `closed`): nothing changes and the run signals. + +A signal names the instrument, the day, the reason and the number of days the day has been unclosed. The run goes on with the +other days and instruments. A day is retried by every later run, never within the same run and never forced; a day that is +still unclosed after repeated runs is a signal of higher severity, not a silent state. **What replaces the reviewed plan.** Amendment 2 required a reviewed date plan because its days were damaged and nobody could -read them. Here the review is replaced by what makes the operation safe to run alone: nothing is deleted; the retirement is -reversible by the restore path of A2.3 until the import is verified; the plan binds the archive hash and the incumbent -identities and is refused as stale if either changed; conservation proves that no live record is lost or altered; every refusal -stops that day only; the run is idempotent and takes the day lock without waiting. A run that finds a day retired and not -imported (a crash) completes it; a day whose verification fails is restored to `valid`, signalled and left. +read them. Here the review is replaced by what makes the operation safe to run alone: nothing is deleted; every retirement is +reversible by the restore path of A2.3; the plan binds the archive hash and the incumbent identities and is refused as stale if +either changed; conservation proves that no live record is lost or altered before any replacement; every failure stops that day +only; the run is idempotent and takes the day lock without waiting. A run that finds a day retired and not imported, whether +after a crash or after a fallback, completes it. **Evidence and state.** No new control table (A2.6). The state of a day is read from the catalog: slices `valid`, slices `invalid` with the archive key `valid`, or refused. The plan, its digest and the verification result are written as report @@ -746,9 +766,10 @@ of a complete day is kept durably is decided by the implementation issue, within **Bounds.** One instrument and one day at a time; a configured maximum number of days per run (a safety bound, not a policy); the live service is never stopped and never waits for the run beyond the short lock of A3.4. -**What this does not do.** It does not make the current day complete: a day is closed only after it ends and the archive of the -day is published. While the service runs in `cycles`, the last day or two stay incomplete and a strict read refuses them; only -the continuous session (`O02`) makes a day complete as it happens. The unattended run closes what is behind; it does not replace +**What this does not do.** It does not make the current day complete: a day is closed only after it ends, at the next 12:00 UTC +run, and from an archive file that exists by then. While the service runs in `cycles`, the day being written is incomplete and a +strict read refuses it, and a day whose archive is late stays marked invalid until the run that finds it; only the continuous +session (`O02`) makes a day complete as it happens. The unattended run closes what is behind; it does not replace the continuous session, and the system the maintainer asks for is the two together. ### A3.13 Acceptance record From c8728906ba4c539cb42de9038bfe6c7e1861f71c Mon Sep 17 00:00:00 2001 From: NeoNix <112125692+NeoNix-Lab@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:31:39 +0100 Subject: [PATCH 4/7] docs(adr): Amendment 3 retries hourly and never blocks the live service (#538) Co-Authored-By: Claude Sonnet 5.5 --- ...multi-instrument-bybit-linear-trades-v1.md | 66 ++++++++++++++----- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md index fe7c2b1..0dd8c6e 100644 --- a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md +++ b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md @@ -602,6 +602,21 @@ one refuses the import only, and A3.12 says what is then done with the day: live publication takes, for a short transaction. The service writes slices of the current day, never of a closed one. The closure of a `cycles` day is about 3,300 such transactions; their total duration and their effect on the publication latency of the live service are to be measured by the implementation proof, not assumed. +- **The live service is never blocked by the closure.** This is a requirement of the design, not a property assumed of it. The + closure is a separate process, started by its own timer, outside the process and the unit of the live service, which neither + starts it, waits for it nor reads its state; the closure can fail, hang or be killed without the service noticing. The one + resource that both touch is the dataset row lock, and the rule is that the closure always yields: + 1. every lock is requested with a short `lock_timeout`; a lock not granted in time ends the attempt on that day, which is + resumed by the next run (the state is read from the catalog, so nothing is lost); + 2. every transaction retires or publishes one object and commits; the closure never holds a lock across a download, a parse + or a verification; + 3. the retirements are paced: a pause between two transactions that is at least as long as the longest one, so that the + service finds the lock free between them; + 4. the heavy work (download, parse, S13/S14 certification, verification) holds no catalog lock and runs under CPU and memory + limits of its own unit and a lower scheduling priority, so that it cannot starve the service or the database; + 5. the whole run has a wall-clock limit, after which it is stopped and the next run resumes. + How much the pacing and the limits cost, and that the publication latency of the service does not grow beyond a stated bound + while the closure runs, are measured by A3.11 and reported; if the bound is not met, the pacing is tightened, not the bound. - **Untouched.** The live checkpoint, the long-gap record files, the manifests, the bytes of the retired slices, other days and other datasets. No deletion, catalog reset or retention is part of the operation ([ADR-0049](ADR-0049-retention-deletion-authority-v1.md)). @@ -683,12 +698,13 @@ the unattended run replaces the reviewed date plan of A2.6 by the guards of A3.1 open record contained in it (proposed; the unattended operation forces the question), or keep the records open and accept a permanent explicit-gap state. A gap that crosses a midnight needs a rule of its own, which one coverage document cannot restate. -3. **Trigger.** Unattended, as the maintainer requires: a daily run at 12:00 UTC for the previous day (A3.12). Still to - decide: the maximum number of days per run and who receives the failure signals. +3. **Trigger.** Unattended, as the maintainer requires: from 12:00 UTC of the following day, retried every hour (A3.12). Still + to decide: the maximum number of days per run, the age after which a day that stays unclosed raises the severity of its signal, + and who receives the failure signals. 4. **Archive availability.** The publication time of the archive file is not measured here, so it is not known whether the file of the previous day exists at 12:00 UTC. The plan records the source-observation time and never waits: a run that cannot - fetch the file takes the fallback of A3.12 and the next run completes the day. If the file is regularly later than the run, - the hour is the thing to change. + fetch the file takes the fallback of A3.12 and the next hourly run completes the day. If the file is regularly later than + 12:00 UTC, the first hour is the thing to change; the hourly retry already absorbs a late file. 5. **Retention.** The retired slices, the directories moved aside on 2026-10-26 and the catalog dump: who keeps them and for how long (ADR-0049). 6. **Complete live days.** A day that the continuous session published without a pause is never replaced (A3.7). Say so @@ -710,22 +726,35 @@ The runtime proof is required after implementation; this design-only proposal do 2. **The overlap guard of A3.6** in the plan of R02, with its own probe. 3. **Operation.** Dry-run, execute and verify on `2026-10-24` first (the first closed slice day); `2026-10-25` and later days only from a new reviewed plan. The duration of the retirements and their effect on the publication latency of the live - service are measured and reported. + service are measured and reported (item 5). -4. **The daily run (A3.12).** Over a disposable PostgreSQL and a fake archive source: two instruments, with days in each of the +4. **The unattended run (A3.12).** Over a disposable PostgreSQL and a fake archive source: two instruments, with days in each of the three outcomes in one run; a refusal on one day does not stop the others; a rerun after a crash completes the day; a stale plan; an archive file that changes between two runs; the per-run bound; a second run changes nothing; no day outside the rule changes by a byte. The fallback: an archive absent at the run leaves the day retired and the next run imports it; a conservation difference, an overlap and a hash change each leave the day retired and signalled; a verification failure retires the imported partition too and signals; the retired slices can be restored to `valid` by the A2.3 restore path. + The hourly retry: a day refused at the first attempt is taken again by the next run without retiring anything twice; a day + that cannot be closed (a conservation difference) is retried every hour without producing a signal per hour; a run that finds + nothing to do reads the catalog and ends. +5. **The live service is not blocked (A3.4).** With the real service publishing slices on a disposable PostgreSQL, a closure runs + and the publication latency of the service (the time of a cycle's publish) is measured before, during and after it: it does + not exceed the stated bound. Probes: a lock held by the live publication makes the closure yield and resume at the next run + with no change to the day; a lock held by the closure beyond the timeout is never waited for by the service; a closure that + hangs, is killed or crashes mid-run leaves the service publishing and the catalog consistent; the closure's unit stays + inside its CPU and memory limits during an import of a full day; the service starts, restarts and runs without the closure + installed. ### A3.12 Unattended operation The requirement is that no day needs a hand. One run, started by a timer on the server, is the only actor: the A2.4 plan followed by the A3.2 steps for every selected day, with no operator in between. -**Schedule.** Once a day at 12:00 UTC, for the previous UTC day and for any earlier day still not closed. The hour is a -configuration of the timer, not of the data. +**Schedule.** A timer starts the run every hour. A day is taken from 12:00 UTC of the following UTC day (the previous day +at its first attempt) and then at every later run until it is closed; an earlier day still not closed is taken in the same +way. Before 12:00 UTC the run finds no day to take and ends after one catalog read. The first hour and the interval are +configuration of the timer, not of the data. A run takes the run lock without waiting: a run that starts while the previous one +is still going ends at once. **Selection.** For each instrument of the allow-list, in a fixed order, the run takes the closed days (A3.3) whose live revisions are slice partitions and that no `valid` archive-sourced `dt=/seg=000000.000` already closes. The selection is @@ -742,14 +771,17 @@ bounded by the data: a day that the rule does not name is never touched, and not day invalid** with what exists already: it retires every slice with the A2.3 reassessment (`valid -> invalid`), writes nothing else, and signals. The day is then honestly not served (a strict read refuses it with `NoCoverage`) instead of being served incomplete or suspect, and the retired slices keep their bytes and can be restored. Because retired slices do not - occupy the day (A3.2), the next run takes the same day again from item 2. + occupy the day (A3.2), the next hourly run takes the same day again from item 2, without retiring anything a second time. 4. *A verification that fails after the import.* The run retires the imported partition as well, so the day is not served, and signals. 5. *The whole operation refused* (the day is not closed; a slice is `writing` or `closed`): nothing changes and the run signals. -A signal names the instrument, the day, the reason and the number of days the day has been unclosed. The run goes on with the -other days and instruments. A day is retried by every later run, never within the same run and never forced; a day that is -still unclosed after repeated runs is a signal of higher severity, not a silent state. +A signal names the instrument, the day, the reason and the number of hours the day has been unclosed. The run goes on with the +other days and instruments. A day is retried by every later run (hourly), never within the same run and never forced. A retry +that ends in the same refusal as the previous one is not signalled again: a signal is sent when the reason of a day changes, +when it is closed after having been signalled, and when its age crosses a threshold, so that a day that cannot be closed raises +its severity with time and does not repeat every hour. The state read by the run is the catalog, not the signals. The archive +host is asked once per day and run, and a refusal (a missing file) is not retried inside the run. **What replaces the reviewed plan.** Amendment 2 required a reviewed date plan because its days were damaged and nobody could read them. Here the review is replaced by what makes the operation safe to run alone: nothing is deleted; every retirement is @@ -763,11 +795,13 @@ after a crash or after a fallback, completes it. files in an operator evidence directory and emitted as signals through the existing observability seam; where the verification of a complete day is kept durably is decided by the implementation issue, within the existing seams. -**Bounds.** One instrument and one day at a time; a configured maximum number of days per run (a safety bound, not a policy); the -live service is never stopped and never waits for the run beyond the short lock of A3.4. +**Bounds.** One instrument and one day at a time; a configured maximum number of days per run (a safety bound, not a policy); a +wall-clock limit per run; the run's unit has CPU and memory limits and a lower priority; the live service is never stopped and +never waits for the run: A3.4 makes the closure yield on every lock, and the run is a separate process whose failure the +service does not see. -**What this does not do.** It does not make the current day complete: a day is closed only after it ends, at the next 12:00 UTC -run, and from an archive file that exists by then. While the service runs in `cycles`, the day being written is incomplete and a +**What this does not do.** It does not make the current day complete: a day is closed only after it ends, at the first run from 12:00 UTC +that finds its archive file. While the service runs in `cycles`, the day being written is incomplete and a strict read refuses it, and a day whose archive is late stays marked invalid until the run that finds it; only the continuous session (`O02`) makes a day complete as it happens. The unattended run closes what is behind; it does not replace the continuous session, and the system the maintainer asks for is the two together. From 7390017734fdc46af48921e83340c787348c3ffe Mon Sep 17 00:00:00 2001 From: NeoNix <112125692+NeoNix-Lab@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:38:11 +0100 Subject: [PATCH 5/7] docs(adr): Amendment 3 abandons a day after 23 attempts and signals to a JSON-lines log (#538) Co-Authored-By: Claude Sonnet 5.5 --- ...multi-instrument-bybit-linear-trades-v1.md | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md index 0dd8c6e..84076f7 100644 --- a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md +++ b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md @@ -698,9 +698,9 @@ the unattended run replaces the reviewed date plan of A2.6 by the guards of A3.1 open record contained in it (proposed; the unattended operation forces the question), or keep the records open and accept a permanent explicit-gap state. A gap that crosses a midnight needs a rule of its own, which one coverage document cannot restate. -3. **Trigger.** Unattended, as the maintainer requires: from 12:00 UTC of the following day, retried every hour (A3.12). Still - to decide: the maximum number of days per run, the age after which a day that stays unclosed raises the severity of its signal, - and who receives the failure signals. +3. **Trigger, bound and signals (decided by the maintainer, 2026-10-28).** Unattended: from 12:00 UTC of the following day, + retried every hour; a day that is not closed after 23 attempts is marked invalid and abandoned; the signals are lines + appended to a JSON-lines log, nothing else for now (A3.12). 4. **Archive availability.** The publication time of the archive file is not measured here, so it is not known whether the file of the previous day exists at 12:00 UTC. The plan records the source-observation time and never waits: a run that cannot fetch the file takes the fallback of A3.12 and the next hourly run completes the day. If the file is regularly later than @@ -735,8 +735,12 @@ The runtime proof is required after implementation; this design-only proposal do conservation difference, an overlap and a hash change each leave the day retired and signalled; a verification failure retires the imported partition too and signals; the retired slices can be restored to `valid` by the A2.3 restore path. The hourly retry: a day refused at the first attempt is taken again by the next run without retiring anything twice; a day - that cannot be closed (a conservation difference) is retried every hour without producing a signal per hour; a run that finds - nothing to do reads the catalog and ends. + that cannot be closed (a conservation difference) is retried every hour; a run that finds nothing to do reads the catalog and + ends. The attempts: the 23rd attempt that does not close a day leaves it invalid and abandoned, the 24th run does not take + it, and an attempt that closes the day on the 23rd is not abandoned; a day that is not closed yet is not counted; a run + cut by its wall-clock limit does not count the days it did not reach; a crash between the catalog change and the log append + costs at most one more attempt; a lost log restarts the counts and changes no data; the log is only appended to, one line per + attempt, and a line is never rewritten. 5. **The live service is not blocked (A3.4).** With the real service publishing slices on a disposable PostgreSQL, a closure runs and the publication latency of the service (the time of a cycle's publish) is measured before, during and after it: it does not exceed the stated bound. Probes: a lock held by the live publication makes the closure yield and resume at the next run @@ -776,12 +780,24 @@ bounded by the data: a day that the rule does not name is never touched, and not signals. 5. *The whole operation refused* (the day is not closed; a slice is `writing` or `closed`): nothing changes and the run signals. -A signal names the instrument, the day, the reason and the number of hours the day has been unclosed. The run goes on with the -other days and instruments. A day is retried by every later run (hourly), never within the same run and never forced. A retry -that ends in the same refusal as the previous one is not signalled again: a signal is sent when the reason of a day changes, -when it is closed after having been signalled, and when its age crosses a threshold, so that a day that cannot be closed raises -its severity with time and does not repeat every hour. The state read by the run is the catalog, not the signals. The archive -host is asked once per day and run, and a refusal (a missing file) is not retried inside the run. +**Attempts and abandonment.** An attempt is one run that takes a closed day and plans it. A day that is not closed yet is not +an attempt, and neither is a day that the run did not reach before its wall-clock limit. A day is retried by every later run +(hourly), never within the same run and never forced. If the 23rd attempt on a day does not close it, the run marks the day +invalid by retiring any slice of it that is still `valid` (item 3 above), records it as **abandoned**, and no later run takes +the day again. With no missed run, the 23rd attempt is at 10:00 UTC of the second day after the day's end. An abandoned day is +honestly not served (`NoCoverage`), its slices keep their bytes and can be restored by the A2.3 path, and what to do with it is +the operator's decision. If the day cannot be retired because a slice is `writing` or `closed` (item 5), the day is left as it +is and recorded as abandoned with that reason. Appending a `reopen` line for the day makes the run take it again, with the count +restarted. The run goes on with the other days and instruments after every attempt. + +**The log.** The signals are lines appended to one JSON-lines file in the operator evidence directory (outside Git, as the +repository rules require for operational data). One line per attempt, written after the attempt and never rewritten: +timestamp, instrument, day, attempt number, outcome (`closed`, `verified`, `retired`, `refused`, `failed`, `abandoned`, +`reopen`), reason, plan digest, archive hash and the row counts of the live day and of the archive day. The run reads the same file +for the attempt count and for the abandoned days; nothing else is read from it. The catalog remains the state of the data. The +log is the state of the attempts only, and every way in which it can go wrong is on the safe side: a line that is lost or +a log that is deleted gives more attempts, never fewer, and changes no data, because every step of the run is idempotent. The +archive host is asked once per day and run, and a refusal (a missing file) is not retried inside the run. **What replaces the reviewed plan.** Amendment 2 required a reviewed date plan because its days were damaged and nobody could read them. Here the review is replaced by what makes the operation safe to run alone: nothing is deleted; every retirement is @@ -791,12 +807,13 @@ only; the run is idempotent and takes the day lock without waiting. A run that f after a crash or after a fallback, completes it. **Evidence and state.** No new control table (A2.6). The state of a day is read from the catalog: slices `valid`, slices -`invalid` with the archive key `valid`, or refused. The plan, its digest and the verification result are written as report -files in an operator evidence directory and emitted as signals through the existing observability seam; where the verification -of a complete day is kept durably is decided by the implementation issue, within the existing seams. +`invalid` with the archive key `valid`, or refused; the attempts and the abandoned days are read from the log. The plan and +the verification result are written as report files beside the log; where the verification of a complete day is kept durably is +decided by the implementation issue, within the existing seams. -**Bounds.** One instrument and one day at a time; a configured maximum number of days per run (a safety bound, not a policy); a -wall-clock limit per run; the run's unit has CPU and memory limits and a lower priority; the live service is never stopped and +**Bounds.** One instrument and one day at a time; the days a run can take are bounded by the data and by the 23 attempts (a day +leaves the selection when it is closed or abandoned), and a wall-clock limit per run stops the rest, which waits for the next +run; the run's unit has CPU and memory limits and a lower priority; the live service is never stopped and never waits for the run: A3.4 makes the closure yield on every lock, and the run is a separate process whose failure the service does not see. From 6d18c839d045aefa43a7a2045bf661e03114cca1 Mon Sep 17 00:00:00 2001 From: NeoNix <112125692+NeoNix-Lab@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:41:32 +0100 Subject: [PATCH 6/7] docs(adr): Amendment 3 decides day validity by archive verification, not by long-gap records (#538) Co-Authored-By: Claude Sonnet 5.5 --- ...multi-instrument-bybit-linear-trades-v1.md | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md index 84076f7..7da18ba 100644 --- a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md +++ b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md @@ -628,11 +628,15 @@ closure. [ADR-0044](ADR-0044-live-ingest-long-gap-remediation-v1.md) reaches `RE cutover, and this amendment does not amend it. A record whose interval lies inside the day does not block the closure: the import is certified by S13 over the whole day. A record whose interval is not contained in the day (a gap that crosses a midnight) blocks the closure of that day until the neighbouring day is in the same plan, because one coverage document names one -partition. The record stays open. The live service keeps loading it and keeps reporting an explicit-gap session state. Run -unattended, a record left open would keep that state for good, so item 2 of A3.10 is a decision that the requirement forces: it -is proposed that a record whose whole interval lies inside a day certified `complete` from the archive be superseded by that -coverage. That amends ADR-0044, so it is a separate amendment of it and not part of this one; until it is accepted the records -stay open. +partition. The record stays open. The live service keeps loading it and keeps reporting an explicit-gap session state. + +**The validity of a day does not depend on the records (decided by the maintainer, 2026-10-28).** When a day closes, its data +are verified against the archive; if the archive is downloaded and verified within the 23 attempts of A3.12 the day is valid, +otherwise it is not. A long-gap record neither makes a day valid nor invalid. The only refusal that names a record is the +technical one above (a record whose interval is not contained in the day cannot be restated by one coverage document); such a +day is retried like any other and, if the plan still cannot be made, is abandoned after the 23 attempts. ADR-0044 is not +amended: the records are not superseded, not closed and not moved, and the explicit-gap state of the live service that an open +record causes is not ended by this amendment. That state is a property of the live service and not of the data of a day. On 2026-10-26 the record files named nine of the replaced days and were left in place; the 30 imports certified. Their effect on the live service and on the gateway after the replacement has not been checked. The open records also name 2026-10-24, the @@ -664,7 +668,7 @@ choose the date of the switch and does not depend on it. | ADR-0075 section 7, "taking the day from the Bybit archive" and "the already damaged days" | Section 7 describes that archive day as a **consolidation**, an optimization of reads opened only on a measured cost. This is a **repair** of an incomplete day on its own evidence (A3.1) and lifts the pause only for the explicitly selected, closed slice days. Consolidation of complete days is not opened. | | This ADR, Amendment 2 (A2.2, A2.4) | Extends retire-and-import to slice families. The refusal "the day has a live slice" is lifted only for the selected day's own slices, which step 1 retires; every other A2 refusal stands; A3.6 is added. | | ADR-0030 (A16) | No change of meaning. The writer of A2.3 is used per slice. | -| ADR-0044 | Not amended here: the supersession of a contained long-gap record is a separate amendment of it (A3.5, A3.10 item 2). | +| ADR-0044 | Not amended: the validity of a day is decided by the archive verification, not by the long-gap records, which stay open (A3.5, A3.10 item 2). | | ADR-0043, ADR-0075 sections 1 to 6 | Unchanged. No reconciliation between cycles is added (A3.9, item 3). | | ADR-0049 | Unchanged: no deletion; retention of the retired slices stays the maintainer's decision. | | S13, S14, identity, ordering, key grammar | Unchanged; the import uses them as they are. | @@ -694,10 +698,10 @@ the unattended run replaces the reviewed date plan of A2.6 by the guards of A3.1 1. **Instruments.** Every instrument of the allow-list, as the maintainer requires. The rule of A3.12 selects only days that exist as slice families: an instrument that has no live ingest has none, and nothing happens for it. -2. **Gap records.** Amend ADR-0044, by its own amendment, so that a certified archive coverage of a whole day supersedes an - open record contained in it (proposed; the unattended operation forces the question), or keep the records open and accept - a permanent explicit-gap state. A gap that crosses a midnight needs a rule of its own, which one coverage document cannot - restate. +2. **Gap records (decided by the maintainer, 2026-10-28).** The validity of a day is decided by the verification against the + archive within 23 attempts, not by the records; ADR-0044 is not amended and the records stay open (A3.5). Still open, and + outside this amendment: whether the explicit-gap state of the live service that an open record causes should ever end, and a + rule for a record that crosses a midnight. 3. **Trigger, bound and signals (decided by the maintainer, 2026-10-28).** Unattended: from 12:00 UTC of the following day, retried every hour; a day that is not closed after 23 attempts is marked invalid and abandoned; the signals are lines appended to a JSON-lines log, nothing else for now (A3.12). From 78930ecf5cc0f83b51d55a82e1b2c8dc511d9cef Mon Sep 17 00:00:00 2001 From: NeoNix <112125692+NeoNix-Lab@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:44:45 +0100 Subject: [PATCH 7/7] docs(adr): Amendment 3 attaches no retention duty to slices retired by an archive closure (#538) Co-Authored-By: Claude Sonnet 5.5 --- ...DR-0074-multi-instrument-bybit-linear-trades-v1.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md index 7da18ba..a8da372 100644 --- a/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md +++ b/docs/decisions/ADR-0074-multi-instrument-bybit-linear-trades-v1.md @@ -670,7 +670,7 @@ choose the date of the switch and does not depend on it. | ADR-0030 (A16) | No change of meaning. The writer of A2.3 is used per slice. | | ADR-0044 | Not amended: the validity of a day is decided by the archive verification, not by the long-gap records, which stay open (A3.5, A3.10 item 2). | | ADR-0043, ADR-0075 sections 1 to 6 | Unchanged. No reconciliation between cycles is added (A3.9, item 3). | -| ADR-0049 | Unchanged: no deletion; retention of the retired slices stays the maintainer's decision. | +| ADR-0049 | Unchanged: the run deletes nothing; the retired slices of a day closed from the archive carry no retention duty (A3.10 item 5), and their disposal, if wanted, is an ADR-0049 act and not the run's. | | S13, S14, identity, ordering, key grammar | Unchanged; the import uses them as they are. | This proposal does not accept the 2026-10-26 replacement as a procedure, does not complete `O02` or `O03`, and changes no @@ -709,8 +709,13 @@ the unattended run replaces the reviewed date plan of A2.6 by the guards of A3.1 of the previous day exists at 12:00 UTC. The plan records the source-observation time and never waits: a run that cannot fetch the file takes the fallback of A3.12 and the next hourly run completes the day. If the file is regularly later than 12:00 UTC, the first hour is the thing to change; the hourly retry already absorbs a late file. -5. **Retention.** The retired slices, the directories moved aside on 2026-10-26 and the catalog dump: who keeps them and for how - long (ADR-0049). +5. **Retention (decided by the maintainer, 2026-10-28, for the slices).** The retired slices of a day that is then closed from + the archive are not retained by this amendment: no retention period or duty is attached to them, because the conservation + check has proved that every live record is in the archive day. The run itself still deletes nothing (A3.4; + [ADR-0049](ADR-0049-retention-deletion-authority-v1.md) holds the deletion authority), so they stay in the catalog and on + disk until a disposal under ADR-0049 removes them; an automatic deletion by the run would need its own amendment of ADR-0049. + The slices of an abandoned or marked-invalid day are the only copy of that day's live data and are not covered by this + decision. Still open: the directories moved aside on 2026-10-26 and the catalog dump. 6. **Complete live days.** A day that the continuous session published without a pause is never replaced (A3.7). Say so explicitly if a replacement should ever be allowed.