Blog · · 9 min read

AI agent conversation state ownership: bind each product chat thread to one owner so client sessions and OpenAI-managed history never double-load

AI agent conversation state ownership: bind each product chat thread to one owner so client sessions and OpenAI-managed history never double-load

Your product already has a chat thread ID. The agent SDK offers a session store. OpenAI also offers conversation_id and previous_response_id. Teams often wire two of those at once "for safety." Then AI agent conversation state ownership breaks: the model sees the same tool call twice, the API returns Duplicate item found with id fc_..., or a browser that still holds a raw conv_* ID resumes another tenant's server conversation. Official Agents SDK docs treat client-managed and server-managed continuation as mutually exclusive strategies for one run (OpenAI Agents SDK: Running agents; OpenAI Agents SDK: Sessions).

Direct answer: one owner per product thread

Ship one product-owned contract before the first customer chat goes live:

  1. Mint a product thread ID at the user-send boundary and keep it as the only client-visible conversation key.
  2. Choose exactly one history owner for that thread: client to_input_list / SDK session, OpenAI conversation_id, or previous_response_id chaining (Running agents).
  3. Persist the choice and any service IDs in trusted application storage mapped from the product thread after authorization (Microsoft Learn: AgentSession).
  4. Send only what that owner expects each turn: reconstructed client history, or new-turn deltas for server-managed continuation (#1789).
  5. Refuse mixed ownership in one run: a session cannot combine with conversation_id, previous_response_id, or auto_previous_response_id (Sessions).
  6. Account for handoffs and approvals under the chosen owner, then delete or detach both sides when the product thread ends.
ConversationOwnerContract {
  product_thread_id: string          // client-visible
  owner: client_session | openai_conversation_id | previous_response_id
  service_ref?: conv_* | resp_*      // server-only, never echoed raw as authz
  mapping: ProductThread -> { owner, service_ref, tenant_id, user_id }

  admit(run):
    assert not (session and server_managed_flags)
    assert authorize(current_user, mapping[product_thread_id])
    if owner == client_session:
      input = session.history + new_turn
    else:
      input = new_turn_only
      attach service_ref from trusted mapping
    resume_approvals with same owner settings
}

Why mixed ownership fails

Four continuation strategies look interchangeable. They are not:

StrategyWhere state livesWhat you pass next turn
result.to_input_list()Your app memoryFull list plus the new user message
sessionYour storage plus the SDKThe same session instance or store
conversation_idOpenAI Conversations APISame conversation ID plus only the new user turn
previous_response_idOpenAI Responses APIlast_response_id plus only the new user turn

That table is the official memory-strategy matrix (Running agents). Client-managed paths (to_input_list, session) rebuild or load history locally. Server-managed paths (conversation_id, previous_response_id) keep history on OpenAI and expect new-turn deltas. Mixing them "can duplicate context unless you are deliberately reconciling both layers," and session persistence "cannot be combined with server-managed conversation settings ... in the same run" (Running agents; Sessions).

Issue #1789 describes Duplicate item found with id fc_... when conversation_id was used with function calling while prior tool items were resent. Maintainers and reporters clarified the split: OpenAIConversationsSession fetches history and resends it, while raw conversation_id continuation must send only new items (#1789). Even after SDK fixes for delta-only sends, a product that also prepends its own session history can recreate the same bug at the application boundary.

Authorization fails quietly next. Microsoft Agent Framework documents that service-issued conversation or response IDs are scoped to the backing API key or project by default. In a hosted multi-user app that reuses one key, treating service_session_id, previous_response_id, or conversation_id as an end-user boundary is unsafe. Store those IDs in trusted application storage, map client-visible session IDs to them, and verify the authenticated user or tenant before resume (Microsoft Learn: AgentSession).

Choose the owner with product constraints

Decide from product constraints, not from whichever SDK example you copied first:

  1. Need handoff input_filter or nested-history redaction for specialists? Prefer client-managed history. Server-managed conversations do not support handoff input filters; a separate filtered run must not reuse the original conversation_id or previous_response_id (OpenAI Agents SDK: Handoffs). This is easy to miss if you adopt server-managed IDs first and discover privacy requirements later.
  2. Need multi-worker sharing of one named server conversation without shipping full history from your DB? conversation_id can fit, with product-side mapping and authz.
  3. Need fork, edit, or retry from a prior turn? previous_response_id chaining is often lighter than creating a conversation resource, but you must persist the latest response ID per product thread (Running agents; #1789 discussion).
  4. Need retention, export, or deletion under your compliance regime? Client-managed sessions keep the transcript where your product already enforces retention. Server-managed history still needs an explicit delete/detach path for the mapped remote resource when the product thread is removed (Sessions; Microsoft Learn: AgentSession).
  5. Already have SQLAlchemy, Redis, or Mongo session backends in the product? Stay on client session and do not also pass server-managed IDs "just in case" (Sessions).

Pick once per product thread. Record the owner in the mapping row so later features cannot silently add a second owner.

Implement the product mapping

1. Client-visible ID vs service ID

product_threads (
  id uuid primary key,              -- returned to browser / mobile
  tenant_id, user_id,
  owner_enum,                       -- client_session | openai_conversation_id | previous_response_id
  service_ref text null,            -- conv_* or resp_*; server-only
  session_store_key text null,      -- for client_session backends
  created_at, deleted_at
)

Raw conv_* and resp_* IDs are scoped to an API key or project, not to end users: echoing them to browsers without a trusted product-thread mapping is a cross-tenant resume hazard. Never put service_ref in a cookie or query string as the resume token. The client sends product_thread_id; the server loads the mapping after authz (Microsoft Learn: AgentSession).

2. Admission gate before Runner.run

function admit(run_request):
  thread = load_thread(run_request.product_thread_id)
  require tenant_and_user_match(thread, authn)
  flags = count_set([
    run_request.session,
    run_request.conversation_id,
    run_request.previous_response_id,
    run_request.auto_previous_response_id,
  ])
  if flags > 1: reject("mixed_conversation_owners")
  if thread.owner == client_session:
    require run_request.session keyed by thread.session_store_key
    forbid server_managed flags
  if thread.owner == openai_conversation_id:
    attach conversation_id = thread.service_ref
    input = new_user_turn_only
  if thread.owner == previous_response_id:
    attach previous_response_id = thread.service_ref
    input = new_user_turn_only

Put the SDK mutual-exclusion rule behind a product admission gate so each call site cannot forget it (Running agents; Sessions).

3. New-turn deltas for server-managed owners

When the owner is server-managed, do not prepend your product transcript or session history to the model input. Pass the new user turn (and only the new items the SDK marks as unsent for that continuation). The #1789 failure mode was resending prior function-call items under conversation_id (#1789). Keep a product-side audit transcript if you need support tooling, but do not feed that audit copy into the same run as the server-managed ID unless you are on an explicit dual-write design with reconciliation tests.

4. Handoff compatibility under the chosen owner

Server-managed conversations disable handoff input filters, so specialist redaction contracts cannot assume the same filter surface under every history owner. If the product needs destination-specific transcript redaction before a specialist agent runs, keep the thread on client-managed history so input_filter / nest helpers remain available. If the thread is already server-managed, do not reuse the original conversation or response ID for a filtered specialist run; start a separate run with explicitly selected input (Handoffs). Document that choice in the owner decision table so privacy work does not fight the continuation strategy.

5. Approval resume under the same owner

When a run pauses for tool approval, resume with the same session instance or the same saved server-managed settings. The Sessions guide states that interrupted runs should resume with the same session (or the same session ID and storage backend). Running agents notes that resuming from RunState keeps saved conversation_id / previous_response_id / auto_previous_response_id settings so the resumed turn continues in the same server-managed conversation (Sessions; Running agents). Approval resume must continue under the same owner settings that created the pause; switching owners mid-thread is a second way to duplicate or orphan history. Load those settings from the thread mapping or RunState, not from the latest global default.

6. Retention and deletion on both sides

When a user deletes a product thread, clear the client session store key and delete or detach the mapped remote conversation when one exists. Do not assume OpenAI retention matches your product retention window. The mapping row is the join key for that cleanup (Sessions; Microsoft Learn: AgentSession).

Handle failure and recovery

  • Mixed-owner configuration at admit time: reject before the model call; log product_thread_id, requested flags, and stored owner.
  • Duplicate item / invalid input from the provider: treat as ownership or delta bugs, not model quality. Inspect whether client history was prepended onto a server-managed run (#1789).
  • Missing service_ref on resume: fail closed for server-managed threads; do not invent a new conversation mid-thread without an explicit "start over" product action.
  • Authorization miss on stolen service ID: if a client somehow presents a raw conv_* / resp_*, ignore it and require the product thread mapping (Microsoft Learn: AgentSession).
  • Specialist handoff required on a server-managed thread: open a separate filtered run with explicit input; do not reuse the original server conversation IDs (Handoffs).
  • Approval resume after deploy: load owner settings from the thread mapping / RunState, not from the latest global default.

Verify the solution

Automate these checks in CI or staging:

  1. Mixed ownership reject: constructing a run with both session and conversation_id fails at the product admission gate.
  2. Delta-only server turns: for a conversation_id thread with prior tool calls, the provider request body for turn N contains only new items, not prior fc_ IDs (#1789).
  3. Tenant resume authz: user B presenting user A's service_ref (if leaked) cannot resume; only the mapped product_thread_id under B's authn works (Microsoft Learn: AgentSession).
  4. Handoff filter compatibility: if the product claims specialist redaction, the thread owner is client-managed, or the specialist path uses a separate filtered run without the original server IDs (Handoffs).
  5. Approval same-owner resume: pause under owner X, approve, resume under owner X; assert no second history load path was added.
  6. Delete both sides: deleting the product thread clears session rows and attempts remote conversation delete/detach when service_ref is present.

Common mistakes

  1. Passing session and previous_response_id together "for redundancy." The SDK documents that combination as unsupported. The second path duplicates context (Sessions).
  2. Returning OpenAI conversation IDs to the browser as the chat ID. That skips product authz and invites cross-user resume on shared keys (Microsoft Learn: AgentSession).
  3. Picking a server-managed owner before you know specialist privacy requirements. Server-managed history does not support handoff input filters, so plan that surface before you lock the owner (Handoffs).
  4. Replaying the full product transcript into a conversation_id run after a tool call. That recreates the duplicate-item class of failure even when the SDK itself is fixed (#1789).
  5. Changing owner mid-thread after an approval pause or a specialist transfer. Resume and handoff paths assume continuity of the chosen owner (Running agents; Sessions).

What to do next

Inventory every call site that starts or resumes a product-agent chat. For each product thread type, write the owner enum value, the mapping table row shape, and the admit-time reject for mixed flags. Add the six verification checks above before enabling specialist handoffs or human approval on that thread. If you are building agent chat on top of your own knowledge base and product actions, keep conversation ownership in your application contract the same way you keep tool authorization there; platforms such as Make Your Agent still need this product-side owner map when they embed multi-turn runs inside an existing SaaS.

Be first in line.

Join the waitlist and we'll email you the moment it's ready. No sales call.

Try the demo →
or talk to us