
    3j.5                    D   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddl
mZ ddlmZmZmZmZmZmZmZmZ dd	lmZ d
ZdZedededededededediZ eh d      Z ed       G d d             Zdddddddd d!Z d)d"Z!d)d#Z"d$ed%	 	 	 	 	 	 	 	 	 d*d&Z#d)d'Z$y()+u  anu_v3.checkpoint_turn_boundary_sweep — PURE READ-ONLY turn-boundary sweep.

task-2553+43 STEP 3 (회장 GO) — runtime checkpoint operationalization 후보.

OPERATIONALIZATION CANDIDATE ONLY. This module is the read-only detection
*candidate* that ANU *could* call at a turn boundary so a finished +31
checkpoint state (drift / stale / recovery / NO-CRON done / result-ready
with no normal callback) is enumerated WITHOUT a chair question. It does
NOT wire itself anywhere; actual operational wiring is a separate post-task
chair GO (task §5 "실 운영 결선 적용" forbidden).

DESIGN BOUNDARY — 9-R.1 Layer A (task §1/§3/§4/§5; regression static+dynamic):
  * PURE read-only function — checkpoint state read -> candidate enumeration
  * ZERO write / cron register|remove / merge / PR / dispatch / closeout
  * idempotent — N calls with identical inputs return identical output
  * +31 runtime_reconcile_checkpoint.py + recovery layer consumed READ-ONLY
    (import + emit=False entrypoint only; emit=True is NEVER reached)
  * recovery-not-primary invariant asserted via the +32 sidecar (read-only):
    callback primary / fallback safety / cancel-on-success paths preserved,
    never replaced (task §5 "fallback safety path 제거" / "primary callback
    대체물로 격상" forbidden)
  * 9-R.1 Layer B (executor §8 completion callback cron) is a SEPARATE
    process-lifecycle signal fired by the executor via external cron tooling
    — NOT this module's behaviour and NOT this module's side-effect.

This module never registers/removes a cron, never writes a file, never
merges, never opens a PR, never mutates the +31 frozen original.
    )annotations)	dataclass)Path)DictList)RuntimeReconcileCheckpoint)DEFAULT_STALE_SECONDS)NO_CRON_TASK_DONERESULT_READY_NO_NORMAL_CALLBACKNORMAL_COLLECTOR_COMPLETEDDUPLICATE_CALLBACK_IGNOREDTRACK_MISMATCHRUNNINGFALLBACK_PENDINGSTALE_OR_BOT_STUCK_CANDIDATE)+runtime_reconcile_checkpoint_recovery_layerz/anu_v3.checkpoint_turn_boundary_sweep.result.v1z9anu_v3.checkpoint_turn_boundary_sweep.wiring_candidate.v1NO_CRON_DONE_CANDIDATERECOVERY_CANDIDATESTALE_CANDIDATEDRIFT_CANDIDATEBENIGN_NORMAL_COMPLETEDBENIGN_DUPLICATE_IGNOREDINFLIGHT_FALLBACK_PENDINGINFLIGHT_RUNNING>   r   r   r   r   T)frozenc                  `    e Zd ZU dZded<   ded<   ded<   ded<   ded<   ded	<   ded
<   ddZy)SweepCandidatez7One read-only enumerated turn-boundary sweep candidate.strtask_idclassificationcandidate_typebool
actionablerecovery_eligibleterminalrecommended_signalc                    | j                   | j                  | j                  | j                  | j                  | j
                  | j                  dS )Nr   r    r!   r#   r$   r%   r&   r(   )selfs    </home/jay/workspace/anu_v3/checkpoint_turn_boundary_sweep.pyto_jsonzSweepCandidate.to_json[   sE    ||"11"11//!%!7!7"&"9"9
 	
    NreturnDict[str, object])__name__
__module____qualname____doc____annotations__r+    r,   r*   r   r   O   s2    ALN	
r,   r   zBANU may recognize NO-CRON completion read-only (no chair question)uE   recovery layer eligible — surface for ANU follow-up (advisory only)uA   stale / bot-stuck candidate — surface for ANU review (advisory)u=   4-tuple drift candidate — surface for ANU review (advisory)u(   no action — normal collector completedu(   no action — duplicate callback ignoredu*   no action — fallback pending (in-flight)u!   no action — running (in-flight))r   r   r   r   r   r   r   r   c                     t        j                         } t        j                         }|  t        |       t        j                         t        j
                         |dS )u  Read-only assertion that the +31 checkpoint stays recovery-not-primary.

    Delegates entirely to the frozen +32 sidecar (imported read-only). Proves
    the callback primary / fallback safety paths are preserved, never replaced
    (task §5). No mutation, no I/O.
    )recovery_not_primary_ok
violationsreplaces_callback_primary_pathdiscards_fallback_safety_pathcontract)	_recovery)assert_checkpoint_is_recovery_not_primaryrecovery_layer_contractlist)checkpoint_replaces_callback_primary_path(checkpoint_discards_fallback_safety_path)r8   r;   s     r*   recovery_invariant_statusrB   y   sR     DDFJ002H'1>:&??A>>@ r,   c                      dddddddddddddS )Nr   z*import + checkpoint_entrypoint(emit=False)Fu   Layer A (9-R.1): pure read-only enumeration. The §8 executor completion callback cron is Layer B — a separate process-lifecycle signal fired by the executor via external cron tooling, NOT this module's behaviour.)writecron_registercron_removemergeprdispatchcloseout_confirmcallback_collector_path_touchedfrozen_plus31_mutationconsumes_plus31_viaemit_true_reachednoter5   r5   r,   r*   _zero_side_effect_proofrP      s2    +,"#K"= r,    )generated_ts_kststale_secondsc               p   t        |       } t        |      }t        | |      }|j                  ||      }|d   }|d   }g }t        |      D ]  }	||	   }
t	        |
d         }t
        j                  |d      }|j                  t        |	|||t        v t        |
j                  dd            t        |
j                  d	d            t        j                  |d
                    i }|D ]7  }|j                  |j                  g       j                  |j                         9 |D cg c]  }|j                  s|j                   }}t         dddd|t	        |      dddd|D cg c]  }|j#                          c}||t%        |      t%        |      t'               t)               dS c c}w c c}w )uM  PURE read-only turn-boundary sweep.

    Reads +31 checkpoint state for ``fixture_path`` via the read-only
    ``checkpoint_entrypoint`` (emit=False) and enumerates drift / stale /
    recovery / NO-CRON-done / result-ready candidates. Returns a fully
    deterministic document — identical inputs => byte-identical output
    (idempotent). Writes NOTHING, registers/removes NO cron, merges NOTHING.

    ``generated_ts_kst`` is passed straight through (caller-supplied, default
    empty) so the function holds no internal clock — a precondition of the
    idempotence guarantee.
    )rS   )rR   decision_packettrack_recordsr    UNKNOWNr$   Fr%   rQ   r(   task-2553+43CHECKPOINT_TURN_BOUNDARY_SWEEP	READ_ONLYz$A_DELIVERABLE_PURE_READ_ONLY (9-R.1)z1anu_v3.runtime_reconcile_checkpoint (+31, frozen)z!checkpoint_entrypoint(emit=False)z@anu_v3.runtime_reconcile_checkpoint_recovery_layer (+32, frozen))module
entrypointrecovery_layer)schemar   sweepmodelayerrR   source_fixtureconsumes_plus31
candidatesby_candidate_typeactionable_candidatesactionable_counttracks_totalrecovery_invariantzero_side_effect_proof)r   r   checkpoint_entrypointsortedr   _CANDIDATE_TYPEgetappendr   _ACTIONABLEr"   _RECOMMENDED_SIGNAL
setdefaultr!   r   r#   SWEEP_RESULT_SCHEMAr+   lenrB   rP   )	repo_rootfixture_pathrR   rS   ckptpacketdecisionrV   rd   tidrecr    ctypeby_typecr#   s                   r*   sweep_turn_boundaryr      s   & YI%L &i}MD'''7 ( F '(H%-o%>M')Jm$ C S!123##NI>.) +"377+>#FG#''*e45266ubA
 		 %'G C1++R077		BC &0@1<<!))@J@ &!17,l+I=H
 -77qqyy{7$!+
OJ79"9";)  A  8s   +F.=F.*F3c                 Z    t         ddddddddd	d
dddddddd
dddddddddgdddddS )u  Machine-readable operational-wiring CANDIDATE enumeration.

    Pure constant data describing hook points where ``sweep_turn_boundary``
    *could* be wired at an ANU turn boundary. Each entry proves read-only /
    side-effect-0 and records conflict + risk tier. NOTHING is wired here —
    actual operational wiring is a separate post-task chair GO (task §5
    "실 운영 결선 적용" forbidden). Returning this dict has no side effect.
    rX   Fu   CANDIDATES ONLY — zero wiring applied (task §5). Each entry is read-only & side-effect-0; actual wiring needs a separate chair GO post-task.WC1z0ANU active-dispatch turn boundary (pre-response)zyANU turn loop, before composing the reply: call sweep_turn_boundary(repo_root, active_dispatch_fixture, emit unreachable)zysweep_turn_boundary delegates to +31 checkpoint_entrypoint(emit=False); no write/cron/merge path exists in the call graphzregression static scan (forbidden write/cron/merge/subprocess tokens absent) + dynamic write/cron sentinel (0 captured) + idempotent N-call equalityuR   none — additive read-only call; does not touch callback/collector/fallback pathsLOW)id
hook_point	call_siteread_only_guaranteeside_effect_zero_proofconflict	risk_tierWC2u5   ANU pre-answer reconcile gate (§11 결선, advisory)z{ANU, before answering a chair query about task state: consult sweep actionable_candidates to self-detect NO-CRON completionz^same read-only call graph as WC1; recommended_signal strings are advisory text, never executedz6shared with WC1 regression (static+dynamic+idempotent)u   none — does not replace the normal completion callback primary path (recovery_invariant asserts recovery-not-primary, task §5)WC3z:external scheduled read-only audit (out-of-band, advisory)zan EXISTING external scheduler (NOT registered by this module) invokes sweep_turn_boundary read-only for an out-of-band drift/stale auditu   this module neither registers nor removes that schedule (task §5 'cron 등록·제거'); it only exposes a pure function the external tool may callztshared with WC1 regression; the schedule itself is owned by external tooling (Layer B-like), not this Layer-A moduleuf   must NOT be conflated with §8 executor completion callback (separate lifecycle signal, 9-R.1 Layer B)MEDIUMu%   task-2553+42 (Step 2 adoption 준비)Tr   )parallel_taskexpected_files_disjointother_track_originals_modified)r^   r   appliedrO   rd   cross_track_isolation)WIRING_CANDIDATE_SCHEMAr5   r,   r*   wiring_candidatesr      s     *!/
 /J(++P@"$ 8A(O+.2 #" 8N(E+* &!E4
l E'+./"
yA Ar,   Nr-   )
ru   r   rv   r   rR   r   rS   intr.   r/   )%r3   
__future__r   dataclassesr   pathlibr   typingr   r   #anu_v3.runtime_reconcile_checkpointr   r	   _CKPT_DEFAULT_STALE_SECONDS#anu_v3.runtime_next_action_resolverr
   r   r   r   r   r   r   r   anu_v3r   r<   rs   r   rm   	frozensetrp   r   rq   rB   rP   r   r   r5   r,   r*   <module>r      s   8 # !   J	 	 	 LG ?  /#%9 "3% 9 :1	    $
 
 
6 	MOKGI J!M;  (0 4III 	I
 I IXJr,   