Skip to content
Star

Threads and runs

Keep messages and commands attached to the right conversation.

Identify the thread, run, and message

A thread or session identifies the conversation. A run, turn, or task identifies one piece of work. Message and part IDs identify what appears in the view. Keep the same IDs when text grows during a stream.

Ghost reads { threadId, revision, runId? }. Use the native thread ID, and include a run ID when the SDK provides one. Increase revision when you clear history, replace the command owner, or switch away and back. Keep it steady during ordinary updates.

Switch conversations safely

Create native hooks/stores per authenticated conversation owner. Mount a hook integration with a key derived from the thread and replacement revision when the SDK reads initial configuration once. Create a new createAgUiRuntime for each native thread/revision; do not mutate its bound client's thread ID in place.

A command captured in an old Ghost snapshot rejects after context replacement. An asynchronous upload must call its supplied context.assertCurrent() before native dispatch. The host must also reject late network results before publishing them: Ghost cannot retract a write made inside an application callback.

Keep native session IDs

Stop, reconnect, and restore history

A UI stop request is not proof that remote work stopped. Use the SDK's cancellation API when available and render its eventual outcome. A disconnect may only stop local observation. Preserve failed, cancelled and denied states; do not replace them with a successful final answer.

Restore history into the native store before sending messages to the view. Your app handles access, storage, retention, and thread lists. On the server, create the store per request and supply a matching getServerSnapshot for hydration. See external stores and the SDK’s recovery guide.