[FEA-1646]: add connect session function without initiating live session for js and python#37
Conversation
📝 WalkthroughWalkthroughBoth SDKs add connect-session APIs for Live V2, reuse existing session init responses during startup, and update live-job delete tests to wait for terminal status before deletion. The JS client version is also bumped. ChangesLive V2 connect-session support
Live V2 terminal-status delete tests
JS client metadata update
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/sdk-js/src/v2/live/client.ts`:
- Around line 49-61: In connectSession on LiveV2Client, stop defaulting
LiveV2InitResponse.created_at to an empty string when it may be used for
lifecycle events. Instead, use the existingSession construction to validate that
connectOptions.created_at is provided whenever
messages_config.receive_lifecycle_events is true, and fail early or require the
field rather than passing an invalid timestamp into LiveV2Session/session.ts.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 191916b1-db74-4b49-877f-a482a81a6b63
📒 Files selected for processing (11)
packages/sdk-js/src/v2/live/client.tspackages/sdk-js/src/v2/live/session.test.tspackages/sdk-js/src/v2/live/session.tspackages/sdk-js/src/v2/live/types.tspackages/sdk-python/src/gladiaio_sdk/__init__.pypackages/sdk-python/src/gladiaio_sdk/v2/live/async_client.pypackages/sdk-python/src/gladiaio_sdk/v2/live/async_session.pypackages/sdk-python/src/gladiaio_sdk/v2/live/client.pypackages/sdk-python/src/gladiaio_sdk/v2/live/session.pypackages/sdk-python/src/gladiaio_sdk/v2/live/types.pypackages/sdk-python/tests/v2/live/test_connect_session.py
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
a3db97c to
5911b91
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/sdk-python/tests/v2/live/test_connect_session.py (1)
100-106: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winUse a monotonic clock for timeout polling.
These loops use
time.time(), which can jump under wall-clock adjustments and make CI waits flaky.time.monotonic()keeps deadline math stable.Suggested change
def _wait_for(predicate: Callable[[], bool], timeout: float = 2.0) -> bool: - deadline = time.time() + timeout - while time.time() < deadline: + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: if predicate(): return True time.sleep(0.01) return False @@ - deadline = time.time() + 2 - while time.time() < deadline: + deadline = time.monotonic() + 2 + while time.monotonic() < deadline: if session.session_id == "session-456" and len(ws_client.sessions) == 1: break await asyncio.sleep(0.01) @@ - deadline = time.time() + 2 - while time.time() < deadline: + deadline = time.monotonic() + 2 + while time.monotonic() < deadline: if session.status == "connected": break await asyncio.sleep(0.01)Also applies to: 184-200
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sdk-python/tests/v2/live/test_connect_session.py` around lines 100 - 106, The timeout polling helper in _wait_for and the other wait loops still use time.time(), which can be affected by wall-clock changes and cause flaky waits. Switch the deadline and elapsed-time checks in these polling helpers to time.monotonic() so the timeout math stays stable regardless of system clock adjustments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/sdk-python/tests/v2/live/test_connect_session.py`:
- Line 206: The test is calling LiveV2AsyncSession.end_session() without waiting
for the async teardown it triggers, so cleanup may still be running when
asyncio.run() exits. Update the test around session.end_session() to wait for
the session shutdown path to fully settle, using the session/task teardown
mechanism exposed by LiveV2AsyncSession (including _do_destroy() and ws.close()
completion) before the coroutine returns.
---
Nitpick comments:
In `@packages/sdk-python/tests/v2/live/test_connect_session.py`:
- Around line 100-106: The timeout polling helper in _wait_for and the other
wait loops still use time.time(), which can be affected by wall-clock changes
and cause flaky waits. Switch the deadline and elapsed-time checks in these
polling helpers to time.monotonic() so the timeout math stays stable regardless
of system clock adjustments.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1793e65f-fbd8-4eb9-9bb2-7b84bbdbe4d8
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (13)
e2e/e2e-node-cjs/test/live_v2_job_management.test.cjse2e/e2e-node-esm/test/live_v2_job_management.test.tse2e/e2e-python/tests/test_live_v2_job_management.pypackages/sdk-js/src/client.test.tspackages/sdk-js/src/v2/live/session.test.tspackages/sdk-js/src/version.tspackages/sdk-python/src/gladiaio_sdk/__init__.pypackages/sdk-python/src/gladiaio_sdk/v2/live/async_client.pypackages/sdk-python/src/gladiaio_sdk/v2/live/async_session.pypackages/sdk-python/src/gladiaio_sdk/v2/live/client.pypackages/sdk-python/src/gladiaio_sdk/v2/live/session.pypackages/sdk-python/src/gladiaio_sdk/v2/live/types.pypackages/sdk-python/tests/v2/live/test_connect_session.py
✅ Files skipped from review due to trivial changes (1)
- packages/sdk-js/src/version.ts
🚧 Files skipped from review as they are similar to previous changes (7)
- packages/sdk-python/src/gladiaio_sdk/v2/live/client.py
- packages/sdk-python/src/gladiaio_sdk/init.py
- packages/sdk-python/src/gladiaio_sdk/v2/live/async_client.py
- packages/sdk-python/src/gladiaio_sdk/v2/live/types.py
- packages/sdk-python/src/gladiaio_sdk/v2/live/session.py
- packages/sdk-js/src/v2/live/session.test.ts
- packages/sdk-python/src/gladiaio_sdk/v2/live/async_session.py
Quick Summary
This PR is to add a new function: 'Connect Session' which is basically a 'init session' but without to define the api key.
for connect session we need the client, id and url of the websocket and that's it
(We added for python and js)
how to use it
const gladiaClient = new GladiaClient({ apiKey: 'your-api-key' }) -> create client
// get the infos from backend
const sessionId = 'abc-123-...'
const websocketUrl = 'wss://api.gladia.io/v2/live/...?token=...'
const createdAt = '2026-06-25T10:00:00Z' // optional
// based on the info, we can connect with
const liveSession = gladiaClient.liveV2().connectSession({
id: sessionId,
url: websocketUrl,
created_at: createdAt, // optional — only needed if you want lifecycle messages
})
// rest is same behavior as initsession
Summary by CodeRabbit
New Features
Bug Fixes
1.0.5.