@@ -293,6 +293,7 @@ def stage_index_source(
293293 dedup_db : Path | None = None ,
294294 dedup_near : bool = True ,
295295 global_symbol_index : Path | None = None ,
296+ memory_limit_gb : float = 10.0 ,
296297) -> Path :
297298 """index_project.py --enriched -> <repo>.enriched.jsonl.
298299
@@ -313,6 +314,7 @@ def stage_index_source(
313314 "--max-tokens" , str (TOKENIZE_BUDGET ),
314315 "--exclude-dirs" , SOURCE_EXTRA_EXCLUDE ,
315316 "--tokenizer-path" , TOKENIZER_PATH ,
317+ "--memory-limit-gb" , str (memory_limit_gb ),
316318 ]
317319 if dedup_db is not None :
318320 cmd += ["--dedup-db" , str (dedup_db )]
@@ -336,7 +338,8 @@ def stage_index_commits(repo: str, commit_inputs: Sequence[Path], work: Path,
336338 dedup_db : Path | None = None ,
337339 dedup_near : bool = True ,
338340 pr_store : Path | None = None ,
339- repo_list : Path | None = None ) -> Path :
341+ repo_list : Path | None = None ,
342+ memory_limit_gb : float = 10.0 ) -> Path :
340343 """process_commits.py -> <repo>.enriched.jsonl (commit edit-signal docs).
341344
342345 A commit is an ATOMIC change-unit: process_commits dedups whole commit DOCS
@@ -352,6 +355,7 @@ def stage_index_commits(repo: str, commit_inputs: Sequence[Path], work: Path,
352355 "--max-tokens" , str (TOKENIZE_BUDGET ),
353356 "--tokenizer-path" , TOKENIZER_PATH ,
354357 "--format" , "both" ,
358+ "--memory-limit-gb" , str (memory_limit_gb ),
355359 ]
356360 if dedup_db is not None :
357361 cmd += ["--dedup-db" , str (dedup_db )]
@@ -371,7 +375,12 @@ def stage_index_commits(repo: str, commit_inputs: Sequence[Path], work: Path,
371375 return enriched
372376
373377
374- def stage_materialize (repo : str , enriched : Path , work : Path ) -> Path :
378+ def stage_materialize (
379+ repo : str ,
380+ enriched : Path ,
381+ work : Path ,
382+ memory_limit_gb : float = 10.0 ,
383+ ) -> Path :
375384 """clang_enriched_to_parquet.py -> tokenized enriched parquet (single file)."""
376385 tok = work / f"{ repo } .tok.parquet"
377386 run_checked (
@@ -385,6 +394,7 @@ def stage_materialize(repo: str, enriched: Path, work: Path) -> Path:
385394 "--materialize-tokenized-enriched" ,
386395 "--overflow-policy" , "drop" ,
387396 "--size" , _budget_size_label (TOKENIZE_BUDGET ),
397+ "--memory-limit-gb" , str (memory_limit_gb ),
388398 ],
389399 log_path = work / f"{ repo } .materialize.log" ,
390400 )
@@ -469,6 +479,7 @@ def process_one_repo(
469479 dedup_db : Path | None = None ,
470480 dedup_near : bool = True ,
471481 global_symbol_index : Path | None = None ,
482+ memory_limit_gb : float = 10.0 ,
472483) -> dict :
473484 """Index a repo, then ROUTE each code doc to exactly ONE length bucket.
474485
@@ -483,9 +494,11 @@ def process_one_repo(
483494 work = work_root / repo
484495 work .mkdir (parents = True , exist_ok = True )
485496 lengths_sorted = sorted (int (x ) for x in target_lengths )
486- enriched = stage_index_source (repo , repo_dir , work , dedup_db , dedup_near ,
487- global_symbol_index )
488- tok = stage_materialize (repo , enriched , work )
497+ enriched = stage_index_source (
498+ repo , repo_dir , work , dedup_db , dedup_near ,
499+ global_symbol_index , memory_limit_gb ,
500+ )
501+ tok = stage_materialize (repo , enriched , work , memory_limit_gb )
489502
490503 _bucket_for , route_by_fit = _route_by_fit_impl ()
491504 route_dir = work / "routed"
@@ -509,13 +522,15 @@ def process_one_commit_source(
509522 repo_dir : Path | None ,
510523 dedup_db : Path | None = None ,
511524 dedup_near : bool = True ,
525+ memory_limit_gb : float = 10.0 ,
512526) -> dict :
513527 work = work_root / key
514528 work .mkdir (parents = True , exist_ok = True )
515529 lengths_sorted = sorted (int (x ) for x in target_lengths )
516530 enriched = stage_index_commits (key , commit_inputs , work , repo_root , repo_dir ,
517- dedup_db , dedup_near )
518- tok = stage_materialize (key , enriched , work )
531+ dedup_db , dedup_near ,
532+ memory_limit_gb = memory_limit_gb )
533+ tok = stage_materialize (key , enriched , work , memory_limit_gb )
519534
520535 _bucket_for , route_by_fit = _route_by_fit_impl ()
521536 route_dir = work / "routed"
@@ -571,6 +586,9 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
571586 "When set, the CODE stage threads it into index_project so "
572587 "unresolved base-lib callees are pulled in as bounded "
573588 "depth-1 deps tagged crosslib:<repo>. DEFAULT off." )
589+ p .add_argument ("--memory-limit-gb" , type = float , default = 10.0 ,
590+ help = "Per-stage fail-loud RSS limit passed to index/materialize/"
591+ "commit processors (default 10.0)." )
574592 return p .parse_args (argv )
575593
576594
@@ -650,7 +668,7 @@ def main(argv: list[str]) -> int:
650668 key , files , target_lengths , work_root ,
651669 Path (args .commit_repo_root ) if args .commit_repo_root else None ,
652670 Path (args .commit_repo_dir ) if args .commit_repo_dir else None ,
653- dedup_db , dedup_near ,
671+ dedup_db , dedup_near , args . memory_limit_gb ,
654672 )
655673 manifest .mark_done (manifest_key , info )
656674 run_report [manifest_key ] = info
@@ -681,7 +699,9 @@ def should_process(repo: str) -> bool:
681699 for repo , repo_dir in gen :
682700 try :
683701 info = process_one_repo (repo , repo_dir , target_lengths , work_root ,
684- dedup_db , dedup_near , global_symbol_index )
702+ dedup_db , dedup_near ,
703+ global_symbol_index ,
704+ args .memory_limit_gb )
685705 manifest .mark_done (repo , info )
686706 run_report [repo ] = info
687707 processed += 1
0 commit comments