77
88The observer is compiled once into each corpus strategy library. Qualification
99compares reconstructed actions to the native accessor from the same stream run,
10- before comparing any runner output. All comparisons preserve physical order and
11- binary64 values. State-selected splits and completion filtering are restricted
10+ before comparing any runner output. Engine comparisons preserve physical order
11+ and binary64 values; HTTP receipts are matched by submission sequence.
12+ State-selected splits and completion filtering are restricted
1213to this contiguous 24x7 ETH tape, not shortened/session-based buckets.
1314Optional tick checks use explicitly synthetic O-H-L-C prints derived from the
1415shipped 1m corpus, not historical observed trades. They prove same-print replay
3940import threading
4041import traceback
4142
43+ from native_live_receipts import receipts_by_sequence
44+
4245
4346PROBES = {
4447 "ta-rsi14-cross-50-01" : {"market" },
@@ -411,8 +414,9 @@ def push(current, packet):
411414
412415
413416def ordered_delivery_effects (attempts , effects , redelivery = None ):
414- sequences = [effect ["sequence" ] for effect in effects ]
415- if sorted (sequences ) != list (range (1 , len (effects ) + 1 )):
417+ indexed_effects = receipts_by_sequence (effects )
418+ sequences = range (1 , len (effects ) + 1 )
419+ if set (indexed_effects ) != set (sequences ):
416420 raise RuntimeError ("effect sequence gap or duplication" )
417421 if len ({effect ["event_id" ] for effect in effects }) != len (effects ):
418422 raise RuntimeError ("duplicate logical effect" )
@@ -425,25 +429,22 @@ def ordered_delivery_effects(attempts, effects, redelivery=None):
425429 or attempt ["idempotency_header" ] != payload .get ("delivery_id" , event_id )):
426430 raise RuntimeError ("idempotency header/payload mismatch" )
427431 if event_id not in bodies :
428- first_attempts .append (payload [ "sequence" ] )
432+ first_attempts .append (payload )
429433 bodies [event_id ] = attempt ["body" ]
430434 elif bodies [event_id ] != attempt ["body" ]:
431435 raise RuntimeError ("retry body changed" )
432- if first_attempts != list (range (1 , len (effects ) + 1 )):
433- raise RuntimeError ("first-attempt deliveries are reordered or incomplete" )
434- for effect in effects :
435- if effect != json .loads (bodies [effect ["event_id" ]]):
436- raise RuntimeError ("effect body differs from its delivery" )
436+ indexed_attempts = receipts_by_sequence (first_attempts )
437+ if set (indexed_attempts ) != set (indexed_effects ):
438+ raise RuntimeError ("first-attempt deliveries are incomplete or unexpected" )
439+ if indexed_effects != indexed_attempts :
440+ raise RuntimeError ("effect body differs from its delivery" )
441+ ordered_effects = [indexed_effects [sequence ] for sequence in sequences ]
437442 if redelivery is None :
438- if sequences != sorted (sequences ):
439- raise RuntimeError ("first-pass effects are reordered" )
440- return effects
443+ return ordered_effects
441444 boundary = redelivery ["effects_before" ]
442445 if not 0 <= boundary <= len (effects ):
443446 raise RuntimeError ("invalid explicit-redelivery boundary" )
444- initial = sequences [:boundary ]
445- if initial != sorted (initial ):
446- raise RuntimeError ("first-pass effects are reordered" )
447+ seen_effects = receipts_by_sequence (effects [:boundary ])
447448 selected = set (redelivery ["event_ids" ])
448449 if not selected <= set (bodies ):
449450 raise RuntimeError ("explicit redelivery selected an unknown event" )
@@ -458,24 +459,27 @@ def ordered_delivery_effects(attempts, effects, redelivery=None):
458459 raise RuntimeError ("invalid explicit-redelivery invocation boundary" )
459460 invocation_attempts = attempts [invocation ["attempts_before" ]:following ["attempts_before" ]]
460461 invocation_effects = effects [invocation ["effects_before" ]:following ["effects_before" ]]
461- redelivery_sequences = [json .loads (attempt ["body" ])["sequence" ]
462- for attempt in invocation_attempts if attempt ["event_id" ] in selected ]
463- if redelivery_sequences != sorted (redelivery_sequences ):
464- raise RuntimeError ("explicit redelivery attempts are reordered" )
465- redelivery_effects = [effect ["sequence" ] for effect in invocation_effects
466- if effect ["event_id" ] in selected ]
467- if redelivery_effects != sorted (redelivery_effects ):
468- raise RuntimeError ("explicit redelivery effects are reordered" )
469- for effect in invocation_effects :
470- if effect ["event_id" ] in selected and not any (
471- attempt ["event_id" ] == effect ["event_id" ] and attempt ["status" ] == 200
472- for attempt in invocation_attempts ):
473- raise RuntimeError ("explicit redelivery effect has no successful attempt" )
474- first_pass = [effect ["sequence" ] for index , effect in enumerate (effects )
475- if index < boundary or effect ["event_id" ] not in selected ]
476- if first_pass != sorted (first_pass ):
477- raise RuntimeError ("non-redelivered effects are reordered" )
478- return sorted (effects , key = lambda effect : effect ["sequence" ])
462+ successful = {}
463+ for attempt in invocation_attempts :
464+ if attempt ["status" ] == 200 :
465+ payload = json .loads (attempt ["body" ])
466+ successful [payload ["sequence" ]] = payload
467+ expected_effects = {sequence : payload for sequence , payload in successful .items ()
468+ if sequence not in seen_effects }
469+ if receipts_by_sequence (invocation_effects ) != expected_effects :
470+ raise RuntimeError ("explicit redelivery effects differ from new successful attempts" )
471+ seen_effects .update (expected_effects )
472+ if seen_effects != indexed_effects :
473+ raise RuntimeError ("explicit redelivery effects are incomplete" )
474+ # The final invocation must replay the whole selection, including effects
475+ # already accepted before an acknowledgement was lost and the process restarted.
476+ replayed = {json .loads (attempt ["body" ])["sequence" ] for attempt in invocation_attempts
477+ if attempt ["event_id" ] in selected }
478+ expected_replay = {sequence for sequence , payload in indexed_attempts .items ()
479+ if payload ["event_id" ] in selected }
480+ if replayed != expected_replay :
481+ raise RuntimeError ("explicit redelivery selection is incomplete" )
482+ return ordered_effects
479483
480484
481485def require_replay_after_restart (attempts , event_id , invocation ):
@@ -525,8 +529,7 @@ def do_POST(self):
525529 if not rejected :
526530 owner .database .execute ("INSERT OR IGNORE INTO effects VALUES(NULL,?,?)" , (event_id , body ))
527531 owner .database .commit ()
528- count = owner .database .execute ("SELECT COUNT(*) FROM effects" ).fetchone ()[0 ]
529- wait_ack = not rejected and is_new and count == owner .restart_action
532+ wait_ack = not rejected and is_new and payload ["sequence" ] == owner .restart_action
530533 if wait_ack :
531534 owner .accepted .set ()
532535 owner .release_ack .wait (120 )
@@ -550,7 +553,7 @@ def log_message(self, *unused):
550553 write_json (self .routes , {"schema_version" : 1 , "default_target" : "default" ,
551554 "targets" : {"default" : {"url" : f"http://127.0.0.1:{ self .server .server_address [1 ]} /actions" ,
552555 "secret_env" : "PINEFORGE_EQUIVALENCE_HMAC" }}, "rules" : [],
553- "delivery" : {"max_in_flight" : 1 , "transport_retries" : 2 ,
556+ "delivery" : {"max_in_flight" : 8 , "transport_retries" : 2 ,
554557 "retry_backoff_ms" : [10 , 20 ]}})
555558
556559 def finish (self , output ):
@@ -664,7 +667,7 @@ def run_case(strategy, batch, bars, rows, timeframe, split, output, runner,
664667 if not expected :
665668 raise RuntimeError ("NOT EXERCISED: no live actions" )
666669 receiver = MockReceiver (output , fail_first , crash_action )
667- result ["delivery_policy" ] = "single-flight , two explicit transport retries"
670+ result ["delivery_policy" ] = "max_in_flight=8 , two explicit transport retries"
668671 command = [str (runner ), "run" , "--strategy" , str (strategy .path ), "--warmup" , str (output / "warmup.csv" ),
669672 "--input-tf" , str (timeframe ), "--script-tf" , str (timeframe ), "--session" , "24x7" , "--timezone" , "UTC" ,
670673 "--chart-timezone" , "UTC" , "--mode" , "ticks" if packets is not None else "bars" ,
@@ -720,7 +723,8 @@ def run_case(strategy, batch, bars, rows, timeframe, split, output, runner,
720723 if set (rejected ) != {row ["event_id" ] for row in effects } or any (count != 1 for count in rejected .values ()):
721724 raise RuntimeError ("fail-first coverage missing" )
722725 if restart :
723- require_replay_after_restart (attempts , effects [crash_action - 1 ]["event_id" ], restart_invocation )
726+ crashed_effect = receipts_by_sequence (effects )[crash_action ]
727+ require_replay_after_restart (attempts , crashed_effect ["event_id" ], restart_invocation )
724728 with sqlite3 .connect (output / "orders.sqlite3" ) as ledger :
725729 ledger_hashes = [row [0 ] for row in ledger .execute ("SELECT state_hash FROM inputs ORDER BY input_index" )]
726730 pending = ledger .execute ("SELECT COUNT(*) FROM events WHERE acknowledged=0" ).fetchone ()[0 ]
0 commit comments