Skip to content

Commit 1b2aa89

Browse files
committed
fix: skip LLM parsing for oversized project affiliation files
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 0bc56e8 commit 1b2aa89

1 file changed

Lines changed: 39 additions & 9 deletions

File tree

services/apps/git_integration/src/crowdgit/services/affiliation/affiliation_service.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class AffiliationService(BaseService):
5252

5353
MAX_CHUNK_SIZE = 5000
5454
MAX_CONCURRENT_CHUNKS = 3
55+
MAX_FILE_SIZE_BYTES = 1_000_000
5556
FILE_PICKER_PREVIEW_MAX_CHARS = 400
5657
FILE_PICKER_BATCH_SIZE = 20
5758

@@ -955,15 +956,44 @@ async def process_affiliations(
955956
raise AffiliationFileNotFoundError(ai_cost=ai_cost)
956957

957958
file_path_on_disk = os.path.join(batch_info.repo_path, latest_file_path)
958-
content = await self.read_text_file(file_path_on_disk)
959-
file_hash = self.compute_file_hash(content)
960-
latest_file_hash = file_hash
961-
962-
affiliations, parse_cost = await self.resolve_snapshot(
963-
registry,
964-
content,
965-
file_hash,
966-
)
959+
file_size_bytes = os.path.getsize(file_path_on_disk)
960+
# Too big for llm — mark unusable and move on.
961+
if file_size_bytes > self.MAX_FILE_SIZE_BYTES:
962+
# Steady state: already gave up on this file; getsize is enough.
963+
if (
964+
registry
965+
and registry.status == AffiliationRegistryStatus.UNUSABLE.value
966+
and registry.file_path == latest_file_path
967+
and registry.file_hash
968+
):
969+
file_hash = registry.file_hash
970+
latest_file_hash = file_hash
971+
affiliations = []
972+
parse_cost = 0.0
973+
else:
974+
# First hit: hash it so the registry can mark it as unusable.
975+
hasher = hashlib.sha256()
976+
async with aiofiles.open(file_path_on_disk, "rb") as affiliation_file:
977+
while file_chunk := await affiliation_file.read(1024 * 1024):
978+
hasher.update(file_chunk)
979+
file_hash = hasher.hexdigest()
980+
latest_file_hash = file_hash
981+
raise AffiliationAnalysisError(
982+
retain_file_hash=True,
983+
error_message=(
984+
f"Affiliation file {latest_file_path!r} is too large for LLM parsing "
985+
f"({file_size_bytes} bytes > {self.MAX_FILE_SIZE_BYTES} bytes)"
986+
),
987+
)
988+
else:
989+
content = await self.read_text_file(file_path_on_disk)
990+
file_hash = self.compute_file_hash(content)
991+
latest_file_hash = file_hash
992+
affiliations, parse_cost = await self.resolve_snapshot(
993+
registry,
994+
content,
995+
file_hash,
996+
)
967997
ai_cost += parse_cost
968998

969999
if repository.parent_repo:

0 commit comments

Comments
 (0)