Skip to content

Commit de8e03f

Browse files
authored
Merge pull request #171 from github/copilot/reference-impl-sync-6-new-commits
Port enableSessionTelemetry option and SDK tracing diagnostics from reference implementation
2 parents 6be0443 + 4a2e79c commit de8e03f

21 files changed

Lines changed: 472 additions & 44 deletions

.lastmerge

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
06bfc5d41d72b76527456dee0bd78fe4697bac86
1+
066a69c1e849adf1bd98564ab1b52316ec471182

pom.xml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
reference-impl-sync workflow and deal with the subsequent
9595
PR.
9696
-->
97-
<readonly-copilot-sdk-ref-impl-version-from-lastmerge-file-updated-by-reference-impl-sync>^1.0.43-0</readonly-copilot-sdk-ref-impl-version-from-lastmerge-file-updated-by-reference-impl-sync>
97+
<readonly-copilot-sdk-ref-impl-version-from-lastmerge-file-updated-by-reference-impl-sync>^1.0.44-2</readonly-copilot-sdk-ref-impl-version-from-lastmerge-file-updated-by-reference-impl-sync>
9898

9999
</properties>
100100

@@ -327,9 +327,8 @@
327327
This handles intermittent failures in E2E tests (e.g.,
328328
CompactionTest) where snapshot matching can be sensitive
329329
to non-deterministic compaction behaviour.
330-
TODO: Fix the root cause of CompactionTest flakiness
331-
(snapshot mismatch after compaction) so this retry is
332-
no longer needed.
330+
Revisit this once this issue is successfully resolved.
331+
https://github.com/github/copilot-sdk/issues/1227
333332
-->
334333
<rerunFailingTestsCount>2</rerunFailingTestsCount>
335334
<systemPropertyVariables>
@@ -346,6 +345,30 @@
346345
<COPILOT_CLI_PATH>${copilot.cli.path}</COPILOT_CLI_PATH>
347346
</environmentVariables>
348347
</configuration>
348+
<executions>
349+
<!--
350+
Run multi-client session resume tests in isolation BEFORE the
351+
main suite. These tests pass reliably alone but can time out
352+
when run after other E2E tests due to harness state leakage.
353+
-->
354+
<execution>
355+
<id>isolated-resume-tests</id>
356+
<phase>test</phase>
357+
<goals>
358+
<goal>test</goal>
359+
</goals>
360+
<configuration>
361+
<groups>isolated-resume</groups>
362+
</configuration>
363+
</execution>
364+
<!-- Exclude the isolated resume tests from the main run -->
365+
<execution>
366+
<id>default-test</id>
367+
<configuration>
368+
<excludedGroups>isolated-resume</excludedGroups>
369+
</configuration>
370+
</execution>
371+
</executions>
349372
</plugin>
350373
<!-- Add src/generated/java as an additional source root -->
351374
<plugin>

scripts/codegen/package-lock.json

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/codegen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"generate:java": "tsx java.ts"
88
},
99
"dependencies": {
10-
"@github/copilot": "^1.0.43-0",
10+
"@github/copilot": "^1.0.44-2",
1111
"json-schema": "^0.4.0",
1212
"tsx": "^4.20.6"
1313
}

src/generated/java/com/github/copilot/sdk/generated/AbortEvent.java

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generated/java/com/github/copilot/sdk/generated/AbortReason.java

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generated/java/com/github/copilot/sdk/generated/SubagentStartedEvent.java

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/github/copilot/sdk/CopilotClient.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)