@@ -188,6 +188,7 @@ private CompletableFuture<Connection> startCore() {
188188
189189 private Connection startCoreBody () {
190190 Process process = null ;
191+ long startNanos = System .nanoTime ();
191192 try {
192193 JsonRpcClient rpc ;
193194
@@ -202,6 +203,9 @@ private Connection startCoreBody() {
202203 processInfo .port ());
203204 }
204205
206+ LoggingHelpers .logTiming (LOG , Level .FINE , "CopilotClient.start transport setup complete. Elapsed={Elapsed}" ,
207+ startNanos );
208+
205209 Connection connection = new Connection (rpc , process , new ServerRpc (rpc ::invoke ));
206210
207211 // Register handlers for server-to-client calls
@@ -211,10 +215,16 @@ private Connection startCoreBody() {
211215
212216 // Verify protocol version
213217 verifyProtocolVersion (connection );
218+ LoggingHelpers .logTiming (LOG , Level .FINE ,
219+ "CopilotClient.start protocol verification complete. Elapsed={Elapsed}" , startNanos );
214220
215- LOG . info ( "Copilot client connected" );
221+ LoggingHelpers . logTiming ( LOG , Level . FINE , "CopilotClient.start complete. Elapsed={Elapsed}" , startNanos );
216222 return connection ;
217223 } catch (Exception e ) {
224+ if (!(e instanceof java .util .concurrent .CancellationException )) {
225+ LoggingHelpers .logTiming (LOG , Level .WARNING , e , "CopilotClient.start failed. Elapsed={Elapsed}" ,
226+ startNanos );
227+ }
218228 // Clean up the spawned process if connection setup failed
219229 if (process != null ) {
220230 cleanupCliProcess (process );
@@ -417,18 +427,23 @@ public CompletableFuture<CopilotSession> createSession(SessionConfig config) {
417427 + "new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)" ));
418428 }
419429 return ensureConnected ().thenCompose (connection -> {
430+ long totalNanos = System .nanoTime ();
420431 // Pre-generate session ID so the session can be registered before the RPC call,
421432 // ensuring no events emitted by the CLI during creation are lost.
422433 String sessionId = config .getSessionId () != null
423434 ? config .getSessionId ()
424435 : java .util .UUID .randomUUID ().toString ();
425436
437+ long setupNanos = System .nanoTime ();
426438 var session = new CopilotSession (sessionId , connection .rpc );
427439 if (options .getExecutor () != null ) {
428440 session .setExecutor (options .getExecutor ());
429441 }
430442 SessionRequestBuilder .configureSession (session , config );
431443 sessions .put (sessionId , session );
444+ LoggingHelpers .logTiming (LOG , Level .FINE ,
445+ "CopilotClient.createSession local setup complete. Elapsed={Elapsed}, SessionId=" + sessionId ,
446+ setupNanos );
432447
433448 // Extract transform callbacks from the system message config.
434449 // Callbacks are registered with the session; a wire-safe copy of the
@@ -444,7 +459,12 @@ public CompletableFuture<CopilotSession> createSession(SessionConfig config) {
444459 request .setSystemMessage (extracted .wireSystemMessage ());
445460 }
446461
462+ long rpcNanos = System .nanoTime ();
447463 return connection .rpc .invoke ("session.create" , request , CreateSessionResponse .class ).thenApply (response -> {
464+ LoggingHelpers .logTiming (LOG , Level .FINE ,
465+ "CopilotClient.createSession session creation request completed. Elapsed={Elapsed}, SessionId="
466+ + sessionId ,
467+ rpcNanos );
448468 session .setWorkspacePath (response .workspacePath ());
449469 session .setCapabilities (response .capabilities ());
450470 // If the server returned a different sessionId (e.g. a v2 CLI that ignores
@@ -455,9 +475,13 @@ public CompletableFuture<CopilotSession> createSession(SessionConfig config) {
455475 session .setActiveSessionId (returnedId );
456476 sessions .put (returnedId , session );
457477 }
478+ LoggingHelpers .logTiming (LOG , Level .FINE ,
479+ "CopilotClient.createSession complete. Elapsed={Elapsed}, SessionId=" + sessionId , totalNanos );
458480 return session ;
459481 }).exceptionally (ex -> {
460482 sessions .remove (sessionId );
483+ LoggingHelpers .logTiming (LOG , Level .WARNING , ex ,
484+ "CopilotClient.createSession failed. Elapsed={Elapsed}, SessionId=" + sessionId , totalNanos );
461485 throw ex instanceof RuntimeException re ? re : new RuntimeException (ex );
462486 });
463487 });
@@ -496,13 +520,18 @@ public CompletableFuture<CopilotSession> resumeSession(String sessionId, ResumeS
496520 + "new ResumeSessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)" ));
497521 }
498522 return ensureConnected ().thenCompose (connection -> {
523+ long totalNanos = System .nanoTime ();
499524 // Register the session before the RPC call to avoid missing early events.
525+ long setupNanos = System .nanoTime ();
500526 var session = new CopilotSession (sessionId , connection .rpc );
501527 if (options .getExecutor () != null ) {
502528 session .setExecutor (options .getExecutor ());
503529 }
504530 SessionRequestBuilder .configureSession (session , config );
505531 sessions .put (sessionId , session );
532+ LoggingHelpers .logTiming (LOG , Level .FINE ,
533+ "CopilotClient.resumeSession local setup complete. Elapsed={Elapsed}, SessionId=" + sessionId ,
534+ setupNanos );
506535
507536 // Extract transform callbacks from the system message config.
508537 var extracted = SessionRequestBuilder .extractTransformCallbacks (config .getSystemMessage ());
@@ -515,7 +544,12 @@ public CompletableFuture<CopilotSession> resumeSession(String sessionId, ResumeS
515544 request .setSystemMessage (extracted .wireSystemMessage ());
516545 }
517546
547+ long rpcNanos = System .nanoTime ();
518548 return connection .rpc .invoke ("session.resume" , request , ResumeSessionResponse .class ).thenApply (response -> {
549+ LoggingHelpers .logTiming (LOG , Level .FINE ,
550+ "CopilotClient.resumeSession session resume request completed. Elapsed={Elapsed}, SessionId="
551+ + sessionId ,
552+ rpcNanos );
519553 session .setWorkspacePath (response .workspacePath ());
520554 session .setCapabilities (response .capabilities ());
521555 // If the server returned a different sessionId than what was requested, re-key.
@@ -525,9 +559,13 @@ public CompletableFuture<CopilotSession> resumeSession(String sessionId, ResumeS
525559 session .setActiveSessionId (returnedId );
526560 sessions .put (returnedId , session );
527561 }
562+ LoggingHelpers .logTiming (LOG , Level .FINE ,
563+ "CopilotClient.resumeSession complete. Elapsed={Elapsed}, SessionId=" + sessionId , totalNanos );
528564 return session ;
529565 }).exceptionally (ex -> {
530566 sessions .remove (sessionId );
567+ LoggingHelpers .logTiming (LOG , Level .WARNING , ex ,
568+ "CopilotClient.resumeSession failed. Elapsed={Elapsed}, SessionId=" + sessionId , totalNanos );
531569 throw ex instanceof RuntimeException re ? re : new RuntimeException (ex );
532570 });
533571 });
0 commit comments