Skip to content

Test: Add e2e test for duplicate events after resume (#567)#630

Closed
SteveSandersonMS wants to merge 1 commit intomainfrom
stevesa/fix-duplicate-sdk-events
Closed

Test: Add e2e test for duplicate events after resume (#567)#630
SteveSandersonMS wants to merge 1 commit intomainfrom
stevesa/fix-duplicate-sdk-events

Conversation

@SteveSandersonMS
Copy link
Contributor

@SteveSandersonMS SteveSandersonMS commented Mar 2, 2026

Overview

Adds a regression test for #567 — duplicate event delivery after calling resumeSession() multiple times.

What the test does

  1. Creates a session and completes one turn
  2. Resumes the session twice, letting the old session handles go away ungracefully (no explicit unsubscribe/cleanup)
  3. Sends a message on the latest resumed session
  4. Asserts that assistant.message arrives exactly once, not duplicated

Without the corresponding runtime fix, this test fails with 3 copies of assistant.message (1 original + 1 per leaked listener from each resume).

Dependency

⚠️ This test will only pass once the runtime fix lands.

Regression test for #567. Verifies that resuming a session multiple times
does not cause duplicate event delivery. The test creates a session, resumes
it twice (letting old handles go ungracefully), then sends a message and
asserts that assistant.message arrives exactly once.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SteveSandersonMS SteveSandersonMS requested a review from a team as a code owner March 2, 2026 16:05
Copilot AI review requested due to automatic review settings March 2, 2026 16:05
Copy link
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

Adds a Node.js E2E regression test (with a matching replay snapshot) to catch duplicate session events after calling resumeSession() multiple times, as reported in #567. This fits into the repo’s cross-SDK replay-based E2E suite to prevent regressions in session lifecycle behavior.

Changes:

  • Added a new E2E test that resumes the same session twice and asserts assistant.message is delivered exactly once.
  • Added a new replay snapshot YAML covering the two-turn conversation used by the test.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/snapshots/session/should_not_receive_duplicate_events_after_resume.yaml Adds replay snapshot for the new regression test scenario (two math prompts/responses).
nodejs/test/e2e/session.test.ts Adds a regression test asserting no duplicate assistant.message events after multiple resumes.

Comment on lines +207 to +221
it("should not receive duplicate events after resume", async () => {
// Regression test for https://github.com/github/copilot-sdk/issues/567
// Each resumeSession call was adding an additional event listener without
// removing the previous one, causing events to be delivered N+1 times after N resumes.

// Create session and do a turn, then let the session handle go away ungracefully
const session1 = await client.createSession({ onPermissionRequest: approveAll });
const sessionId = session1.sessionId;
await session1.sendAndWait({ prompt: "What is 1+1?" });

// Resume twice (simulating two reconnects) without cleaning up previous handles.
// The old session handles just go away as they would in a real disconnect.
await client.resumeSession(sessionId, { onPermissionRequest: approveAll });
const session3 = await client.resumeSession(sessionId, { onPermissionRequest: approveAll });

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

This new regression test is expected (per PR description) to fail until the Copilot CLI/runtime fix lands, but this PR doesn’t bump the bundled CLI dependency or otherwise gate/skip the test. As-is, merging this PR is likely to make CI fail for the SDK repo. Consider temporarily marking this test as skipped with a TODO referencing the runtime PR (and unskip once the CLI package version used in tests includes the fix), or bump the CLI/runtime dependency in the same PR so the test is green immediately.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Cross-SDK Consistency Review

Thank you for adding this regression test for issue #567! The test verifies that duplicate events are not received after multiple resumeSession() calls.

🔍 Consistency Gap Identified

This PR adds the test only to the Node.js/TypeScript SDK, but the underlying issue is in the runtime's initializeSession() method (as mentioned in the PR description). This means the bug potentially affects all SDK implementations.

📋 Recommendation

Consider adding equivalent tests to the other SDK implementations:

  • Python: python/e2e/test_session.py
  • Go: go/internal/e2e/session_test.go
  • .NET: dotnet/test/SessionTests.cs

The good news is that the test snapshot file (test/snapshots/session/should_not_receive_duplicate_events_after_resume.yaml) is already in the shared location and can be used by all SDKs. Each language implementation would just need to:

  1. Create a session and complete one turn ("What is 1+1?")
  2. Resume the session twice without cleaning up previous handles
  3. Send a message on the latest resumed session ("What is 3+3?")
  4. Assert that assistant.message arrives exactly once, not duplicated

This would ensure all SDKs have regression coverage for this issue.


Note: This doesn't block the current PR if the plan is to add tests to other SDKs separately. Just flagging it for visibility.

AI generated by SDK Consistency Review Agent

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