← Back to Technical blog

Technical article

Will the Answer Survive a Disconnect? Streaming, Run State, and Saved Turns in Data Agent

A regional operations analysis has started generating a response when an elevator cuts off the connection. The page shows half a sentence. Once connectivity returns, the page needs to find the status of the original task and retrieve its saved result. In HENGSHI SENSE 7.0, the event stream, run lookup, and conversation history serve distinct purposes. Together, they let the page recover a result without submitting the task again.

Dec 4, 2026Technical blogHENGSHI13 min read

Article body

Full article

A regional operations analysis has started generating a response when an elevator cuts off the connection. The page shows half a sentence. Once connectivity returns, the page needs to find the status of the original task and retrieve its saved result. In HENGSHI SENSE 7.0, the event stream, run lookup, and conversation history serve distinct purposes. Together, they let the page recover a result without submitting the task again.

1 SSE reports live progress, and history preserves the result

1.1 Render progress from live events

While the connection is open, clients can consume analysis summaries, tool status, text deltas, charts, sources, and clarification events. The SDK does not guarantee transparent resumption after a disconnect. SENSE 7.0 provides no interface to replay the original LUI stream by event sequence number. After reconnecting, read back the run and historical turn, then replace the temporary display with the complete result.

1.2 Check stream completion and task success separately

The done event indicates that the stream has ended. Use run status and the saved turn to determine what conclusion to show the user. At a minimum, distinguish connecting, streaming, recovering, and result ready. During recovery, a partial response can stay visible as a preview. Mark it as incomplete and keep it out of exports, subscriptions, and handoffs.

After reconnecting, check whether the user is still signed in. Use the original authenticated user session for history and run lookups. If a resource is unauthorized or no longer visible, retain the request ID for troubleshooting and direct the user to conversations they can access. Previously cached content must follow the host’s data retention rules.

2 Record conversation, turn, and run identifiers

In the Data SDK, run and conversation metadata are under event.metadata. With the raw HTTP API, the fields are in the original event envelope. On chat.created, promptly record the real runId, chatUid, and conversationId. Prefer these server identifiers during recovery and call the interfaces as the current authenticated user.

IdentifierObjectHow it is used during recovery
conversationIdA multi-turn conversationLocate the conversation and history list. Combine with another identifier to locate a run or specific answer
chatUidAn established turnRetrieve the turn by conversation and turn identifiers
runIdAn individual executionRead run state or request cancellation
requestId or clientRequestIdServer request correlation or client submission correlationLog and trace submissions. Neither serves as a turn identifier or idempotency key
traceId or seqServer trace or order within a streamDiagnose problems or process events within one stream. Neither resumes a stream

3 Recover the original run after a disconnect

3.1 Read the status when runId is known

Keep the conversation and run identifiers and call getRun. While the run is active, show a recovery state and poll within defined limits. At a terminal state, read the saved turn using the original chatUid and check status and completeness. Display the complete answer only when the server reports the relevant terminal state and returns the required content.

To recover after a refresh, keep the pending item for the original question and associate the real identifiers as soon as they arrive. If the browser retains this mapping, scope it to the user, tenant, and conversation. After sign-out, another account must be unable to read it. Temporary message numbers are for locating items locally. Use server identifiers to read turns.

3.2 Locate the turn first when only conversationId is known

If the first event never arrived, use listChats to view recent saved turns. Separate user actions can produce the same question, and one user might ask it twice in separate tabs. Wording and timestamps can help with reconciliation, but cannot uniquely identify a turn. Let the user select a visible saved turn or leave the page in a verification state. The server may have accepted a request even when the list has no match yet.

Data SDK recovery example. Implement isTerminal according to the status contract for the deployed version.

async function inspectInterruptedTurn(agent, saved, isTerminal) {
  const { conversationId, runId, chatUid } = saved;
  if (!runId) {
    const history = await agent.listChats(conversationId, { limit: 20 });
    return { phase: "match_history", candidates: history.data };
  }
  const run = await agent.getRun({ conversationId, runId });
  if (run.found === false) return { phase: "verify_run", run };
  if (!isTerminal(run.status)) return { phase: "wait", run };
  const targetChatUid = chatUid || run.chatUid;
  if (!targetChatUid) return { phase: "verify_history", run };
  const chat = await agent.getChat(conversationId, targetChatUid);
  return { phase: chat ? "render_with_status" : "verify_history", run, chat };
}

The example separates reads from display decisions. The host bounds wait by attempt count and elapsed time, and keeps a run that has not yet been found in a verification state. For render_with_status, label success, failure, or cancellation using the server’s terminal state and use the turn content to decide what to display. For GET authentication or permission errors, prompt the user to resolve the current identity. Network errors can use bounded read retries.

