Skip to content

Native compaction rejects retained developer messages from live instruction updates #63434

Closed

Description

@ngbrown

Description

OpenCode 2.2.6 reports provider.invalid-output: Invalid compaction response during native compaction, despite HTTP 200 and a nonempty encrypted checkpoint. Observed with Azure OpenAI; direct OpenAI has not been tested.

The returned window contains 3 developer messages injected by OpenCode: one Code Mode catalog update and two live AGENTS.md change notifications. The compaction validator accepts only user/assistant message roles and rejects the entire response.

Both OpenAI and Azure document passing the returned compacted window as-is. OpenAI’s response schema permits developer messages.

Rejected response shape below:

{
  "id": "resp_redacted",
  "object": "response.compaction",
  "created_at": 1794448779,
  "output": [
    {
      "id": "msg_redacted_1",
      "type": "message",
      "status": "completed",
      "content": [
        {
          "type": "input_text",
          "text": "[Code Mode tool-catalog update redacted]"
        }
      ],
      "role": "developer"
    },
    {
      "id": "msg_redacted_2",
      "type": "message",
      "status": "completed",
      "content": [
        {
          "type": "input_text",
          "text": "[User message redacted]"
        }
      ],
      "role": "user"
    },
    {
      "id": "cmp_redacted",
      "type": "compaction",
      "encrypted_content": "[redacted]"
    }
  ],
  "usage": {
    "input_tokens": 231591,
    "input_tokens_details": {
      "cache_write_tokens": 0,
      "cached_tokens": 231498
    },
    "output_tokens": 4393,
    "output_tokens_details": {
      "reasoning_tokens": 0
    },
    "total_tokens": 235984
  }
}

Plugins

n/a

OpenCode version

2.2.6

Steps to reproduce

  1. Use OpenCode 2.2.6 with an Azure OpenAI Responses model and native compaction enabled.
  2. Edit AGENTS.md during an active session so OpenCode injects an instruction-change notification. The observed session also received a Code Mode catalog update.
  3. Continue until automatic compaction runs.
  4. When the endpoint returns retained developer messages, OpenCode rejects the response with Invalid compaction response.

Native compaction previously worked in other sessions; these steps describe the observed failing conditions, not a verified minimal reproduction.

Screenshot

Screenshot 2026-11-11 191630

Operating System

Windows 11

Terminal

Chrome 157

