Skip to content

[Reasoning retention 2/2] Replay persisted reasoning safely to vLLM #153

Description

@franciscojavierarceo

Parent: #151

Depends on: #152

Goal

Replay complete persisted reasoning items through previous_response_id and conversation continuations in original history order while adapting only the vLLM-bound request copy for vLLM's plaintext continuation capabilities.

Preconditions

Land #152 first so streamed first turns persist the same complete reasoning item as non-streamed first turns.

Scope

Persistence and rehydration

  • Keep the complete typed reasoning item in stored response/conversation history.
  • Preserve its position relative to assistant messages and function calls.
  • Rehydrate historical reasoning before the next turn's new input.
  • Preserve the original stored item unchanged, including summary, encrypted_content, and status.
  • Confirm _agentic_item_kind never appears in serialized upstream JSON.

vLLM request preparation

Prepare only ctx.enriched_request.input (the vLLM-bound copy):

  • Replay plaintext reasoning from content[].text.
  • Treat encrypted_content: null as valid.
  • When plaintext content and non-null encrypted state coexist, preserve the stored item but omit incompatible encrypted state from the vLLM-bound copy.
  • If a reasoning item has non-null encrypted content but no plaintext content, return a clear ExecutorError::InvalidRequest before request serialization/network I/O.
  • Never substitute reasoning summaries for continuation state.
  • Never attempt to decrypt opaque content.
  • Apply the same validation before both streaming and non-streaming inference.

Ordering

Verify the second upstream request preserves this sequence when present:

  1. historical user input;
  2. historical reasoning item;
  3. historical assistant message;
  4. historical function call;
  5. new function call output;
  6. new user input.

The typed storage marker must not appear anywhere in that request.

Sensitive logging

  • Remove the uncommitted raw request-body, response-body, error-body, and SSE-line trace statements in executor/inference.rs.
  • Retain safe structured diagnostics such as byte counts, response IDs, item types, status, URL, and whether authentication is configured.
  • Do not add logs containing reasoning text or encrypted content.

Test plan

Extend the existing stateful Responses integration framework rather than creating a parallel harness:

  • two-turn streamed continuation records the first turn's complete reasoning item in the second upstream request;
  • equivalent two-turn non-streamed continuation;
  • streamed and non-streamed second-turn histories are structurally equivalent;
  • original ordering across reasoning, assistant message, function call, function call output, and new user input;
  • complete summary, encrypted_content, and status remain present after persistence/rehydration even when vLLM does not consume them;
  • plaintext reasoning with encrypted_content: null reaches vLLM;
  • plaintext reasoning with preserved non-null encrypted state uses the vLLM-compatible enriched copy while storage remains unchanged;
  • encrypted-only reasoning fails clearly before any mock upstream request is recorded;
  • a summary-only item is not silently used as reasoning continuation state;
  • _agentic_item_kind is absent recursively from upstream JSON.

Use the existing mock request recorder and literal hand-checked response fixtures. Do not hand-author replay cassettes.

Likely files

  • crates/agentic-server-core/src/executor/engine.rs
  • crates/agentic-server-core/src/executor/rehydrate.rs or a focused executor-side vLLM preparation helper
  • crates/agentic-server-core/src/executor/inference.rs
  • crates/agentic-server-core/src/types/io/input.rs only if a focused typed traversal helper is warranted
  • crates/agentic-server-core/tests/stateful_responses_integration.rs
  • existing test support helpers

Avoid transport concerns in core wire types and avoid changing storage migrations.

Acceptance criteria

  • Streamed and non-streamed continuations send equivalent complete historical reasoning items upstream.
  • Plaintext reasoning reaches vLLM in correct history order.
  • Stored summary and encrypted state remain lossless even when excluded from vLLM interpretation.
  • Encrypted-only reasoning returns a clear 400-class invalid-request error before any vLLM call.
  • Summaries are never promoted into continuation reasoning.
  • _agentic_item_kind never leaks upstream.
  • Normal logs contain no reasoning text, encrypted content, or raw bodies.
  • No schema migration or alternate reasoning-text persistence is introduced.

Related work

Verification

cargo test -p agentic-server-core --test stateful_responses_integration
cargo test -p agentic-server-core
cargo clippy -p agentic-server-core --all-targets -- -D warnings
cargo fmt -- --check

Report the exact commands and results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions