Fix macOS-flaky tests: testShouldGetLastSessionId and testShouldGetSessionMetadataById#215
Merged
edburns merged 1 commit intoMay 19, 2026
Conversation
…ssionMetadataById The Copilot CLI persists session state asynchronously, so querying session metadata or the last session ID immediately after sendAndWait() is a race condition. On Linux (CI) and Windows the I/O completes fast enough to mask the issue, but on macOS the tests fail consistently. Align the Java tests with the .NET and Node.js reference implementations: - testShouldGetLastSessionId: close the session before calling getLastSessionId() (matches .NET DisposeAsync-then-query pattern), and poll with a 10-second deadline and 50ms intervals (matches Node.js client_lifecycle.e2e.test.ts polling pattern). - testShouldGetSessionMetadataById: poll getSessionMetadata() with a 10-second deadline and 50ms intervals until it returns non-null (matches .NET WaitForConditionAsync pattern). Signed-off-by: Ed Burns <edburns@microsoft.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates flaky session lifecycle E2E tests to account for Copilot CLI’s asynchronous session persistence, primarily by closing the session before querying the “last session id” and by polling for persisted metadata.
Changes:
- Close the session before querying
getLastSessionId(), then poll until the expected ID appears. - Poll
getSessionMetadata(sessionId)until it becomes available (non-null), with a bounded wait window.
Show a summary per file
| File | Description |
|---|---|
src/test/java/com/github/copilot/sdk/CopilotSessionTest.java |
Adds polling/ordering adjustments to reduce macOS-specific flakiness when querying asynchronously persisted session state. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/test/java/com/github/copilot/sdk/CopilotSessionTest.java:869
- This loop intends to wait up to 10s, but each
getSessionMetadata(...).get(30, TimeUnit.SECONDS)can block for 30s, so the total wait can exceed the deadline significantly if the RPC call is slow/hung. Use a timeout derived from the remaining time (or a small per-call timeout) to ensure the test is actually bounded to ~10s.
com.github.copilot.sdk.json.SessionMetadata metadata = null;
long deadline = System.currentTimeMillis() + 10_000;
while (System.currentTimeMillis() < deadline) {
metadata = client.getSessionMetadata(sessionId).get(30, TimeUnit.SECONDS);
if (metadata != null) {
break;
}
Thread.sleep(50);
}
- Files reviewed: 1/1 changed files
- Comments generated: 1
Comment on lines
+769
to
+777
| String lastId = null; | ||
| long deadline = System.currentTimeMillis() + 10_000; | ||
| while (System.currentTimeMillis() < deadline) { | ||
| lastId = client.getLastSessionId().get(30, TimeUnit.SECONDS); | ||
| if (sessionId.equals(lastId)) { | ||
| break; | ||
| } | ||
| Thread.sleep(50); | ||
| } |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Copilot CLI persists session state asynchronously, so querying session metadata or the last session ID immediately after sendAndWait() is a race condition. On Linux (CI) and Windows the I/O completes fast enough to mask the issue, but on macOS the tests fail consistently.
Align the Java tests with the .NET and Node.js reference implementations:
testShouldGetLastSessionId: close the session before calling getLastSessionId() (matches .NET DisposeAsync-then-query pattern), and poll with a 10-second deadline and 50ms intervals (matches Node.js client_lifecycle.e2e.test.ts polling pattern).
testShouldGetSessionMetadataById: poll getSessionMetadata() with a 10-second deadline and 50ms intervals until it returns non-null (matches .NET WaitForConditionAsync pattern).