Skip to content

Commit 679049a

Browse files
committed
fix(sdk): make the 0.2.0 SDK release safe to publish
The v2 SDK migration (#5273, #6564) shipped five breaking changes in both SDKs but got the release mechanics wrong in three separate ways, and left one of the two rewrites unable to complete a single successful call. Versions. packages/ts-sdk/package.json read 0.1.3 -- a patch digit added inside an unrelated compatibility commit, never deliberated. npm expands ^0.1.2 to >=0.1.2 <0.2.0, so every existing consumer would have picked the break up on a lockfile refresh: AsyncExecutionResult.jobId renamed to runId, executionId dropped from that interface, a failed sync run now throwing instead of resolving {success:false}, the request body reshaped, and the endpoint moved to /api/v2 with no fallback. 0.2.0 excludes every existing range, so the upgrade becomes opt-in. packages/python-sdk carries the identical break and was never bumped at all, so its publish job would have skipped green at the "version already exists" gate and left the repo and PyPI silently divergent; it moves 0.1.2 -> 0.2.0 in lockstep, along with the __version__ string in simstudio/__init__.py, which tracks pyproject and would otherwise have started lying. setup.py is left at 0.1.1: it is unchanged from main and demonstrably unread (0.1.2 published from pyproject while setup.py already said 0.1.1). It wants deleting, in its own commit. A 404 fallback was considered and rejected. The legacy 202 body's statusUrl points at /api/jobs/{jobId}, so mapping jobId onto runId would hand the caller an id that getWorkflowRun cannot resolve against that same old server -- a successful execute followed by an inexplicable failure on the next call is a worse contract than a clean 404. Both READMEs instead state the minimum server version and name the endpoint to check for. Cancelled runs. packages/python-sdk computed success as status != 'failed', so a run cancelled out of band reported success=True. The TypeScript SDK uses a closed whitelist and reports False, and before the migration both SDKs read the server's own value, which was False -- so this was a Python regression, not merely an inconsistency. Fixed by mirroring the whitelist. The v2 contract enumerates exactly completed|failed|paused|cancelled, so narrowing the blacklist to a whitelist cannot drop a live value, and a status added later now defaults to "not successful" rather than silently reporting True. WorkflowExecutionResult gains a status field because Python, unlike TypeScript, does not throw on 'failed' -- so success=False alone is ambiguous there in a way it is not in the TypeScript SDK, which is why status is not added to both. Rate-limit header. Found while auditing the two SDKs for further divergence, and the reason the Python bump could not have shipped as it stood: every authenticated v2 response now carries X-RateLimit-Reset as an ISO 8601 timestamp (recorded by v2RateLimits.publicApi, stamped by withRouteHandler). The Python SDK parsed it with int(), raising a bare ValueError that no handler in execute_workflow catches -- so every successful v2 execution raised instead of returning. None of the legacy endpoints the SDK previously called record a rate-limit snapshot, which is why the latent int() survived until the v2 move. The TypeScript SDK already branches on the format; _parse_reset_header mirrors it, including degrading an unrecognised value to 0, because a quota hint must not take down the call it rode in on. Timing metadata. The v2 rewrite stopped forwarding startedAt/endedAt, which main passed through and the TypeScript SDK still reports; restored under the same startTime/endTime keys the TypeScript SDK uses. Tests: cancelled/failed/paused status coverage, the ISO reset header, and the restored metadata keys, each verified red against the unfixed line first. The TypeScript suite gains matching cancelled/paused and ISO-reset pins -- they pass against today's source by design, and were confirmed to fail against a deliberately degraded copy so they are not toothless. Deliberately not included: a CI guard failing a PR that changes SDK source without a version bump. It would have caught this twice over, but it is a new script and workflow rather than a fix to the defect at hand. Review revision. bun.lock recorded packages/ts-sdk at 0.1.3 and was left stale by the first pass, so the repo asserted two versions for the same workspace package -- in a change whose whole thesis is that the version strings had diverged. It does not break CI (bun 1.3.14 accepts the mismatch under --frozen-lockfile, confirmed here), but 092311e bumped the lock in lockstep with package.json, and the next unfrozen install would otherwise drop the line into an unrelated PR. _parse_reset_header gated the numeric branch on str.isdigit(), which accepts characters int() rejects ('²'.isdigit() is True, int('²') raises) -- and that int() sits outside the try, so the one function added to stop a quota hint raising could still raise, contradicting its own docstring. str.isdecimal() is exactly the set int() accepts. The tolerates-unparseable test is parametrized over both forms and was confirmed red on '²' against isdigit. Docs and docstrings: apps/docs api-reference/python.mdx mirrors the README's dataclass block and was the only copy left without the new status field. RateLimitInfo now names its units, because reset is epoch seconds for the legacy integer and milliseconds for the ISO form that v2 sends. execute_workflow's Args entry still described the pre-v2 body shape ("spread at root level"); every input is nested under input now, and this is the commit that ships that help() text to PyPI. The "declared last so positional construction keeps working" sentence was a maintainer's note that belongs in this message, not in every user's help(WorkflowExecutionResult).
1 parent b5d9e93 commit 679049a

9 files changed

Lines changed: 248 additions & 18 deletions

File tree

apps/docs/content/docs/en/api-reference/python.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,11 @@ class WorkflowExecutionResult:
275275
metadata: Optional[Dict[str, Any]] = None
276276
trace_spans: Optional[List[Any]] = None
277277
total_duration: Optional[float] = None
278+
status: Optional[str] = None
278279
```
279280

281+
`success` is `True` only for the `completed` and `paused` statuses. `status` carries the server's terminal status verbatim, so a cancelled run (`success=False`, `error=None`) is distinguishable from a failed one.
282+
280283
### AsyncExecutionResult
281284

282285
```python

bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/python-sdk/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
The official Python SDK for [Sim](https://sim.ai), allowing you to execute workflows programmatically from your Python applications.
44

5+
## Server compatibility
6+
7+
`0.2.x` talks to the v2 API and has no fallback to the older endpoints, so it requires a Sim deployment that serves `POST /api/v2/workflows/{id}/execute`. That surface is newer than the endpoints `0.1.x` used, and a deployment can also have it switched off — a self-hosted build serves `/api/v2` only when the operator enables `V2_API`. Where it is unavailable every v2 route answers 404, so `execute_workflow` raises `SimStudioError('HTTP 404: Not Found')` — enable or upgrade the v2 API on the server, or pin `simstudio-sdk<0.2`, which keeps using `/api/workflows/{id}/execute` and `/api/jobs/{id}`.
8+
9+
## Upgrading from 0.1.x to 0.2.0
10+
11+
`0.2.0` is a breaking release.
12+
13+
- **Requests move to `/api/v2`.** `execute_workflow` posts to `/api/v2/workflows/{workflow_id}/execute`, sends the workflow input nested under `input`, and carries `async` / `executionTimeoutSeconds` in the body instead of the `X-Execution-Mode` and `X-Execution-Timeout-Seconds` headers.
14+
- **`AsyncExecutionResult.job_id` is now `run_id`,** and `execution_id` has been removed from that dataclass. Replace `result.job_id` with `result.run_id`.
15+
- **`get_job_status(job_id)` is legacy.** It still calls `/api/jobs/{job_id}` and only resolves IDs from a `0.1.x` async execution. For runs started by `0.2.x`, use `get_workflow_run(workflow_id, run_id)`, which reads `/api/v2/workflows/{workflow_id}/runs/{run_id}`.
16+
- **`WorkflowExecutionResult.success` is derived from the run status** rather than read from the response body, and is `True` only for `completed` and `paused` runs — so a run cancelled while it was in flight now reports `success=False`, as it did before the v2 migration. The new `WorkflowExecutionResult.status` field carries the server's terminal status (`'completed'`, `'failed'`, `'paused'` or `'cancelled'`), which is how you tell a cancelled run from a failed one.
17+
- **`metadata` is now built by the SDK,** with the keys `duration`, `runId`, `startTime` and `endTime`. The v2 response carries no execution logs or trace spans, so `logs` and `trace_spans` are always `None`; the pre-v2 `metadata['executionId']` is now `metadata['runId']`.
18+
19+
Note one deliberate difference from the TypeScript SDK: a failed synchronous run *throws* there, but here it returns normally with `error` set and `status='failed'`.
20+
521
## Installation
622

723
```bash
@@ -245,8 +261,11 @@ class WorkflowExecutionResult:
245261
metadata: Optional[Dict[str, Any]] = None
246262
trace_spans: Optional[list] = None
247263
total_duration: Optional[float] = None
264+
status: Optional[str] = None
248265
```
249266

267+
`success` is `True` only for the `completed` and `paused` statuses. `status` carries the server's terminal status verbatim, so a cancelled run (`success=False`, `error=None`) is distinguishable from a failed one.
268+
250269
### WorkflowStatus
251270

252271
```python

packages/python-sdk/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "simstudio-sdk"
7-
version = "0.1.2"
7+
version = "0.2.0"
88
authors = [
99
{name = "Sim", email = "help@sim.ai"},
1010
]

packages/python-sdk/simstudio/__init__.py

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from typing import Any, Dict, Optional, Union
88
from dataclasses import dataclass
9+
from datetime import datetime
910
import time
1011
import random
1112
import os
@@ -14,7 +15,12 @@
1415

1516
MAX_EXECUTION_TIMEOUT_SECONDS = 604_800
1617

17-
__version__ = "0.1.2"
18+
# Run statuses that count as a successful synchronous execution. Deliberately a
19+
# whitelist: a status later added to the API then defaults to "not successful"
20+
# rather than silently reporting True.
21+
_SUCCESSFUL_RUN_STATUSES = ('completed', 'paused')
22+
23+
__version__ = "0.2.0"
1824
__all__ = [
1925
"SimStudioClient",
2026
"SimStudioError",
@@ -28,14 +34,22 @@
2834

2935
@dataclass
3036
class WorkflowExecutionResult:
31-
"""Result of a workflow execution."""
37+
"""
38+
Result of a workflow execution.
39+
40+
``success`` is True only for the 'completed' and 'paused' statuses, so a
41+
run the server cancels and a run that fails both report False. Read
42+
``status`` to tell those apart -- it carries the server's own terminal
43+
status ('completed', 'failed', 'paused' or 'cancelled').
44+
"""
3245
success: bool
3346
output: Optional[Any] = None
3447
error: Optional[str] = None
3548
logs: Optional[list] = None
3649
metadata: Optional[Dict[str, Any]] = None
3750
trace_spans: Optional[list] = None
3851
total_duration: Optional[float] = None
52+
status: Optional[str] = None
3953

4054

4155
@dataclass
@@ -58,7 +72,13 @@ class AsyncExecutionResult:
5872

5973
@dataclass
6074
class RateLimitInfo:
61-
"""Rate limit information from API response headers."""
75+
"""
76+
Rate limit information from API response headers.
77+
78+
``reset`` is epoch milliseconds when the server sends the ISO 8601
79+
``X-RateLimit-Reset`` the v2 API uses, and epoch seconds for the bare
80+
integer older endpoints sent. ``retry_after`` is milliseconds.
81+
"""
6282
limit: int
6383
remaining: int
6484
reset: int
@@ -82,6 +102,23 @@ def __init__(self, message: str, code: Optional[str] = None, status: Optional[in
82102
self.status = status
83103

84104

105+
def _parse_reset_header(value: str) -> int:
106+
"""
107+
Parse the ``X-RateLimit-Reset`` header, matching the TypeScript SDK.
108+
109+
The v2 API sends an ISO 8601 timestamp, which yields epoch milliseconds;
110+
older endpoints sent an epoch integer, which is kept as-is. A quota hint
111+
must never take down the call it rode in on, so an unrecognised value
112+
degrades to 0 rather than raising.
113+
"""
114+
if value.isdecimal():
115+
return int(value)
116+
try:
117+
return int(datetime.fromisoformat(value.replace('Z', '+00:00')).timestamp() * 1000)
118+
except ValueError:
119+
return 0
120+
121+
85122
class SimStudioClient:
86123
"""
87124
Sim API client for executing workflows programmatically.
@@ -166,9 +203,11 @@ def execute_workflow(
166203
167204
Args:
168205
workflow_id: The ID of the workflow to execute
169-
input: Input data to pass to the workflow. Can be a dict (spread at root level),
170-
primitive value (string, number, bool), or list (wrapped in 'input' field).
171-
File-like objects within dicts are automatically converted to base64.
206+
input: Input data to pass to the workflow, sent nested under the request
207+
body's 'input' field. A dict becomes the workflow input as-is; any
208+
other value (string, number, bool, list) is wrapped as
209+
{'input': value}. File-like objects within it are automatically
210+
converted to base64.
172211
timeout: Timeout in seconds (default: 30.0)
173212
stream: Enable streaming responses (default: None)
174213
selected_outputs: Block outputs to stream (e.g., ["agent1.content"])
@@ -270,15 +309,19 @@ def execute_workflow(
270309
)
271310

272311
execution_error = result_data.get('error')
312+
status = result_data.get('status')
273313
return WorkflowExecutionResult(
274-
success=result_data.get('status') != 'failed',
314+
success=status in _SUCCESSFUL_RUN_STATUSES,
275315
output=result_data.get('output'),
276316
error=execution_error.get('message') if execution_error else None,
277317
metadata={
278318
'duration': result_data.get('durationMs'),
279-
'runId': result_data['runId']
319+
'runId': result_data['runId'],
320+
'startTime': result_data.get('startedAt'),
321+
'endTime': result_data.get('endedAt')
280322
},
281-
total_duration=result_data.get('durationMs')
323+
total_duration=result_data.get('durationMs'),
324+
status=status
282325
)
283326

284327
except requests.Timeout:
@@ -593,7 +636,7 @@ def _update_rate_limit_info(self, response: requests.Response) -> None:
593636
self._rate_limit_info = RateLimitInfo(
594637
limit=int(limit) if limit else 0,
595638
remaining=int(remaining) if remaining else 0,
596-
reset=int(reset) if reset else 0,
639+
reset=_parse_reset_header(reset) if reset else 0,
597640
retry_after=int(retry_after) * 1000 if retry_after else None
598641
)
599642

packages/python-sdk/tests/test_client.py

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,32 @@
77
from simstudio import SimStudioClient, SimStudioError, WorkflowExecutionResult, WorkflowStatus
88

99

10-
def v2_execution_response(output=None):
10+
def v2_execution_response(output=None, status="completed", error=None):
1111
return {
1212
"data": {
1313
"runId": "execution-123",
1414
"workflowId": "workflow-id",
15-
"status": "completed",
15+
"status": status,
1616
"output": {} if output is None else output,
17-
"error": None,
17+
"error": error,
18+
"startedAt": "2026-08-11T12:00:00.000Z",
19+
"endedAt": "2026-08-11T12:00:00.010Z",
1820
"durationMs": 10
1921
}
2022
}
2123

2224

25+
def mock_execution_post(mock_post, status="completed", error=None, headers=None):
26+
"""Wire a mocked 200 v2 execution response with the given terminal status."""
27+
mock_response = Mock()
28+
mock_response.ok = True
29+
mock_response.status_code = 200
30+
mock_response.json.return_value = v2_execution_response(status=status, error=error)
31+
mock_response.headers.get.side_effect = lambda h: (headers or {}).get(h)
32+
mock_post.return_value = mock_response
33+
return mock_response
34+
35+
2336
def test_simstudio_client_initialization():
2437
"""Test SimStudioClient initialization."""
2538
client = SimStudioClient(api_key="test-api-key", base_url="https://test.sim.ai")
@@ -161,10 +174,58 @@ def test_sync_execution_returns_result(mock_post):
161174
)
162175

163176
assert result.success is True
177+
assert result.status == "completed"
164178
assert result.output == {"result": "completed"}
179+
assert result.metadata == {
180+
"duration": 10,
181+
"runId": "execution-123",
182+
"startTime": "2026-08-11T12:00:00.000Z",
183+
"endTime": "2026-08-11T12:00:00.010Z"
184+
}
165185
assert not hasattr(result, 'task_id')
166186

167187

188+
@patch('simstudio.requests.Session.post')
189+
def test_sync_execution_cancelled_is_not_success(mock_post):
190+
"""A run cancelled out of band is not a success, matching the TypeScript SDK."""
191+
mock_execution_post(mock_post, status="cancelled")
192+
193+
client = SimStudioClient(api_key="test-api-key")
194+
result = client.execute_workflow("workflow-id", {})
195+
196+
assert result.success is False
197+
assert result.status == "cancelled"
198+
199+
200+
@patch('simstudio.requests.Session.post')
201+
def test_sync_execution_failed_is_not_success(mock_post):
202+
"""A failed run is not a success and surfaces the server's error message."""
203+
mock_execution_post(
204+
mock_post,
205+
status="failed",
206+
error={"code": "BLOCK_EXECUTION_FAILED", "message": "Invalid credentials"}
207+
)
208+
209+
client = SimStudioClient(api_key="test-api-key")
210+
result = client.execute_workflow("workflow-id", {})
211+
212+
assert result.success is False
213+
assert result.status == "failed"
214+
assert result.error == "Invalid credentials"
215+
216+
217+
@patch('simstudio.requests.Session.post')
218+
def test_sync_execution_paused_is_success(mock_post):
219+
"""A paused run is still a success -- it is waiting, not broken."""
220+
mock_execution_post(mock_post, status="paused")
221+
222+
client = SimStudioClient(api_key="test-api-key")
223+
result = client.execute_workflow("workflow-id", {})
224+
225+
assert result.success is True
226+
assert result.status == "paused"
227+
228+
168229
@patch('simstudio.requests.Session.post')
169230
def test_async_header_not_set_when_false(mock_post):
170231
"""Test X-Execution-Mode header is not set when async_execution is None."""
@@ -497,6 +558,48 @@ def test_get_rate_limit_info_after_api_call(mock_post):
497558
assert info.reset == 1704067200
498559

499560

561+
@patch('simstudio.requests.Session.post')
562+
def test_rate_limit_reset_accepts_iso_timestamp(mock_post):
563+
"""The v2 API sends X-RateLimit-Reset as an ISO 8601 timestamp, not an epoch int."""
564+
mock_execution_post(mock_post, headers={
565+
'x-ratelimit-limit': '100',
566+
'x-ratelimit-remaining': '99',
567+
'x-ratelimit-reset': '2024-01-01T00:00:00.000Z'
568+
})
569+
570+
client = SimStudioClient(api_key="test-api-key")
571+
result = client.execute_workflow("workflow-id", {})
572+
573+
assert result.success is True
574+
info = client.get_rate_limit_info()
575+
assert info is not None
576+
assert info.reset == 1704067200000
577+
578+
579+
@pytest.mark.parametrize('reset_header', ['not-a-timestamp', '²'])
580+
@patch('simstudio.requests.Session.post')
581+
def test_rate_limit_reset_tolerates_unparseable_value(mock_post, reset_header):
582+
"""
583+
An unrecognised quota hint reports 0 rather than failing the execution.
584+
585+
'²' covers the digit-like characters str.isdigit() accepts but int()
586+
rejects.
587+
"""
588+
mock_execution_post(mock_post, headers={
589+
'x-ratelimit-limit': '100',
590+
'x-ratelimit-remaining': '99',
591+
'x-ratelimit-reset': reset_header
592+
})
593+
594+
client = SimStudioClient(api_key="test-api-key")
595+
result = client.execute_workflow("workflow-id", {})
596+
597+
assert result.success is True
598+
info = client.get_rate_limit_info()
599+
assert info is not None
600+
assert info.reset == 0
601+
602+
500603
@patch('simstudio.requests.Session.get')
501604
def test_get_usage_limits_success(mock_get):
502605
"""Test getting usage limits."""

packages/ts-sdk/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
The official TypeScript/JavaScript SDK for [Sim](https://sim.ai), allowing you to execute workflows programmatically from your applications.
44

5+
## Server compatibility
6+
7+
`0.2.x` talks to the v2 API and has no fallback to the older endpoints, so it requires a Sim deployment that serves `POST /api/v2/workflows/{id}/execute`. That surface is newer than the endpoints `0.1.x` used, and a deployment can also have it switched off — a self-hosted build serves `/api/v2` only when the operator enables `V2_API`. Where it is unavailable every v2 route answers 404, so `executeWorkflow` fails with `HTTP 404: Not Found` — enable or upgrade the v2 API on the server, or stay on `simstudio-ts-sdk@0.1.x`, which keeps using `/api/workflows/{id}/execute` and `/api/jobs/{id}`.
8+
9+
## Upgrading from 0.1.x to 0.2.0
10+
11+
`0.2.0` is a breaking release. It is a minor bump rather than a patch precisely so that `^0.1.2` does not pick it up — you upgrade when you choose to.
12+
13+
- **Requests move to `/api/v2`.** `executeWorkflow` posts to `/api/v2/workflows/{id}/execute`, sends the workflow input nested under `input`, and carries `async` / `executionTimeoutSeconds` in the body instead of the `X-Execution-Mode` and `X-Execution-Timeout-Seconds` headers.
14+
- **`AsyncExecutionResult.jobId` is now `runId`,** and `executionId` has been removed from that interface. Replace `result.jobId` with `result.runId`.
15+
- **`getJobStatus(taskId)` is legacy.** It still calls `/api/jobs/{taskId}` and only resolves IDs from a `0.1.x` async execution. For runs started by `0.2.x`, use `getWorkflowRun(workflowId, runId)`, which reads `/api/v2/workflows/{id}/runs/{runId}` and returns a typed `WorkflowRunStatus`.
16+
- **A failed synchronous run now throws.** Previously it resolved with `{ success: false }`; it now rejects with a `SimStudioError` carrying the server's `error.code` and `error.message`. Any `if (!result.success)` branch that handled failures must move into a `catch`.
17+
- **`success` is derived from the run status.** It is `true` for `completed` and `paused` runs only, so a run cancelled while it was in flight resolves with `success: false` rather than throwing. Combined with the point above: a rejection means the run failed, and a resolved `success: false` means it was cancelled.
18+
519
## Installation
620

721
```bash

packages/ts-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simstudio-ts-sdk",
3-
"version": "0.1.3",
3+
"version": "0.2.0",
44
"description": "Sim SDK - Execute workflows programmatically",
55
"type": "module",
66
"exports": {

0 commit comments

Comments
 (0)