Repository navigation
refactor: unify checkpoints and fix compaction parity gaps - #506
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]>
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]>
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
…factor/append-only-turns
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]>
Signed-off-by: maral <[email protected]>
tjtanaa
left a comment
There was a problem hiding this comment.
Two compaction and session-retention issues need attention.
Signed-off-by: maral <[email protected]>
tjtanaa
left a comment
There was a problem hiding this comment.
Two additional compaction issues on the updated revision.
Signed-off-by: maral <[email protected]>
Signed-off-by: maral <[email protected]>
tjtanaa
left a comment
There was a problem hiding this comment.
Two further issues in the updated storage and compaction paths.
| None => Vec::new(), | ||
| }; | ||
| let previous_response_id = parent.and_then(|parent| parent.response_id.as_deref()); | ||
| let mut item_ids = parent.map(|parent| parent.history_item_ids.clone()).unwrap_or_default(); |
There was a problem hiding this comment.
Could we reconcile or validate this cached history against the durable parent before committing? For example, store A → B, let C rehydrate B, then delete A before C persists. Deletion removes A's IDs from B, but C now copies its stale A+B IDs and commits successfully because B still exists. A later continuation of C can therefore read A's deleted context again. Current main reloads B during persistence, so this completed-delete-before-persist ordering does not restore A. Please add an interleaved deletion regression and reject or refresh a stale checkpoint.
There was a problem hiding this comment.
Thanks for catching this. I checked it on OpenAI first with your order: store A ("Reply with only SAPPHIRE.") → B ("Reply with only ORCHID."), start C from B as a streamed turn, delete A while C streams, then list C's input items and continue C asking for the word the first user message asked for. I ran it four times and OpenAI was not consistent:
| Run | C's input items | Next turn's answer | Next turn's input items | Deleted A came back |
|---|---|---|---|---|
| 1 | A gone | ORCHID | A gone | no |
| 2 | A still listed | SAPPHIRE | A gone | yes, the model saw it |
| 3 | A gone | SAPPHIRE | A listed again | yes |
| 4 | A gone | ORCHID | A gone | no |
So OpenAI has the same race and does not guarantee either result. Since main reloads the parent during persistence and OpenAI's clean runs drop A, I kept that behavior: persist now re-reads the parent's current history and keeps only the cached IDs that are still in it, so a deletion during the turn is never undone. The compaction trim on the cached IDs is kept, and if the parent itself was deleted the turn fails as on main. deleting_an_ancestor_during_a_turn_does_not_restore_its_history covers your order. I did not add these OpenAI recordings because the result is not deterministic. The session checkpoint case will be covered with WebSocket cassettes in the follow-up PR.
Signed-off-by: maral <[email protected]>
### Summary `messages_test` failed on CI after #506 merged, in two tests at once: - `messages_returns_anthropic_error_for_unreachable_upstream` got `200` instead of `502`. - `messages_provider_tools_preserve_proxy_body_and_stream_events` counted 2 upstream requests instead of 1. Both come from one flaky setup, not from #506. The two "unreachable upstream" tests bound `127.0.0.1:0`, read the address, and dropped the listener to free the port. Tests in the file run in parallel, so the OS could hand that port to another test's mock upstream. The "unreachable" request then reached that mock: it answered `200`, and the other test saw an extra request. The tests now keep the port reserved for their whole run with a socket that is bound but never listens. Connections to it are refused, which is the `502` path the tests check, and no other test can take the port while the socket is alive. The new `refused_upstream()` helper is shared by both tests. `health_test.rs` (two tests) and `agentic_process/tests.rs` use the same drop-the-listener pattern and could flake the same way. This PR leaves them unchanged to stay a quick fix. ### Test Plan - `cargo test -p agentic-server --test messages_test`: 16 passed, and 20 consecutive runs passed with no failure. - `cargo clippy -p agentic-server --tests -- -D warnings` and pre-commit passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: maral <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
### 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]>
Summary
Part 5 of the storage/refactoring stack (#500), following the merged PRs 1–4.
Cleanup
ResponseCheckpointfrom rehydration into persistence. Response persistence extends the row IDs already loaded, and session checkpoints retain the IDs they stored. Split commit reuses its checkpoint or loads only the parent response row through typedget; the shared rehydration path still runs before inference.get/get_or_createread, creating a missing conversation only when required for a stored turn.main. The query selects the earliest(created_at, id)row per requested ID inside bounded batches, avoiding both one query per ID and loading every repeated occurrence. Repeated-ID support itself predates PR5.ResponseDatainside the store and remove unusedDbResponseexports. Type request metadata, consolidate reasoning normalization, and use one typed validator for complete upstream responses.CompactedWindowinstead of recovering the compaction item from the end of a list. Keepcompact_responseas the public endpoint and one shared summary operation; remove forwarding wrappers, the unreachable multi-agent branch, and repeated summary-settings/threshold selection. Keep privatewrite_turnto separate storage work from persistence timing and error handling.OpenAI parity gaps fixed in PR5
store: false. Evidence: thein-turn-chain,in-turn-chain-stream, andstore-falseOpenAI/gateway captures.in-turn-chainand its streaming variant, plus the tool-loop captures and live gateway replays.stalecaptures and their replay with the concurrent commit interleaved.tools/listrequest merely because the current declaration is broader. Evidence:compaction-mcpcaptures and integration tests that count actual discovery calls.mcp_list_toolsrecords from compacted output and invalidate them for later context, so the next turn discovers tools again. Evidence: the standalone and automatic compaction cases incompaction-mcp, with gateway integration coverage for stored and session continuations.Earlier public tool-item ID/status fixes and repeated-ID support are preserved; they are not counted as new parity fixes here. OpenAI's opaque compaction contents were not inspected.
Remaining observed differences
multi_agent.enabledexplicitly on continuation; the gateway inherits it. PR5 fixes history trimming for inherited settings without changing that admission behavior.Benchmarks
Rerun on 2026-11-09: this PR at
a342815versusmainatf410869(the PR base). These measurements isolate PR5 from the already-merged stack.Fresh SQLite files, 100 samples per case, 3-second warmup and 5-second target measurement. Two passes per revision in the order main → this PR → this PR → main; each cell is the median of its two run medians. Store-only persistence timings exclude setup; this PR receives the parent checkpoint already loaded during setup, as it does after normal rehydration.
Response-persistence latency measured 13.5–18.6% lower across the three history sizes; both PR passes were faster than both main passes. Conversation persistence and executor rehydration were broadly unchanged within run variation. Read timings varied substantially between passes—for example, conversation rehydration at 300 items ranged from 5.331–6.805 ms on main and 5.668–6.802 ms on this PR—so these measurements do not establish an overall rehydration speedup.
Only executor depth 1 is reported: the existing higher-depth benchmark cases do not extend their seeded chain, so they cannot establish depth scaling. These are local storage/rehydration measurements, not model-inference or compaction-throughput measurements.
Test Plan
The compaction replays execute current Rust gateway code with fresh SQLite storage and scripted inference. Responses management replays run against the release gateway. Existing OpenAI captures establish the wire behavior; MCP integration tests also assert actual discovery-call counts. No new YAML refresh is included, and no duplicate unit tests were added for the helper restoration.
These are local results. macOS jobs and remote GitHub Actions were not run as part of this validation; publication/deployment workflows were not run. The retained lifecycle fixture passed; separate fresh OpenAI probes showed inconsistent immediate post-deletion history, which is not treated as a new persistence contract in this PR.