Repository navigation
refactor: append conversation turns like OpenAI instead of rejecting them (3/5) - #503
Merged
Merged
Conversation
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
…to 0009 Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
…_output_item Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
…factor/append-only-turns
Signed-off-by: maral <[email protected]>
maralbahari
marked this pull request as ready for review
November 4, 2026 18:34
maralbahari
requested review from
bbrowning,
franciscojavierarceo,
haoshan98,
jiahuei,
leseb,
noobHappylife,
qandrew and
tjtanaa
as code owners
November 4, 2026 18:34
tjtanaa
reviewed
Nov 4, 2026
tjtanaa
left a comment
Member
There was a problem hiding this comment.
Found two correctness issues involving upgrades and concurrent multi-agent turns.
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
tjtanaa
reviewed
Nov 5, 2026
tjtanaa
left a comment
Member
There was a problem hiding this comment.
Two concurrency cases still need protection before stale turns can safely append.
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
tjtanaa
reviewed
Nov 5, 2026
tjtanaa
left a comment
Member
There was a problem hiding this comment.
One session checkpoint retention issue remains.
Signed-off-by: maral <[email protected]>
This was referenced Nov 10, 2026
Open
franciscojavierarceo
added a commit
that referenced
this pull request
Nov 14, 2026
### Summary The [#500](#500) stack (#501, #502, #503, #505, #506) changed what the gateway stores: history now holds only client-facing items, and model-facing shapes are built at one lowering point for each request. This PR writes that contract down where contributors and coding agents will read it, brings the roadmap up to date with what has merged since October, and removes API docs that still describe behavior main no longer has. - `ARCHITECTURE.md`: a new "What a turn persists" section under `storage/`. It states the rule (client-facing items only; model-facing shapes are never stored), the rehydrate, persist and session flow around `ResponseCheckpoint`, and the recorded OpenAI behavior a continuation follows for compaction, a compaction sent back as input, items sent back by ID, deletion, and conversations. It also replaces a stale paragraph that still described model-facing calls being persisted as input items, and names `file_search` as the one remaining exception ([#482](#482)). - `AGENTS.md` and the `storage-schema-change` skill point to the new section and add the client-facing history rule to the checklist, so a change to persisted data starts from it. - `ROADMAP.md`: - The Responses goal now describes client-facing persistence and the #500 stack, with `input_items`/`DELETE` (#466) and HTTP `store: false` running through the gateway (#475). - Shipped capabilities are marked "shipped" with what remains: multi-agent (#405 remaining; `last_task_message` waits on observed OpenAI behavior, #395), single-agent WebSocket steering (approval-aware steering depends on #145), file search (#356, #482), async tools, hosted tool search and web search providers, Messages threads and native server tool calls, rate limiting, and observability. - The closed `store=false` follow-up (#433) is removed, and the closed #244 is cited as delivered. - The website copies the root roadmap at build time, so only `ROADMAP.md` changes; strikethrough is not used because the roadmap page renders without GFM. - `docs/api/index.md` (and its website snapshot): removes the "direct HTTP pass-through" description of `/v1/responses`, which #475 replaced with gateway execution for every request; multi-agent is documented over WebSocket as well (#407); replayed `mcp_call`, `web_search_call` and `code_interpreter_call` items are described as lowered for the model, with parity recordings tracked in [#492](#492). - `README.md`: the "Roadmap at a Glance" checklist marks multi-agent and file search as shipped. ### Test Plan - Docs only; no code changes. - Every roadmap item marked as shipped was checked against its merged PR or closed issue; items whose issue is still open stay listed as remaining (#330, #356, #395, #405, #482, #145). - Each statement in "What a turn persists" was checked against the code on `main` (`ResponseCheckpoint`, `write_turn`, `ResponseStore::persist`, `continue_from_compaction`, `filter_for_compaction`, `resolve_input_items`, `delete_in_tx`); the removed pass-through text was checked against `handler/http/responses.rs`, where every request goes through `ExecuteRequest`. - `pre-commit` hooks pass on the changed files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: maral <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Francisco Javier Arceo <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the RFC #500 (one typed path for rehydrating and persisting history).
Summary
A conversation turn no longer fails when its conversation changes while it runs. As on OpenAI, the turn is stored after whatever the conversation holds when it finishes, and its response keeps the history the turn started from. The version check behind
400 conversation_locked, the conversationrevisionthat fed it, and the error plumbing for it are removed; the row lock that gives concurrent writers distinct sequence numbers stays.The turn's stored history comes from the rehydration checkpoint planned for PR5, brought forward here so that
input_itemsmatch OpenAI when the conversation changes mid-turn.ConversationVersion { last_sequence, response_id, revision }and carried it onRequestContextConversationVersionandRequestContext::conversation_versionare removedMAX(seq)and compared the version; a mismatch failed the turn with400 conversation_locked(anerrorevent on SSE and WebSocket) and stored nothingconversations.revision(create with items, add items, delete an item, persist)conversations.revisionis droppedResponseCheckpoint::history_item_ids) followed by the turn's own items: the history the turn started from, as OpenAI'sinput_itemsshowResponseCheckpointtypeResponseCheckpointin storage, from rehydration to persist; the session keeps the history items in itSchema
A new migration,
0010_drop_conversation_revision.sql. 0009 is onmainand stays byte for byte unchanged: a database records each applied migration's checksum, so editing 0009 would stop every databasemaincreated from starting.OpenAI behaviour
Verified against
gpt-4.1while a streamed turn B was running on the conversation (recorded inconversations-concurrent-writes-openai.yaml):The gateway now does the same (
conversations-concurrent-writes-gateway.yaml), including B'sinput_items: the history B started from, without the item added mid-turn and still with the item deleted mid-turn.The conflict was added in #162 ("reject stale conversation turns") as optimistic conflict detection, and extended to item writes with
revisionin #351. It reused OpenAI'sconversation_lockedcode, but OpenAI raises that code only as a short busy lock between overlapping turns, never for item writes or response deletion (see Known limitations).Redundancy removed
ConversationVersionbuilt at rehydration, carried onRequestContext::conversation_version, and rebuilt under the lock at persist withlast_conversation_sequence_in_tx. Removed.ids_for_conversation_in_txre-read every item of the conversation that rehydration had just read. Persist now extends the checkpoint's rows. Removed.ResponseCheckpointand the conversation snapshot'slatest_response_idandturn_metadata. One storageResponseCheckpointreplaces them.bump_revision_in_txincreate(with items),create_items,delete_itemandpersist, for a column only the version check read. Removed with the column.StorageError::ConversationConflictandis_conversation_conflict,ExecutorError::ConversationLocked, theclient_visible_errorunwrapping throughPersistence, theconversation_lockedtelemetry category, and the HTTP, SSE and WebSocket mappings. Removed.Changes
migrations/0010_drop_conversation_revision.sqldropsconversations.revision; supervisor-mode verification expects 47 columns (withmain's file search tables) and 4 integer columns, and the PostgreSQL integer widening no longer touchesrevision.models::conversation:Conversationlosesrevision;bump_revision_in_txis removed;get_with_itemstells its header row apart by the conversation ID.models::item::last_conversation_sequence_in_txandids_for_conversation_in_txare removed.ResponseCheckpointmoves from the session tostorage::types::responseand carries the continued turn's ID and metadata and its history rows (history_item_ids).ConversationStore::rehydratereturns the conversation's items and that checkpoint;ConversationStore::persist(id, checkpoint, response_id, items, snapshot, metadata)no longer takes a version: it locks the conversation, appends the items, and stores the response with the checkpoint's rows followed by its own.create,create_itemsanddelete_itemno longer bump a revision.RequestContext::conversation_versionandExecutorError::ConversationLockedare removed;ConversationHandler::persistmaps storage errors directly.conversation_lockedtelemetry category is removed.generate: false): the turn completes and is stored after the competing write, and racing turns both commit with contiguous sequence numbers.merged_migrations_are_unchangedpins the checksums of the migrations onmain, anddatabase_migrated_by_main_upgrades_and_keeps_its_dataupgrades a database at 0009 to 0010.concurrent-writesscenario inrecord_cassette.pyandrecord_conversations_api_cassettes.sh, recorded against OpenAI and the gateway. The recorder now numbers each request in send order (anx-recording-turnheader the proxy strips), so a side request that finishes before the streamed turn it overlaps keeps its place.conversations_api_cassette_test.rschecks both recordings, including B'sinput_itemson both providers, and compares them; the existing scenarios are unchanged.ARCHITECTURE.md;docs/deploying/container.mdloses theconversation_lockedparagraph and therevisionwidening statement;observability.mdloses theconversation_lockedcategory.Behaviour changes
400 conversation_lockedand store nothing. It now completes and is stored after the conversation's current items, as on OpenAI.error.typeno longer reportsconversation_locked.Known limitations
400 conversation_locked("Another process is currently operating on this conversation. Please retry in a few seconds."), depending on timing: a turn started while a non-streamed turn runs is rejected at once, while a turn started during another turn's streaming usually succeeds. The gateway accepts both turns and stores them in commit order; it does not reproduce that busy lock.Size
Measured against
main, which now includes PR2. Production code excludes integration tests (tests/,*tests.rs), cassettes, benches and docs; unit tests insidesrcfiles count as production code.Stack
The cleanup is split into five stacked PRs; each builds on the previous one and passes CI on its own. This is PR3.
refactor/storage-layerrehydrateand onepersistper handler.refactor/storage-schemaitems.metadata,public_id NOT NULL, theresponses.snapshotcolumn, recreate/reject for databases from earlier releases (migration 0009).revision.refactor/append-only-turnsconversation_lockedwhen the conversation changes while they run; a turn stores the history it started from (oneResponseCheckpointfrom rehydration to persist);conversations.revisionis dropped (migration 0010); theconcurrent-writescassette records OpenAI and the gateway.refactor/public-historypersist.rs;input_itemsmatch OpenAI for gateway tools.refactor/typed-requestmetadata, concurrency edge cases with multi-agent state and compaction.RequestContextstays a follow-up.Test Plan
pre-commit run --all-files,cargo clippy --all-targets -- -D warnings, MSRV (cargo +1.98.1 check --workspace --all-targets --all-features --locked)cargo test --workspace --no-fail-fast: 2958 passed, 0 failed, 18 ignoredTEST_POSTGRES_URLand--ignored: schema (3),postgres_storage_integration(5),postgres_tenant_isolation_test(6)conversations-concurrent-writesrecorded against OpenAI (gpt-4.1) and the gateway (vLLM,Qwen/Qwen3.8-27B-FP8), 22 turns each with driver-assigned turn numbers;conversations_api_cassette_test: 11 passed