Skip to content

fix: stabilize SDK bridge lifecycle, port reuse, and shutdown guards#27

Open
wbugitlab1 wants to merge 8 commits into
standardagents:mainfrom
wbugitlab1:pr/sdk-bridge-lifecycle
Open

fix: stabilize SDK bridge lifecycle, port reuse, and shutdown guards#27
wbugitlab1 wants to merge 8 commits into
standardagents:mainfrom
wbugitlab1:pr/sdk-bridge-lifecycle

Conversation

@wbugitlab1

@wbugitlab1 wbugitlab1 commented Jul 12, 2026

Copy link
Copy Markdown

Summary

Fixes recurring local Responses API failures caused by stale or incompletely disposed Cursor SDK bridge state in the packaged macOS app.

  • Bridge child: reject new work on shutdown, await Symbol.asyncDispose for cached agents, parent-PID watchdog, bounded drain (CURSOR_SDK_BRIDGE_SHUTDOWN_TIMEOUT_MS)
  • Swift owner: cooperative async stop with grace before SIGKILL; one process-wide bridge recycle on retryable pre-output transport / 503 / cursor_sdk_unavailable failures
  • Shutdown guards: no bridge relaunch after shutdown(), no retry on bridge_shutting_down, health check before bridge reuse
  • Port stability: remember last successful bridge port (87928892) instead of rescanning on every launch
  • Public OpenAI-compatible request/response shapes unchanged

Problem

After repeated use, the owned bridge process could retain poisoned SDK state. Restarts picked variable bridge ports, shutdown did not always wait for in-flight agent disposal, and shutdown-time 503 responses could still trigger bridge recycle — leading to flaky /v1/responses calls until a full app restart.

Test plan

  • npm test — 236/236 passed (includes 65 bridge lifecycle tests)
  • npm run typecheck
  • swift build -c release from macos/CursorAPI
  • Swift XCTest via Xcode (ConnectivityCheckTests, CursorSDKBridgeServerTests) — requires full Xcode toolchain
  • Local macOS app packaged (package-app.sh --development) and installed to /Applications
  • Bridge /health verified after install (port 8793)

Notes

  • @cursor/sdk remains at 1.0.13
  • Bridge recycle is intentionally process-wide: all local SDK sessions share one bridge process; interrupted callers keep the existing error contract and can retry
  • Supersedes the earlier single-commit PR draft; includes shutdown-guard fixes previously on cursor/f82fde30 (now integrated and branch deleted)

Willi Budzinski and others added 8 commits July 12, 2026 11:59
Session: Cursor API root cause
Project: composer-api
Branch: fix-cursor-api-lifecycle
Workspace: b6de4c1d-a4b3-4b67-aaf1-053ecb648b00
Files: 12 changed

Auto-saved before the worktree was removed so no work is lost.
Restore it as a branch with `git branch <name> <this-commit>`.
Await SDK disposal, terminate orphaned bridge processes, and recycle retryable stale bridge state before response output.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Document the combined lifecycle and stable bridge-port installation, record the process-wide recycle trade-off, and remove generated XCTest metadata artifacts.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Port-preference code and tests from stabilize-bridge-port are already
present via febf69b; this ancestry-only merge records branch history
without reapplying changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Lifecycle bridge shutdown, harness, and script changes from
fix-cursor-api-lifecycle are already present via 9d71542; this
ancestry-only merge records branch history without reapplying changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Exclude bridge_shutting_down from pre-output recovery, refuse endpoint launches after shutdown, and always verify bridge health before reuse.
@wbugitlab1
wbugitlab1 force-pushed the pr/sdk-bridge-lifecycle branch from d69ae71 to 5a0bb71 Compare July 12, 2026 15:54
@wbugitlab1 wbugitlab1 changed the title fix: stabilize SDK bridge lifecycle and port reuse fix: stabilize SDK bridge lifecycle, port reuse, and shutdown guards Jul 12, 2026
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.

1 participant