Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(agent): deliver the copilot prompt on stdin (MUL-8105) (#9380)
Multica Eve74281e313d3c
diff --git a/server/pkg/agent/argv_limit.go b/server/pkg/agent/argv_limit.gonew file mode 100644index 0000000000..3dcb5eedd9--- /dev/null+++ b/server/pkg/agent/argv_limit.go@@ -0,0 +1,41 @@+package agent++import (+ "errors"+ "fmt"+ "runtime"+ "syscall"+)++// ErrArgvLimitExceeded reports that the OS refused to start a runtime because+// its command line was too large. Without it the member only ever sees a raw+// errno ("argument list too long") with no hint at the cause or the remedy+// (#9362). It wraps the original error, so errors.Is on the errno still holds.+var ErrArgvLimitExceeded = errors.New("agent command line exceeds the OS argument size limit")++// windowsErrorFilenameExcedRange is ERROR_FILENAME_EXCED_RANGE (206), the code+// CreateProcess returns for an over-long command line ("The filename or+// extension is too long", #6538).+const windowsErrorFilenameExcedRange = syscall.Errno(206)++// isArgvLimitError reports whether err is the OS refusing an oversized command+// line: E2BIG from execve on Unix, ERROR_FILENAME_EXCED_RANGE on Windows.+func isArgvLimitError(err error) bool {+ if err == nil {+ return false+ }+ if errors.Is(err, syscall.E2BIG) {+ return true+ }+ return runtime.GOOS == "windows" && errors.Is(err, windowsErrorFilenameExcedRange)+}++// wrapArgvLimitError turns an oversized-command-line start failure into a+// named, actionable error and returns every other error unchanged.+func wrapArgvLimitError(err error) error {+ if !isArgvLimitError(err) {+ return err+ }+ return fmt.Errorf("%w (large content such as pasted logs in the issue thread or oversized custom_args can cause this; move large artifacts into issue attachments): %w",+ ErrArgvLimitExceeded, err)+}diff --git a/server/pkg/agent/argv_limit_test.go b/server/pkg/agent/argv_limit_test.gonew file mode 100644index 0000000000..bf07326244--- /dev/null+++ b/server/pkg/agent/argv_limit_test.go@@ -0,0 +1,40 @@+package agent++import (+ "errors"+ "fmt"+ "io/fs"+ "strings"+ "syscall"+ "testing"+)++func TestWrapArgvLimitErrorNamesE2BIG(t *testing.T) {+ t.Parallel()++ // The shape os/exec returns for the #9362 incident.+ raw := &fs.PathError{Op: "fork/exec", Path: "/usr/bin/copilot", Err: syscall.E2BIG}+ got := wrapArgvLimitError(raw)++ if !errors.Is(got, ErrArgvLimitExceeded) {+ t.Fatalf("expected ErrArgvLimitExceeded on the chain, got %v", got)+ }+ if !errors.Is(got, syscall.E2BIG) {+ t.Fatalf("raw errno must stay on the chain, got %v", got)+ }+ if !strings.Contains(got.Error(), "attachments") {+ t.Fatalf("expected the remedy in the message, got %q", got.Error())+ }+}++func TestWrapArgvLimitErrorPassesOtherErrorsThrough(t *testing.T) {+ t.Parallel()++ raw := fmt.Errorf("start: %w", syscall.ENOENT)+ if got := wrapArgvLimitError(raw); got != raw {+ t.Fatalf("unrelated error was rewritten: %v", got)+ }+ if wrapArgvLimitError(nil) != nil {+ t.Fatal("nil must stay nil")+ }+}diff --git a/server/pkg/agent/copilot.go b/server/pkg/agent/copilot.goindex ad8a205485..8c4957fa5c 100644--- a/server/pkg/agent/copilot.go+++ b/server/pkg/agent/copilot.go@@ -4,17 +4,20 @@ import ("context""encoding/json""fmt"+ "io""log/slog""os/exec""strings"+ "sync""time")// copilotBackend implements Backend by spawning the GitHub Copilot CLI// with --output-format json and parsing its JSONL event stream.//-// The v1 integration uses the -p (pipe) mode which is the stable-// automation/CI channel. The prompt is passed as a CLI argument (not stdin).+// The integration runs Copilot non-interactively with the prompt piped on+// stdin and no -p, never as a CLI argument: an argv prompt dies at fork/exec+// once it clears the OS argument size limit (#9362; see buildCopilotArgs).// Events arrive as newline-delimited JSON on stdout in the Copilot CLI's// own envelope format: { "type": "dotted.event.name", "data": {...}, ... }type copilotBackend struct {@@ -40,6 +43,9 @@ type copilotEventState struct {activeModel stringfinalStatus stringfinalError string+ // sawResult records that the terminal "result" event arrived, i.e. the CLI+ // consumed the whole stdin prompt and ran to completion.+ sawResult bool// Token usage arrives on up to three different events, so each source is// accumulated separately and resolved once at the end by resolveUsage.@@ -310,6 +316,7 @@ func handleCopilotEvent(evt copilotEvent, st *copilotEventState) []Message {}case "result":+ st.sawResult = trueif evt.SessionID != "" {st.sessionID = evt.SessionID}@@ -344,13 +351,20 @@ func (b *copilotBackend) Execute(ctx context.Context, prompt string, opts ExecOpreturn nil, fmt.Errorf("copilot executable not found at %q: %w", execName, err)}+ // Without -p the CLI takes its prompt from stdin; an empty stdin would+ // leave it nothing to run, so refuse before spawning anything.+ if strings.TrimSpace(prompt) == "" {+ return nil, fmt.Errorf("copilot: empty prompt")+ }+timeout := opts.TimeoutrunCtx, cancel := runContext(ctx, timeout)- args := buildCopilotArgs(prompt, opts, b.cfg.Logger)+ // The task prompt is delivered on stdin, never argv (see buildCopilotArgs).+ args := buildCopilotArgs(opts, b.cfg.Logger)cmd, _, _ := b.cfg.commandAt(execName).execVia(runCtx, chooseCopilotInvocation, lookedUp, args, b.cfg.Logger)hideAgentWindow(cmd)- b.cfg.logAgentCommand(cmd, newAgentCommandLogArgs(args))+ b.cfg.logAgentCommandWithPrompt(cmd, newAgentCommandLogArgs(args), len(prompt))cmd.WaitDelay = 10 * time.Secondif opts.Cwd != "" {cmd.Dir = opts.Cwd@@ -362,14 +376,33 @@ func (b *copilotBackend) Execute(ctx context.Context, prompt string, opts ExecOpcancel()return nil, fmt.Errorf("copilot stdout pipe: %w", err)}+ stdin, err := cmd.StdinPipe()+ if err != nil {+ cancel()+ return nil, fmt.Errorf("copilot stdin pipe: %w", err)+ }+ var closeStdinOnce sync.Once+ closeStdin := func() { closeStdinOnce.Do(func() { _ = stdin.Close() }) }stderrBuf := newStderrTail(newLogWriter(b.cfg.Logger, "[copilot:stderr] "), agentStderrTailBytes)cmd.Stderr = stderrBufif err := startOwnedProcessTree(cmd, b.cfg.Logger); err != nil {+ closeStdin()cancel()return nil, fmt.Errorf("start copilot: %w", err)}+ // Write the prompt from its own goroutine so it cannot deadlock against the+ // stdout reader: a prompt larger than the OS pipe buffer blocks mid-write+ // until Copilot drains it, and Copilot cannot drain while nobody consumes+ // its stdout. Closing stdin is what ends the prompt, so close on every path.+ writeErrCh := make(chan error, 1)+ go func() {+ _, err := io.WriteString(stdin, prompt)+ closeStdin()+ writeErrCh <- err+ }()+b.cfg.Logger.Info("copilot started", "pid", cmd.Process.Pid, "cwd", opts.Cwd, "model", opts.Model)msgCh := make(chan Message, 256)@@ -389,6 +422,8 @@ func (b *copilotBackend) Execute(ctx context.Context, prompt string, opts ExecOpgo func() {<-runCtx.Done()+ // Release a prompt write still blocked on a full stdin pipe.+ closeStdin()_ = stdout.Close()}()@@ -418,6 +453,10 @@ func (b *copilotBackend) Execute(ctx context.Context, prompt string, opts ExecOpreleaseProcessGroup(cmd)duration := time.Since(startTime)+ // Wait closes the process pipes, so a prompt write still blocked when+ // Copilot exited has returned by now. The writer sends exactly once.+ writeErr := <-writeErrCh+if runCtx.Err() == context.DeadlineExceeded {st.finalStatus = "timeout"st.finalError = fmt.Sprintf("copilot timed out after %s", timeout)@@ -427,6 +466,19 @@ func (b *copilotBackend) Execute(ctx context.Context, prompt string, opts ExecOp} else if exitErr != nil && st.finalStatus == "completed" {st.finalStatus = "failed"st.finalError = fmt.Sprintf("copilot exited with error: %v", exitErr)+ } else if writeErr != nil && !st.sawResult {+ // A broken prompt write is benign only once the run is proven to have+ // finished: Copilot reads stdin to EOF before it starts, so a run that+ // reached its terminal "result" event received the whole prompt and a+ // late EPIPE just means the pipe closed on the way out. Without that+ // proof the prompt may never have landed — never report that as a+ // clean success.+ st.finalStatus = "failed"+ if st.finalError == "" {+ st.finalError = fmt.Sprintf("copilot prompt write failed: %v", writeErr)+ } else {+ st.finalError = fmt.Sprintf("%s; copilot prompt write failed: %v", st.finalError, writeErr)+ }}if st.finalError != "" {st.finalError = withAgentStderr(st.finalError, "copilot", stderrBuf.Tail())@@ -625,11 +677,18 @@ var copilotBlockedArgs = map[string]blockedArgMode{// buildCopilotArgs assembles the argv for a one-shot copilot invocation.//-// copilot -p "<prompt>" --output-format json --allow-all --no-ask-user+// copilot --output-format json --allow-all --no-ask-user// [--resume <session-id>] [--model <model>]-func buildCopilotArgs(prompt string, opts ExecOptions, logger *slog.Logger) []string {+//+// The prompt is NOT on argv: Copilot CLI enters non-interactive mode when its+// stdin is piped and no -p is given, running the piped text as the entire+// prompt (verified on Copilot CLI 1.0.98, including --resume). Inlining it as+// `-p <prompt>` fails at fork/exec with E2BIG on Linux once the prompt clears+// MAX_ARG_STRLEN (131,072 bytes) — a long issue thread is enough (#9362) — and+// hits the 32,767-character CreateProcess ceiling on Windows. "-p" stays in+// copilotBlockedArgs so custom_args cannot reintroduce that path.+func buildCopilotArgs(opts ExecOptions, logger *slog.Logger) []string {args := []string{- "-p", prompt,"--output-format", "json","--allow-all", // tools + paths + URLs — full headless mode"--no-ask-user",diff --git a/server/pkg/agent/copilot_invocation.go b/server/pkg/agent/copilot_invocation.goindex 50f4beeb07..371b9d4a1c 100644--- a/server/pkg/agent/copilot_invocation.go+++ b/server/pkg/agent/copilot_invocation.go@@ -51,11 +51,11 @@ func chooseCopilotInvocation(execName, lookedUp string, args []string, logger *s// is re-tokenised — the same defect already documented for cursor-agent// in buildCursorArgs (#5649).//-// Copilot has no stdin prompt channel (the escape hatch cursor-agent offers),-// so the prompt must stay on the command line and the launchers have to go.-// Spawning copilot.exe directly leaves exactly one hop, Go -> native binary,-// and Go's syscall.EscapeArg is the exact inverse of the CRT parsing the-// binary uses.+// The task prompt itself now rides stdin (see buildCopilotArgs, #9362), but+// model ids, session ids and custom_args still travel on argv, so the native+// binary stays preferred. Spawning copilot.exe directly leaves exactly one+// hop, Go -> native binary, and Go's syscall.EscapeArg is the exact inverse of+// the CRT parsing the binary uses.//// Layout when installed via `npm install -g @github/copilot` (verified// against @github/copilot 1.0.77):diff --git a/server/pkg/agent/copilot_invocation_windows.go b/server/pkg/agent/copilot_invocation_windows.goindex 37e88351aa..a6d36b6a64 100644--- a/server/pkg/agent/copilot_invocation_windows.go+++ b/server/pkg/agent/copilot_invocation_windows.go@@ -7,8 +7,8 @@ import ("os")-// platformCopilotInvocation keeps the multi-line -p prompt built by-// buildCopilotArgs intact on Windows by spawning the native copilot.exe+// platformCopilotInvocation keeps the argv built by buildCopilotArgs intact+// on Windows (the prompt itself rides stdin) by spawning the native copilot.exe// bundled in the npm package, so neither cmd.exe's %* expansion nor// PowerShell's $args re-serialisation can re-tokenise it (see// resolveCopilotNativeFromShim for why neither launcher can be made safe).diff --git a/server/pkg/agent/copilot_stdin_unix_test.go b/server/pkg/agent/copilot_stdin_unix_test.gonew file mode 100644index 0000000000..af970df7c7--- /dev/null+++ b/server/pkg/agent/copilot_stdin_unix_test.go@@ -0,0 +1,199 @@+//go:build unix++package agent++import (+ "context"+ "fmt"+ "log/slog"+ "os"+ "path/filepath"+ "strings"+ "testing"+ "time"+)++// copilotStreamTail is the minimal successful Copilot JSONL stream the fake+// CLIs below emit once they have recorded what the backend handed them.+const copilotStreamTail = `printf '%s\n' '{"type":"assistant.message","data":{"content":"ok"}}'+printf '%s\n' '{"type":"result","sessionId":"sess-fake","exitCode":0}'+`++func runCopilotFake(t *testing.T, script, prompt string, opts ExecOptions) Result {+ t.Helper()++ fakePath := filepath.Join(t.TempDir(), "copilot")+ writeTestExecutable(t, fakePath, []byte(script))++ backend, err := New("copilot", Config{ExecutablePath: fakePath, Logger: slog.Default()})+ if err != nil {+ t.Fatalf("New(copilot): %v", err)+ }+ if opts.Timeout == 0 {+ opts.Timeout = 30 * time.Second+ }+ session, err := backend.Execute(t.Context(), prompt, opts)+ if err != nil {+ t.Fatalf("Execute: %v", err)+ }+ go func() {+ for range session.Messages {+ }+ }()+ select {+ case result := <-session.Result:+ return result+ case <-time.After(30 * time.Second):+ t.Fatal("copilot run never produced a result")+ return Result{}+ }+}++// TestCopilotExecuteSendsLargePromptOnStdinNotArgv is the regression for+// #9362: a task prompt above Linux's 131,072-byte MAX_ARG_STRLEN used to be+// inlined as `-p <prompt>` and died at fork/exec with E2BIG. The prompt must+// now reach Copilot byte-for-byte on stdin while argv keeps only the daemon's+// own flags.+func TestCopilotExecuteSendsLargePromptOnStdinNotArgv(t *testing.T) {+ t.Parallel()++ dir := t.TempDir()+ argvPath := filepath.Join(dir, "argv.txt")+ stdinPath := filepath.Join(dir, "stdin.txt")+ script := fmt.Sprintf("#!/bin/sh\n"++ ": > %[1]q\n"++ "for a in \"$@\"; do printf '%%s\\n' \"$a\" >> %[1]q; done\n"++ "cat > %[2]q\n", argvPath, stdinPath) + copilotStreamTail++ // ~1.2 MB, far above MAX_ARG_STRLEN and every pipe buffer.+ prompt := "MULTICA_COPILOT_PROMPT\n" + strings.Repeat("pasted daemon log line 0123456789 \"quoted\"\n", 28_000)+ if len(prompt) <= 131_072 {+ t.Fatalf("test prompt must exceed MAX_ARG_STRLEN, got %d bytes", len(prompt))+ }++ result := runCopilotFake(t, script, prompt, ExecOptions{Model: "gpt-5", ResumeSessionID: "sess-prev"})++ stdinRaw, err := os.ReadFile(stdinPath)+ if err != nil {+ t.Fatalf("read recorded stdin: %v", err)+ }+ if string(stdinRaw) != prompt {+ t.Errorf("prompt corrupted on stdin: got %d bytes, want %d", len(stdinRaw), len(prompt))+ }+ argvRaw, err := os.ReadFile(argvPath)+ if err != nil {+ t.Fatalf("read recorded argv: %v", err)+ }+ argv := strings.Split(strings.TrimSuffix(string(argvRaw), "\n"), "\n")+ for _, a := range argv {+ if a == "-p" || strings.Contains(a, "MULTICA_COPILOT_PROMPT") {+ t.Fatalf("prompt leaked onto argv: %v", argv)+ }+ }+ joined := strings.Join(argv, " ")+ for _, want := range []string{"--output-format json", "--allow-all", "--no-ask-user", "--model gpt-5", "--resume sess-prev"} {+ if !strings.Contains(joined, want) {+ t.Errorf("expected %q in argv, got %v", want, argv)+ }+ }+ if result.Status != "completed" || result.Output != "ok" || result.SessionID != "sess-fake" {+ t.Fatalf("result = %+v, want completed/ok/sess-fake", result)+ }+}++// TestCopilotExecuteLargePromptDoesNotDeadlock forces both pipes past+// capacity: the child floods stdout before reading stdin while the parent+// writes a large prompt. Only concurrent writing and scanning can advance.+func TestCopilotExecuteLargePromptDoesNotDeadlock(t *testing.T) {+ t.Parallel()++ script := "#!/bin/sh\n" ++ "yes '{\"type\":\"noise\",\"data\":{\"pad\":\"0123456789012345678901234567890123456789\"}}' | head -n 8000\n" ++ "cat > /dev/null\n" + copilotStreamTail+ prompt := strings.Repeat("copilot stdin payload 0123456789\n", 20_000)++ result := runCopilotFake(t, script, prompt, ExecOptions{})+ if result.Status != "completed" {+ t.Fatalf("status = %q, want completed; error=%q", result.Status, result.Error)+ }+}++// A complete, successful stream must not be failed by a prompt write that broke+// on the way out (child exits without draining stdin -> timing-dependent EPIPE).+func TestCopilotExecuteIgnoresBenignPromptWriteEPIPE(t *testing.T) {+ t.Parallel()++ script := "#!/bin/sh\n" + copilotStreamTail+ prompt := strings.Repeat("benign epipe payload 0123456789\n", 40_000)++ result := runCopilotFake(t, script, prompt, ExecOptions{})+ if result.Status != "completed" || result.Output != "ok" {+ t.Fatalf("result = %+v, want completed with output ok", result)+ }+}++// Counterpart to the test above: a child that emits nothing, never reads the+// prompt, and exits 0 must not be reported as a clean success.+func TestCopilotExecuteFailsWhenPromptWriteBreaksWithoutResult(t *testing.T) {+ t.Parallel()++ prompt := strings.Repeat("undelivered prompt payload 0123456789\n", 36_000)+ result := runCopilotFake(t, "#!/bin/sh\nexit 0\n", prompt, ExecOptions{})++ if result.Status == "completed" {+ t.Fatalf("undelivered prompt reported as success: %+v", result)+ }+ if !strings.Contains(result.Error, "prompt write failed") {+ t.Errorf("error = %q, want it to name the failed prompt write", result.Error)+ }+}++// Cancelling must release a prompt writer blocked on a full stdin pipe and+// still settle the run as aborted rather than hang.+func TestCopilotExecuteCancelReleasesBlockedPromptWriter(t *testing.T) {+ t.Parallel()++ fakePath := filepath.Join(t.TempDir(), "copilot")+ writeTestExecutable(t, fakePath, []byte("#!/bin/sh\n"++ "printf '%s\\n' '{\"type\":\"session.start\",\"data\":{\"sessionId\":\"sess-x\"}}'\n"++ "exec sleep 60\n"))++ backend, err := New("copilot", Config{ExecutablePath: fakePath, Logger: slog.Default()})+ if err != nil {+ t.Fatalf("New(copilot): %v", err)+ }+ ctx, cancel := context.WithCancel(context.Background())+ prompt := strings.Repeat("blocked prompt payload 0123456789\n", 32_768)+ session, err := backend.Execute(ctx, prompt, ExecOptions{Timeout: 30 * time.Second})+ if err != nil {+ t.Fatalf("Execute: %v", err)+ }+ go func() {+ for range session.Messages {+ }+ }()+ cancel()++ select {+ case result := <-session.Result:+ if result.Status != "aborted" {+ t.Fatalf("status = %q, want aborted; error=%q", result.Status, result.Error)+ }+ case <-time.After(30 * time.Second):+ t.Fatal("cancelled run never produced a result; the prompt writer likely deadlocked")+ }+}++func TestCopilotExecuteRefusesEmptyPrompt(t *testing.T) {+ t.Parallel()++ fakePath := filepath.Join(t.TempDir(), "copilot")+ writeTestExecutable(t, fakePath, []byte("#!/bin/sh\nexit 0\n"))+ backend, err := New("copilot", Config{ExecutablePath: fakePath, Logger: slog.Default()})+ if err != nil {+ t.Fatalf("New(copilot): %v", err)+ }+ if _, err := backend.Execute(t.Context(), " \n", ExecOptions{}); err == nil {+ t.Fatal("expected an error for an empty prompt")+ }+}diff --git a/server/pkg/agent/copilot_test.go b/server/pkg/agent/copilot_test.goindex 57a03f1c35..c71ed2b220 100644--- a/server/pkg/agent/copilot_test.go+++ b/server/pkg/agent/copilot_test.go@@ -987,9 +987,9 @@ func TestCopilotExecuteSurfacesStderrOnNonZeroResult(t *testing.T) {func TestBuildCopilotArgsBaseline(t *testing.T) {t.Parallel()- args := buildCopilotArgs("write a haiku", ExecOptions{}, slog.Default())+ args := buildCopilotArgs(ExecOptions{}, slog.Default())+ // No -p: the prompt rides stdin (#9362).expected := []string{- "-p", "write a haiku","--output-format", "json","--allow-all","--no-ask-user",@@ -1008,7 +1008,7 @@ func TestBuildCopilotArgsBaseline(t *testing.T) {func TestBuildCopilotArgsWithModel(t *testing.T) {t.Parallel()- args := buildCopilotArgs("hi", ExecOptions{Model: "gpt-4o"}, slog.Default())+ args := buildCopilotArgs(ExecOptions{Model: "gpt-4o"}, slog.Default())var foundModel boolfor i, a := range args {@@ -1028,7 +1028,7 @@ func TestBuildCopilotArgsWithModel(t *testing.T) {func TestBuildCopilotArgsWithResume(t *testing.T) {t.Parallel()- args := buildCopilotArgs("hi", ExecOptions{ResumeSessionID: "sess-42"}, slog.Default())+ args := buildCopilotArgs(ExecOptions{ResumeSessionID: "sess-42"}, slog.Default())var foundResume boolfor i, a := range args {@@ -1048,7 +1048,7 @@ func TestBuildCopilotArgsWithResume(t *testing.T) {func TestBuildCopilotArgsOmitsOptionalWhenEmpty(t *testing.T) {t.Parallel()- args := buildCopilotArgs("hi", ExecOptions{}, slog.Default())+ args := buildCopilotArgs(ExecOptions{}, slog.Default())for _, a := range args {if a == "--model" {t.Fatalf("expected no --model flag when Model is empty, got args=%v", args)@@ -1062,7 +1062,7 @@ func TestBuildCopilotArgsOmitsOptionalWhenEmpty(t *testing.T) {func TestBuildCopilotArgsPassesThroughCustomArgs(t *testing.T) {t.Parallel()- args := buildCopilotArgs("hi", ExecOptions{+ args := buildCopilotArgs(ExecOptions{CustomArgs: []string{"--max-turns", "50"},}, slog.Default())@@ -1074,7 +1074,7 @@ func TestBuildCopilotArgsPassesThroughCustomArgs(t *testing.T) {func TestBuildCopilotArgsFiltersBlockedCustomArgs(t *testing.T) {t.Parallel()- args := buildCopilotArgs("hi", ExecOptions{+ args := buildCopilotArgs(ExecOptions{CustomArgs: []string{"--output-format", "text", "--max-turns", "50"},}, slog.Default())@@ -1097,7 +1097,7 @@ func TestBuildCopilotArgsFiltersBlockedCustomArgs(t *testing.T) {func TestBuildCopilotArgsBlocksResumeAndACP(t *testing.T) {t.Parallel()- args := buildCopilotArgs("hi", ExecOptions{+ args := buildCopilotArgs(ExecOptions{CustomArgs: []string{"--resume", "bad-session", "--acp", "--yolo"},}, slog.Default())@@ -1113,3 +1113,19 @@ func TestBuildCopilotArgsBlocksResumeAndACP(t *testing.T) {}}}++// A user-supplied -p would put a prompt back on argv — the exact path #9362+// moved off — so it must stay filtered.+func TestBuildCopilotArgsBlocksPromptFlag(t *testing.T) {+ t.Parallel()++ args := buildCopilotArgs(ExecOptions{+ CustomArgs: []string{"-p", "injected prompt", "--max-turns", "50"},+ }, slog.Default())++ for _, a := range args {+ if a == "-p" || a == "injected prompt" {+ t.Fatalf("blocked -p should have been filtered: %v", args)+ }+ }+}diff --git a/server/pkg/agent/proc_other.go b/server/pkg/agent/proc_other.goindex 0fe2813626..8669e4490e 100644--- a/server/pkg/agent/proc_other.go+++ b/server/pkg/agent/proc_other.go@@ -38,7 +38,11 @@ func configureProcessGroup(cmd *exec.Cmd) {//// It is still the only way this package starts a long-lived runtime process,// so the two platforms share one call site per backend.-func startOwnedProcessTree(cmd *exec.Cmd, _ *slog.Logger) error { return cmd.Start() }+//+// An oversized command line (E2BIG) is reported as ErrArgvLimitExceeded.+func startOwnedProcessTree(cmd *exec.Cmd, _ *slog.Logger) error {+ return wrapArgvLimitError(cmd.Start())+}// releaseProcessGroup is a no-op on non-Windows platforms: a process group needs// no handle and is gone once its members are.diff --git a/server/pkg/agent/proc_windows.go b/server/pkg/agent/proc_windows.goindex 4003bd0b40..0d68fe6f34 100644--- a/server/pkg/agent/proc_windows.go+++ b/server/pkg/agent/proc_windows.go@@ -104,7 +104,8 @@ func startOwnedProcessTree(cmd *exec.Cmd, logger *slog.Logger) error {cmd.SysProcAttr.CreationFlags |= createSuspendedif err := cmd.Start(); err != nil {- return err+ // An over-long command line is reported as ErrArgvLimitExceeded.+ return wrapArgvLimitError(err)}if err := ownProcessTree(cmd); err != nil && logger != nil {