Skip to content

data: R02 - operator-run rebuild of selected closed legacy live days (ADR-0074 Amendment 2) - #531

Merged
NeoNix-Lab merged 6 commits into
implement/fidfrom
agent/issue-520-dgr-r02-rebuild
Oct 25, 2026
Merged

NeoNix-Lab merged 6 commits into
implement/fidfrom
agent/issue-520-dgr-r02-rebuild

Conversation

@NeoNix-Lab

Copy link
Copy Markdown
Owner

data: R02 - operator-run rebuild of selected closed legacy live days (ADR-0074 Amendment 2)

Refs #520. Parent: DG-R (SCOPE.md Part D, R02); builds on R01 (PR #530). Post-version. Nothing here runs on the server: the execution on 2026-10-20 and any further day is the operator's, from a reviewed plan.

What changes

  • tools/rebuild_bybit_legacy_days.py over application/bybit_legacy_day_rebuild.py (BTCUSDT only): plan (read-only, writes a plan file that is never overwritten, prints its digest), execute --plan --digest (one day at a time), verify (read-only, repeatable), restore (explicit, never automatic). The DSN comes from an environment variable, never from the command line; the producing commit is the clean HEAD or --code-ref.
  • Per day, in order: retire the live revision of dt=<day> with the R01 reassessment (valid -> invalid, nothing deleted), import the whole archive day as revision 1 of dt=<day>/seg=000000.000 through the ordinary S13/S14 path, verify it (the Parquet is identical to the archive field by field, and a strict DataGateway read returns exactly the archive records, in (exchange_ts, trade_id) order, once each).
  • Importer variant (bybit_archive_import.import_bybit_archive_day_after_retirement, never a --force): the live revision of the exact key dt=<day> in the state invalid does not occupy the day; a valid/closed/degraded/writing revision of that key and every partition dt=<day>/... (the key it would create included) still refuse; the key is fixed; the lock is the day's (.import-dt=<day>.lock, the same file as the ordinary import, which a two-level key name would have broken); the coverage id carries a -rebuild suffix. The ordinary importer is unchanged and still refuses an occupied day, a retired one included.
  • Plan and digest. Per day: the incumbent (partition UUID, key, revision, hashes, coverage, assessment suite and profile read from its report, not wired), the archive file (URL, SHA-256, size, observation time, rows), the producing commit, the key to create, the conservation summary and the refusals. The executor recomputes the plan from the catalog, the files and the clock and refuses (STALE) if the digest differs; it never takes another target nor widens the days (at most 31, ascending, named by the operator). The digest binds what the operation depends on, not its progress (the incumbent's state and the action are excluded), so a plan stays current after a retire that was not followed by the import; the executor then acts on the live state of the same targets.
  • Refusals (nothing changes for the day): not closed in UTC (end less than 24 h before execution); a live slice, a checkpoint bound to one of its partitions, or an open gap record whose span overlaps it (an unreadable gap manifest refuses too); the live revision is not valid (or invalid but not retired by this operation for the same archive file); the key to create exists in another state or two valid partitions would cover the day; the incumbent's Parquet or durable manifests are missing or do not hash to the catalog's; the archive file is missing or fails Amendment 1's strict parsing; conservation: every record of the incumbent, by (exchange_ts, trade_id), exists in the archive file of its own UTC day with equal venue, instrument, exchange time (millisecond), side, price and size (a trailing zero is a text difference, not a value one), that day's archive file is present, and that day is readable afterwards (in the same plan or already valid). Any difference refuses the day: no partial acceptance.
  • Crashes: after the retire and before the import, or after the import and before the verification, the same plan run again completes (proved with injected crashes). A failure stops the run; later days are not attempted.
  • Runbook: docs/engineering/BYBIT_ARCHIVE_IMPORT_RUNBOOK.md section 6 (before, plan, execute, verify and the way back, what it does not do). CI: job legacy-day-rebuild-postgres.

Tests

  • tests/integration_bybit_legacy_day_rebuild_postgres.py, real PostgreSQL, the real importer, S13/S14, R01 and the DataGateway. Legacy-shaped days are made with the ordinary importer (a partial archive day is one valid revision of dt=<day>). Pilot-shaped day 2026-10-20: after the rebuild a strict read returns exactly the archive's records, in order, without duplicates, equal field by field, with null receive_ts and sequence; the retired incumbent's bytes, the other days' states and files, and the live checkpoint are byte-identical. Each refusal above, each on its own, leaves the catalog, every file and the checkpoint byte-identical; a wrong or edited digest and a stale plan do nothing; both crash windows are recovered by the same plan; the restore (refused over a rebuilt day, returning a retired day to valid and the day still rebuildable afterwards); a neighbouring day whose legacy coverage crossed midnight overlaps the rebuilt day (the strict read is refused) until it is rebuilt by its own plan; conservation across days (rows of a neighbouring day found, missing, differing, not readable, readable because in the plan); the variant's own guards; the verification's checks of count, order, duplicates and non-identity (with the gateway's answer altered).
  • tests/test_bybit_legacy_day_rebuild_v1.py (10): request rules, manifest naming by artifact suffix, field comparison, the digest (what it binds and what it ignores), command-line usage errors, the runbook.
  • Mutation checks: 34 changes, one at a time (retire/import skipped, the 24 h limit, each refusal, conservation parts, the neighbour rules, digest and staleness, executor choices and stop, verification checks, restore guards, the variant's key, foreign partition, valid incumbent, lock name and coverage id). Seven survived the first round, each a missing test (an unreadable gap manifest, a key to create in another state, two valid partitions, a non-identical Parquet, restoring a valid day, the variant's foreign-partition guard, the coverage id); each drove a test; all caught.
  • Measured once, synthetic, not the real archive: a day of 1,568,861 rows (the pilot's count; a ~3,000-row incumbent): plan 20 s, execute (re-plan, retire, import, verify) 101 s, peak RSS 2.4 GB, strict read 1,568,861 records, identical to the archive. Real archive content, real catalog size and the server's disk and memory are the operator's to check; the plan is read-only so it can be run first.

Not claimed

  • No run on the server, none on real data: the real 2026-10-20 file (1,568,861 rows, SHA-256 d4589…447d per the amendment), the 31-date inventory, the manifests of the real legacy days (the incumbent's manifest and coverage file names are derived from its artifact suffix and checked against the catalog hashes; whether the server's 31 days have them where this expects them is the operator's check, and a plan that cannot find them says so as a refusal) are not exercised. The 529 rows outside 2026-10-20 are handled by the conservation check across days but only proved on a crafted Parquet.
  • The loss of the provider sequence on the rows the incumbent served is declared and accepted (A2.4); the old bytes are kept. Nothing is deleted; retention of retired or superseded revisions stays the maintainer's. No A10 repair, atomic replacement, S13/S14 change, checkpoint or live-slice change, schema or governance file.
  • Between the retire and the import the day is served by nothing (by design, A2.5). I have not read this PR's CI.

Checks

Ruff, markdown links, git diff --check, workflow.py preflight --base implement/fid, package boundaries; the new PostgreSQL gate and the regression gates of the archive import, the live slices and R01 pass on a disposable PostgreSQL 16.

🤖 Generated with Claude Code

… days (ADR-0074 A2) (#520)

Plan (read-only, with a digest), execute (one day at a time: retire with R01, import the archive
day as revision 1 of dt=<day>/seg=000000.000 through S13/S14, verify) and verify, restore, as
tools/rebuild_bybit_legacy_days.py over application/bybit_legacy_day_rebuild.py.

- Importer variant: the invalid live revision of the exact key dt=<day> does not occupy the day;
  any other partition of the day still refuses; the key is fixed; the lock is the day's.
- Refusals: open day (< 24 h), live slice, checkpoint binding, open gap, incumbent not valid (or
  invalid but not retired by this operation for the same archive), failed strict parsing, and
  conservation (every incumbent record exists in the archive file of its own day with equal
  fields, and that day is readable afterwards). Nothing changes for a refused day.
- The digest binds what the operation depends on, not its progress: a crash between steps is
  recovered by running the same plan; anything changed makes it stale.
- Runbook section 6. Real-PostgreSQL gate and CI job; 34 mutants, 0 survivors; the rebuild of a
  pilot-sized synthetic day (1,568,861 rows) measured.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

CI fix (Lightweight deterministic checks): tests/test_canonical_v1.py inventories every canonical_bytes call site and the rebuild plan's digest (_digest, sorted-compact-ascii-v1, allow_nan=False) was not declared. Declared it next to the other application codecs (test file only). I had not run the full suite before opening the PR; I have now: on Windows 164 of 165, the one failure being the known environment-specific test_promote_main_v1. The PostgreSQL gates were already green.

NeoNix-Lab and others added 2 commits October 25, 2026 10:55
… plan digest (#520)

tests/test_canonical_v1.py inventories every canonical_bytes call site; the plan digest of the
R02 rebuild (sorted-compact-ascii-v1, allow_nan False) is declared there like the other
application codecs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…in the plan, refuse a duplicated trade id (#520 review)

- The live publisher before the slices (#510) wrote partition-manifest-<HHMMSS>.json and coverage-manifest-<HHMMSS>.json in the
  dataset root, not beside the Parquet. The rebuild now looks beside the artifact and then in the root, and the catalog's manifest
  hash chooses the location, so a root file that a later day overwrote in the same second is never taken for this revision's.
- The plan loads the incumbent's manifests with the S13 loader and compares the coverage hashes and ids with those its quality
  reports certified; the coverage and assertion ids are part of the plan's identity. A manifest that does not load or is not the
  certified one refuses the day in the plan, not at the retire.
- A trade id that the incumbent holds twice with different content refuses the day instead of keeping the last row.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

Review findings validated against the code and the history of the live publisher; fixed in f47d296.

B1 (CI red on test_canonical_v1) - already fixed in 66800ab (the _digest call site is declared). Not a new change.

B2 (valid): the legacy manifests are in the dataset root. Confirmed in 24d9112: the publisher before the slices wrote partition-manifest-<HHMMSS>.json and coverage-manifest-<HHMMSS>.json in the root of the dataset, the time without the date. _manifest_files looked only beside the Parquet, so a plan on the real days would have refused them all. It now looks beside the artifact and then in the dataset root, and the catalog's manifest hash chooses the location. A root file that a later day overwrote in the same second does not hash to the catalog's, so the day is refused with that reason (this refusal is the expected outcome for such a day: its manifest is not recoverable here).

M1 (valid): coverage manifest checked in the plan. The plan now loads the incumbent's manifests with the S13 loader, compares the coverage hashes and ids with those its quality reports certified (coverage_manifest_sha256, coverage_manifest_ids, present in the publication code of 24d9112 too), and records the coverage and assertion ids in the incumbent's identity (so they are in the digest). A manifest that does not load, is not the certified one, or reports that certify more than one set refuse the day in the plan, not at the retire.

M2 (valid): duplicated trade id. The incumbent's rows were put in a dict keyed by trade_id, so the last of two different rows won. A trade id held twice with different content now refuses the day; an identical duplicate is counted in the summary.

Section 3 (what to expect on the server) - both points are already covered and I added nothing for them: the neighbouring archive files are required by the conservation check (a missing one is a refusal naming the file), and a neighbour whose valid revision crosses midnight makes the strict read of the rebuilt day refuse until the neighbour is rebuilt by its own plan (section 10 of the PostgreSQL gate, runbook 6.4). The read-only look at ts_start/ts_end of the valid revisions of the days around 2026-10-20 before execute is a sensible operator step; plan does not need it.

Tests. Unit: manifest location by the catalog hash (beside, root, overwritten, both), duplicate trade ids (different and identical), the coverage and assertion ids in the digest. PostgreSQL gate: a tampered coverage manifest (not the certified one), an unreadable one, reports certifying two sets, and a day in the root layout planned with the located manifests. 7 mutants on the new code, one at a time: 6 caught at once, 1 survived (the ids not in the digest) and drove its test; all caught. Full suite 164/165 (the known Windows test_promote_main_v1); the PostgreSQL gates of the rebuild, R01 and the archive import pass on a disposable PostgreSQL 16.

Not proved. The retire with the manifests in the root layout is not exercised on PostgreSQL: simulating that layout by renaming files leaves the partition manifest naming the old artifact, and the lifecycle refuses it. The root layout is proved up to the plan (the located files and the checks); the retire only joins the same relative paths. The real server files remain the operator's check, and a plan that cannot find or verify them refuses the day and says why.

🤖 Generated with Claude Code

@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

Fallback di review per identità condivisa: GitHub ha rifiutato la review formale REQUEST_CHANGES perché autore e revisore usano lo stesso account. Questo commento registra il verdetto tecnico; non imposta lo stato formale di review.

Revisione indipendente di PR #531: REQUEST CHANGES tecnico.

Head verificato: f47d296e01b43a15f87ef9ee161777cc3ea41e88; base implement/fid @ 3ff0c4cb7439808cad2e640cab328dd1aae1fc47. Autorità: issue #520, ADR-0074 Amendment 2 A2.4/A2.5/A2.7, R01. Tre finding riprodotti sul codice invariato con PostgreSQL 16 temporaneo, S13/S14 e DataGateway reali.

  1. [P1] La conservazione fuori giorno non prova che i record restino serviti. src/quant_platform/application/bybit_legacy_day_rebuild.py:280-281 accetta il giorno vicino se esiste una sua partizione valid (_readable_without_us, righe 129-143), anche se è proprio un altro ultimo batch parziale che non contiene i trade da conservare. Ho pubblicato con il profilo live reale una revisione legacy di dt=2026-10-18 con un trade alle 23:59:59 e cross-B alle 00:00:01 del 19; la revisione valid del 19 contiene solo later-B alle 00:00:10. Entrambi i trade del 19 esistono e coincidono nell'archivio del 19. Prima del rebuild, il gateway serve ['cross-B', 'later-B']; il piano del solo 18 non ha rifiuti, l'esecuzione restituisce rebuilt e verification.passed=true, ma dopo il gateway serve solo ['later-B']. I vecchi byte restano, ma un record prima servito scompare dalle letture. Anche la scorciatoia owner in plan_days è insufficiente: includendo il 19 nel piano ma rendendolo closed, il piano dà ['retire+import', 'refused'], esegue ['rebuilt', 'refused'] e perde ugualmente cross-B. Occorre provare la leggibilità effettiva dei record interessati al di fuori della revisione da ritirare; un giorno nel piano può contribuire solo se sarà effettivamente ricostruito. In assenza della prova, il giorno dipendente va rifiutato prima del ritiro. Questo viola la conservazione di A2.4, non è il buco temporaneo tra retire e import accettato da A2.5.

  2. [P1] restore e import non condividono la guardia sul giorno: possono lasciare due partizioni valid. src/quant_platform/application/bybit_archive_import.py:178-183 ricontrolla l'incumbent prima della lettura/materializzazione, ma rilascia la transazione; restore_retired_day (bybit_legacy_day_rebuild.py:647-663) non prende il lock del giorno dell'importer. Ho sospeso deterministicamente l'importer subito prima della materializzazione, dopo entrambi i controlli invalid, ed eseguito il vero restore_retired_day da una seconda connessione: il restore termina valid, poi l'import completa S13/S14 e termina anch'esso valid. Catalogo finale: dt=2026-10-18 = valid, dt=2026-10-18/seg=000000.000 = valid. Il confronto fisico è identico (8/8), ma il gateway strict rifiuta con CatalogConflict: eligible partitions have unexplained temporal overlap. I lock brevi sul dataset serializzano le singole transazioni, senza preservare la precondizione fra controllo e pubblicazione. Serve coordinare restore e import con la stessa guardia per giorno e rivalidare la precondizione protetta nella pubblicazione; nessuna necessità di un cutover atomico o di bloccare il dataset durante la lettura dell'archivio.

  3. [P1] Il contenuto importato non è vincolato all'hash del piano approvato. src/quant_platform/application/bybit_legacy_day_rebuild.py:560-565 passa all'importer solo il percorso; l'hash atteso non viene passato né verificato. Il re-plan iniziale non protegge le successive letture dell'archivio. Ho presentato un piano valido, lasciato eseguire il vero ritiro, poi sostituito il file con un altro gzip perfettamente valido dello stesso giorno, con 8 ID differenti. Risultato: hash pianificato 791e852f...2ad91, hash effettivamente importato aebb476b...437cb; l'esecutore restituisce il digest originario, outcome=rebuilt, verification.passed=true. I 4 ID dell'incumbent prima leggibili scompaiono tutti: la conservazione era stata verificata sul vecchio file, mentre import e verify usano entrambi quello sostituito. Succede anche senza concorrenza sul catalogo e la finestra può allungarsi in un piano di più giorni. Occorre vincolare i byte realmente parsati/materializzati alla SHA-256 approvata e alla stessa fonte usata per la conservazione; anche la verifica deve mantenere quel vincolo, anziché accettare il file corrente qualunque esso sia.

Verifiche positive, che non coprono questi casi:

  • pytest mirato: 63 passati, 1 skip (campione archivio esterno assente), 115 subtest passati: regole R02, source/comparator archivio, R01, package boundaries.
  • PostgreSQL 16 temporaneo: gate R02, import archivio, R01 e live slices 4/4 passati.
  • Ruff sui file di produzione/test interessati, link Markdown (124 documenti), git diff --check, preflight su implement/fid: passati.
  • CI run 40183657899: 13/13 job verdi, compreso PostgreSQL 17 R02. Letto il log della suite: 165/165 script. Il log conferma il merge sintetico 746c794805c7534bfb1730cd74b0a6d629a99d1e di questo esatto head nella base sopra.

Prove locali conservate in /var/tmp/qp-review531-lftl6arf: adversarial.py, adversarial-logged.py, adversarial.log, refused-neighbour-logged.py/.log, source-race.py/.log e i quattro log dei gate. Per R1 il fixture è pubblicato tramite il profilo live reale; per R2 solo il punto di interleaving è strumentato, restore/import/catalogo sono reali; per R3 solo la sostituzione esterna del file viene programmata al confine tra ritiro e import. Nessun codice della PR modificato. Nessun merge, push, deploy o operazione sui dati reali; nessuna prova del pilot operativo o della scala di 1,568,861 righe dichiarata dall'autore rieseguita in questa revisione.

…the restore, bind the import to the approved archive hash (#520 review)

- The records of the incumbent that belong to another day must stay served: a valid partition of that day must hold those very records,
  or that day must be in the same plan and not refused (a refused day contributes nothing; the refusal propagates). Decided in the plan,
  before the retire. The plan also binds the hash of every neighbouring archive file it read.
- The restore takes the day's import lock and decides under it: it cannot slip in between the import's check and its publication, so the
  two cannot leave both partitions valid.
- The rebuild import and the verification check the SHA-256 of the bytes they parse against the plan's: a file replaced after the plan is
  refused (SOURCE), a file replaced after the import fails the verification. `verify --plan` binds a standalone verification too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

The three P1 of the review of f47d296 are valid; fixed in a555550. I did not re-run the reviewer's reproductions on the old code: I confirmed the cause of each in the code the report points to, and the new PostgreSQL sections 12-14 exercise the fixed behaviour.

P1-1, conservation of other days' records (valid). _readable_without_us accepted any valid partition of the neighbouring day, and the owner in plan_days shortcut accepted a day that the same plan then refused. Now the plan decides, before any retire:

  • the records of the incumbent that belong to another day are collected (outside); outside_held[day] says whether a valid partition of that day holds those very trade ids (read from its Parquet; a partial later batch, or a closed partition, does not count);
  • a second pass over the plan (_resolve_dependencies) refuses a day whose records are held by no valid partition and whose owner day is not in the plan or is in the plan and refused; the refusal propagates along the chain until nothing changes. A day that is already retired is not judged again.
  • The plan's conservation summary carries the SHA-256 of every neighbouring archive file it read (so the digest binds them) and outside_held.
    Test (gate section 12): an incumbent holding two trades of the next day, whose own valid revision is a later partial batch: refused alone; refused with the next day in the plan but closed; both rebuilt when the next day is in the plan and not refused (the two trades are served afterwards); and a day whose neighbour's valid partition does hold them is planned. Unit: the dependency rules and the chain.
    Honest limit: if a run stops after a day that depended on a later day of the plan, that later day is retired or untouched (A2.5's hole, now written in the runbook).

P1-2, restore vs import (valid). restore_retired_day did not take the day's lock. It now takes .import-dt=<day>.lock (the one the rebuild import holds from its check to its publication; the lock never waits, so the restore is refused RESTORE while an import runs) and decides under it. An import after a restore finds a valid day and refuses, as before. Test (section 13): the lock held refuses the restore; and the deterministic interleaving - the restore attempted from inside the import, after its checks and before the materialization - is refused, the import completes, the catalog ends with the legacy revision invalid and the rebuilt one valid, and a strict read works.

P1-3, the digest and the imported bytes (valid). The importer variant now requires expected_source_sha256 and refuses (SOURCE, before anything is written) bytes that hash to something else; compare_archive_day_with_parquet reports the hash of the bytes it compared; verify_rebuilt_day(expected_archive_sha256=...) makes another file a finding; the executor passes the plan's hash to both. verify --plan FILE binds a standalone verification too. Test (section 14): a file replaced between the retire and the import is import_refused/SOURCE (the day stays retired, nothing created) and resumes with the approved file; a file replaced after the import is verify_failed; a verification of another file does not pass.

Checks. 12 mutants on the new code, one at a time: 11 caught; one survived (the held check counting a partition that is not valid) and drove a test; all caught. Full suite 164/165 (the known Windows test_promote_main_v1); PostgreSQL 16 gates of the rebuild, R01 and the archive import pass; Ruff and git diff --check clean. The live-slices gate and the CI jobs on this commit I have not run/read.

Not claimed: nothing on the server or on real data; the retire in the legacy root layout is still proved only up to the plan (see the previous comment).

🤖 Generated with Claude Code

@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

Fallback per identità condivisa: GitHub ha rifiutato la review formale REQUEST_CHANGES perché autore e revisore usano lo stesso account. Questo è il verdetto tecnico della rivalidazione, non uno stato di review formale.

Rivalidazione indipendente di PR #531: REQUEST CHANGES tecnico su un nuovo P2. I tre P1 della revisione precedente sono corretti.

Head: a555550d0e8131be8c98987e0133ed320da9e905; base invariata implement/fid @ 3ff0c4cb7439808cad2e640cab328dd1aae1fc47. Confrontato il fix con f47d296, con issue #520 e con ADR-0074 A2.4/A2.5/A2.7. Nessuna modifica al codice della PR.

[P2] Il progresso di un piano con giorni collegati modifica il digest e impedisce il recupero con lo stesso piano. In src/quant_platform/application/bybit_legacy_day_rebuild.py:449-451, conservation.outside_held viene ricalcolato dal catalogo corrente; _digest (riga 338) include tutto conservation, quindi include anche questo valore che il rebuild stesso cambia. Il digest esclude state/action/created proprio per non vincolare il progresso, ma questa nuova proprietà lo reintroduce indirettamente.

Riproduzione con PostgreSQL reale e gli stessi costruttori di fixture live della prima review:

  • A = 2026-10-18: la sua revisione legacy serve un trade del 18 e cross-B del 19. B = 2026-10-19: la sua revisione legacy serve solo later-B. Entrambi gli archivi completi sono presenti. Il piano seleziona esplicitamente A e B e consente entrambi i rebuild; A ha outside_held[B]=false, con dipendenza soddisfatta dal rebuild di B nel piano.
  • L'esecutore ricostruisce A, poi ritira e importa B. Inietto un crash immediatamente prima della verifica di B, senza alterare file sorgente o catalogo dall'esterno: esattamente la seconda finestra di crash di A2.5.
  • Al retry, i due giorni hanno legittimamente azione verify, ma A ha ora outside_held[B]=true, perché B ricostruito serve cross-B. Il digest cambia da 8908c181...33057c a d25bbf30...f1a7b1; presentando il piano originale, execute_rebuild rifiuta STALE prima di verificare.
  • Ho isolato la causa: cambiare soltanto outside_held[B] da true a false nel piano corrente ricostruisce esattamente il digest originale. Entrambe le verifiche indipendenti dei giorni passano: i dati sono integri, è il recupero dichiarato con il medesimo piano/digest a non funzionare. Servirebbe un nuovo piano da rivedere per un progresso interamente previsto dal piano già approvato.

Distinguere nel digest le prove vincolanti e immutabili dal progresso previsto dei target della stessa esecuzione, mantenendo i controlli sui cambiamenti esterni; aggiungere una regressione di crash/retry di un piano multi-giorno con una reale dipendenza di conservazione. Non basta il retry di un giorno isolato. Violati il recupero con lo stesso piano di A2.5 e il criterio 3 della #520.

Chiusura dei finding precedenti (prove ripetute, non solo lettura dei nuovi test):

  • P1 conservazione: il vicino valid privo di cross-B viene rifiutato; se il vicino è nel piano ma refused, vengono rifiutati entrambi. Snapshot di catalogo e file invariati dopo l'esecuzione dei piani rifiutati.
  • P1 restore/import: stesso punto di interleaving alla materializzazione, con il vero restore su una seconda connessione; il restore viene rifiutato dal lock, l'import termina valid con il legacy invalid e la verifica strict passa. Per la nuova firma dell'importer è stato fornito l'hash del piano.
  • P1 fonte/digest: stessa sostituzione del gzip dopo il vero ritiro; import rifiutato in fase SOURCE e nessuna nuova partizione. Ripristinando file e osservazione temporale originali, il medesimo piano riparte e completa il giorno isolato.

Verifiche: 68 test mirati passati, 1 skip (campione archivio esterno assente), 115 subtest; i quattro gate PostgreSQL 16 (R02, import archivio, R01, live slices) passati; Ruff, Markdown (124 file), diff check e preflight sulla base passati. CI run 40203958545: 13/13 job verdi, PostgreSQL 17 R02 incluso; log suite letto: 165/165 script. Il merge sintetico 9dc9e8bbcb52ec4ca932ca3b18577d2714d0a774 contiene questo esatto head e la base sopra.

Prove: /var/tmp/qp-review531-a555550-1qxjs_24/recheck-and-crash.py e .log, progress-diagnostic.py, progress-digest-before.json, progress-digest-after.json, più i quattro log dei gate. I probe precedenti restano conservati in /var/tmp/qp-review531-lftl6arf; per questa esecuzione sono riusati i costruttori di fixture, con aspettative aggiornate al comportamento corretto e il solo adattamento della nuova firma dell'importer. Nessun merge, push, deploy o operazione sui dati reali; il pilot operativo e la misura di scala dell'autore non sono parte di questa rivalidazione.

@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

The P2 of the revalidation of a555550 is valid. conservation.outside_held is progress: it turns true when the plan itself rebuilds the other day, and it sat inside the digest, so the second crash window of A2.5 on a plan of linked days made the original plan STALE.

Fix. _digest leaves outside_held out of the conservation it binds. Nothing the check protects is lost: what the value means for the plan is its refusals (a held record no longer held, or a day of the plan no longer rebuildable, refuses the day), and the refusals stay in the digest. The executor still acts on the live state of the same targets.

Tests.

  • PostgreSQL gate, new section 12b: two linked days (the first holds two trades of the second; the second's valid revision is a later partial batch), A rebuilt, B retired and imported, crash injected immediately before B's verification. The plan made again has both days at verify, outside_held[B] has gone false -> true, the digest equals the original, and the same plan and digest complete with verified, verified and two strict reads equal to the archives. With outside_held put back in the digest this test fails on the digest assertion (checked by hand).
  • Section 12: a change from outside (the owner day's valid partition becomes closed) still refuses the day and changes the digest; put back, the digest is the original.
  • Unit: outside_held moved from "what the digest binds" to "progress is not part of the digest".
  • 2 mutants (held decision in the digest; refusals out of the digest): both caught.

Full suite 164/165 (the known Windows test_promote_main_v1); the PostgreSQL 16 gates of the rebuild, R01 and the archive import pass; Ruff and git diff --check clean. CI on this commit not read.

🤖 Generated with Claude Code

…digest (#520 review)

`outside_held` (whether a valid partition of another day holds the incumbent's records of that day) turns true when the plan itself
rebuilds that day, so it was progress inside the digest and a crash before the second day's verification made the original plan STALE.
It is left out of the digest; its consequence for the plan is in the refusals, which stay bound, so a change from outside still changes
the digest.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

Fallback per identità condivisa: GitHub ha rifiutato la review formale REQUEST_CHANGES perché autore e revisore usano lo stesso account. Questo commento registra il verdetto tecnico, non lo stato di review formale.

Rivalidazione indipendente PR #531, head 0b1368c3e75cbcd0d09baa78d7bf199fb7f19e9f, base invariata implement/fid @ 3ff0c4cb7439808cad2e640cab328dd1aae1fc47: REQUEST CHANGES tecnico per un nuovo P2 sul controllo dei cambiamenti esterni al retry.

Il P2 della review precedente è corretto: ho ripetuto il medesimo fixture live A/B con cross-B e il crash prima della verifica di B. outside_held[B] passa false -> true, il digest resta identico e il piano originale completa con ['verified', 'verified']. Restano superate anche le prove dei tre P1: vicino privo dei trade rifiutato, vicino nel piano ma refused propagato senza mutazioni, restore da seconda connessione respinto durante import, fonte sostituita dopo ritiro respinta SOURCE senza nuova partizione; il giorno isolato riparte con file/mtime originali e lo stesso piano.

[P2] L'esclusione incondizionata di outside_held nasconde una dipendenza esterna persa dopo il ritiro. src/quant_platform/application/bybit_legacy_day_rebuild.py:343 rimuove dal digest l'intero outside_held, anche per i giorni non selezionati nel piano. La motivazione nelle righe 333-335 dice che un cambiamento esterno continuerà a produrre rifiuti e quindi cambierà il digest. Questo non vale per un retry dopo il ritiro: _resolve_dependencies, righe 490-491, salta le azioni import e verify, quindi il nuovo rifiuto non viene prodotto.

Riproduzione su PostgreSQL 16 temporaneo, con pubblicazioni live/S13/S14 e ritiro R01 reali:

  1. A = 2026-10-18 contiene un trade del 18 e cross-B del 19. B = 2026-10-19 contiene cross-B e later-B; è valid e conserva effettivamente quei record. Il piano seleziona solo A e viene accettato grazie a outside_held[B]=true.
  2. Eseguo il vero ritiro di A e simulo l'interruzione prima del suo import. In questo momento il gateway serve ancora cross-B e later-B da B.
  3. Una seconda operazione ritira B tramite R01. B non è un target del piano originale: è un cambiamento esterno della dipendenza di conservazione, non il progresso atteso di quel piano.
  4. Il re-plan di A vede correttamente outside_held[B]=false, ma l'azione è import, i rifiuti restano vuoti e il digest resta esattamente 88741278...c95a93. L'esecuzione con il piano originale non rifiuta STALE: importa A e restituisce outcome=rebuilt, verification.passed=true, benché B non sia più leggibile (gateway=None).

La perdita di copertura di B avviene già con la seconda operazione: non attribuisco al retry di A una cancellazione o un nuovo P1 di perdita dei byte. Il difetto è accettare il piano obsoleto e certificare il suo completamento senza più la condizione di conservazione esterna sulla quale era stato approvato. Il controllo A2.4 sui cambiamenti di catalogo e la promessa del fix nelle righe 333-335 non sono soddisfatti. Il digest precedente, che includeva questo booleano, rilevava la differenza.

Distinguere il progresso dei target del medesimo piano dalle dipendenze esterne: mantenere il controllo della conservazione esterna anche nei retry import/verify, oppure vincolarne la prova nel digest senza vincolare il progresso interno. Coprire entrambi i casi: progresso A/B nello stesso piano consentito, ritiro esterno di B fra ritiro e retry di A rifiutato prima di nuove mutazioni.

Verifiche positive: 68 test mirati, 1 skip (campione archivio esterno assente), 115 subtest; 4/4 gate PostgreSQL 16 (R02, import archivio, R01, live slices); Ruff, Markdown (124 file), diff check e preflight passati. CI 40205211488: 13/13 job verdi, suite 165/165 script, log letto sul merge sintetico 1badfb53040a74dda2569339dbc3ab5b54e62797 di questo esatto head nella base sopra.

Prove conservate: /var/tmp/qp-review531-0b1368c-wpdjw760/recheck-and-crash.py/.log, external-dependency.py/.log, external-original-plan.json, external-current-plan.json e quattro log dei gate. I probe precedenti restano conservati; riusati gli stessi costruttori e punti di interleaving, aggiornando l'aspettativa del retry multi-giorno al comportamento corretto. Nessuna modifica al codice della PR, merge, push, deploy o operazione sui dati reali; nessun pilot operativo o misura di scala rieseguiti.

@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

The P2 of the revalidation of 0b1368c is valid. I had left outside_held out of the digest on the argument that a dependency lost from outside would still produce a refusal, and _resolve_dependencies skipped the days whose action is import or verify, so on a retry after a crash that refusal was never produced and the digest did not move.

Fix. _resolve_dependencies now judges every day that is not refused, a retirement to come and a day already retired or rebuilt alike. The progress of the days of the plan is allowed (the other day, in the plan and not refused, serves the records); the loss of an external dependency (the other day not in the plan, no longer holding them) is a refusal, so the planning at the retry differs from the approved one: STALE before any further change. The docstrings of _resolve_dependencies and _digest say so.

Tests.

  • PostgreSQL gate, new section 12c: A's incumbent holds two trades of B, B's valid revision holds them, plan [A]; A is retired and the import crashes; the plan made again is the same (import, same digest); B is retired by another operation; the plan made again refuses A, with a different digest; running the original plan is STALE and the snapshot of catalog, files and checkpoint is byte-identical; B back to valid, the same plan completes. With the previous condition (!= "retire+import") this test fails exactly as in your reproduction (action import, no refusals, same digest).
  • The progress case (A/B in one plan, crash before B's verification) is section 12b of the previous round and still passes.
  • Unit: a retry (import/verify) with a lost dependency is refused; with the other day in the plan, progress is allowed. This replaces the unit test that stated the opposite.

Full suite 164/165 (the known Windows test_promote_main_v1); PostgreSQL 16 gates of the rebuild, R01 and the archive import pass; Ruff and git diff --check clean. CI on this commit not read.

🤖 Generated with Claude Code

…oo (#520 review)

`outside_held` is out of the digest because the plan's own progress changes it, but the digest then relied on the refusals to notice a
dependency lost from outside, and `_resolve_dependencies` skipped the days already retired or rebuilt. A day retired by something else
between the retire of the first day and its retry therefore left the digest unchanged and the retry completed. Every day that is not
refused is now judged on each planning: the progress of the days of the plan is allowed, the loss of an external dependency is a
refusal, so the digest changes (STALE) before any further change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@NeoNix-Lab

Copy link
Copy Markdown
Owner Author

Fallback per identità condivisa: GitHub ha rifiutato la review formale APPROVE perché autore e revisore usano lo stesso account. Questo commento registra l APPROVE tecnico della rivalidazione, non uno stato di approvazione formale GitHub.

Rivalidazione indipendente di PR #531: APPROVE tecnico sul commit f0d9e850af5c9d24cd9820c4f169c0281de82f6a, base implement/fid @ 3ff0c4cb7439808cad2e640cab328dd1aae1fc47. Nessun finding azionabile emerso nel perimetro verificato; i tre P1 e i due P2 precedenti sono chiusi.

Ho confrontato l'ultimo fix con 0b1368c e riletto il comportamento rispetto a issue #520 e ADR-0074 Amendment 2 A2.4/A2.5/A2.7. La modifica rivaluta le dipendenze di conservazione anche nelle azioni import/verify, senza vincolare il digest al progresso previsto dei giorni del medesimo piano.

Prove indipendenti su PostgreSQL 16 temporaneo, con gli stessi fixture live e punti di interleaving conservati dalle review precedenti:

  • Ultimo P2, dipendenza esterna dopo il ritiro: piano del solo A approvato quando B conserva cross-B; ritiro di A, interruzione prima dell'import, poi vero ritiro R01 di B da un'altra operazione. Il re-plan di A ora è refused, cambia digest e il piano originale è rifiutato STALE; snapshot di catalogo e file invariato. Con il vero restore di B, il medesimo piano originale torna valido e completa; cross-B e later-B restano leggibili. Ripetuta la perdita della dipendenza anche dopo il rebuild di A, per coprire il retry verify: STALE e nessuna mutazione anche lì.
  • P2 sul progresso multi-giorno: piano A/B con cross-B inizialmente non detenuto dalla revisione legacy di B; crash dopo import B, prima della sua verifica. Il progresso false -> true di outside_held mantiene il digest originale; lo stesso piano completa con verified/verified e i due giorni sono valid.
  • P1 conservazione: vicino valid privo dei trade rifiutato; vicino selezionato ma refused propagato al giorno dipendente, senza mutazioni di catalogo/file.
  • P1 restore/import: vero restore su seconda connessione allo stesso punto di interleaving della prima review, prima della materializzazione. Rifiutato dal lock del giorno; import valid, legacy invalid, verifica strict passante.
  • P1 fonte approvata: stessa sostituzione del gzip dopo il vero ritiro. Rifiuto SOURCE, nessuna nuova partizione; ripristinando file e mtime originali, lo stesso piano riparte e completa.

Verifiche positive sull'head esatto:

  • 68 test mirati passati, 1 skip (campione archivio esterno assente), 115 subtest passati: regole R02, source/comparator archivio, R01 e package boundaries.
  • 4/4 gate PostgreSQL 16: R02, import archivio, R01 e live slices.
  • Ruff sui file interessati, link Markdown (124 file), git diff --check e preflight su implement/fid: passati; checkout pulito.
  • CI run 40206739028: 13/13 job verdi, PostgreSQL 17 R02 incluso. Letto il log della suite: 165/165 script; il merge sintetico b357ea447b351256c218c60d1ab3a5be7c983db7 combina questo head con la base indicata. Head/base ricontrollati prima della pubblicazione, PR ancora OPEN.

Prove conservate in /var/tmp/qp-review531-f0d9e85-eu2zwqqr: recheck-and-crash.py/.log, external-dependency.py/.log, i piani prima/dopo la perdita della dipendenza e i quattro log dei gate. Gli originali delle review precedenti sono conservati; qui sono riusati gli stessi fixture e interleaving, con aspettative aggiornate al comportamento corretto.

Convalida del codice e dei test, non esecuzione operativa: il pilot reale 2026-10-20, i 31 giorni del server e la misura di scala dell'autore non sono stati rieseguiti. Nessuna modifica al codice della PR, merge, push, deploy, modifica di governance o operazione sui dati reali.

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