4 Check the final state after cancellation

AbortSignal, closing a page, and stopping reads affect the client connection. To cancel the task, send cancelRun and then query the server-side run state. If a change was already written, inspect the resource receipt and current object state. The run may have finished before cancellation arrived. Show its actual terminal result.

A canceled turn can show the partial content that was saved, with an appropriate status marker. The page can also direct users to inspect affected resources, review history in the original conversation, or explicitly start another analysis.

5 Carry clarification into the next turn

On lui.clarification, the front end can display unresolved slots as a form. When the user confirms, submit a normal new turn in the same conversation, carrying the clarification ID and structured selections in runtimeContext.clarificationResolution. The server updates the earlier clarification when it creates the new turn and saves validated choices. Restore the original selections from the returned selections field when displaying history.

If the user closes the form, use abandonClarification. A normal submission needs no additional dismissal, and an ordinary reply also ends a clarification that is still waiting. Integrations using the old answerClarification flow should switch to the new-turn flow after upgrading. Operation proposals use their supported confirmation entry point and require explicit confirmation.

A recovered chart and a recovered operation proposal can be in different states. Render charts from their persisted structure. For proposals, show available actions according to expiry, user permissions, and server state. If the browser received a proposal before the disconnect, display the proposed target again and let the user confirm it explicitly.

6 Keep read retries separate from task submission

The SDK retries idempotent reads within limits and does not automatically replay the POST that starts a turn. Server requestId and client clientRequestId support correlation and troubleshooting. After a gateway timeout or interrupted response, reconcile the server-side run and turn first, especially for tasks that can write resources. A retryable error flag alone does not authorize resubmission.

SituationClient actionFinal evidence
Connection drops and runId is knownQuery getRun, then getChat for the matching turn once the run is terminalServer status and the specified turn
Page refreshes before the first eventRead history for the same conversationIdTarget saved turn confirmed by the user or trusted correlation
User clicks cancelSend cancelRun and keep checking the runFinal server state and affected resources
User submits a clarificationSend a normal new turn with structured selectionsNew turn and selections saved in history
Submission may have arrived but is not yet visibleKeep a verification state and suggest reviewing history or checking laterEstablish the outcome before starting another task

7 Fictional scenario: Recovering a weekly regional report answer

A retail team asks Data Agent in its portal to compare regional business data for this week and last week. An analyst selects the payment week and sees streamed text, then switches networks. After reconnecting, check runId first. If the run completed, use the original chatUid to read the conclusions, charts, and sources. If the portal already has a newer follow-up, restore the intended result by its original chatUid.

A second test disconnects before chat.created. The page retains only the conversation ID and no confirmed match appears in history. Show “Checking your previous request” and let the user review history later. In a regression case, submit the same question concurrently from two places and confirm that the client does not assume the final list entry is the unique match.

If the weekly report will be submitted to a business system, test recovery for its charts, citations, and filters. Ask the business owner to review the week using the saved result, then have another tester read it by the original turn ID. Verify the period and scope even when totals agree. A different turn can produce the same aggregate.

7.1 Include state integrity in integration tests

Cover at least one complete data question, one valid plain-text turn, one clarification with multiple options, and one server-side cancellation. Record submission count, terminal run state, turn ID, and expected visible content. For a browser backend used with a proxy, observe time to the first data chunk, text deltas, and history recovery separately to isolate buffering and timeouts.

For tasks that may write resources, use a pilot environment and verifiable test objects. Confirm there is no duplicate submission after disconnecting and use actual receipts to check writes made before cancellation. Keep traceId, requestId, run state, and timing in operational records. Avoid forwarding raw logs containing business data or credentials.

8 Recovery acceptance criteria

Recovery succeeds when the original run can be identified, the page displays the saved result for the same turn, and recovery does not add another submission. Implement run lookup and history reconciliation, then add regression coverage for cancellation, clarification, and retries.

About HENGSHI

Founded in 2016, HENGSHI develops next-generation Agentic BI for a Data+AI world. Its enterprise analytics platform, HENGSHI SENSE, works with HENGSHI’s digital employees, the HENGSHI CLI execution engine, and the privately deployed HENGSHI BOX to provide an integrated service offering. With a decade in BI analytics and its Powered by Hengshi ecosystem, HENGSHI enables software providers across industries and delivers end-to-end private, trusted AI analytics for operations and decision-making in manufacturing, finance, retail, and government.

HENGSHI SENSE

Resources, ecosystem, and implementation stories

Explore how teams design and ship analytics with HENGSHI.

Request a trial

Enterprise deployment, embedded delivery, and trial requests can all be handled quickly.