
    3j                        d Z ddlmZ ddlmZ dZdZdZdZdZ	d	Z
d
Z ed       G d d             ZddZddZddZddZdd	 	 	 	 	 ddZy)u:  anu_v3.result_ready_recovery — RESULT_READY recovery + fallback-fire classifier.

Standalone module for task-2553+29 (NO-CRON variant). Encodes the rule that
RESULT_READY_NO_NORMAL_CALLBACK is a *collector recovery target*, NOT a task
failure (구현목표 3·4·6), and the deterministic fallback-fire taxonomy
(구현목표 7, regression 3·6).

NO-CRON note (9-R.1): this module performs zero cron register/remove. It only
classifies observed state; recovery == reading result.json / .done existence
(dogfooding self-recognition), never re-arming a collector cron.
    )annotations)	dataclassRESULT_READY_NO_NORMAL_CALLBACKNORMAL_COLLECTOR_COMPLETEDWAIT_FOR_FALLBACKRESULT_MISSING_BOT_STALEDISPATCH_FAILEDDUPLICATE_CALLBACK_IGNOREDRESULT_READY_ALREADY_COLLECTEDT)frozenc                  J    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   y	)
RuntimeObservationbooldispatch_okresult_presentdone_presentnormal_collector_executedby_design_no_normal_collectorstrfallback_stateN)__name__
__module____qualname____annotations__     >/home/jay/workspace/scripts/../anu_v3/result_ready_recovery.pyr   r      s&    ###''r   r   c                    | j                   st        S | j                  xs | j                  }| j                  rt
        S |rt        S | j                  dk(  rt        S | j                  dk(  rt        S t        S )uD   Primary state classifier (구현목표 3·4·6, regression 1·4·5).PENDINGFIRED)
r   r	   r   r   r   r   r   r   r   r   )obs
has_results     r   classify_runtimer#   '   sm    ??##7s'7'7J
$$)) /.
Y&  
W$''r   c                    | t         k(  S )zDRESULT_READY_NO_NORMAL_CALLBACK is a recovery target, not a failure.r   )classifications    r   is_recovery_eligibler'   :   s    <<<r   c                "    | t         k7  ry|r	 y	 y)N uz   by-design fallback-only track: result/.done present, normal collector intentionally absent — benign, no recovery action.zcollector recovery target: result is complete; normal-collector cron self-registration was missed. NOT a task failure. Recovery == registry reconcile-read of result/.done (NO-CRON, 9-R.1).r%   )r&   	by_designs     r   recovery_noter+   ?   s'    88M	

	Dr   c                6    | j                   xs | j                  S )u   Is immediate collector recovery possible? (구현목표 6)

    Possible iff a complete result/.done exists for the track so the registry
    can reconcile it by read alone (no cron needed). by-design tracks count.
    )r   r   )r!   s    r   can_recover_nowr-   N   s     1!1!11r   F)track_mismatchc               |    |ry| j                   xs | j                  }|r| j                  rt        S t        S t
        S )u  Classify a fallback callback firing against registry truth.

    구현목표 7 / regression 3·6:
      - 4-tuple mismatch                         -> TRACK_MISMATCH
      - result ready + normal already collected  -> RESULT_READY_ALREADY_COLLECTED
      - result ready + no normal collector       -> DUPLICATE_CALLBACK_IGNORED
      - no result                                -> RESULT_MISSING_BOT_STALE
    TRACK_MISMATCH)r   r   r   r   r
   r   )r!   r.   r"   s      r   classify_fallback_firer1   W   s>     ##7s'7'7J((11))##r   N)r!   r   returnr   )r&   r   r2   r   )r&   r   r*   r   r2   r   )r!   r   r2   r   )r!   r   r.   r   r2   r   )__doc__
__future__r   dataclassesr   r   r   r   r   r	   r
   r   r   r#   r'   r+   r-   r1   r   r   r   <module>r6      s   
 # ! #D 9 ' 5 # : !A  $  &=
2 !$	$ $ 		$r   