Skip to content

[FEA-1646]: add connect session function without initiating live session for js and python#37

Merged
egenthon-cmd merged 9 commits into
mainfrom
feat/add-connectSession-function
Jun 29, 2026
Merged

[FEA-1646]: add connect session function without initiating live session for js and python#37
egenthon-cmd merged 9 commits into
mainfrom
feat/add-connectSession-function

Conversation

@egenthon-cmd

@egenthon-cmd egenthon-cmd commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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

    • Added a way to connect to an existing live session without starting a new one.
    • This is available in both JavaScript and Python SDKs, for sync and async clients.
    • Live session options can now include session details and lifecycle message settings.
  • Bug Fixes

    • Improved live job deletion flow so deletion happens only after jobs reach a terminal state.
    • Updated SDK version to 1.0.5.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Both 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.

Changes

Live V2 connect-session support

Layer / File(s) Summary
Connect-session types and exports
packages/sdk-js/src/v2/live/types.ts, packages/sdk-python/src/gladiaio_sdk/v2/live/types.py, packages/sdk-python/src/gladiaio_sdk/__init__.py
New LiveV2ConnectSessionOptions types are added in both SDKs, and the Python top-level package re-exports the new type.
JS connect-session flow
packages/sdk-js/src/v2/live/client.ts, packages/sdk-js/src/v2/live/session.ts, packages/sdk-js/src/v2/live/session.test.ts
LiveV2Client adds connectSession, LiveV2Session can reuse an existing init response, and tests cover existing-session and normal start-session behavior.
Python sync connect-session flow
packages/sdk-python/src/gladiaio_sdk/v2/live/client.py, packages/sdk-python/src/gladiaio_sdk/v2/live/session.py
LiveV2Client.connect_session builds an existing session response, and LiveV2Session starts from that response when provided.
Python async connect-session flow
packages/sdk-python/src/gladiaio_sdk/v2/live/async_client.py, packages/sdk-python/src/gladiaio_sdk/v2/live/async_session.py, packages/sdk-python/tests/v2/live/test_connect_session.py
LiveV2AsyncClient.connect_session and LiveV2AsyncSession accept existing session data, and async tests cover connect-session and start-session paths.

Live V2 terminal-status delete tests

Layer / File(s) Summary
Terminal-status polling helpers
e2e/e2e-node-cjs/test/live_v2_job_management.test.cjs, e2e/e2e-node-esm/test/live_v2_job_management.test.ts, e2e/e2e-python/tests/test_live_v2_job_management.py
New helpers poll live job status until done or error, then return the terminal result or time out.
Delete waits for terminal status
e2e/e2e-node-cjs/test/live_v2_job_management.test.cjs, e2e/e2e-node-esm/test/live_v2_job_management.test.ts, e2e/e2e-python/tests/test_live_v2_job_management.py
The delete tests now await terminal-state polling before calling delete.

JS client metadata update

Layer / File(s) Summary
Header test updates and version bump
packages/sdk-js/src/client.test.ts, packages/sdk-js/src/version.ts
GladiaClient test inputs include apiKey, and SDK_VERSION is updated from 1.0.4 to 1.0.5.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • MaximeGaudin
  • jqueguiner
  • tnesztler
  • lrossillon-gladia

Poem

🐰 Hop, hop, the session found its way,
Reusing old init data to greet the day.
When jobs turn done, delete hops in line,
And version bumps sparkle — all looks fine.
Ears up, the SDKs twinkle and play!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.81% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main feature: adding connect-session support for JS and Python without starting a new live session.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-connectSession-function

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3f58528 and a3db97c.

📒 Files selected for processing (11)
  • packages/sdk-js/src/v2/live/client.ts
  • packages/sdk-js/src/v2/live/session.test.ts
  • packages/sdk-js/src/v2/live/session.ts
  • packages/sdk-js/src/v2/live/types.ts
  • 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/async_session.py
  • packages/sdk-python/src/gladiaio_sdk/v2/live/client.py
  • packages/sdk-python/src/gladiaio_sdk/v2/live/session.py
  • packages/sdk-python/src/gladiaio_sdk/v2/live/types.py
  • packages/sdk-python/tests/v2/live/test_connect_session.py

Comment thread packages/sdk-js/src/v2/live/client.ts
@karamouche karamouche self-requested a review June 25, 2026 17:22
egenthon-cmd and others added 2 commits June 25, 2026 13:27
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@egenthon-cmd egenthon-cmd force-pushed the feat/add-connectSession-function branch from a3db97c to 5911b91 Compare June 25, 2026 17:52
@egenthon-cmd egenthon-cmd changed the title Feat/add connect session function [FEA-1646]: add connect session function without initiating live session for js and python Jun 25, 2026
Comment thread packages/sdk-js/src/v2/live/client.ts
Comment thread packages/sdk-js/src/version.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/sdk-python/tests/v2/live/test_connect_session.py (1)

100-106: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Use 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

📥 Commits

Reviewing files that changed from the base of the PR and between a3db97c and aec043d.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • e2e/e2e-node-cjs/test/live_v2_job_management.test.cjs
  • e2e/e2e-node-esm/test/live_v2_job_management.test.ts
  • e2e/e2e-python/tests/test_live_v2_job_management.py
  • packages/sdk-js/src/client.test.ts
  • packages/sdk-js/src/v2/live/session.test.ts
  • packages/sdk-js/src/version.ts
  • 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/async_session.py
  • packages/sdk-python/src/gladiaio_sdk/v2/live/client.py
  • packages/sdk-python/src/gladiaio_sdk/v2/live/session.py
  • packages/sdk-python/src/gladiaio_sdk/v2/live/types.py
  • packages/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

Comment thread packages/sdk-python/tests/v2/live/test_connect_session.py
@egenthon-cmd egenthon-cmd requested a review from karamouche June 29, 2026 15:50
@egenthon-cmd egenthon-cmd merged commit 63cce90 into main Jun 29, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants