Skip to content

sandbox.exec - streaming issues with pty #245

@paulgroves

Description

@paulgroves

pty=True results in truncated stdout

Summary

When running commands with pty=True, stdout is truncated. The same command with pty=False returns complete output.

Reproduction

import modal                                                                                                                                                                    
                                                                                                                                                                                
SIZE = 102400  # 100KB                                                                                                                                                          
CMD = f"head -c {SIZE} /dev/zero | tr '\\0' 'X'"                                                                                                                                
                                                                                                                                                                                
app = modal.App.lookup("pty-bug-repro", create_if_missing=True)                                                                                                                 
                                                                                                                                                                                
print(f"Testing {SIZE} bytes output (3 runs)...\n")                                                                                                                             
                                                                                                                                                                                
for i in range(3):                                                                                                                                                              
    sb1 = modal.Sandbox.create("bash", "-c", CMD, app=app, timeout=60, pty=False)                                                                                               
    out1 = sb1.stdout.read()                                                                                                                                                    
    sb1.wait()                                                                                                                                                                  
                                                                                                                                                                                
    sb2 = modal.Sandbox.create("bash", "-c", CMD, app=app, timeout=60, pty=True)                                                                                                
    out2 = sb2.stdout.read()                                                                                                                                                    
    sb2.wait()                                                                                                                                                                  
    pty_bytes = out2.count("X")                                                                                                                                                 
                                                                                                                                                                                
    print(f"Run {i+1}: pty=False {len(out1)*100//SIZE}% | pty=True {pty_bytes*100//SIZE}%")                                                                                     
                                                                                                                                                                                
print("\nExpected: Both should be 100%")     

Output

Testing 102400 bytes output (3 runs)...

Run pty false pty true
1 100% 71%
2 100% 79%
3 100% 67%

Environment

  • modal version: 1.3.1 (Python)
  • Python: 3.14
  • Also reproducible with Typescript and Go sdks

Expected behavior

Both pty=False and pty=True should return 100% of the command's output.

Observed behavior

With pty=True, only 67-79% of the output is received. The amount varies between runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions