Commit d950601
Defer sessionId to server for cloud sessions (#1479)
When a caller creates a session with `cloud` set and does not supply a
`sessionId`, the SDK now omits `sessionId` from the `session.create`
request and lets the CLI/server assign one. The returned id is captured
synchronously when the response is parsed (via an inline response
callback) so that any subsequent `session.event` notification routes to
the registered session without race.
For all other cases (no `cloud`, or caller supplied `sessionId`), the
SDK continues to generate a UUID client-side (when none is supplied)
and pre-register the session BEFORE issuing the RPC. Pre-registration
is required because the CLI may issue session-scoped requests (e.g.
`sessionFs.writeFile` for workspace metadata) during `session.create`
processing, before it has sent the response — without pre-registration
those requests would have no handler. A caller-supplied `sessionId` is
always passed to the server so the server can validate it; mismatched
returned ids fail the call with a clear error.
In addition, the .NET implementation extracts the session-init local
function from CreateSessionAsync into a private InitializeSession
helper that is now shared by both CreateSessionAsync and
ResumeSessionAsync, eliminating duplicated handler-wiring code.
Per-SDK summary:
.NET (dotnet/src/Client.cs): New private InitializeSession helper
shared by CreateSessionAsync and ResumeSessionAsync. CreateSessionAsync
branches on (Cloud != null && SessionId == null): the cloud/no-id path
registers the session lazily from an `onResponseInline` callback; all
other paths pre-register before the RPC. Validates that the server-
returned id matches a caller-supplied id.
Python (python/copilot/client.py): create_session uses the same
conditional. Cloud+no-id installs an `on_response_inline` callback that
registers the session as soon as the response is parsed. Otherwise the
session is pre-registered via uuid.uuid4() (or the caller-supplied id).
Go (go/client.go): createSession uses the same conditional. Cloud+no-id
installs an inline callback that registers from the read loop the
instant the response arrives. Otherwise the session is pre-registered
via uuid.NewString() (or the caller-supplied id).
Rust (rust/src/session.rs): create_session uses the same conditional.
Cloud+no-id installs an InlineResponseCallback that validates the
returned id and registers in the router. Otherwise the session is
pre-registered via uuid::Uuid::new_v4() (or the caller-supplied id).
SessionConfig::into_wire now takes the local session id (or None when
the server is generating one).
Java (java/src/main/java/com/github/copilot/CopilotClient.java):
createSession uses the same conditional. Cloud+no-id defers
registration to the .thenCompose continuation (race-free because
CompletableFuture sync continuations run on the JSON-RPC reader
thread). Otherwise the session is pre-registered via UUID.randomUUID()
(or the caller-supplied id) before the RPC.
Node.js (nodejs/src/client.ts): createSession uses the same
conditional. Cloud+no-id lazy-initializes after the response (race-free
because vscode-jsonrpc dispatches each message via setImmediate, so
microtasks flush before the next message is read). Otherwise the
session is pre-registered via randomUUID() (or the caller-supplied id).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 1121577 commit d950601
21 files changed
Lines changed: 1081 additions & 499 deletions
File tree
- dotnet
- src
- test/Unit
- go
- internal/jsonrpc2
- java/src
- main/java/com/github/copilot
- test/java/com/github/copilot
- nodejs
- src
- test
- python
- copilot
- e2e
- rust/src
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
77 | 88 | | |
78 | 89 | | |
79 | 90 | | |
80 | | - | |
| 91 | + | |
81 | 92 | | |
82 | 93 | | |
83 | 94 | | |
| |||
166 | 177 | | |
167 | 178 | | |
168 | 179 | | |
169 | | - | |
| 180 | + | |
170 | 181 | | |
171 | 182 | | |
172 | 183 | | |
| |||
447 | 458 | | |
448 | 459 | | |
449 | 460 | | |
450 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
451 | 479 | | |
452 | 480 | | |
453 | 481 | | |
| |||
765 | 793 | | |
766 | 794 | | |
767 | 795 | | |
768 | | - | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
769 | 807 | | |
770 | 808 | | |
771 | 809 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
314 | 323 | | |
315 | 324 | | |
316 | 325 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
| 194 | + | |
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
689 | 689 | | |
690 | 690 | | |
691 | 691 | | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
697 | 747 | | |
698 | | - | |
699 | | - | |
700 | | - | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
701 | 751 | | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
730 | 771 | | |
731 | 772 | | |
732 | | - | |
733 | | - | |
734 | | - | |
| 773 | + | |
| 774 | + | |
735 | 775 | | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
741 | | - | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
742 | 784 | | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
750 | 807 | | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
751 | 815 | | |
752 | | - | |
753 | 816 | | |
754 | 817 | | |
755 | | - | |
| 818 | + | |
756 | 819 | | |
757 | | - | |
758 | | - | |
759 | | - | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
760 | 825 | | |
761 | 826 | | |
762 | 827 | | |
763 | 828 | | |
764 | 829 | | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
765 | 843 | | |
766 | | - | |
| 844 | + | |
767 | 845 | | |
768 | | - | |
| 846 | + | |
769 | 847 | | |
770 | 848 | | |
771 | 849 | | |
| |||
0 commit comments