Skip to content

typescript: add managed subscription lifetimes - #423

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

typescript: add managed subscription lifetimes#423
Josh (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 (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 (joshmouch) marked this pull request as draft August 27, 2026 05:08
@joshmouch
Josh (joshmouch) marked this pull request as ready for review August 27, 2026 12:45
export interface ManagedSubscriptionLease {
readonly subscription: ManagedSubscription;
readonly events: AsyncIterableIterator<SubscriptionEvent>;
release(): void;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Prefer Symbol.dispose for fully RAII-style usage

* options; conflicting options throw rather than silently changing the
* already-active server subscription.
*/
acquire(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest allowing the consumer to spec the type of state and events they're getting here.

We actually have some prior art for this in vscode sources, see these methods and IAgentSubscription https://github.com/microsoft/vscode/blob/c19945aab6c07dac9e1afd386704af16a4d212c7/src/vs/platform/agentHost/common/agentService.ts#L1046-L1054

@jackfreemanceo-dotcom

This comment was marked as spam.

@joshmouch
Josh (joshmouch) force-pushed the pr/typescript-managed-subscriptions branch from 5c577c6 to 2e14524 Compare August 27, 2026 22:10
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