6868 wait ,
6969)
7070from pathlib import Path
71- from typing import Callable , Sequence
71+ from typing import Callable , Iterable , Sequence
7272
7373# Reuse the proven machinery. streaming_reindex_commits already re-exports the
7474# shared primitives from streaming_reindex (MLX_ROOT, Manifest, RepoFailure, ...)
@@ -1362,16 +1362,40 @@ def run_code_half(
13621362 stage_db = sr .code_stage_db (work_root / repo , repo ) if dedup_db is not None else None
13631363 promoted = False
13641364 try :
1365- info = sr .process_one_repo (
1366- repo , repo_dir , lengths_code , work_root , dedup_db , dedup_near ,
1367- global_symbol_index , memory_limit_gb , parse_workers , index_timeout_s ,
1368- index_stall_timeout_s ,
1369- promote_dedup_on_success = False ,
1370- )
1365+ try :
1366+ info = sr .process_one_repo (
1367+ repo , repo_dir , lengths_code , work_root , dedup_db , dedup_near ,
1368+ global_symbol_index , memory_limit_gb , parse_workers , index_timeout_s ,
1369+ index_stall_timeout_s ,
1370+ promote_dedup_on_success = False ,
1371+ )
1372+ except RepoFailure as exc :
1373+ if is_no_trainable_source_failure (exc ):
1374+ promoted = True
1375+ return {
1376+ "source" : "code" ,
1377+ "repo" : repo ,
1378+ "skipped" : True ,
1379+ "skip_reason" : "no_trainable_source" ,
1380+ "lengths" : {},
1381+ "stage_timings_s" : {},
1382+ "detail" : exc .detail ,
1383+ }
1384+ raise
13711385 if info .get ("skipped" ):
13721386 return info
1373- # zstd-max the per-length code parquet files this repo just wrote.
13741387 timings = dict (info .get ("stage_timings_s" , {}))
1388+ try :
1389+ timings .update (sr .promote_dedup_stage (dedup_db , stage_id , stage_db ))
1390+ except Exception as exc :
1391+ remove_code_outputs (repo , info .get ("lengths" , {}).keys ())
1392+ raise RepoFailure (
1393+ repo ,
1394+ "dedup_promote" ,
1395+ f"{ type (exc ).__name__ } : { exc } " ,
1396+ ) from exc
1397+ promoted = True
1398+ # zstd-max the per-length code parquet files this repo just wrote.
13751399 started = time .monotonic ()
13761400 deferred = 0
13771401 for L in info .get ("lengths" , {}):
@@ -1385,9 +1409,7 @@ def run_code_half(
13851409 timings ["recompress_s" ] = round (time .monotonic () - started , 6 )
13861410 if deferred :
13871411 timings ["recompress_deferred" ] = float (deferred )
1388- timings .update (sr .promote_dedup_stage (dedup_db , stage_id , stage_db ))
13891412 info ["stage_timings_s" ] = timings
1390- promoted = True
13911413 return info
13921414 finally :
13931415 if not promoted :
@@ -1413,6 +1435,20 @@ def run_code_half(
14131435]
14141436
14151437
1438+ def remove_code_outputs (repo : str , lengths : Iterable [str | int ]) -> None :
1439+ for length in lengths :
1440+ dest = sr .OUTPUT_ROOT / str (length ) / f"{ repo } .parquet"
1441+ if dest .exists ():
1442+ dest .unlink ()
1443+
1444+
1445+ def is_no_trainable_source_failure (exc : RepoFailure ) -> bool :
1446+ return (
1447+ exc .stage == "index_project"
1448+ and "no training docs (no_trainable_source)" in exc .detail .lower ()
1449+ )
1450+
1451+
14161452def is_retryable_index_project_failure (exc : RepoFailure ) -> bool :
14171453 detail = exc .detail .lower ()
14181454 return (
@@ -2303,33 +2339,50 @@ def process_one_repo(
23032339 code_index_stall_timeout_s ,
23042340 recompressor = code_recompressor ,
23052341 )
2306- with manifest_lock :
2307- manifest .mark_done (ck , cinfo )
2308- totals = _length_totals (cinfo )
2309- with manifest_lock :
2310- cumulative ["valid" ] += totals ["valid_tokens" ]
2311- cumulative_valid = cumulative ["valid" ]
2312- if progress is not None :
2313- progress .emit (
2314- "unit_done" ,
2315- stream = "code" ,
2316- repo = repo ,
2317- unit = ck ,
2318- rows = totals ["rows" ],
2319- valid_tokens = totals ["valid_tokens" ],
2320- capacity_tokens = totals ["capacity_tokens" ],
2321- ** _primary_bucket_progress (cinfo , lengths_code ),
2322- lengths = cinfo .get ("lengths" , {}),
2323- stage_timings_s = cinfo .get ("stage_timings_s" , {}),
2324- cumulative_valid_tokens = cumulative_valid ,
2342+ if cinfo .get ("skipped" ):
2343+ with manifest_lock :
2344+ manifest .mark_done (ck , cinfo )
2345+ if progress is not None :
2346+ progress .emit (
2347+ "unit_skipped" ,
2348+ stream = "code" ,
2349+ repo = repo ,
2350+ unit = ck ,
2351+ reason = cinfo .get ("skip_reason" , "skipped" ),
2352+ detail = str (cinfo .get ("detail" , "" ))[:2000 ],
2353+ )
2354+ result ["code" ] = cinfo
2355+ _log (
2356+ f"SKIP { ck } : { cinfo .get ('skip_reason' , 'skipped' )} "
2357+ )
2358+ else :
2359+ with manifest_lock :
2360+ manifest .mark_done (ck , cinfo )
2361+ totals = _length_totals (cinfo )
2362+ with manifest_lock :
2363+ cumulative ["valid" ] += totals ["valid_tokens" ]
2364+ cumulative_valid = cumulative ["valid" ]
2365+ if progress is not None :
2366+ progress .emit (
2367+ "unit_done" ,
2368+ stream = "code" ,
2369+ repo = repo ,
2370+ unit = ck ,
2371+ rows = totals ["rows" ],
2372+ valid_tokens = totals ["valid_tokens" ],
2373+ capacity_tokens = totals ["capacity_tokens" ],
2374+ ** _primary_bucket_progress (cinfo , lengths_code ),
2375+ lengths = cinfo .get ("lengths" , {}),
2376+ stage_timings_s = cinfo .get ("stage_timings_s" , {}),
2377+ cumulative_valid_tokens = cumulative_valid ,
2378+ )
2379+ if checkpoint is not None :
2380+ checkpoint .maybe_checkpoint (cumulative_valid )
2381+ result ["code" ] = cinfo
2382+ _log (
2383+ f"DONE { ck } : buckets={ sorted (cinfo ['lengths' ].keys ())} "
2384+ f"(cum_all={ cumulative ['valid' ]} )"
23252385 )
2326- if checkpoint is not None :
2327- checkpoint .maybe_checkpoint (cumulative_valid )
2328- result ["code" ] = cinfo
2329- _log (
2330- f"DONE { ck } : buckets={ sorted (cinfo ['lengths' ].keys ())} "
2331- f"(cum_all={ cumulative ['valid' ]} )"
2332- )
23332386 except RepoFailure as exc :
23342387 _log (f"FAIL { ck } : { exc } " )
23352388 with manifest_lock :
0 commit comments