Skip to content

Commit 99f10d0

Browse files
authored
fix(daytona): update variable names and simplify preview link fetch (#216)
Signed-off-by: Toma Puljak <[email protected]>
1 parent a26c533 commit 99f10d0

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

src/swerex/deployment/daytona.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def __init__(
3131
):
3232
self._config = DaytonaDeploymentConfig(**kwargs)
3333
self._runtime: RemoteRuntime | None = None
34-
self._workspace = None
35-
self._workspace_id = None
34+
self._sandbox = None
35+
self._sandbox_id = None
3636
self.logger = logger or get_logger("rex-deploy")
3737
self._hooks = CombinedDeploymentHook()
3838
self._daytona = None
@@ -74,13 +74,13 @@ async def is_alive(self, *, timeout: float | None = None) -> IsAliveResponse:
7474
Raises:
7575
DeploymentNotStartedError: If the deployment was not started.
7676
"""
77-
if self._runtime is None or self._workspace is None:
77+
if self._runtime is None or self._sandbox is None:
7878
raise DeploymentNotStartedError()
7979

8080
# Check if the workspace is still running
8181
try:
8282
# Get session status to verify the workspace is still active
83-
sessions = self._workspace.process.list_sessions()
83+
sessions = self._sandbox.process.list_sessions()
8484
if not sessions:
8585
msg = "Daytona workspace has no active sessions"
8686
raise RuntimeError(msg)
@@ -105,9 +105,9 @@ async def start(self):
105105
)
106106
assert self._daytona is not None
107107

108-
self._workspace = self._daytona.create(params)
109-
self._workspace_id = self._workspace.id
110-
self.logger.info(f"Created Daytona sandbox with ID: {self._workspace_id}")
108+
self._sandbox = self._daytona.create(params)
109+
self._sandbox_id = self._sandbox.id
110+
self.logger.info(f"Created Daytona sandbox with ID: {self._sandbox_id}")
111111

112112
# Generate authentication token
113113
self._auth_token = self._get_token()
@@ -118,20 +118,18 @@ async def start(self):
118118

119119
# Create a session for the long-running process
120120
session_id = f"swerex-server-{uuid.uuid4().hex[:8]}"
121-
self._workspace.process.create_session(session_id)
121+
self._sandbox.process.create_session(session_id)
122122

123-
req = SessionExecuteRequest(command=command)
123+
req = SessionExecuteRequest(command=command, runAsync=True)
124124
# Execute the command in the session
125-
response = self._workspace.process.execute_session_command(session_id, req)
125+
response = self._sandbox.process.execute_session_command(session_id, req)
126126
if response.exit_code != 0:
127127
self.logger.error(f"Failed to start SWE Rex server: {response.output}")
128128
await self.stop()
129129
msg = f"Failed to start SWE Rex server: {response.output}"
130130
raise RuntimeError(msg)
131131

132-
sandboxHost = await self._get_sandbox_host()
133-
134-
sweRexHost = f"https://{self._config.port}-{self._workspace_id}.{sandboxHost}"
132+
sweRexHost = self._sandbox.get_preview_link(self._config.port)
135133

136134
# Create the remote runtime
137135
self._runtime = RemoteRuntime(host=sweRexHost, port=None, auth_token=self._auth_token, logger=self.logger)
@@ -141,32 +139,22 @@ async def start(self):
141139
await self._wait_until_alive(timeout=self._config.runtime_timeout)
142140
self.logger.info(f"Runtime started in {time.time() - t0:.2f}s")
143141

144-
async def _get_sandbox_host(self) -> str:
145-
"""Get the host address of the Daytona sandbox."""
146-
assert self._workspace is not None
147-
runner_domain = self._workspace.runner_domain
148-
if runner_domain is not None:
149-
return runner_domain
150-
else:
151-
msg = "No runner domain found for Daytona sandbox"
152-
raise RuntimeError(msg)
153-
154142
async def stop(self):
155143
"""Stops the runtime and removes the Daytona sandbox."""
156144
if self._runtime is not None:
157145
await self._runtime.close()
158146
self._runtime = None
159147

160-
if self._workspace is not None and self._daytona is not None:
148+
if self._sandbox is not None and self._daytona is not None:
161149
try:
162-
self.logger.info(f"Removing Daytona sandbox with ID: {self._workspace_id}")
163-
self._daytona.delete(self._workspace)
150+
self.logger.info(f"Removing Daytona sandbox with ID: {self._sandbox_id}")
151+
self._daytona.delete(self._sandbox)
164152
self.logger.info("Daytona sandbox removed successfully")
165153
except Exception as e:
166154
self.logger.error(f"Failed to remove Daytona sandbox: {str(e)}")
167155

168-
self._workspace = None
169-
self._workspace_id = None
156+
self._sandbox = None
157+
self._sandbox_id = None
170158
self._auth_token = None
171159

172160
@property

0 commit comments

Comments
 (0)