Repository navigation
fix: send snapshot-form stats in full_state and conversation info - #6823
Conversation
The full_state ConversationStateUpdateEvent sent on every session/events
socket connect and the REST ConversationInfo dumped ConversationStats with
every per-call cost, latency and token-usage entry. Past ~1,550 LLM calls
the full_state frame exceeds the 4 MiB session-socket frame budget, so the
server closes every connection with frame_too_large and Canvas loops on
reconnecting.
Dump both with context={"use_snapshot": True}, like the incremental stats
update already does. Persistence keeps the full history.
Fixes #6741
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Coverage Report •
|
||||||||||||||||||||||||||||||
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
|
📁 PR Artifacts Notice This PR adds or changes temporary PR-specific documents under |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Scope: The change belongs here. Both touched source files (openhands-sdk/openhands/sdk/event/conversation_state.py, openhands-agent-server/openhands/agent_server/conversation_service.py) are core SDK/Agent Server conversation-state and REST/WebSocket transport code — squarely in this repository's ownership. Linked issue #6741 is filed in this repo (open, ready-for-dev, priority:medium), so no maintainer decision is needed on scope.
Review result: no material findings.
What I verified against the current head (6e38e2cf):
- Fix correctness.
from_conversation_state()and_compose_conversation_info()now serialize withcontext={"use_snapshot": True}, matching the incrementalstatsevent path (ConversationStateUpdateEvent.validate_value), which has shipped this exact shape since #1308.ConversationStats._serialize_with_contextswaps eachMetricsfor itsMetricsSnapshotdump, sofull_stateand RESTConversationInfo.statskeep the aggregates (accumulated_cost,accumulated_token_usage,max_budget_per_task,model_name) while per-callcosts/response_latencies/token_usageslists are dropped — the payload no longer grows with LLM-call count. - Round-trip safety.
RemoteState.statsvalidates the snapshot dict viaConversationStats.model_validate; the omitted list fields default to empty lists andinitialize_accumulated_token_usagefills a zeroedTokenUsagewhen absent, so remote clients receive a validConversationStatsandget_combined_metrics()still reports correct aggregates (used for budget checks). - Persistence unchanged.
ConversationState._save()serializes with only theciphercontext (nouse_snapshot), sobase_state.jsonkeeps the full per-call history; the live-server test asserts every entry survives. - Cross-layer consistency. All
_compose_conversation_infocall sites (get, search, create, fork, navigate, webhooks) flow through the single changed function, so no path serves a different shape.ConversationInfo.metricswas alreadyMetricsSnapshot | None. The TypeScript client modelsusage_to_metricsasRecord<string, MetricsSnapshot>and has no consumers of the per-call lists, so the disclosed empty-list behavior doesn't break the generated client. - Regression tests. I ran the three new tests against
main's source: all three fail there (full_state event grows with history; REST info carries per-call lists) and all 26 unit tests pass on this head. The live-server test exercises the real/sockets/session/{id}handshake againstMAX_FRAME_BYTES— reproducing the1013 frame_too_largefailure mode onmain— and the PR's manual Canvas before/after evidence ties the reconnect-loop symptom to this root cause through the supported entry point. - CI on
6e38e2cf. 52 checks pass, includingsdk-tests,agent-server-tests,cross-tests,integration-test, OpenAPI schema, and persisted-settings gates.
One CI failure to flag for the human author (not a code defect): the Validate PR description check fails with Add a short human-written note between HUMAN: and AGENT:. The HUMAN: section still contains only the template placeholder while the PR is marked ready for review. Per this repository's rules AI agents must not edit that section, so the human author needs to replace the placeholder with a short note in their own words before merge; the code itself is unaffected.
✅ APPROVED
Co-authored-by: openhands <openhands@all-hands.dev>
HUMAN:
I read the implementation and validation, this looks good to me.
AGENT:
Why
Long conversations stop connecting. Each
/sockets/session/{id}(and/sockets/events/{id}) connection gets onefull_stateConversationStateUpdateEvent.ConversationStateUpdateEvent.from_conversation_state()dumpedConversationStatewithoutuse_snapshot. Sostatsheld every per-callcosts,response_latenciesandtoken_usagesentry, about 0.5 KB per LLM call. Past about 1,550 LLM calls the frame is larger than the 4 MiBMAX_FRAME_BYTESbudget. The server then closes every connection with1013 frame_too_large, and Canvas loops on "Reconnecting…" / "Unable to connect to server" for that conversation.The incremental
statsupdate already usescontext={"use_snapshot": True}(#1308). Thefull_statepath and the RESTConversationInfo(_compose_conversation_info, which servesGET /api/conversations/{id}and/search) did not.Summary
ConversationStateUpdateEvent.from_conversation_state()dumps state withcontext={"use_snapshot": True}. Thefull_statesnapshot carries per-usage aggregates (accumulated_cost,accumulated_token_usage,max_budget_per_task,model_name) and no per-call lists. Its size no longer grows with the number of LLM calls._compose_conversation_info()does the same. RESTConversationInfo.statskeeps the same schema and aggregates, but its per-call lists are now empty.base_state.json) is unchanged and keeps the full per-call history. Only the wire payloads change.Issue Number
Fixes #6741 (Canvas symptom: OpenHands/OpenHands#18935)
How to Test
Automated:
uv run pytest tests/sdk/conversation/test_stats_update_event_snapshot.py \ tests/agent_server/test_conversation_info_model.py uv run pytest tests/cross/test_remote_conversation_live_server.py \ -k "full_state_fits or conversation_stats_with_live"test_long_conversation_full_state_fits_session_frame(live server): fills a conversation with per-call metrics untilConversationStateis larger thanMAX_FRAME_BYTES, then connects to/sockets/session/{id}. Onmainthe test fails withConnectionClosedError: received 1013 (try again later) frame_too_large. On this branch it gets thefull_stateframe, and that frame has snapshot-form stats with the correct aggregates. The test also checks thatGET /api/conversations/{id}and/searchare under 100 KB, and thatbase_state.jsonstill has every per-call entry.mainand pass here. The existingtest_conversation_stats_with_live_serverstill passes.Manual end-to-end check (Agent Canvas
main46f20abaf + agent-server from this checkout):base_state.json(4.6 MB), then start the agent-server again.session_socket_frame_too_largein ~35 s/sockets/sessionconnections opened by the pageGET /api/conversations/{id}Video/Screenshots
Before (main 91e8b5b): the server closes every connection with
frame_too_large, and Canvas stays on "Reconnecting…":After (this PR): one connection, no
frame_too_large, no reconnect banner:Type
Notes
RemoteConversation.conversation_statsand theRemoteStatefull_statehandler already validate snapshot-form stats (Metricslist fields default to empty). The aggregates stay correct, and the incrementalstatsupdates already send this shape.costs,token_usages,response_latencies) from the REST response or thefull_stateevent now get empty lists. The full history is still persisted on the server.F07.snapshot-compact-statsxfail entry proposed in docs(verify): map maintenance 2026-11-12 #6753 can be switched to pass..pr/images are PR-only evidence. The next release PR removes them.This PR was created by an AI agent (OpenHands) on behalf of Graham Neubig.
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:17da74b-pythonRun
All tags pushed for this build
About Multi-Architecture Support
17da74b-python) is a multi-arch manifest supporting both amd64 and arm6417da74b-python-amd64) are also available if needed