Skip to content

fix: streaming tar extraction for large repo cloning - #862

Merged
RhysSullivan merged 1 commit into
mainfrom
fix/streaming-git-clone-memory
Jan 3, 2026
Merged

fix: streaming tar extraction for large repo cloning#862
RhysSullivan merged 1 commit into
mainfrom
fix/streaming-git-clone-memory

Conversation

@RhysSullivan

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes memory exhaustion when cloning large repositories like antiwork/gumroad in the AI chat feature
  • Reduces peak memory usage from ~1.2GB to ~275MB (4x improvement)

Problem

The git clone implementation for the /chat feature was loading the entire decompressed tar archive into memory, then parsing all files into a Map, then converting to strings. For large repos like antiwork/gumroad (149MB compressed, 328MB decompressed, ~4000 files), this caused ~1.2GB peak memory usage, exceeding Convex's 512MB action limit and causing "Transient error while executing action" failures.

Solution

Rewrote git-clone.ts to use streaming tar extraction:

  • Stream the download and decompression
  • Parse tar headers on-the-fly as data arrives
  • Write files to the virtual filesystem immediately instead of batching them
  • Only hold one file's content in memory at a time

Testing

Tested locally with antiwork/gumroad:

  • Before: 1.2GB peak memory, crashes in Convex
  • After: 275MB peak memory, completes successfully in ~10 seconds with all 4000 files

The git clone implementation was loading the entire decompressed tar
archive into memory, parsing all files into a Map, then converting to
strings. For large repos like antiwork/gumroad (149MB compressed),
this caused ~1.2GB peak memory usage, exceeding Convex's 512MB limit.

Rewrote to stream the tar extraction:
- Parse tar headers on-the-fly as data arrives
- Write files to the virtual filesystem immediately
- Only hold one file's content in memory at a time

Memory usage reduced from ~1.2GB to ~275MB (4x improvement).
@vercel

vercel Bot commented Jan 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
answer-overflow-main-site Ready Ready Preview, Comment Jan 3, 2026 6:06pm

@RhysSullivan
RhysSullivan merged commit e7a25ec into main Jan 3, 2026
5 of 7 checks passed
@RhysSullivan
RhysSullivan deleted the fix/streaming-git-clone-memory branch January 3, 2026 18:10
This was referenced Jan 4, 2026

@mrmeomeo-cybersecurity mrmeomeo-cybersecurity left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mrmeomeo-cybersecurity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants