-
Notifications
You must be signed in to change notification settings - Fork 840
fix(ci): stream Copilot inference prompts over stdin #1883
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
lidge-jun
merged 17 commits into
lidge-jun:dev
from
Wibias:agent/fix-copilot-inference-stdin
Aug 18, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8dffa53
fix(ci): stream Copilot prompts over stdin
Wibias f500a05
test(ci): cover Copilot stdin transport
Wibias 984d8a6
test(ci): require stdin Copilot runner
Wibias 85e043e
test(ci): run Copilot transport regression
Wibias 9fd51c5
fix(ci): avoid E2BIG in Copilot triage
Wibias 1af2ce3
fix(ci): stream issue translation prompts to Copilot
Wibias f6f388e
test(ci): cover hung Copilot timeout
Wibias f86fb37
fix(ci): bound Copilot inference runtime
Wibias a62d55a
test(ci): add digest-pinned Copilot installer
Wibias 9ac5029
test(ci): require digest-pinned Copilot install
Wibias 5358bf4
test(ci): cover pinned Copilot installer changes
Wibias a3b7dac
fix(ci): install digest-pinned Copilot release
Wibias e9eaddc
fix(ci): install digest-pinned Copilot release
Wibias 30a5279
test(ci): require supported Copilot token env
Wibias 5e3b07e
test(ci): require supported Copilot token mapping
Wibias 2df0e57
fix(ci): map Copilot token to supported CLI env
Wibias 7db1bf8
test(ci): keep explicit Copilot secret fallback
Wibias 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| COPILOT_VERSION="v1.0.74" | ||
| COPILOT_ASSET="copilot-linux-x64.tar.gz" | ||
| COPILOT_SHA256="4a708b0a1cbaef4c2ca5c546a622f887a3b70e8a0432bc3cee0d386704816650" | ||
| COPILOT_URL="https://github.com/github/copilot-cli/releases/download/${COPILOT_VERSION}/${COPILOT_ASSET}" | ||
|
|
||
| install_root="${RUNNER_TEMP:?RUNNER_TEMP is required}/copilot-cli-${COPILOT_VERSION}" | ||
| archive="${install_root}/${COPILOT_ASSET}" | ||
| bin_dir="${install_root}/bin" | ||
|
|
||
| rm -rf -- "$install_root" | ||
| mkdir -p "$bin_dir" | ||
|
|
||
| curl \ | ||
| --proto '=https' \ | ||
| --tlsv1.2 \ | ||
| --fail \ | ||
| --silent \ | ||
| --show-error \ | ||
| --location \ | ||
| --retry 3 \ | ||
| "$COPILOT_URL" \ | ||
| --output "$archive" | ||
|
|
||
| printf '%s %s\n' "$COPILOT_SHA256" "$archive" | sha256sum --check --status | ||
|
|
||
| tar -xzf "$archive" -C "$bin_dir" | ||
| chmod +x "$bin_dir/copilot" | ||
| "$bin_dir/copilot" --version | ||
|
|
||
| printf '%s\n' "$bin_dir" >> "${GITHUB_PATH:?GITHUB_PATH is required}" |
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,73 @@ | ||
| const fs = require('node:fs'); | ||
| const crypto = require('node:crypto'); | ||
| const { spawnSync } = require('node:child_process'); | ||
|
|
||
| function fail(message, code = 1) { | ||
| process.stderr.write(`${message}\n`); | ||
| process.exit(code); | ||
| } | ||
|
|
||
| const promptPath = process.argv[2]; | ||
| let userPrompt; | ||
| try { | ||
| userPrompt = promptPath | ||
| ? fs.readFileSync(promptPath, 'utf8') | ||
| : fs.readFileSync(0, 'utf8'); | ||
| } catch (error) { | ||
| fail(`Unable to read Copilot prompt: ${error instanceof Error ? error.message : String(error)}`); | ||
| } | ||
|
|
||
| const systemPrompt = String(process.env.COPILOT_SYSTEM_PROMPT || '').trim(); | ||
| const prompt = systemPrompt | ||
| ? `${systemPrompt}\n\n${userPrompt}` | ||
| : userPrompt; | ||
|
|
||
| const rawTimeout = Number(process.env.COPILOT_TIMEOUT_MS || 120_000); | ||
| const timeout = Number.isFinite(rawTimeout) && rawTimeout > 0 | ||
| ? Math.floor(rawTimeout) | ||
| : 120_000; | ||
|
|
||
| const args = [ | ||
| '-s', | ||
| '--no-ask-user', | ||
| '--no-custom-instructions', | ||
| '--no-auto-update', | ||
| ]; | ||
|
|
||
| const copilotEnv = { ...process.env }; | ||
| if (copilotEnv.COPILOT_GITHUB_TOKEN) { | ||
| // Copilot CLI v1.0.74 authenticates from GH_TOKEN or GITHUB_TOKEN. | ||
| copilotEnv.GITHUB_TOKEN = copilotEnv.COPILOT_GITHUB_TOKEN; | ||
| } | ||
|
|
||
| const result = spawnSync('copilot', args, { | ||
| input: prompt, | ||
| encoding: 'utf8', | ||
| env: copilotEnv, | ||
| maxBuffer: 16 * 1024 * 1024, | ||
| timeout, | ||
| killSignal: 'SIGKILL', | ||
| }); | ||
|
|
||
| if (result.stderr) { | ||
| process.stderr.write(result.stderr); | ||
| } | ||
|
|
||
| if (result.error) { | ||
| const errorCode = result.error.code || 'spawn_error'; | ||
| const signal = result.signal || 'none'; | ||
| fail(`Copilot CLI execution failed (${errorCode}; signal=${signal}): ${result.error.message}`); | ||
| } | ||
|
|
||
| if (result.status !== 0) { | ||
| process.exit(Number.isInteger(result.status) ? result.status : 1); | ||
| } | ||
|
|
||
| const outputFile = process.env.GITHUB_OUTPUT; | ||
| if (!outputFile) { | ||
| fail('GITHUB_OUTPUT is not set.'); | ||
| } | ||
|
|
||
| const response = String(result.stdout || '').trimEnd(); | ||
| const delimiter = `COPILOT_RESPONSE_${crypto.randomBytes(12).toString('hex')}`; | ||
| fs.appendFileSync(outputFile, `response<<${delimiter}\n${response}\n${delimiter}\n`); | ||
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,123 @@ | ||
| const test = require('node:test'); | ||
| const assert = require('node:assert/strict'); | ||
| const fs = require('node:fs'); | ||
| const os = require('node:os'); | ||
| const path = require('node:path'); | ||
| const { spawnSync } = require('node:child_process'); | ||
|
|
||
| const RUNNER = path.join(__dirname, 'run-copilot-inference.cjs'); | ||
|
|
||
| function makeFakeCopilot(source) { | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'fake-copilot-')); | ||
| const file = path.join(dir, 'copilot'); | ||
| fs.writeFileSync(file, `#!/usr/bin/env node\n${source}\n`, { mode: 0o755 }); | ||
| return { dir, file }; | ||
| } | ||
|
|
||
| function outputValue(file, key) { | ||
| const text = fs.readFileSync(file, 'utf8'); | ||
| const match = text.match(new RegExp(`${key}<<([^\\n]+)\\n([\\s\\S]*?)\\n\\1(?:\\n|$)`)); | ||
| assert.ok(match, `missing ${key} output in ${text}`); | ||
| return match[2]; | ||
| } | ||
|
|
||
| test('streams a large prompt over stdin and maps the Copilot token to GITHUB_TOKEN', () => { | ||
| const fake = makeFakeCopilot(` | ||
| const fs = require('node:fs'); | ||
| const input = fs.readFileSync(0, 'utf8'); | ||
| const argvBytes = Buffer.byteLength(process.argv.slice(2).join(' ')); | ||
| if (argvBytes > 8192) { | ||
| console.error('prompt leaked into argv'); | ||
| process.exit(91); | ||
| } | ||
| process.stdout.write(JSON.stringify({ | ||
| inputBytes: Buffer.byteLength(input), | ||
| argv: process.argv.slice(2), | ||
| githubToken: process.env.GITHUB_TOKEN || '', | ||
| })); | ||
| `); | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'copilot-runner-test-')); | ||
| const promptFile = path.join(dir, 'prompt.txt'); | ||
| const outputFile = path.join(dir, 'output.txt'); | ||
| const prompt = 'x'.repeat(512 * 1024); | ||
| fs.writeFileSync(promptFile, prompt); | ||
| fs.writeFileSync(outputFile, ''); | ||
|
|
||
| const result = spawnSync(process.execPath, [RUNNER, promptFile], { | ||
| encoding: 'utf8', | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${fake.dir}${path.delimiter}${process.env.PATH}`, | ||
| GITHUB_OUTPUT: outputFile, | ||
| COPILOT_SYSTEM_PROMPT: 'system instruction', | ||
| COPILOT_GITHUB_TOKEN: 'test-token', | ||
| GITHUB_TOKEN: '', | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal(result.status, 0, result.stderr); | ||
| const response = JSON.parse(outputValue(outputFile, 'response')); | ||
| assert.ok(response.inputBytes > Buffer.byteLength(prompt)); | ||
| assert.deepEqual(response.argv, ['-s', '--no-ask-user', '--no-custom-instructions', '--no-auto-update']); | ||
| assert.equal(response.githubToken, 'test-token'); | ||
| }); | ||
|
|
||
| test('surfaces Copilot stderr and preserves a non-zero exit code', () => { | ||
| const fake = makeFakeCopilot(` | ||
| process.stdin.resume(); | ||
| process.stdin.on('end', () => { | ||
| console.error('copilot auth failed: test diagnostic'); | ||
| process.exit(7); | ||
| }); | ||
| `); | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'copilot-runner-test-')); | ||
| const promptFile = path.join(dir, 'prompt.txt'); | ||
| const outputFile = path.join(dir, 'output.txt'); | ||
| fs.writeFileSync(promptFile, 'hello'); | ||
| fs.writeFileSync(outputFile, ''); | ||
|
|
||
| const result = spawnSync(process.execPath, [RUNNER, promptFile], { | ||
| encoding: 'utf8', | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${fake.dir}${path.delimiter}${process.env.PATH}`, | ||
| GITHUB_OUTPUT: outputFile, | ||
| COPILOT_SYSTEM_PROMPT: 'system instruction', | ||
| COPILOT_GITHUB_TOKEN: 'test-token', | ||
| }, | ||
| }); | ||
|
|
||
| assert.equal(result.status, 7); | ||
| assert.match(result.stderr, /copilot auth failed: test diagnostic/); | ||
| assert.equal(fs.readFileSync(outputFile, 'utf8'), ''); | ||
| }); | ||
|
|
||
| test('kills a hung Copilot process at the configured timeout', () => { | ||
| const fake = makeFakeCopilot(` | ||
| process.stderr.write('copilot started\\n'); | ||
| setInterval(() => {}, 1000); | ||
| `); | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'copilot-runner-test-')); | ||
| const promptFile = path.join(dir, 'prompt.txt'); | ||
| const outputFile = path.join(dir, 'output.txt'); | ||
| fs.writeFileSync(promptFile, 'hello'); | ||
| fs.writeFileSync(outputFile, ''); | ||
|
|
||
| const result = spawnSync(process.execPath, [RUNNER, promptFile], { | ||
| encoding: 'utf8', | ||
| timeout: 5000, | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${fake.dir}${path.delimiter}${process.env.PATH}`, | ||
| GITHUB_OUTPUT: outputFile, | ||
| COPILOT_SYSTEM_PROMPT: 'system instruction', | ||
| COPILOT_GITHUB_TOKEN: 'test-token', | ||
| COPILOT_TIMEOUT_MS: '75', | ||
| }, | ||
| }); | ||
|
|
||
| assert.notEqual(result.status, 0); | ||
| assert.match(result.stderr, /ETIMEDOUT/); | ||
| assert.match(result.stderr, /SIGKILL/); | ||
| assert.equal(fs.readFileSync(outputFile, 'utf8'), ''); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.