Repository navigation
fix(github): drop trailing assistant prefill for Copilot chat #5802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2bbc762
fix(github): drop trailing assistant prefill for Copilot chat
diegosouzapw e32e6b2
Merge remote-tracking branch 'origin/release/v3.8.43' into fix/port-p…
diegosouzapw 6a99a20
fix(release): resolve CHANGELOG merge with release/v3.8.43, preserve …
diegosouzapw c7598ce
Merge remote-tracking branch 'origin/release/v3.8.43' into fix/port-p…
diegosouzapw 36fc7c4
chore: resolve CHANGELOG conflict for #5802 (release cascade)
diegosouzapw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
|
|
||
| import { GithubExecutor } from "../../open-sse/executors/github.ts"; | ||
|
|
||
| // GitHub Copilot's /chat/completions endpoint rejects a conversation that ends with an | ||
| // assistant message: "This model does not support assistant message prefill. The | ||
| // conversation must end with a user message." Anthropic clients (e.g. newest Claude | ||
| // Desktop) send a trailing assistant turn as a prefill seed — the Anthropic API honors | ||
| // it, but Copilot 400s. GithubExecutor.dropTrailingAssistantPrefill() strips the | ||
| // trailing assistant message(s) before dispatch, scoped to the github executor only. | ||
| // Port of 9router#2143 (author: Manuel <baslr@users.noreply.github.com>). | ||
|
|
||
| test("dropTrailingAssistantPrefill drops a single trailing assistant message", () => { | ||
| const executor = new GithubExecutor(); | ||
| const messages = [ | ||
| { role: "user", content: "Hi" }, | ||
| { role: "assistant", content: "Here is the answer:" }, | ||
| ]; | ||
|
|
||
| const out = executor.dropTrailingAssistantPrefill(messages); | ||
|
|
||
| assert.equal(out.length, 1); | ||
| assert.equal(out[0].role, "user"); | ||
| }); | ||
|
|
||
| test("dropTrailingAssistantPrefill drops multiple consecutive trailing assistant messages", () => { | ||
| const executor = new GithubExecutor(); | ||
| const messages = [ | ||
| { role: "user", content: "Hi" }, | ||
| { role: "assistant", content: "one" }, | ||
| { role: "assistant", content: "two" }, | ||
| ]; | ||
|
|
||
| const out = executor.dropTrailingAssistantPrefill(messages); | ||
|
|
||
| assert.equal(out.length, 1); | ||
| assert.equal(out[0].role, "user"); | ||
| }); | ||
|
|
||
| test("dropTrailingAssistantPrefill is a no-op (same reference) when the conversation ends with a user message", () => { | ||
| const executor = new GithubExecutor(); | ||
| const messages = [ | ||
| { role: "user", content: "Hi" }, | ||
| { role: "assistant", content: "Hello" }, | ||
| { role: "user", content: "More" }, | ||
| ]; | ||
|
|
||
| const out = executor.dropTrailingAssistantPrefill(messages); | ||
|
|
||
| assert.equal(out, messages, "must return the same array reference when nothing changes"); | ||
| assert.equal(out.length, 3); | ||
| }); | ||
|
|
||
| test("dropTrailingAssistantPrefill is a no-op when the conversation ends with a tool message", () => { | ||
| const executor = new GithubExecutor(); | ||
| const messages = [ | ||
| { role: "user", content: "Hi" }, | ||
| { role: "assistant", content: null, tool_calls: [{ id: "x" }] }, | ||
| { role: "tool", tool_call_id: "x", content: "result" }, | ||
| ]; | ||
|
|
||
| const out = executor.dropTrailingAssistantPrefill(messages); | ||
|
|
||
| assert.equal(out, messages, "must return the same array reference when nothing changes"); | ||
| assert.equal(out.length, 3); | ||
| assert.equal(out[2].role, "tool"); | ||
| }); | ||
|
|
||
| test("dropTrailingAssistantPrefill never empties an assistant-only conversation", () => { | ||
| const executor = new GithubExecutor(); | ||
| const messages = [{ role: "assistant", content: "only" }]; | ||
|
|
||
| const out = executor.dropTrailingAssistantPrefill(messages); | ||
|
|
||
| assert.equal(out.length, 1, "must keep at least one message"); | ||
| assert.equal(out[0].role, "assistant"); | ||
| }); | ||
|
|
||
| test("dropTrailingAssistantPrefill is null/empty safe", () => { | ||
| const executor = new GithubExecutor(); | ||
|
|
||
| assert.deepEqual(executor.dropTrailingAssistantPrefill([]), []); | ||
| assert.equal(executor.dropTrailingAssistantPrefill(undefined), undefined); | ||
| assert.equal(executor.dropTrailingAssistantPrefill(null), null); | ||
| }); | ||
|
|
||
| test("GithubExecutor.transformRequest drops the trailing assistant prefill end-to-end", () => { | ||
| const executor = new GithubExecutor(); | ||
| const body = { | ||
| model: "claude-sonnet-4.6", | ||
| messages: [ | ||
| { role: "user", content: "Hi" }, | ||
| { role: "assistant", content: "Here is the answer:" }, | ||
| ], | ||
| }; | ||
|
|
||
| const out = executor.transformRequest("claude-sonnet-4.6", body, false, {}); | ||
|
|
||
| assert.equal(out.messages.length, 1); | ||
| assert.equal(out.messages[0].role, "user"); | ||
| }); | ||
|
|
||
| test("GithubExecutor.transformRequest leaves a user-terminated conversation untouched end-to-end", () => { | ||
| const executor = new GithubExecutor(); | ||
| const body = { | ||
| model: "claude-sonnet-4.6", | ||
| messages: [ | ||
| { role: "user", content: "Hi" }, | ||
| { role: "assistant", content: "Hello" }, | ||
| { role: "user", content: "More" }, | ||
| ], | ||
| }; | ||
|
|
||
| const out = executor.transformRequest("claude-sonnet-4.6", body, false, {}); | ||
|
|
||
| assert.equal(out.messages.length, 3); | ||
| assert.equal(out.messages[2].role, "user"); | ||
| }); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check for the
assistantrole is case-sensitive (messages[end - 1]?.role === "assistant"). However, some clients may send roles in mixed-case or uppercase (e.g.,"Assistant"or"ASSISTANT"). To ensure robustness and prevent unexpected HTTP 400 errors from GitHub Copilot, the role check should be case-insensitive, similar to how it is handled intransformRequest.