
    3js                        d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZmZ dZd	Zdd
Zddd	 	 	 	 	 	 	 	 	 ddZddZy)u)  anu_v3.batch_runtime_reconciler — top-level +29 reconciler.

Consumes (read-only):
  * memory/fixtures/task-2553.runtime-reconcile.fixture.json   (normalized)
  * memory/events/task-2553.parallel-batch-state.json          (frozen v1)

Emits (NEW writable authority — separate path, 9-R.2):
  * memory/events/task-2553.parallel-runtime-registry.batch-state.json

Standalone (9-R.3): zero coupling to anu_v3.parallel_batch_coordinator. The
frozen durable v1 file is read for provenance only and is NEVER mutated.

batch_state is the single authority (구현목표 9). It represents +26 MERGED,
+27 PASS, +28 DONE simultaneously (regression 13). consolidated_summary
carries final decision fields only (regression 15). closeout eligibility is
derived from batch_state and only PROPOSED (regression 14, §7).
    )annotationsN)Path)DictOptional)ParallelRuntimeRegistry)TrackJoinViewjoinderive_closeout_proposalz#anu_v3.parallel_runtime_registry.v1z(batch-task-2553-runtime-registry-2553p29c                v    t        j                  t        |       j                               j	                         S )N)hashlibsha256r   
read_bytes	hexdigest)paths    6/home/jay/workspace/anu_v3/batch_runtime_reconciler.py_sha256r   %   s'    >>$t*//12<<>>     )contaminationgenerated_ts_kstc               D   t        j                  |       }|j                          |j                         }t	        |      }t        |      j                         rt        |      nd}t        |xs g       }|j                         D cg c],  }t        |d   |d   |d   |d   |d   |d   xs |d   	      . }	}t        |	|
      }
t        t        t	        |       t        |       ||d|||
j                  |
j                  |
j                   |
j"                  d|j%                         ||
j&                  d}t)        |      }||d<   |j+                         D ci c]  \  }}||d   |d   |d   d c}}|
j&                  t-        |d         d|d<   |S c c}w c c}}w )z=Build the authority batch-state document (does not write it).r   task_idterminal_outcomeclassificationhold_for_chairfallback_stateresult_presentdone_present)r   r   r   r   r   
has_result)r   z?read-only provenance only; zero mutation/coupling (9-R.2/9-R.3))independent_done_tracksheld_trackswaiting_tracksblocking_relations)schemabatch_idsource_fixturesource_fixture_sha256frozen_batch_state_reffrozen_batch_state_sha256frozen_couplingr   tracksjoin_policymissing_normal_collectorr   batch_next_actioncloseout_proposal)r   r   r   eligible)r+   r.   closeout_eligibleconsolidated_summary)r   load_fixturereconcile_allrecords_jsonstrr   is_filer   listvaluesr   r	   SCHEMABATCH_IDr    r!   r"   r#   missing_normal_collectorsr.   r
   itemsbool)fixture_pathfrozen_state_pathr   r   regrecords
frozen_ref
frozen_sharecviewsjrbatch_stateproposaltids                 r   	reconcilerK   )   s    "
.
.|
<C G &'J/34E/F/N/N/P*+VXJ,"-M >>#
  		N !34/0/0/0+,CN0C	

E 
 
e=	1B l+!(!6",%/\,')'A'A>> //"$"7"7	
 %($A$A$C&11%&K, (4H'/K#$ $MMO
 S $'(:$;"%&6"7"%&6"7 
  11!(:"67+K&' g
P
s   1FFc                    t        |      }|j                  dk(  rt        d      |j                  j	                  dd       |j                  t        j                  | dd      dz   d	
       |S )u   Write the NEW authority file (9-R.2 — separate path, never the frozen v1).

    Hard guard: refuses to write the frozen durable v1 path.
    z#task-2553.parallel-batch-state.jsonzrefusing to write frozen durable v1 (9-R.2): authority file must be the separate task-2553.parallel-runtime-registry.batch-state.jsonT)parentsexist_okF   )ensure_asciiindent
zutf-8)encoding)r   nameRuntimeErrorparentmkdir
write_textjsondumps)rH   out_pathouts      r   write_authority_stater]   q   sv    
 x.C
xx88S
 	
 JJTD1NN

;U1=D   Jr   )r   r   returnr6   )
r?   r   r@   r   r   zOptional[list]r   r6   r^   Dict[str, object])rH   r_   r[   r   r^   r   )__doc__
__future__r   r   rY   pathlibr   typingr   r    anu_v3.parallel_runtime_registryr    anu_v3.batch_runtime_join_policyr   r	   r
   r:   r;   r   rK   r]    r   r   <module>rg      s   " #    ! D  
/5? %)EEE "	E
 E EPr   