opencode-copilot-chat icon indicating copy to clipboard operation
opencode-copilot-chat copied to clipboard

[BUG] gpt-5.6-luna: invalid_prompt (400) on long sessions via Responses API

Open ltmoerdani opened this issue 3 months ago • 0 comments

gpt-5.6-luna dies with HTTP 400 once a session crosses roughly 1.5 MB of payload. Short chats are fine.

OpenCode Go API request failed (400) model=gpt-5.6-luna payloadBytes=1528273:
Error from provider (Console Go): Upstream request failed:
[invalid_prompt] Invalid Responses API request

After this point every subsequent request in the same session fails. New session resets it.

Steps to reproduce

  1. Pick gpt-5.6-luna in Copilot Chat (OpenCode Go provider)
  2. Start a fresh session in agent mode with tools
  3. Keep going: tool outputs, file reads, code blocks, the usual agent loop
  4. Around 1.5 MB payload, every request starts returning invalid_prompt

What I found

buildResponsesRequestBody() in src/extension.ts has three gaps. I went in suspecting the gateway, came out blaming us.

1. truncation is never sent. Defaults to disabled.

Per the OpenAI Responses API docs, truncation: "disabled" (the default) means the request fails with 400 once input exceeds the context window. We never set "auto". Long sessions hard-fail instead of truncating. This is almost certainly the main cause.

2. max_output_tokens is not capped against the remaining window.

gpt-5.6-luna: context window 1,050,000, max_output_tokens 128,000. The request fails the moment the prompt exceeds 922,000 tokens. We ship the static number from metadata without subtracting input size.

3. text.verbosity is sent on every Responses call.

Native OpenAI field. But the OpenCode Go gateway is a proxy in front of other providers, and there's no guarantee they forward it. Providers that reject unknown fields would return invalid_prompt from this alone.

Why this is not a duplicate of #93 / #41

#93 and #41 fixed response parsing: the gateway sends finish_reason: null and our extractor didn't flush tool calls. Those work now.

This is one layer earlier. The request never reaches the response parser because the provider rejects it up front.

Proposed fix

  1. Send truncation: "auto" on the Responses body. This one alone probably fixes the bulk of long-session failures.
  2. Cap max_output_tokens against contextWindow − estimatedPromptTokens. Handles the edge case.
  3. Drop text.verbosity. Lower priority, but free.

Apply to all GPT models routed to Responses, not just gpt-5.6-luna. The bug is in the transport, not the model.

Environment

  • Extension: 0.4.5
  • Model: gpt-5.6-luna (OpenCode Go provider)
  • VS Code: latest
  • Payload at failure: ~1.5 MB

Internal tracking

Engineering notes in docs/issues/44-20260804-gpt56-luna-responses-api-invalid-prompt.md.

ltmoerdani avatar Aug 03 '26 23:08 ltmoerdani