perf(ssh,modal): bulk file sync via tar pipe and tar/base64 archive#8014
perf(ssh,modal): bulk file sync via tar pipe and tar/base64 archive#8014alt-glitch merged 2 commits intomainfrom
Conversation
SSH: symlink-staging + tar -ch piped over SSH in a single TCP stream. Eliminates per-file scp round-trips. Handles timeout (kills both processes), SSH Popen failure (kills tar), and tar create failure. Modal: in-memory gzipped tar archive, base64-encoded, decoded+extracted in one exec call. Checks exit code and raises on failure. Both backends use shared helpers extracted into file_sync.py: - quoted_mkdir_command() — mirrors existing quoted_rm_command() - unique_parent_dirs() — deduplicates parent dirs from file pairs Migrates _ensure_remote_dirs to use the new helpers. 28 new tests (21 SSH + 7 Modal), all passing. Closes #7465 Closes #7467
- Modal bulk upload: stream base64 payload through proc.stdin in 1MB chunks instead of embedding in command string (Modal SDK enforces 64KB ARG_MAX_BYTES — typical payloads are ~4.3MB) - Modal single-file upload: same stdin fix, add exit code checking - Remove what-narrating comments in ssh.py and modal.py (keep WHY comments: symlink staging rationale, SIGPIPE, deadlock avoidance) - Remove unnecessary `sandbox = self._sandbox` alias in modal bulk - Daytona: use shared helpers (unique_parent_dirs, quoted_mkdir_command) instead of inlined duplicates
|
|
@BugBot review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9000d31. Configure here.
| await proc.stdin.drain.aio() | ||
| offset += chunk_size | ||
| proc.stdin.write_eof() | ||
| await proc.stdin.drain.aio() |
There was a problem hiding this comment.
Single-file Modal upload silently swallows failures
High Severity
_modal_upload discards the return value of await proc.wait.aio() without checking for a non-zero exit code. In contrast, _modal_bulk_upload properly captures and checks exit_code. Since FileSyncManager.sync() commits files to _synced_files when no exception is raised, a failed upload is permanently marked as "synced," and future sync cycles will never retry it. The PR description explicitly states "Modal single-file upload now checks exit code" but the check was not implemented.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 9000d31. Configure here.
| # avoid deadlock if tar produces more than PIPE_BUF of errors. | ||
| tar_stderr_raw = b"" | ||
| if tar_proc.poll() is None: | ||
| _, tar_stderr_raw = tar_proc.communicate(timeout=10) |
There was a problem hiding this comment.
Calling communicate() on Popen with closed stdout crashes
Medium Severity
tar_proc.communicate(timeout=10) is called after tar_proc.stdout.close(). If tar_proc.poll() returns None (tar process still running), communicate() internally calls selector.register(self.stdout, ...) which invokes fileno() on the closed file object, raising ValueError: I/O operation on closed file. Since only stderr needs draining (stdout is already closed), tar_proc.wait() plus tar_proc.stderr.read() avoids both the crash and the deadlock concern noted in the comment.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 9000d31. Configure here.
|
Pushed b075d08 to address Bugbot findings:
Both fixes also in #8018 (sync-back PR). |
…ousResearch#8014) * perf(ssh,modal): bulk file sync via tar pipe and tar/base64 archive SSH: symlink-staging + tar -ch piped over SSH in a single TCP stream. Eliminates per-file scp round-trips. Handles timeout (kills both processes), SSH Popen failure (kills tar), and tar create failure. Modal: in-memory gzipped tar archive, base64-encoded, decoded+extracted in one exec call. Checks exit code and raises on failure. Both backends use shared helpers extracted into file_sync.py: - quoted_mkdir_command() — mirrors existing quoted_rm_command() - unique_parent_dirs() — deduplicates parent dirs from file pairs Migrates _ensure_remote_dirs to use the new helpers. 28 new tests (21 SSH + 7 Modal), all passing. Closes NousResearch#7465 Closes NousResearch#7467 * fix(modal): pipe stdin to avoid ARG_MAX, clean up review findings - Modal bulk upload: stream base64 payload through proc.stdin in 1MB chunks instead of embedding in command string (Modal SDK enforces 64KB ARG_MAX_BYTES — typical payloads are ~4.3MB) - Modal single-file upload: same stdin fix, add exit code checking - Remove what-narrating comments in ssh.py and modal.py (keep WHY comments: symlink staging rationale, SIGPIPE, deadlock avoidance) - Remove unnecessary `sandbox = self._sandbox` alias in modal bulk - Daytona: use shared helpers (unique_parent_dirs, quoted_mkdir_command) instead of inlined duplicates --------- Co-authored-by: kshitijk4poor <[email protected]>
…ousResearch#8014) * perf(ssh,modal): bulk file sync via tar pipe and tar/base64 archive SSH: symlink-staging + tar -ch piped over SSH in a single TCP stream. Eliminates per-file scp round-trips. Handles timeout (kills both processes), SSH Popen failure (kills tar), and tar create failure. Modal: in-memory gzipped tar archive, base64-encoded, decoded+extracted in one exec call. Checks exit code and raises on failure. Both backends use shared helpers extracted into file_sync.py: - quoted_mkdir_command() — mirrors existing quoted_rm_command() - unique_parent_dirs() — deduplicates parent dirs from file pairs Migrates _ensure_remote_dirs to use the new helpers. 28 new tests (21 SSH + 7 Modal), all passing. Closes NousResearch#7465 Closes NousResearch#7467 * fix(modal): pipe stdin to avoid ARG_MAX, clean up review findings - Modal bulk upload: stream base64 payload through proc.stdin in 1MB chunks instead of embedding in command string (Modal SDK enforces 64KB ARG_MAX_BYTES — typical payloads are ~4.3MB) - Modal single-file upload: same stdin fix, add exit code checking - Remove what-narrating comments in ssh.py and modal.py (keep WHY comments: symlink staging rationale, SIGPIPE, deadlock avoidance) - Remove unnecessary `sandbox = self._sandbox` alias in modal bulk - Daytona: use shared helpers (unique_parent_dirs, quoted_mkdir_command) instead of inlined duplicates --------- Co-authored-by: kshitijk4poor <[email protected]>
…ousResearch#8014) * perf(ssh,modal): bulk file sync via tar pipe and tar/base64 archive SSH: symlink-staging + tar -ch piped over SSH in a single TCP stream. Eliminates per-file scp round-trips. Handles timeout (kills both processes), SSH Popen failure (kills tar), and tar create failure. Modal: in-memory gzipped tar archive, base64-encoded, decoded+extracted in one exec call. Checks exit code and raises on failure. Both backends use shared helpers extracted into file_sync.py: - quoted_mkdir_command() — mirrors existing quoted_rm_command() - unique_parent_dirs() — deduplicates parent dirs from file pairs Migrates _ensure_remote_dirs to use the new helpers. 28 new tests (21 SSH + 7 Modal), all passing. Closes NousResearch#7465 Closes NousResearch#7467 * fix(modal): pipe stdin to avoid ARG_MAX, clean up review findings - Modal bulk upload: stream base64 payload through proc.stdin in 1MB chunks instead of embedding in command string (Modal SDK enforces 64KB ARG_MAX_BYTES — typical payloads are ~4.3MB) - Modal single-file upload: same stdin fix, add exit code checking - Remove what-narrating comments in ssh.py and modal.py (keep WHY comments: symlink staging rationale, SIGPIPE, deadlock avoidance) - Remove unnecessary `sandbox = self._sandbox` alias in modal bulk - Daytona: use shared helpers (unique_parent_dirs, quoted_mkdir_command) instead of inlined duplicates --------- Co-authored-by: kshitijk4poor <[email protected]>
…ousResearch#8014) * perf(ssh,modal): bulk file sync via tar pipe and tar/base64 archive SSH: symlink-staging + tar -ch piped over SSH in a single TCP stream. Eliminates per-file scp round-trips. Handles timeout (kills both processes), SSH Popen failure (kills tar), and tar create failure. Modal: in-memory gzipped tar archive, base64-encoded, decoded+extracted in one exec call. Checks exit code and raises on failure. Both backends use shared helpers extracted into file_sync.py: - quoted_mkdir_command() — mirrors existing quoted_rm_command() - unique_parent_dirs() — deduplicates parent dirs from file pairs Migrates _ensure_remote_dirs to use the new helpers. 28 new tests (21 SSH + 7 Modal), all passing. Closes NousResearch#7465 Closes NousResearch#7467 * fix(modal): pipe stdin to avoid ARG_MAX, clean up review findings - Modal bulk upload: stream base64 payload through proc.stdin in 1MB chunks instead of embedding in command string (Modal SDK enforces 64KB ARG_MAX_BYTES — typical payloads are ~4.3MB) - Modal single-file upload: same stdin fix, add exit code checking - Remove what-narrating comments in ssh.py and modal.py (keep WHY comments: symlink staging rationale, SIGPIPE, deadlock avoidance) - Remove unnecessary `sandbox = self._sandbox` alias in modal bulk - Daytona: use shared helpers (unique_parent_dirs, quoted_mkdir_command) instead of inlined duplicates --------- Co-authored-by: kshitijk4poor <[email protected]>


Summary
Salvage of #7558 by @kshitijk4poor onto current main. Contributor commits cherry-picked with authorship preserved.
tar -ch | ssh tar xsingle-stream bulk upload with symlink staging, ControlMaster reuse, full error/timeout handlingproc.stdinin 1MB chunks, avoiding Modal SDK's 64KBARG_MAX_BYTESlimitquoted_mkdir_command()andunique_parent_dirs()extracted tofile_sync.pyFollow-up fixes (second commit)
bash -ccommand string, exceeding Modal SDK's 64KBARG_MAX_BYTESexec-arg limit. Rewrote both_modal_uploadand_modal_bulk_uploadto pipe throughproc.stdinwith chunked writes._daytona_bulk_uploadnow usesunique_parent_dirs()+quoted_mkdir_command()instead of inlined duplicates.Backend status
upload_files()tar -ch | ssh tar xtar+base64 | proc.stdin44 tests passing (21 SSH, 9 Modal, 14 file_sync).
Closes #7465
Closes #7467
Supersedes #7558
Test plan
test_payload_not_in_command_stringtesttest_stdin_chunked_for_large_payloadstest🤖 Generated with Claude Code