SDK: filter out empty sessions in use_cloud_browser (#4473)

This commit is contained in:
Stanislav Novosad
2026-01-16 09:55:33 -07:00
committed by GitHub
parent 52c30e5733
commit 7c2167616b
2 changed files with 11 additions and 7 deletions

View File

@@ -254,12 +254,13 @@ export class Skyvern extends SkyvernClient {
const browserSessions = await this.getBrowserSessions(); const browserSessions = await this.getBrowserSessions();
const browserSession = browserSessions const browserSession = browserSessions
.filter((s) => s.runnable_id == null) .filter((s) => s.runnable_id == null && s.started_at != null && s.browser_address != null)
.sort((a, b) => { .sort((a, b) => {
const aTime = a.started_at ? new Date(a.started_at).getTime() : 0; const aTime = new Date(a.started_at!).getTime();
const bTime = b.started_at ? new Date(b.started_at).getTime() : 0; const bTime = new Date(b.started_at!).getTime();
return bTime - aTime; return bTime - aTime;
})[0]; })
.at(0);
if (!browserSession) { if (!browserSession) {
LOG.info("No existing cloud browser session found, launching a new session"); LOG.info("No existing cloud browser session found, launching a new session");

View File

@@ -529,9 +529,12 @@ class Skyvern(AsyncSkyvern):
""" """
self._ensure_cloud_environment() self._ensure_cloud_environment()
browser_sessions = await self.get_browser_sessions() browser_sessions = await self.get_browser_sessions()
browser_session = max( available_sessions = [
(s for s in browser_sessions if s.runnable_id is None), key=lambda s: s.started_at, default=None s
) for s in browser_sessions
if s.runnable_id is None and s.started_at is not None and s.browser_address is not None
]
browser_session = max(available_sessions, key=lambda s: s.started_at, default=None)
if browser_session is None: if browser_session is None:
LOG.info("No existing cloud browser session found, launching a new session") LOG.info("No existing cloud browser session found, launching a new session")
browser_session = await self.create_browser_session( browser_session = await self.create_browser_session(