Skip to content

test(e2e): fix flaky model switchto test race condition#1628

Draft
Morabbin wants to merge 5 commits into
github:mainfrom
Morabbin:morabbin/fix-rpc-model-flake
Draft

test(e2e): fix flaky model switchto test race condition#1628
Morabbin wants to merge 5 commits into
github:mainfrom
Morabbin:morabbin/fix-rpc-model-flake

Conversation

@Morabbin

@Morabbin Morabbin commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The previous test attempted to await the session.model_change event after switchTo resolved. This caused a timeout because the event was often already emitted during the switchTo execution (resulting in a race condition that failed frequently on Windows CI). Additionally, hardcoding 'gpt-4.1' in the event listener and assertions caused timeouts in environments that gracefully fall back to default models when auth is missing.

This PR fixes the test by starting the event listener concurrently with the switchTo call, and asserts that the resulting model IDs match what the server actually resolved.

Copilot AI review requested due to automatic review settings June 11, 2026 07:32
@Morabbin Morabbin requested a review from a team as a code owner June 11, 2026 07:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the Session-scoped RPC e2e test to avoid asserting a specific model ID value.

Changes:

  • Replaced exact modelId assertions with truthiness checks in the session-scoped RPC test.
Show a summary per file
File Description
nodejs/test/e2e/rpc_session_state.e2e.test.ts Loosens model ID assertions in the RPC session state e2e test.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread nodejs/test/e2e/rpc_session_state.e2e.test.ts
@Morabbin Morabbin marked this pull request as draft June 11, 2026 07:47
@Morabbin Morabbin force-pushed the morabbin/fix-rpc-model-flake branch from 1a6c603 to 0d4933d Compare June 11, 2026 07:50
@Morabbin Morabbin requested a review from Copilot June 11, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread nodejs/test/e2e/rpc_session_state.e2e.test.ts Outdated
Comment thread nodejs/test/e2e/rpc_session_state.e2e.test.ts Outdated
The previous fix attempted to await the `session.model_change` event
after `switchTo` resolved, which caused a timeout because the event
was often already emitted during the `switchTo` execution. Additionally,
hardcoding 'gpt-4.1' in the event listener caused timeouts on environments
that gracefully fall back to default models when auth is missing.

This commit starts the event listener concurrently with the `switchTo`
call, and asserts that the resulting model IDs match what the server actually resolved.
@Morabbin Morabbin force-pushed the morabbin/fix-rpc-model-flake branch from 0d4933d to 0ad49f7 Compare June 11, 2026 07:59
@Morabbin Morabbin requested a review from Copilot June 11, 2026 08:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 5

Comment thread nodejs/test/e2e/rpc_session_state.e2e.test.ts Outdated
Comment thread nodejs/test/e2e/rpc_session_state.e2e.test.ts Outdated
Comment thread nodejs/test/e2e/rpc_session_state.e2e.test.ts Outdated
Comment thread nodejs/test/e2e/rpc_session_state.e2e.test.ts
Comment thread nodejs/test/e2e/rpc_session_state.e2e.test.ts Outdated
@Morabbin Morabbin changed the title test(e2e): mitigate flaky model switchto test test(e2e): fix flaky model switchto test race condition Jun 11, 2026
Morabbin and others added 4 commits June 12, 2026 08:50
Wrap the multi-arg waitForEvent call and drop trailing whitespace so
npm run format:check passes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CI environments without entitlement for the requested model (gpt-4.1)
fall back to a different model, so switchTo can echo the requested id
while getCurrent reports the fallback. Assert truthiness instead of
equality to the requested/returned id, matching the getCurrent pattern.

Use a proper session.model_change type guard so event.data.newModel is
typed without an `as any` cast, clearing the no-explicit-any lint warning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Register the model_change listener before calling switchTo so a fast event
cannot fire before the listener is attached (the original race). Assert the
switchTo result and the model_change event agree (same server operation)
instead of hard-coding gpt-4.1, which fails in fallback/no-auth environments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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