Skip to content

feat(protocols): ✨ Preserve encrypted reasoning content across multi-turn replay#14

Merged
jorben merged 7 commits into
masterfrom
feat/reasoning-id-encrypted
Jun 29, 2026
Merged

feat(protocols): ✨ Preserve encrypted reasoning content across multi-turn replay#14
jorben merged 7 commits into
masterfrom
feat/reasoning-id-encrypted

Conversation

@jorben

@jorben jorben commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Extend StreamPart::ReasoningDelta with optional id and encrypted_content fields so provider-issued reasoning item ids and encrypted reasoning payloads survive through the IR and can be replayed verbatim on subsequent turns.
  • Rework the OpenAI Responses codec to preserve encrypted_content across request decode, response decode, and streaming encode/decode, including empty-summary encrypted-only reasoning items (summary: []).
  • Update chat_completions, gemini, and messages codecs to construct the new fields as None (no behavioral change).
  • Add cross-protocol and streaming regression tests for encrypted reasoning round-trip and the output_item.done summary shape.

Test Plan

  • cargo test -p tiygate-protocols --all-features — 314 passed
  • cargo clippy -p tiygate-protocols --all-targets --all-features -- -D warnings — clean
  • New test test_stream_encoder_encrypted_only_reasoning_empty_summary asserts summary: [], encrypted_content, and provider rs_... id on output_item.done

🤖 Generated with TiyCode

jorben added 7 commits June 26, 2026 14:44
Upgrade the Responses codec to handle Codex CLI's non-standard
input/output item types and reasoning extensions on top of the
reasoning-id-encrypted baseline, enabling TiyGate to sit between
standard Responses clients and Codex providers without semantic
loss.

Codex tool call items:
- local_shell_call / local_shell_call_output mapped to IR
  ToolCall (name="local_shell", action as arguments, call_id
  set for Responses round-trip fidelity) and ToolResult
- custom_tool_call / custom_tool_call_output mapped to ToolCall
  (input wrapped as {"input": "..."} JSON arguments) and
  ToolResult

Codex opaque items preserved for same-protocol replay:
- tool_search_call, tool_search_output, agent_message,
  compaction, compaction_trigger, context_compaction stored
  in extensions["codex_opaque_items"] and restored on
  encode_request; silently dropped on cross-protocol egress

Reasoning extensions:
- Parse reasoning.summary into IR ThinkingConfig.summary
- Store full reasoning object in extensions["reasoning_full"]
  for verbatim same-protocol replay (preserves summary etc.)
- Re-emit reasoning.summary on encode when no full replay
  path is taken

Other passthrough:
- Add client_metadata to responses_extra preserve list

Streaming:
- Handle local_shell_call / custom_tool_call in
  response.output_item.added so saw_function_call is set,
  producing ToolCalls finish_reason instead of Stop

All changes are additive: existing function_call, reasoning,
and message handling is unchanged. No breaking changes to
standard Responses protocol behavior.
Guard against `"usage": null` in both streaming and non-streaming
decoders to prevent zero-valued Usage structs from poisoning
cross-protocol encoders.

OpenAI sends `"usage": null` on every non-final chunk when
`stream_options.include_usage` is true. Without this guard, the
decoder would emit a zero-valued `StreamPart::Usage` that causes
downstream encoders (e.g. Responses) to trigger `response.completed`
prematurely, discarding the real usage that arrives later.

Added regression tests verifying null usage is correctly ignored
in both streaming and non-streaming code paths.
Allow overriding the multimodal request body size limit through the
`TIYGATE_MAX_MULTIMODAL_BODY_BYTES` environment variable. Also increase
the default limit from 32 MiB to 64 MiB to accommodate larger payloads.
@jorben jorben merged commit eed5228 into master Jun 29, 2026
7 checks passed
@jorben jorben deleted the feat/reasoning-id-encrypted branch June 29, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant