﻿# Which history snapshot should an Agents SDK SQLite branch inherit?

Keep content selection and history copying in one transaction and check persisted state after cancellation.

Author: Retrivium editorial team
Updated: 2026-12-01
Canonical URL: https://retrivium.ai/journal/daily-20261201-agents-sdk-sqlite-content-branch-snapshot/
Language: en

OpenAI Agents SDK for Python v0.26.1, published November 30, changes content-based branching in `AdvancedSQLiteSession`. The operation used to find a matching turn and pass its number to the history copy. Upstream found that a concurrent branch switch or replacement could make that number point at a different history. The fix finds the match inside the same write transaction that copies the prefix.

## Preserve the meaning of the branch

The selected turn identifies a position in a specific history. A numeric position by itself cannot preserve that identity when the underlying history changes. A transaction makes the search and copy observe the same protected state. According to the change, a failed match leaves the name available for a retry. The branch need not be created just to report that no turn matched.

## Verify durable outcomes

The upstream notes that a write may commit even if its caller cancels. Before retrying after cancellation, check whether the branch exists and whether its messages match the expected prefix. Teams that subclass the session should also review their assumptions. This content-based path no longer calls overrides of the separate search and numeric branching methods.

## Use a file-backed test

Create two synthetic histories with distinct markers. Compare the resulting prefix with the marked source under controlled concurrency, then test no-match recovery. Record the branch identity and copied messages. Those assertions capture more than a successful return value.

## Measure the cost of protecting the snapshot

A search inside a write transaction holds a write reservation for longer than a copy-only transaction. Measure the latency of competing writes on a database with realistic history lengths. Keep the number of simultaneous writers and the storage configuration in the result. If content-based branching makes the shared session too contended, reconsider when your application creates branches or route independent histories to separate sessions. A faster implementation is useful only if it preserves the relation between the matched turn and the copied prefix. Review durability and write wait time together before adopting the new SDK version in a busy service.

## Sources

- [Primary source · openai-agents-python v0.26.1](https://github.com/openai/openai-agents-python/releases/tag/v0.26.1)
- [Primary source · openai-agents-python #6259](https://github.com/openai/openai-agents-python/pull/6259)

## Related reading

- [SQLite WAL growth: a long reader can limit checkpoint progress](/journal/edge-sqlite-wal-long-reader-checkpoint-progress/)
- [Parallel evidence needs a common source version](/journal/frontier-swarm-branch-evidence-versions/)
