Repository navigation
refactor: typed item metadata and a response snapshot column (2/5) - #502
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]>
…to 0009 Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
…_output_item Signed-off-by: maral <[email protected]>
maralbahari
marked this pull request as ready for review
November 4, 2026 14:05
maralbahari
requested review from
bbrowning,
franciscojavierarceo,
haoshan98,
jiahuei,
leseb,
noobHappylife,
qandrew and
tjtanaa
as code owners
November 4, 2026 14:05
maralbahari
marked this pull request as draft
November 4, 2026 14:06
Signed-off-by: maral <[email protected]>
maralbahari
marked this pull request as ready for review
November 4, 2026 14:15
tjtanaa
reviewed
Nov 4, 2026
tjtanaa
left a comment
Member
There was a problem hiding this comment.
Found one data-safety issue in the outdated-schema reset gate.
maralbahari
marked this pull request as draft
November 4, 2026 14:20
Signed-off-by: maral <[email protected]>
franciscojavierarceo
approved these changes
Nov 4, 2026
maralbahari
marked this pull request as ready for review
November 4, 2026 16:49
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
This PR changes what is stored. Item rows record their kind in a typed
metadatacolumn instead of hidden keys inside the item JSON, every item row carries its public ID, and the retrievable response moves out of the continuation metadata into its own column. Databases holding data written by earlier releases are not migrated: the default SQLite database is recreated, and any other database is rejected until its operator resets it._agentic_*keys insideitems.dataitems.metadataholds typedItemMetadata { kind };items.datais the item's plain serde JSONitems.public_idwas nullable and lookups usedCOALESCE(public_id, reference_id, id);reference_idwas unusedpublic_idisNOT NULLon every row, lookups match it directly, andreference_idis droppedresponses.metadata(response_snapshot), so continuations decoded it and then discarded itresponses.snapshotholds it;ResponseMetadataholds only what a continuation needsGET /v1/responses/{id}/input_itemsdecoded the whole stored response to find its outputCodeInterpreterCallOrigintold gateway-executed and upstream calls apartcode_interpreter_callis the gateway's public projection and is never replayed upstream; the model sees thecode_interpreterfunction call and its outputReasoningOutputis the only reasoning shape; lenient JSON ingestion drops an item the typed schema rejects and logs its typeSchema (migration
0008_typed_item_metadata.sql)Migrations 0001 to 0007 are unchanged. 0008 alters the tables instead of rebuilding them, and its
NOT NULLcolumns without defaults are valid because it only ever runs on empty tables (see below). The same file runs on SQLite and PostgreSQL.Databases written by earlier releases
MINIMUM_SUPPORTED_MIGRATION = 8(storage/schema/outdated.rs). Before migrating, startup checks whether a database migrated by an earlier release holds any conversations, items or responses:$AGENTIC_API_HOME/agentic_api.db, used when no database URL is set) is dropped and recreated at the latest schema in one transaction, and a warning is logged.DATABASE_URL) is rejected with an error telling the operator to reset it. Its data is left untouched. Supervisor mode (AGENTIC_API_SCHEMA_READY) rejects it too.ExecutionContext::from_configdecides which database is the default one, so the gateway, llm-d and other library callers behave the same.Redundancy removed
_agentic_item_kindkeys insideitems.dataand implied by how the row was written. Now only the typeditems.metadata;items.datais the item's plain JSON.COALESCE(public_id, reference_id, id), withreference_idnever written. Nowpublic_id NOT NULLis the one public identity andreference_idis dropped.responses.metadata, decoded by each continuation and stripped again at several call sites. Now a separateresponses.snapshotcolumn that only retrieval reads.LegacyReasoning(from_legacy_value,opaque_state) besideReasoningOutput. Now onlyReasoningOutput.CodeInterpreterCallOriginand its manualPartialEq, tracking a distinction the item type already carries. Removed.input_itemsdecoding the whole stored response only to count its output items. Now counted without decoding.Changes
migrations/0008_typed_item_metadata.sqlas above.storage/schema/outdated.rs: outdated-data detection, the atomic SQLite drop (PRAGMA defer_foreign_keysinside one transaction), and the reset error.items.public_id NOT NULL,items.metadataandresponses.snapshot.Itemgainspublic_id: Stringandmetadata; the model no longer generates IDs or timestamps.storage/types::encodebuilds the row (row ID, public ID, kind) andTryFrom<&Item> for InOutItemreads it back by kind.Responsegainssnapshot;TryFrom<&ResponsePayload> for String(which strips request-scoped MCP credentials) andTryFrom<&str> for ResponsePayloadconvert it, andsnapshot_output_countcounts its outputs without decoding them.ResponseMetadata.response_snapshotis removed.ResponseStore::persist(…, snapshot: Option<&ResponsePayload>, metadata)andConversationStore::persist(…, snapshot, metadata)write the snapshot column.ResponseStore::get_snapshotreads it, andget_input_itemsreturns the history without the response's own output in one row read (Nonewhen the response has no snapshot).ResponseHandler::get_snapshotandlist_input_itemsread the snapshot column. Continuations no longer have to strip a snapshot from the parent's metadata or from session checkpoints.persist.rspasses the snapshot to the handlers'persistbeside the turn metadata.CodeInterpreterCallOriginand its manualPartialEqare removed;OutputItem::to_input_itemnever replays acode_interpreter_call.types/io/reasoning/legacy.rs(LegacyReasoning,from_legacy_value,opaque_state) is removed. Lenient JSON ingestion logs the type of an output item it drops; streamed completions keep the item as it was opened.ARCHITECTURE.md: the storage section is updated, with a new "Schema, migrations, and where data goes" subsection: one connection layer with portable model SQL, migration rules, incompatible-data handling, and when data gets its own column instead of going intometadata..agents/skills/storage-schema-change/SKILL.md, referenced fromAGENTS.mdand the engineering skill, is a checklist for schema and persistence changes.docs/deploying/container.mdandkubernetes.mddescribe how databases from earlier releases are handled and how to upgrade.Behaviour changes
DATABASE_URL). Stop every older replica first, then pointDATABASE_URLat an empty database or drop the persistence tables; back up first if the data must be kept. See the deployment docs.code_interpreter_callitems are no longer replayed to the model, including any an upstream returned natively. The gateway's own calls were already replayed as theircode_interpreterfunction call and output.GET /v1/responses/{id}andinput_itemsreturn the same payloads as before.Known limitations
Size
Measured against PR1. 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 PR2.
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.Benchmarks
cargo bench -p agentic-server-core --bench benches -- '^(response|conversation)_(rehydrate|persist)/'on a SQLite file database, median of 100 samples;refactor/storage-layersaved as the criterion baseline and this PR compared against it.Response rehydration of long histories is faster because item rows decode as plain serde. Conversation rehydration moves within a few percent, from parsing the
metadatacolumn per item. Persist timings are dominated by SQLite write and sync variance, with overlapping confidence intervals.Test Plan
cargo clippy --all-targets -- -D warningscargo test --no-fail-fast(workspace): 2965 passed, 0 failed, 18 ignored (PostgreSQL-only)cargo +1.98.1 check --workspace --all-targets --all-features --locked(MSRV)cargo fmt -- --check, Rust file sizes (scripts/check_rust_file_sizes.py),git diff --checkTEST_POSTGRES_URLand--ignored: schema tests (3 passed),postgres_storage_integration(5 passed),postgres_tenant_isolation_test(6 passed)responses_api_test(29 passed) andconversations_api_cassette_test(10 passed) replay the committed recordingsmain, the previous PR and this PR against vLLM (Qwen/Qwen3.8-27B-FP8): all 11 Responses and 9 Conversations gateway scenarios. This PR matchesmainand the previous PR on every turn (method, path, status, error type/code/param, output and input item types and statuses, page shape), apart from model and concurrency variance in twotool-itemsturns. The re-recordings are not committed.