Skip to content

Fix macOS-flaky tests: testShouldGetLastSessionId and testShouldGetSessionMetadataById#215

Merged
edburns merged 1 commit into
github:mainfrom
edburns:edburns/fix-timing-related-test-failures
May 19, 2026
Merged

Fix macOS-flaky tests: testShouldGetLastSessionId and testShouldGetSessionMetadataById#215
edburns merged 1 commit into
github:mainfrom
edburns:edburns/fix-timing-related-test-failures

Conversation

@edburns
Copy link
Copy Markdown
Collaborator

@edburns edburns commented May 19, 2026

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).

…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>
Copilot AI review requested due to automatic review settings May 19, 2026 18:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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);
}
@edburns edburns merged commit 7f11dcc into github:main May 19, 2026
7 checks passed
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.

2 participants