Activity

  1. added
    area/providers
    type/bug
    version/v2
    on Nov 12, 2026
  2. opencodejr commented on Nov 12, 2026

    @opencodejr
    Contributor

    Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

    Thanks for the detailed report. I reproduced this with a mock standing in for Azure OpenAI, since I don't have an Azure account here.

    What I did:

    • Set up a provider using the Azure package with compaction.type: "native", sent one prompt, then triggered compaction.
    • The mock's /responses/compact returned the window shape from your report: a developer message, a user message and a compaction checkpoint.
    • OpenCode 2.2.6 rejected it with provider.invalid-output: Invalid compaction response (HTTP 200).
    • With the same response minus the developer item, compaction succeeded. So the retained developer message alone causes the failure.

    The response validator in packages/ai/src/protocols/utils/responses-compaction.ts only accepts user and assistant messages. This still happens on the latest dev (f5ca39a). The script below reproduces it, mock included.

    One limit: I didn't check that real Azure returns these developer items. That part comes from your report and the mock returns that shape.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #63434: native compaction (Azure route, /responses/compact) rejects a
    # compacted window that keeps a `developer` message. Needs `bun` and `opencode` on PATH.
    # Set OC_DEV=/path/to/checkout to run the CLI from source instead.
    set -u
    DIR=$(cd "$(dirname "$0")" && pwd)
    PROJ=$(mktemp -d); export HOME=$(mktemp -d)
    export XDG_DATA_HOME=$HOME/.local/share XDG_CONFIG_HOME=$HOME/.config XDG_STATE_HOME=$HOME/.local/state
    if [ -n "${OC_DEV:-}" ]; then
      oc() { bun --conditions=browser --preload="$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js" "$OC_DEV/packages/cli/src/index.ts" "$@"; }
    else
      oc() { opencode "$@"; }
    fi
    echo "version: $(cd "$PROJ" && oc --version)"
    
    # Mock Azure OpenAI Responses endpoint. Set MOCK_NO_DEVELOPER=1 for the control run (no developer item).
    cat > "$PROJ/mock.ts" <<'MOCK'
    // Mock OpenAI/Azure Responses endpoint. /responses streams a short reply; /responses/compact
    // returns the window shape from issue #63434 (a retained `developer` message + user message + checkpoint).
    const log = (...a: unknown[]) => console.log(new Date().toISOString(), ...a)
    Bun.serve({
      port: 4010,
      async fetch(req) {
        const url = new URL(req.url)
        const body = req.method === "POST" ? await req.text() : ""
        log(req.method, url.pathname, body.slice(0, 200))
        if (url.pathname.endsWith("/responses/compact")) {
          return Response.json({
            id: "resp_cmp", object: "response.compaction", created_at: 1794448779,
            output: [
              ...(process.env.MOCK_NO_DEVELOPER ? [] : [{ id: "msg_1", type: "message", status: "completed", role: "developer",
                content: [{ type: "input_text", text: "Instructions updated: AGENTS.md changed." }] }]),
              { id: "msg_2", type: "message", status: "completed", role: "user",
                content: [{ type: "input_text", text: "hello" }] },
              { id: "cmp_1", type: "compaction", encrypted_content: "ENCRYPTED" },
            ],
            usage: { input_tokens: 100, input_tokens_details: { cached_tokens: 0 }, output_tokens: 10,
              output_tokens_details: { reasoning_tokens: 0 }, total_tokens: 110 },
          })
        }
        if (url.pathname.endsWith("/responses")) {
          const id = "resp_" + Date.now()
          const item = { id: "msg_a", type: "message", status: "completed", role: "assistant",
            content: [{ type: "output_text", text: "Hi there.", annotations: [] }] }
          const resp = (status: string, output: unknown[]) => ({ id, object: "response", created_at: 1, status, model: "gpt-test", output,
            usage: { input_tokens: 10, input_tokens_details: { cached_tokens: 0 }, output_tokens: 3, output_tokens_details: { reasoning_tokens: 0 }, total_tokens: 13 } })
          const events = [
            { type: "response.created", sequence_number: 0, response: resp("in_progress", []) },
            { type: "response.output_item.added", sequence_number: 1, output_index: 0, item: { ...item, status: "in_progress", content: [] } },
            { type: "response.output_text.delta", sequence_number: 2, item_id: "msg_a", output_index: 0, content_index: 0, delta: "Hi there." },
            { type: "response.output_item.done", sequence_number: 3, output_index: 0, item },
            { type: "response.completed", sequence_number: 4, response: resp("completed", [item]) },
          ]
          return new Response(events.map((e) => `event: ${e.type}\ndata: ${JSON.stringify(e)}\n\n`).join(""),
            { headers: { "content-type": "text/event-stream" } })
        }
        return new Response("not found", { status: 404 })
      },
    })
    log("mock on 4010")
    MOCK
    bun "$PROJ/mock.ts" > "$PROJ/mock.log" 2>&1 & MOCK=$!
    cat > "$PROJ/opencode.jsonc" <<'EOF'
    {
      "providers": {
        "mock": {
          "package": "@opencode/ai/providers/azure",
          "settings": { "baseURL": "http://127.0.0.1:4010/openai", "apiKey": "test-key", "compaction": { "type": "native" } },
          "models": { "gpt-test": { "name": "GPT Test", "limit": { "context": 200000, "output": 32000 } } }
        }
      }
    }
    EOF
    cd "$PROJ" && git init -q
    oc serve --port 4096 --hostname 127.0.0.1 > "$PROJ/serve.log" 2>&1 & SERVE=$!
    for i in $(seq 1 120); do grep -q password "$PROJ/serve.log" && break; sleep 1; done
    sleep 5
    export OPENCODE_PASSWORD=$(grep password "$PROJ/serve.log" | awk '{print $3}')
    S=$(oc run --server http://127.0.0.1:4096 --format json -m mock/gpt-test "hello" 2>&1 | grep -o '"sessionID":"ses[^"]*"' | head -1 | cut -d'"' -f4)
    echo "session: $S"
    oc api --server http://127.0.0.1:4096 session.compact --param sessionID="$S" -d '{}'; echo
    sleep 8
    echo "--- mock requests"; cut -c1-120 "$PROJ/mock.log"
    echo "--- session messages (compaction errors)"
    oc api --server http://127.0.0.1:4096 GET "/api/session/$S/message" 2>/dev/null | grep -o '"error":{"type":"provider[^}]*' | cut -c1-300 | head -3; echo "(no error above means compaction succeeded)"
    grep -i "compaction" "$PROJ/serve.log" | head -5
    kill $SERVE $MOCK 2>/dev/null; wait $SERVE $MOCK 2>/dev/null

    Run it: bash repro.sh

  3. added
    status/repro-simulated
    on Nov 12, 2026
  4. neriousy commented on Nov 19, 2026

    @neriousy
    Member

    Fixed by #64542, which makes native compaction accept developer messages in the returned window instead of rejecting the whole response. If you still see this on the latest version, comment here and we'll reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/providersplatform/windowsstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions