Repository navigation
refactor: one typed storage layer for rehydration and persistence (1/5) - #501
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]>
maralbahari
marked this pull request as ready for review
November 4, 2026 12:21
maralbahari
requested review from
bbrowning,
franciscojavierarceo,
haoshan98,
jiahuei,
leseb,
noobHappylife,
qandrew and
tjtanaa
as code owners
November 4, 2026 12:21
franciscojavierarceo
approved these changes
Nov 4, 2026
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
This PR simplifies how history is rehydrated and persisted. It does not change what is stored on disk; the schema is the next PR in this stack.
Item::as_input/as_output/as_inout,decode_metadata,Response::metadata_as, three copies of the item encoder, and conversation metadata parsed in the HTTP layerstorage/types; each item row is parsed oncepersist,persist_if_version,persist_with_conversation_id,rehydrate,rehydrate_snapshot,create,create_with_metadata_and_itemscreate,get,get_or_create,rehydrate,persistInOutItemand storage types, never rowsprevious_response_idturn read the parent response row three timesResponseHandler::rehydratereturns the response and its history in one call (two queries)getandget_in_tx,get_item_ids,get_snapshot,get_items_by_conversation)execute_turn,execute_turn_with_metadataandcommit_tree(plus aCommittedResponsereceipt)rehydrateand onepersist;persist.rsbuilds the turn'sResponseMetadata(including any multi-agent tree) in one placeresponse_metadata_at_version,ResponseHandler::get) to restore tool-search state after compactionRequestContext::checkpoint;prepare_request_tools(ctx)reads it and makes no storage queryprevious_response_idthey can never have, and the code kept checks for that impossible caseprevious_response_id = NULL;ConversationStore::persistno longer takes itLayering after this PR
Redundancy removed
Item::as_input,Item::as_output,Item::as_inoutand ad-hoc decoding in the handlers. Now oneTryFrom<&Item> for InOutIteminstorage/types.encode.decode_metadataandResponse::metadata_as. Now one conversion pair for the column.storage/types.persist/persist_if_version/persist_with_conversation_id,rehydrate/rehydrate_snapshot,create/create_with_metadata_and_items. Now one function per operation.execute_turn,execute_turn_with_metadataandcommit_treewith aCommittedResponsereceipt. Now onepersistper handler.getbesideget_in_tx, plusget_item_ids,get_snapshotandget_items_by_conversation. Now one SQL function per table operation.previous_response_idturn. Now twice:rehydratereturns the response with its history.response_metadata_at_version,ResponseHandler::get) although rehydration had loaded it. Now read from the checkpoint onRequestContext.previous_response_ida conversation turn can never have. Removed.Changes
storage/types: one conversion pair per columnTryFrom<&Item> for InOutItemandTryFrom<&InOutItem> for Stringforitems.data. Each row is parsed once; before, it could be parsed up to four times.TryFrom<&str> for ResponseMetadataandTryFrom<&ResponseMetadata> for Stringforresponses.metadata, replacingdecode_metadataandResponse::metadata_as.ConversationData.metadatais now typedConversationMetadata, so the HTTP layer no longer parses JSON.ItemKindandCodeInterpreterCallOrigin, instead of string constants and hand-written matching.storage/models: one SQL function per operationresponse::getworks with either a pool or a transaction, replacinggetplusget_in_tx.response::get_item_ids,conversation::create,item::get_items_by_conversation,conversation::get_snapshotand its two row structs.conversation::get_with_itemsreads the conversation's version, the latest turn's metadata and every item in one portableUNION ALLstatement, returned as oneConversationHistorystruct. It selects only the header values rehydration needs, and orders items in Rust so the database doesn't sort item data.response::get_conversation_turnis removed, andresponse::delete_in_txno longer checks a child's conversation: children are found byprevious_response_id, so none is a conversation turn.ConversationStore:create(tenant_id, metadata, items),get,get_or_create,rehydrate(items, version andturn_metadatain one query), andpersist(…, expected_version: ConversationVersion, …). The latest turn's metadata is decoded instorage/types(decode_turn_metadata).list_itemslooks the conversation up only for an empty page or an unknown cursor, instead of on every call.persistalways checks the captured version; the unchecked mode existed only for tests.InOutItems.ResponseStore:get,rehydrate(the response and its history),get_items(the response and its public items),persist,delete.persist_if_version,persist_with_conversation_id(ResponseHandlercan never have a conversation id, sinceconversationandprevious_response_idare mutually exclusive),rehydrate_snapshot,create_with_metadata_and_items.ConversationHandler::rehydrate(ctx)returns the snapshot, andfrom_conversationmakes that one call.ResponseHandler::rehydrate(ctx)returns the parent response and its history together, sofrom_responseandfrom_session_responseno longer callgetfirst. A continuation now makes two storage queries instead of three.persist(ctx, output_items, metadata).execute_turn,execute_turn_with_metadata,commit_treeandCommittedResponseare removed.persist.rsbuilds the metadata in a privateprepare_metadataand attaches the multi-agent tree there.RequestContext::checkpointholds the turn the request continues, using the session's existingResponseCheckpointtype (response ID, metadata, durability; itshistorystays empty outside a session): rehydration fills it from a stored response, a conversation's latest turn, or a session's parent.prepare_request_tools(ctx)takes only the context, andConversationHandler::response_metadata_at_versionandConversationStore::response_metadata_at_versionare removed.ResponseHandler::retrieveis renamedget_snapshot.ConversationHandler::create(tenant_id, metadata, items)replacescreate()andcreate_with_metadata_and_items.ResponseHandler::list_input_itemsreads the response and its items in one store call and takes the snapshot from it, instead of decoding the response metadata twice.ResponseCheckpoint.conversation_idis removed; it was written but never read.engine::create_conversation()is removed; only tests used it, and it created conversations with no tenant.benches/storage_crud.rsis rewritten. The old rehydrate benchmarks timed a persist call inside the measured section (the setup returned an unawaited future), and the response benchmarks chained every iteration onto a growing history. Each benchmark now times exactly one store call, at 3, 30 and 300 history items.BENCH_DATABASE_URLselects another database.ARCHITECTURE.mddescribes the new storage layering.Behaviour changes
ConversationStore::persistrequires the version captured at rehydration. The executor already passed it, so production behaviour is unchanged. Tests that need concurrent same-conversation writes usecreate_items, which allocates sequences through the same lock.engine::create_conversationis removed;ConversationHandler::createtakes the tenant, metadata and items; handler persistence ispersist;ResponseHandler::retrieveisget_snapshot;prepare_request_toolstakes only the context.Size
Measured against
main. 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 PR1.
refactor/storage-layerrehydrateand onepersistper handler.refactor/storage-schemaitems.metadata,public_id NOT NULL, theresponses.snapshotcolumn, recreate/reject for databases from earlier releases (migration 0008).revision.refactor/append-only-turnsconversation_lockedwhen the conversation changes while they run;conversations.revisionis dropped (in 0008); theconcurrent-writescassette records OpenAI and the gateway.input_itemsdiffer from OpenAI's when items change mid-turn (PR5).refactor/public-historypersist.rs;input_itemsmatch OpenAI for gateway tools.input_items.refactor/typed-requestResponseCheckpointfrom rehydrate to persist: a turn stores the history it started from (completing PR3's behaviour), fewer reads and statements per turn, typed requestmetadata.RequestContextstays a follow-up.This is the first PR of a stack:
Benchmarks
cargo bench -p agentic-server-core --bench benches -- '^(response|conversation)_(rehydrate|persist)/'on a SQLite file database, median of 100 samples.mainis measured with the same benchmark adapted to its API, timing the readsmainperforms per turn (get+rehydratefor responses,rehydrate_snapshot+response_metadata_at_versionfor conversations).mainRehydrate timings are stable (tight confidence intervals). The persist SQL is unchanged in this PR; persist timings are dominated by SQLite write and sync variance, with overlapping confidence intervals between runs, so they show no meaningful difference.
Test Plan
cargo clippy --all-targets -- -D warningscargo test --no-fail-fast(workspace): 2976 passed, 0 failed, 19 ignored (PostgreSQL-only)cargo +1.98.1 check --workspace --all-targets --all-features --locked(MSRV)scripts/tests/agentic-launchers-test.sh,scripts/tests/agentic-cli-e2e-test.py,test_otel_fixtures.pycargo fmt -- --check, Rust file sizes (scripts/check_rust_file_sizes.py),git diff --checkTEST_POSTGRES_URLand--ignored:postgres_storage_integration(6 passed),postgres_tenant_isolation_test(6 passed) and the schema tests (3 passed)