Skip to content

Add shared session watch APIs - #2415

Open
toliaqat wants to merge 5 commits into
mainfrom
toliaqat-expose-shared-watch-api
Open

Add shared session watch APIs#2415
toliaqat wants to merge 5 commits into
mainfrom
toliaqat-expose-shared-watch-api

Conversation

@toliaqat

@toliaqat toliaqat commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • generate the additive Node and Rust sessions.watch({ sessionId }) RPC surface from Runtime schema commit 7c34f30aa270d2a6214d1aa0274fc1afd4c9790d (SHA-256 dec3e7be93b7a3ca023eff9f6e90e9858bb6305d15f547d0e599283828a9b310)
  • add passive SharedSessionWatch handles with immutable read-only metadata, ordered replay/live session.event delivery, idempotent sessions.close, and no interactive or lane-credential surface
  • propagate the exact connection-scoped { type: "session.disconnected", sessionId } terminal lifecycle signal and atomically clean up watch routing after preceding events
  • make client shutdown classify watch entries in the router so concurrent disconnect cleanup cannot select session.destroy
  • document and test the generated payload, replay registration, passive surface, terminal propagation, close cleanup, and shutdown cleanup

Validation

  • Node focused watch/lifecycle tests (3 passed)
  • Node typecheck
  • Node lint (existing unrelated warnings only)
  • Rust focused watch/shutdown tests (2 passed)
  • Rust generated watch payload test
  • Rust lifecycle-union test
  • Rust clippy with all features/targets
  • Rust nightly format check

Runtime and publication dependency

The generated API is pinned to the main-based schema-only Runtime commit above. Execution and normal package-backed regeneration remain blocked until a new @github/copilot publication carries Runtime PR github/copilot-agent-runtime#17282 (0179092d8c319b60b4b8cb7df0b0829c095adb4f) together with sessions.watch and the hand-written session.disconnected lifecycle union. The lifecycle variant is intentionally absent from generated/api.schema.json.

Expose passive shared-session watch handles for Node and Rust, with generated RPC types, ordered event routing, lifecycle cleanup, and tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 26, 2026 19:40
@toliaqat
toliaqat requested a review from a team as a code owner August 26, 2026 19:40
expect((client as any).sharedSessionWatches.has("watch-session")).toBe(false);
expect("send" in watch).toBe(false);
expect("abort" in watch).toBe(false);
if (false) {
@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds passive shared-session watch APIs for Node.js and Rust, including event replay, lifecycle handling, cleanup, documentation, and generated RPC types.

Changes:

  • Adds read-only shared-session watch handles and sessions.watch integration.
  • Propagates session.disconnected lifecycle events and cleans up routing.
  • Updates generated schemas, tests, documentation, and line-ending rules.
Show a summary per file
File Description
.gitattributes Standardizes Node.js and Rust line endings.
nodejs/README.md Documents shared-session watching.
nodejs/src/client.ts Implements watch creation and cleanup.
nodejs/src/generated/rpc.ts Adds generated watch RPC types.
nodejs/src/generated/session-events.ts Refreshes generated event types.
nodejs/src/index.ts Exports watch and lifecycle APIs.
nodejs/src/session.ts Adds the passive watch handle.
nodejs/src/types.ts Adds disconnected lifecycle typing.
nodejs/test/client.test.ts Tests watch behavior and payloads.
rust/README.md Documents Rust watch usage.
rust/src/generated/api_types.rs Refreshes generated RPC payload types.
rust/src/generated/rpc.rs Adds the generated watch RPC method.
rust/src/generated/session_events.rs Refreshes generated event types.
rust/src/handler.rs Updates permission-context example.
rust/src/lib.rs Tracks watches and lifecycle cleanup.
rust/src/router.rs Makes the session router cloneable.
rust/src/session.rs Updates permission-context fixtures.
rust/src/types.rs Adds disconnected lifecycle support.
rust/src/watch.rs Implements Rust shared-session watches.
rust/tests/api_types_test.rs Tests credential-free payload shapes.
rust/tests/session_test.rs Tests replay, disconnect, and close behavior.

Review details

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 16/21 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment thread rust/src/lib.rs Outdated
Comment on lines +1677 to +1680
if event.event_type == SessionLifecycleEventType::Disconnected
&& watch_sessions.lock().remove(&event.session_id)
{
router.unregister(&event.session_id);
);
assert_eq!(terminal.session_id, "watch-session");
assert!(terminal.metadata.is_none());
assert!(watch.events().recv().await.is_none());
Comment thread nodejs/src/session.ts
Comment on lines +145 to +147
for (const event of pending) {
handler(event);
}
toliaqat and others added 2 commits August 26, 2026 12:50
Guard the hand-authored Node and Rust lifecycle unions against silent drift from the Runtime notification contract.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Regenerate the watch RPC from the accepted contract while preserving the SDK's published CLI schema surface and removing unrelated newer Runtime event/type drift.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: be0a255d-04f8-4830-888a-59f54ad1e607
@github-actions

This comment has been minimized.

Keep the generated watch API additive against the SDK's pinned CLI schema and leave repository-wide line-ending policy unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: be0a255d-04f8-4830-888a-59f54ad1e607
@github-actions

Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review

This PR adds two new capabilities to the Node.js and Rust SDKs:

  1. watchSharedSession / watch_shared_session API — attaches to a session shared by another user as a read-only watcher, returning a SharedSessionWatch handle with ordered event delivery, immutable metadata, and idempotent close().
  2. session.disconnected lifecycle event — a new terminal connection-loss lifecycle event type with no metadata payload.

Feature parity gaps

The following SDKs do not yet implement either feature:

SDK Missing feature
Python (python/copilot/client.py) watch_shared_session() method, SessionDisconnectedEvent class, "session.disconnected" in SessionLifecycleEventType
Go (go/client.go, go/types.go) WatchSharedSession() method, SessionLifecycleDisconnected constant in SessionLifecycleEventType
.NET (dotnet/src/Client.cs, dotnet/src/Types.cs) WatchSharedSession() method, SessionDisconnectedEvent class, "session.disconnected" handling in lifecycle dispatch
Java (java/sdk/src/main/java/com/github/copilot/) watchSharedSession() method, DISCONNECTED constant in SessionLifecycleEventTypes

Notes

  • The session.disconnected event gap is lower-friction to backfill than the full watch API — it only requires adding a new type constant and handling it in lifecycle dispatch.
  • The watchSharedSession API is marked @experimental in Node.js and Rust, so incomplete parity at this stage is understandable. Consider filing tracking issues for Python, Go, .NET, and Java.
  • Both Node.js and Rust correctly use sessions.close (not session.destroy) when cleaning up a watch handle — this behavioral distinction should be replicated in other SDKs when they implement the feature.

Generated by SDK Consistency Review Agent for #2415 · sonnet46 57.4 AIC · ⌖ 8.31 AIC · ⊞ 6.6K ·

Route disconnect cleanup in the ordered session notification task and store watch classification with router entries so shutdown always uses sessions.close without racing terminal cleanup.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: be0a255d-04f8-4830-888a-59f54ad1e607
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