@@ -3854,6 +3854,30 @@ def _reddog_queue_stage_rejected(stage_callable: Any) -> bool:
38543854 return isinstance (raw , Mapping ) and raw .get ("accepted" ) is False
38553855
38563856
3857+ def _reddog_queue_stage_receipt_ids (stage_callable : Any ) -> tuple [str , ...]:
3858+ """Return receipt IDs recorded by a queue control stage."""
3859+
3860+ raw = getattr (stage_callable , "last_result" , None )
3861+ if not isinstance (raw , Mapping ):
3862+ return ()
3863+ values = raw .get ("receipt_ids" )
3864+ if not isinstance (values , (list , tuple )):
3865+ return ()
3866+ return tuple (str (value ) for value in values if str (value or "" ).strip ())
3867+
3868+
3869+ def _reddog_queue_stage_rejection_reasons (stage_callable : Any ) -> tuple [str , ...]:
3870+ """Return rejection reasons recorded by a queue control stage."""
3871+
3872+ raw = getattr (stage_callable , "last_result" , None )
3873+ if not isinstance (raw , Mapping ):
3874+ return ()
3875+ values = raw .get ("rejection_reasons" )
3876+ if not isinstance (values , (list , tuple )):
3877+ return ()
3878+ return tuple (str (value ) for value in values if str (value or "" ).strip ())
3879+
3880+
38573881def run_reddog_resident_queue_control_loop_preflight (repo_root : Path ) -> bool :
38583882 """
38593883 Drive the resident queue through bounded serial/claim rounds.
@@ -3880,8 +3904,46 @@ def run_reddog_resident_queue_control_loop_preflight(repo_root: Path) -> bool:
38803904 )
38813905 if not requested :
38823906 if not run_reddog_resident_queue_serial_loop_preflight (repo_root ):
3907+ run_reddog_resident_queue_control_loop_preflight .last_result = {
3908+ "accepted" : False ,
3909+ "status" : "SERIAL_LOOP_REJECT" ,
3910+ "rounds" : 0 ,
3911+ "serial_progress" : _reddog_queue_stage_progress (
3912+ run_reddog_resident_queue_serial_loop_preflight ,
3913+ default_progress = 0 ,
3914+ ),
3915+ "claim_progress" : 0 ,
3916+ "receipt_ids" : (),
3917+ "rejection_reasons" : _reddog_queue_stage_rejection_reasons (
3918+ run_reddog_resident_queue_serial_loop_preflight
3919+ ),
3920+ }
38833921 return False
3884- return run_reddog_openclaw_signed_worker_claim_loop_preflight (repo_root )
3922+ claim_ok = run_reddog_openclaw_signed_worker_claim_loop_preflight (repo_root )
3923+ claim_receipts = _reddog_queue_stage_receipt_ids (
3924+ run_reddog_openclaw_signed_worker_claim_loop_preflight
3925+ )
3926+ run_reddog_resident_queue_control_loop_preflight .last_result = {
3927+ "accepted" : bool (claim_ok )
3928+ and not _reddog_queue_stage_rejected (
3929+ run_reddog_openclaw_signed_worker_claim_loop_preflight
3930+ ),
3931+ "status" : "PASS" if claim_ok else "CLAIM_LOOP_REJECT" ,
3932+ "rounds" : 1 ,
3933+ "serial_progress" : _reddog_queue_stage_progress (
3934+ run_reddog_resident_queue_serial_loop_preflight ,
3935+ default_progress = 1 ,
3936+ ),
3937+ "claim_progress" : _reddog_queue_stage_progress (
3938+ run_reddog_openclaw_signed_worker_claim_loop_preflight ,
3939+ default_progress = 1 if claim_ok else 0 ,
3940+ ),
3941+ "receipt_ids" : claim_receipts ,
3942+ "rejection_reasons" : _reddog_queue_stage_rejection_reasons (
3943+ run_reddog_openclaw_signed_worker_claim_loop_preflight
3944+ ),
3945+ }
3946+ return claim_ok
38853947
38863948 enforced = os .getenv ("REDDOG_RESIDENT_QUEUE_CONTROL_LOOP_ENFORCED" , "0" ) != "0"
38873949 raw_rounds = os .getenv ("REDDOG_RESIDENT_QUEUE_CONTROL_LOOP_MAX_ROUNDS" , "8" ).strip ()
@@ -3891,11 +3953,21 @@ def run_reddog_resident_queue_control_loop_preflight(repo_root: Path) -> bool:
38913953 max_rounds = 0
38923954 if max_rounds < 1 :
38933955 print ("[REDDOG-QUEUE-CONTROL] preflight=FAIL error=invalid_max_rounds" )
3956+ run_reddog_resident_queue_control_loop_preflight .last_result = {
3957+ "accepted" : False ,
3958+ "status" : "INVALID_MAX_ROUNDS" ,
3959+ "rounds" : 0 ,
3960+ "serial_progress" : 0 ,
3961+ "claim_progress" : 0 ,
3962+ "receipt_ids" : (),
3963+ "rejection_reasons" : ("invalid_max_rounds" ,),
3964+ }
38943965 return not enforced
38953966
38963967 completed_rounds = 0
38973968 serial_progress_total = 0
38983969 claim_progress_total = 0
3970+ receipt_ids : list [str ] = []
38993971 stopped_reason = "max_rounds"
39003972 for round_index in range (1 , max_rounds + 1 ):
39013973 serial_ok = run_reddog_resident_queue_serial_loop_preflight (repo_root )
@@ -3907,6 +3979,17 @@ def run_reddog_resident_queue_control_loop_preflight(repo_root: Path) -> bool:
39073979 if not serial_ok or _reddog_queue_stage_rejected (
39083980 run_reddog_resident_queue_serial_loop_preflight
39093981 ):
3982+ run_reddog_resident_queue_control_loop_preflight .last_result = {
3983+ "accepted" : False ,
3984+ "status" : "SERIAL_LOOP_REJECT" ,
3985+ "rounds" : completed_rounds ,
3986+ "serial_progress" : serial_progress_total ,
3987+ "claim_progress" : claim_progress_total ,
3988+ "receipt_ids" : tuple (receipt_ids ),
3989+ "rejection_reasons" : _reddog_queue_stage_rejection_reasons (
3990+ run_reddog_resident_queue_serial_loop_preflight
3991+ ),
3992+ }
39103993 print (
39113994 f"[REDDOG-QUEUE-CONTROL] preflight=FAIL round={ round_index } "
39123995 "stage=serial_loop"
@@ -3918,9 +4001,25 @@ def run_reddog_resident_queue_control_loop_preflight(repo_root: Path) -> bool:
39184001 default_progress = 1 if claim_ok else 0 ,
39194002 )
39204003 claim_progress_total += claim_progress
4004+ receipt_ids .extend (
4005+ _reddog_queue_stage_receipt_ids (
4006+ run_reddog_openclaw_signed_worker_claim_loop_preflight
4007+ )
4008+ )
39214009 if not claim_ok or _reddog_queue_stage_rejected (
39224010 run_reddog_openclaw_signed_worker_claim_loop_preflight
39234011 ):
4012+ run_reddog_resident_queue_control_loop_preflight .last_result = {
4013+ "accepted" : False ,
4014+ "status" : "CLAIM_LOOP_REJECT" ,
4015+ "rounds" : completed_rounds ,
4016+ "serial_progress" : serial_progress_total ,
4017+ "claim_progress" : claim_progress_total ,
4018+ "receipt_ids" : tuple (dict .fromkeys (receipt_ids )),
4019+ "rejection_reasons" : _reddog_queue_stage_rejection_reasons (
4020+ run_reddog_openclaw_signed_worker_claim_loop_preflight
4021+ ),
4022+ }
39244023 print (
39254024 f"[REDDOG-QUEUE-CONTROL] preflight=FAIL round={ round_index } "
39264025 "stage=openclaw_claim_loop"
@@ -3931,10 +4030,22 @@ def run_reddog_resident_queue_control_loop_preflight(repo_root: Path) -> bool:
39314030 stopped_reason = "idle"
39324031 break
39334032
4033+ receipt_ids_tuple = tuple (dict .fromkeys (receipt_ids ))
4034+ run_reddog_resident_queue_control_loop_preflight .last_result = {
4035+ "accepted" : True ,
4036+ "status" : "PASS" ,
4037+ "rounds" : completed_rounds ,
4038+ "serial_progress" : serial_progress_total ,
4039+ "claim_progress" : claim_progress_total ,
4040+ "receipt_ids" : receipt_ids_tuple ,
4041+ "rejection_reasons" : (),
4042+ }
4043+ receipts = "," .join (receipt_ids_tuple ) or "(none)"
39344044 print (
39354045 f"[REDDOG-QUEUE-CONTROL] preflight=PASS rounds={ completed_rounds } "
39364046 f"max_rounds={ max_rounds } stopped_reason={ stopped_reason } "
3937- f"serial_progress={ serial_progress_total } claim_progress={ claim_progress_total } "
4047+ f"serial_progress={ serial_progress_total } claim_progress={ claim_progress_total } "
4048+ f"receipts={ receipts } "
39384049 )
39394050 return True
39404051
0 commit comments