The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): render a typed synthetic in-flight prompt like its persisted row on reconnect
teknium1b75396a70739
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.tsindex 340a44955c9..39b5399d98c 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts@@ -1264,6 +1264,46 @@ describe('preserveLocalPendingTurnMessages', () => {})describe('appendLiveSessionProjection', () => {+ // A synthetic starting prompt keeps the display typing its persisted row+ // will get: on reconnect it renders as the same timeline event as history,+ // never as a user bubble; a real user quoting the marker text stays a user+ // bubble because the gateway typed nothing (#112144).+ it('renders a typed synthetic in-flight prompt as its timeline event, not a user bubble', () => {+ const typed = appendLiveSessionProjection([], {+ session_id: 'runtime-1',+ inflight: {+ user: '[IMPORTANT: Background process finished] fixture',+ display_kind: 'process_complete',+ display_metadata: { display_text: 'Background Process Finished: fixture' },+ assistant: '',+ streaming: true+ }+ })++ const inflightRow = (message: ChatMessage) => message.id === 'user-inflight-runtime-1'++ expect(typed.filter(inflightRow).map(message => [message.role, chatMessageText(message)])).toEqual([+ ['system', 'Background Process Finished: fixture']+ ])++ const quoted = appendLiveSessionProjection([], {+ session_id: 'runtime-1',+ inflight: { user: '[IMPORTANT: Background process finished] fixture', assistant: '', streaming: true }+ })++ expect(quoted.filter(inflightRow).map(message => [message.role, chatMessageText(message)])).toEqual([+ ['user', '[IMPORTANT: Background process finished] fixture']+ ])+ })++ it('omits a hidden synthetic in-flight prompt but keeps its streaming reply', () => {+ const restored = appendLiveSessionProjection([], {+ session_id: 'runtime-1',+ inflight: { user: 'scaffolding the model must see', display_kind: 'hidden', assistant: 'On it.', streaming: true }+ })++ expect(restored.map(message => [message.role, chatMessageText(message)])).toEqual([['assistant', 'On it.']])+ })// Corrections typed while a turn ran are their own user bubbles on the same// turn, ordered by ARRIVAL. Without boundary offsets (older gateway) the// whole dump precedes them — never the old prompt → corrections → replydiff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.tsindex 7ae23f45d8c..8a4fa8f312f 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts@@ -1,7 +1,7 @@import { resolveSessionRpcOwner } from '@/app/contrib/wiring-routing'import { textWithoutReferenceLines } from '@/components/assistant-ui/reference-kinds'import { getSession } from '@/hermes'-import { assistantTextPart, type ChatMessage, chatMessageText, textPart } from '@/lib/chat-messages'+import { assistantTextPart, type ChatMessage, chatMessageText, textPart, toChatMessages } from '@/lib/chat-messages'import { normalizePersonalityValue } from '@/lib/chat-runtime'import { embeddedImageUrls, textWithoutEmbeddedImages } from '@/lib/embedded-images'import { parseErrorSurface } from '@/lib/error-surface'@@ -837,11 +837,33 @@ export function appendLiveSessionProjection(messages: ChatMessage[], projection:projection[safelyPersistedInflightUser] === true || (Boolean(inflightUser) && persistedInLatestRun(inflightUser))if (inflightUser && !inflightUserAlreadyPersisted) {- projected.push({- id: `user-inflight-${sessionId}`,- role: 'user',- parts: [textPart(inflightUser)]- })+ // A synthetic starting prompt (process_complete, hidden, …) carries the+ // display typing its persisted row will get: render it through the same+ // timeline projection history uses instead of as a user bubble (#112144).+ // `toChatMessages` yields nothing for `hidden`, so the prompt is omitted.+ const displayKind = projection.inflight?.display_kind+ const typed = displayKind+ ? toChatMessages([+ {+ role: 'user',+ content: inflightUser,+ display_kind: displayKind,+ ...(projection.inflight?.display_metadata !== undefined+ ? { display_metadata: projection.inflight.display_metadata }+ : {})+ }+ ])+ : null++ if (typed) {+ projected.push(...typed.map(message => ({ ...message, id: `user-inflight-${sessionId}` })))+ } else {+ projected.push({+ id: `user-inflight-${sessionId}`,+ role: 'user',+ parts: [textPart(inflightUser)]+ })+ }}// Keep a pending assistant boundary even before the first delta when adiff --git a/apps/desktop/src/types/hermes.ts b/apps/desktop/src/types/hermes.tsindex b6b7f4bb7f8..64b6af0ad0a 100644--- a/apps/desktop/src/types/hermes.ts+++ b/apps/desktop/src/types/hermes.ts@@ -664,6 +664,12 @@ export interface SessionResumeResult {* and before the output it redirected (#73793). Omitted by older* gateways. */correction_offsets?: number[]+ /** Display classification of a synthetic starting prompt (`process_complete`,+ * `async_delegation_complete`, `hidden`, …) — the same typing the persisted+ * row gets, so a reconnect renders the live prompt like history will+ * (#112144). Omitted for genuine user input and by older gateways. */+ display_kind?: SessionMessage['display_kind']+ display_metadata?: SessionMessage['display_metadata']/** Retained failed turn: the error the terminal frame carried (the frame* itself may have been lost to a disconnect). */error?: stringdiff --git a/website/docs/developer-guide/programmatic-integration.md b/website/docs/developer-guide/programmatic-integration.mdindex fdf060b0483..c69beea972a 100644--- a/website/docs/developer-guide/programmatic-integration.md+++ b/website/docs/developer-guide/programmatic-integration.md@@ -90,6 +90,10 @@ Methods: `approval` → `{choice}`; `clarify` → `{answer}` (single) or `{answeWhen the gateway withdraws a question (timeout, interrupt, answered from another surface) it emits `request.cancel` `{ id, method, reason }`; clear only the matching prompt. `session.resume` / `session.activate` results and `session.events.since` carry `open_requests` — the still-open frames — so a reconnecting client re-renders (and can still answer) them.+### Rebuilding the in-flight turn on reconnect++`session.resume` / `session.activate` results carry `inflight` — the turn still running (or the retained failed one) that history does not hold yet: `user`, `assistant` streamed so far, `streaming`, mid-turn `corrections`, and error fields. When the turn was started by the gateway rather than typed by a person (a background-process completion, an async delegation result, a hidden scaffolding prompt) `inflight` also carries the same `display_kind` / `display_metadata` the persisted `messages` row will get, so a client renders the live prompt exactly as it will render history after the turn lands — a `process_complete` timeline marker with `display_metadata.display_text`, nothing at all for `hidden`. Both fields are absent for genuine user input; never infer origin from the prompt text (a user quoting a marker string is still a user).+### Pi-style RPC mappingEvery command in the Pi-mono RPC spec ([issue #360](https://github.com/NousResearch/hermes-agent/issues/360)) has a TUI-gateway equivalent: