Skip to content

Preserve encrypted_content for multi-turn reasoning #15

@HXYerror

Description

@HXYerror

Part of #1. Depends on #3.

Goal

When the upstream returns reasoning items with encrypted_content, copilot-api must preserve that field byte-exact across turns. Stripping or re-serializing it produces upstream errors like "encrypted content could not be verified" or silent reasoning-quality regression on subsequent turns.

Why this matters

OpenAI's Responses API reasoning items contain an opaque encrypted_content blob (returned only when include: ["reasoning.encrypted_content"] and store: false). The next turn must echo every reasoning item back verbatim in input so the model can resume its chain of thought. Otherwise:

  • Server may reject with verification error, OR
  • Model silently re-thinks from scratch — repeated reasoning-token cost, degraded answers, longer latency.

This is exactly the bug litellm fixed in PR #17130 and refined in PR #22370: the parent OpenAIResponsesAPIConfig._handle_reasoning_item was stripping encrypted_content, so they overrode it for Copilot.

Tasks

  • In the ResponseReasoningItem type (Add upstream Responses API service client #3), declare encrypted_content?: string
  • In any response normalization / serialization layer, never drop encrypted_content — round-trip it as-is
  • If we ever have to set defaults or strip null fields (Copilot rejects status: null), do it surgically — only the empty fields, not encrypted_content
  • Document in code comment that this field is opaque and must be preserved byte-exact
  • On the input side (turn N+1), accept reasoning items in input and forward them upstream untouched

Acceptance criteria

  • Two-turn manual test against gpt-5.3-codex: turn 1 returns reasoning with encrypted_content. Turn 2 includes that reasoning item in input. Upstream does not return verification errors. Reasoning cost on turn 2 is materially lower than turn 1 (cache hit).
  • Unit test: parsing an upstream response with encrypted_content and re-serializing produces a bytes-identical reasoning item.

File pointers

Metadata

Metadata

Assignees

No one assigned

    Labels

    reasoningReasoning / thinking / encrypted_contentresponses-apiOpenAI /v1/responses API support

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions