Skip to content

typescript: add managed subscription lifetimes - #423

Open
Josh Mouch (joshmouch) wants to merge 1 commit into
microsoft:mainfrom
joshmouch:pr/typescript-managed-subscriptions
Open

Josh Mouch (joshmouch) wants to merge 1 commit into
microsoft:mainfrom
joshmouch:pr/typescript-managed-subscriptions

Conversation

@joshmouch

Copy link
Copy Markdown
Contributor

Summary

Add a framework-neutral ManagedSubscriptionManager to the official TypeScript client entry point. It provides reusable ownership and lifecycle semantics above the existing subscribe and unsubscribe wire methods without adding protocol vocabulary.

The manager owns:

  • one wire subscription per resource URI
  • synchronous named leases for independent holders
  • one event iterator per holder, attached before the subscribe request
  • retention of actions that arrive during the initial subscribe round trip
  • deterministic holder and reference-count inspection
  • last-holder unsubscribe and manager-wide shutdown
  • failed-subscribe cleanup followed by deterministic reacquisition
  • entry-identity fencing so a late result cannot overwrite a replacement subscription
  • rejection of incompatible delivery or view options for an already shared resource

It deliberately does not import VS Code Event, observable, URI, Disposable, DI, or workbench abstractions. Reducer-backed state, optimistic action reconciliation, and multi-host reconnect restoration remain separate SDK decisions.

Why this belongs in the SDK

Subscriptions are already an AHP protocol concept, and the official client already owns the wire subscription plus state-mirror primitives. Reference ownership, initial-roundtrip delivery, deterministic reacquisition, and final unsubscribe are generic client lifecycle rules; leaving them to each product produces multiple subscription managers above the same SDK.

Validation

  • TypeScript client typecheck
  • TypeScript client build
  • complete TypeScript client suite: 72 passed
  • focused managed-subscription lifecycle and race suite: 6 passed
  • change-fragment verification: 21 fragments
  • npm pack dry run includes the source, compiled JavaScript, declarations, and source maps
  • git diff --check

The implementation is stateless when a subscription returns no snapshot, so it also supports notification-only resources.

@joshmouch

Josh Mouch (joshmouch) commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up integration is ready on the fork branch pr/typescript-managed-host-subscriptions at 7ac6302. It preserves one managed lease across real MultiHostClient transport generations, routes replay/snapshot/missing restoration into that lease, and fences stale generation events and results. The full TypeScript suite is 78/78; focused host and reconnect suites are green. I kept it out of this PR so the shared subscription lifetime can be reviewed independently. The coordinated VS Code consumer and deletion proposal is microsoft/vscode#332854.

@joshmouch
Josh Mouch (joshmouch) marked this pull request as draft August 27, 2026 05:08
@joshmouch
Josh Mouch (joshmouch) marked this pull request as ready for review August 27, 2026 12:45
Comment thread clients/typescript/src/client/managed-subscriptions.ts Outdated
Comment thread clients/typescript/src/client/managed-subscriptions.ts Outdated
@jackfreemanceo-dotcom

This comment was marked as spam.

@joshmouch
Josh Mouch (joshmouch) force-pushed the pr/typescript-managed-subscriptions branch from 5c577c6 to 2e14524 Compare August 27, 2026 22:10
@joshmouch
Josh Mouch (joshmouch) force-pushed the pr/typescript-managed-subscriptions branch from 2e14524 to 5a47ef1 Compare September 14, 2026 14:49
@joshmouch

Copy link
Copy Markdown
Contributor Author

Connor Peet (@connor4312) Dmitriy Vasyura (@dmitrivMS) Could you take another look at this TypeScript client PR? Connor’s requested Disposable support and consumer-selected state/event types are in the current head, and I’ve replied in both review threads and marked them resolved. The PR is also rebased onto current main.

Dmitri, I’m including you because you reviewed the original TypeScript client in #148. If the approach and current changes look good to you, an approving review would help move this forward; otherwise, please flag what you’d like changed.

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.

3 participants