fix(api): persist compressed responses history - #56996
Conversation
Store the effective agent session id and compacted result transcript for /v1/responses chaining after compression. Detect same-session compressed transcripts by matching the current user boundary on role and content so internal persistence metadata does not cause old history to be reattached.
Duplicate of #56933 (izumi0uu) -- both PRs fix #56895 ( |
|
Thanks for covering the stale snapshot and effective-session-id paths. The premise is confirmed on current main: Suggested changes
The current implementation otherwise addresses the verified non-streaming and streaming persistence sites. Automated hermes-sweeper review. |
|
Fixed via #69306 (merged), which salvaged #58133 using the same two authoritative signals your PR identified (session rotation + in-place compaction flag). Your metadata-insensitive boundary matching informed the review. Note #56933 by @izumi0uu proposed the same mechanism ~2h before yours — first-submitter credit went there and to #41700. Thanks! |
What does this PR do?
This PR fixes repeated context compression in the
/v1/responsesprevious_response_idchain after Hermes compacts an agent transcript.The Responses endpoint stores snapshots in
response_store.dbso later requests can continue from a previous response. When the agent compressed context, it returned a compactedresult["messages"]transcript, but the API server could fail to recognize that transcript as the current turn's canonical history. In same-session compression, returned messages may include internal metadata such as_db_persistedor_compressed_summary, so full dict equality against the current user message failed.When that boundary detection failed, the snapshot builder reattached the old oversized parent history in front of the compacted transcript. The next
previous_response_idrequest therefore loaded stale history again and triggered compression repeatedly.This fix:
session_idreturned by_run_agent, so chains follow compression-rotated sessions.result["messages"]transcript after compression instead of rebuilding from stale parent history.roleandcontent, ignoring internal persistence metadata./v1/responsespaths.Related Issue
Fixes #56895
Type of Change
Changes Made
gateway/platforms/api_server.pyroleandcontent.tests/gateway/test_api_server.pyprevious_response_idchaining after compression rotates to a new session._db_persisted/_compressed_summarymetadata.How to Test
Run syntax compilation:
Run targeted Responses regression coverage:
Run the same async test methods through a focused manual runner:
Expected result:
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) - N/Acli-config.yaml.exampleif I added/changed config keys - N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows - N/AScreenshots / Logs
Targeted verification on Windows: