Skip to main content
The Zeus message queue covers two layers: the user-facing message queue that lets users queue messages while the Agent is processing, and the backend event persistence system that ensures reliable delivery.

User Message Queue

When the Agent is processing a response, users can continue typing and queue additional messages instead of waiting.

Behavior

ScenarioBehavior
Agent is processing + user sendsMessage is added to the queue (not sent immediately)
Agent completes normallyNext queued message is auto-sent after 100 ms
Agent is stopped (truncated)Queue does not auto-consume; user decides what to send next
User clicks Send Now (↑) on a queued itemStops current generation (if active), then sends that message

Queue UI

The queue panel appears above the chat input when messages are queued:
  • Edit (pencil icon) — inline-edit the queued message content
  • Send Now (↑ arrow icon) — stop current generation and send this message immediately
  • Remove (trash icon) — delete from queue

Truncated Context

When a response is stopped mid-stream, the partial AI content is preserved in the conversation history and used as context for subsequent messages. It is also persisted to the database so it survives page refresh.

Conversation & File Rollback

Users can roll back to any previous conversation turn, similar to Cursor’s fork model.

Conversation Rollback

  1. Hover over a user message → click the Rollback button (↺)
  2. Messages after the rollback point are dimmed (40 % opacity), not deleted
  3. A fork divider appears with a Cancel Rollback option
  4. New messages are appended below the divider
  5. Chat history sent to the backend only includes messages up to the fork point

File Rollback

When the user rolls back, sandbox files modified after the fork point are restored to their earlier state:
handleRollback(forkMessageId)
  → Save current files as preRollbackFiles
  → Collect FileSnapshots for messages after forkMessageId
  → POST /api/sandbox/restore-files (write old versions back)
  → Update trajectoryStore.sandboxFiles
Cancel rollback reverses the process, restoring the latest file versions from preRollbackFiles.

File Recovery on Refresh

Sandbox files are restored from database events — not just the live E2B sandbox — so files persist even after the sandbox expires. Content is lazy-loaded: when the user clicks a file tab whose content is empty, the frontend calls GET /api/sandbox/read-file to fetch it from the sandbox on demand.

Event Persistence

RealtimeEventSaver

RealtimeEventSaver is responsible for batch-persisting real-time SSE events to the database:

Configuration

SettingValueDescription
Batch size3 eventsTriggers a write when the buffer reaches this count
Batch interval100msFlushes on a timer even if the batch is not full
Retry count3Maximum number of retries
Retry strategyExponential backoff1s → 2s → 4s
FallbackLocalStorageBackup storage after all retries are exhausted

Message Batching

Frontend Message Merging

The frontend merges rapid successive text updates to avoid excessive re-rendering:
StrategyDescription
UI batch flushBatch updates at ~60fps, merging rapid successive tokens
Virtual scrollingOnly renders message cards within the visible viewport
Selective persistenceOnly persists sessionId and messageIds; message content is loaded on demand

Chat History Construction

The frontend loads the current session’s message history from the Zustand Store, excludes the message currently being sent, and passes it to the backend. The backend converts it to LangChain message types, limiting to a maximum of 30 messages.

Concurrency & Isolation

Isolation DimensionMechanismDescription
Sessionthread_idEach session has its own independent Checkpointer state
Contextsession_idContext Cache is isolated by session_id; resume only restores the corresponding session
Tool executionLangGraphTools execute serially within the same session, never concurrently
Workspaceuser_idUser file systems are fully isolated by user_id

Session Recovery

The system supports recovery after session interruption:

Save Triggers

  • After a tool call completes
  • After a message is sent
  • During HITL interruption (via Checkpointer)

Recovery Flow


Messages

Complete message flow, request parameters, and state management

Retry Policy

Error handling, retry strategies, and fallback mechanisms