You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Restore expired sessions via summary-based catch-up (#52)
When the backend loses a session (typically: HF Space restarted), the
chat now shows a small inline banner instead of silently erroring:
Where were we?
Let me skim the conversation so far and pick up right where we left
off — or we can start something new.
[ Catch me up ] [ Start fresh ]
Flow, in one pass:
* Frontend stashes the raw backend messages in localStorage on every
mount-hydrate and turn_complete. When the backend 404s for the
session id, the SSE transport and the mount effect both fire
onSessionDead → the session is flagged `expired` in sessionStore;
the sidebar marks it "needs a catch-up".
* Catch me up → POST /api/session/restore-summary with the cached
messages. Backend creates a fresh session, runs the existing
summarizer (factored into summarize_messages() and shared with
in-session compaction) with a restore-specific prompt that
preserves the tool-call trail, and seeds the new session with that
summary wrapped in a [SYSTEM: ...] user turn. New id is swapped
back via renameSession; UIMessages + backend-cache move with it.
* Start fresh → delete the session + its caches.
* The design is lazy per session: users with 5 stale tabs only pay
for a summary on the ones they actually reopen.
Frontend filters [SYSTEM: ...] user turns from rendering so the seed
message (plus existing doom-loop / compact nudges) stays invisible.
For sessions that predate the raw-message cache, fall back to
reconstructing the backend message list from the longstanding
UIMessage cache (tool calls + paired results, text preserved).
Also sets litellm.modify_params = True globally in agent/__init__.py
(moved out of agent/main.py) so the backend entry also picks it up —
required for Anthropic to accept a history containing tool_calls
without a `tools=` kwarg, which is exactly the summarization shape.
"""Manages conversation context and message history for the agent"""
73
130
@@ -318,32 +375,32 @@ async def compact(
318
375
ifnotmessages_to_summarize:
319
376
return
320
377
321
-
messages_to_summarize.append(
322
-
Message(
323
-
role="user",
324
-
content="Please provide a concise summary of the conversation above, focusing on key decisions, the 'why' behind the decisions, problems solved, and important context needed for developing further. Your summary will be given to someone who has never worked on this project before and they will be have to be filled in.",
0 commit comments