Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion modal/io_streams.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright Modal Labs 2022
import asyncio
import time
import uuid
from collections.abc import AsyncGenerator, AsyncIterator
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -370,6 +371,7 @@ def __init__(self, object_id: str, object_type: Literal["sandbox", "container_pr
self._client = client
self._is_closed = False
self._buffer = bytearray()
self.writer_id = str(uuid.uuid4())

def _get_next_index(self) -> int:
index = self._index
Expand Down Expand Up @@ -449,7 +451,11 @@ async def drain(self) -> None:
await retry_transient_errors(
self._client.stub.SandboxStdinWrite,
api_pb2.SandboxStdinWriteRequest(
sandbox_id=self._object_id, index=index, eof=self._is_closed, input=data
sandbox_id=self._object_id,
index=index,
eof=self._is_closed,
input=data,
writer_id=self.writer_id,
),
)
else:
Expand Down
2 changes: 2 additions & 0 deletions modal_proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,7 @@ message RuntimeInputMessage {
bytes message = 1;
uint64 message_index = 2;
bool eof = 3;
string writer_id = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there are two spots where we create RuntimeInputMessages in the client. Do those need to be updated to take this new writer_id value, too?

Copy link
Author

Choose a reason for hiding this comment

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

I included the field because RuntimeInputMessage was used in server code for the code flow of a SandboxStdinWriteRequest and it needs to be sent over to the worker for deduplication (monorepo PR). The us of RuntimeInputMessage PR in the client looks like it's once for non-sandbox tasks and another for modal shell.

I think that if the field is not included in when it is sent it gets set to a default string value ("") and it'll be ignored on the code paths for those two.

}

message RuntimeOutputBatch {
Expand Down Expand Up @@ -2876,6 +2877,7 @@ message SandboxStdinWriteRequest {
bytes input = 2;
uint32 index = 3;
bool eof = 4;
string writer_id = 5;
}

message SandboxStdinWriteResponse {
Expand Down
Loading