
    vj                        d Z ddlmZ ddlmZmZ ddlmZmZ dZ	dZ
dZdZ eeeh      Zd	Zdd
Z ed       G d d             ZddZddZdZe G d d             ZddZddZ	 	 	 	 	 	 	 	 	 	 ddZd dZd dZy)!ui  dispatch.executor_completion_contract — executor completion callback contract.

task-2553+32 — EXECUTOR COMPLETION CALLBACK MANDATORY RULE 복원 (코드/파일 자동화).

회장 정정 (memory/events/task-2553.normal-callback-mandatory-doctrine-correction
_260518.json):

    executor completion callback = MANDATORY lifecycle signal.
    NO-CRON ≠ executor completion callback 금지.

This standalone module encodes that rule as executable code so that ANY future
executor task cannot omit its normal completion callback (§1/§4).

Standalone, zero-mutation: imports/edits ZERO tracked module. The huge
dispatch/__init__.py body is NOT touched (§8 기존 산출물 수정 0). File-level
contract only — the same pattern as anu_v3.callback_4tuple_index /
anu_v3.result_ready_recovery (+29).

NO-CRON note (9-R.1): this module performs ZERO cron register/remove. It only
*declares and validates* the contract. The executor's normal completion
callback is a designed lifecycle signal — NOT an ad-hoc cron-add by the
registry/checkpoint, and NOT a cron-remove by +32 (회장 금지 준수).

Closeout note (9-R.2): requiring an executor's own normal-completion callback /
result.json / report / .done is a *lifecycle signal*, NOT an escalation of
repository/task-state finalization authority. The latter (closeout 확정 권한)
remains forbidden; the former is REQUIRED.
    )annotations)	dataclassfield)ListOptionalz(dispatch.executor_completion_contract.v1NORMAL_COLLECTOR_COMPLETEDRESULT_READY_NO_NORMAL_CALLBACKDISPATCH_FAILEDaR  NO-CRON == registry/checkpoint(+29/+30/+31) MUST NOT arbitrarily add/remove cron. It does NOT mean the executor is forbidden from sending its normal completion callback. The executor normal completion callback is a MANDATORY lifecycle signal, not a registry-initiated ad-hoc cron, and is therefore explicitly exempt from the cron-add ban.c                      y)u   §6.5 — executor completion callback is NOT a 'cron 신규 등록 금지' breach.

    Always False: the normal completion callback is a designed lifecycle
    signal, distinct from a registry/checkpoint ad-hoc cron add.
    F r       (dispatch/executor_completion_contract.py0is_executor_completion_callback_a_cron_violationr   ;   s     r   T)frozenc                  :    e Zd ZU dZded<   ded<   ded<   ded<   y)	Callback4Tupleu   {task_id, dispatch_cron_id, normal_collector_cron_id*, fallback_cron_id}.

    normal_collector_cron_id is MANDATORY (§4.5). A None/empty value makes the
    contract invalid (§6.12) — it is NOT a valid NO-CRON degradation.
    strtask_iddispatch_cron_idOptional[str]normal_collector_cron_idfallback_callback_cron_idN)__name__
__module____qualname____doc____annotations__r   r   r   r   r   E   s      L++""r   r   c                    g }| j                   s|j                  d       | j                  s|j                  d       | j                  s|j                  d       | j                  s|j                  d       |S )u3   Return invalidity reasons (empty == valid). §6.12.ztask_id emptyzdispatch_cron_id emptyu{   normal_collector_cron_id missing — MANDATORY lifecycle signal (§4.5/§6.12). NO-CRON does NOT exempt this (§6.3/§6.5).u4   fallback_callback_cron_id empty (safety path, §6.6))r   appendr   r   r   )treasonss     r   validate_4tupler"   S   sh    G99'/0%%J	
 &&MNNr   c                    t        |        S N)r"   )r    s    r   tuple_is_validr%   d   s    q!!!r   )result_json_presentdone_marker_presentreport_present%normal_callback_registration_evidencec                  ~    e Zd ZU dZded<   dZded<   dZded<   dZded<   dZded	<   dZ	ded
<    e
e      Zded<   y)ExecutorCloseoutEvidenceFboolr&   r'   r(   r)   Nr   r   claims_finalization_authority)default_factory	List[str]notes)r   r   r   r&   r   r'   r(   r)   r   r-   r   listr0   r   r   r   r+   r+   s   sV     %% %% ND  38)47.2m2 +0!4/T2E92r   r+   c                f   g }| j                   s|j                  d       | j                  s|j                  d       | j                  s|j                  d       | j                  s|j                  d       | j
                  s|j                  d       | j                  r|j                  d       |S )u   FAIL reasons for an executor closeout (§4.4 / §4.6 / 9-R.2).

    Missing normal callback registration evidence == FAIL (not a valid
    closeout) even when result.json/.done/report all exist.
    zresult.json missingz.done marker missingzreport missingu   normal callback registration evidence missing — executor normal completion callback is MANDATORY (§4.4/§4.6). Not a valid normal lifecycle completion.u<   normal_collector_cron_id absent in closeout evidence (§4.5)uz   closeout evidence claims repository/task-state finalization authority — forbidden (9-R.2/§6.15). Lifecycle signal only.)r&   r   r'   r(   r)   r   r-   )evr!   s     r   validate_closeout_evidencer4      s     G!!,-!!-.'(331	

 &&J	
 
''M	
 Nr   c                    t        |        S r$   )r4   )r3   s    r   closeout_is_validr6      s    )"---r   c                J    | st         S |xs |}|rt        S |rt        S t         S )u   §4.6 / §6.8 / §6.9 completion classifier.

    result.json + .done exist but normal callback never registered ->
    RESULT_READY_NO_NORMAL_CALLBACK (a recovery state, NOT a normal
    lifecycle complete).
    )r
   r   r	   )dispatch_okresult_presentdone_presentnormal_callback_registered
has_results        r   classify_completionr=      s/     /<J!))..r   c                    | t         k(  S )uE   §6.9 — RESULT_READY_NO_NORMAL_CALLBACK is NOT a normal completion.)r   classifications    r   is_accepted_normal_lifecyclerA      s    777r   c                    | t         k(  S )u4   §6.6/§6.9 — recovery target, not a task failure.)r	   r?   s    r   is_recovery_staterC      s    <<<r   N)returnr,   )r    r   rD   r/   )r    r   rD   r,   )r3   r+   rD   r/   )r3   r+   rD   r,   )
r8   r,   r9   r,   r:   r,   r;   r,   rD   r   )r@   r   rD   r,   )r   
__future__r   dataclassesr   r   typingr   r   CONTRACT_SCHEMAr   r	   r
   	frozensetNON_NORMAL_LIFECYCLENO_CRON_CORRECTED_DEFINITIONr   r   r"   r%   EXECUTOR_CLOSEOUT_CHECKLISTr+   r4   r6   r=   rA   rC   r   r   r   <module>rM      s   8 # ( !< :  #D # !$o6 M  $
# 
# 
#""  3 3 3>.  	
 !% 	.8
=r   