Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(queue): preserve pending follow-ups when a reload fails

Steven Enamakelcfd29f1dc2b4
diff --git a/app/src/features/conversations/Conversations.tsx b/app/src/features/conversations/Conversations.tsx
index 807eadd4a2..b0bfae8896 100644
--- a/app/src/features/conversations/Conversations.tsx
+++ b/app/src/features/conversations/Conversations.tsx
@@ -1588,7 +1588,9 @@ const Conversations = ({
});
if (!ack.requestId) throw new Error('The core did not identify the queued follow-up');
if (attachmentParts.length > 0 && ack.queuedAttachments.length === 0) {
- throw new Error('The core did not return staged attachment references for the queued follow-up');
+ throw new Error(
+ 'The core did not return staged attachment references for the queued follow-up'
+ );
}
// Only clear the composer once the backend has accepted the queue, so a
// failed send leaves the user's draft + attachments intact to retry.
diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsx
index f9be0d5c9f..000bd8f613 100644
--- a/app/src/providers/ChatRuntimeProvider.tsx
+++ b/app/src/providers/ChatRuntimeProvider.tsx
@@ -46,7 +46,6 @@ import {
} from '../services/chatService';
import { socketService } from '../services/socketService';
import { store } from '../store';
-import { pendingFollowupCompleted } from '../store/queueSlice';
import {
appendSubagentStreamDelta,
beginInferenceTurn,
@@ -94,6 +93,7 @@ import {
upsertArtifactReadyForThread,
} from '../store/chatRuntimeSlice';
import { useAppDispatch, useAppSelector } from '../store/hooks';
+import { pendingFollowupCompleted } from '../store/queueSlice';
import { setRunMode } from '../store/runModeSlice';
import { selectSocketStatus } from '../store/socketSelectors';
import { clearThreadGoal, setThreadGoal } from '../store/threadGoalSlice';
diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
index c2da072f0e..ec079779db 100644
--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
@@ -105,9 +105,9 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
vi.clearAllMocks();
resetRuntimeState();
vi.mocked(threadApi.appendMessage).mockImplementation(async (_tid, msg) => msg);
- vi.mocked(threadApi.getThreadMessages).mockResolvedValue({
- messages: [],
- } as unknown as Awaited<ReturnType<typeof threadApi.getThreadMessages>>);
+ vi.mocked(threadApi.getThreadMessages).mockResolvedValue({ messages: [] } as unknown as Awaited<
+ ReturnType<typeof threadApi.getThreadMessages>
+ >);
vi.mocked(threadApi.getThreads).mockResolvedValue({ threads: [], count: 0 });
vi.mocked(threadApi.getTurnState).mockResolvedValue(null);
vi.mocked(threadApi.listRuns).mockResolvedValue([]);
@@ -976,14 +976,7 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
},
];
const stagedParts = [
- {
- ...parts[0],
- media: {
- ...parts[0].media,
- url: null,
- opaqueId: 'opaque-upload',
- },
- },
+ { ...parts[0], media: { ...parts[0].media, url: null, opaqueId: 'opaque-upload' } },
];
store.dispatch(
pendingFollowupAdded({
@@ -1028,12 +1021,13 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
});
await waitFor(() => expect(threadApi.getThreadMessages).toHaveBeenCalledWith('t-upload'));
expect(
- vi.mocked(threadApi.appendMessage).mock.calls.some(([, message]) => message.sender === 'user')
+ vi
+ .mocked(threadApi.appendMessage)
+ .mock.calls.some(([, message]) => message.sender === 'user')
).toBe(false);
const persisted = store
.getState()
- .thread.messagesByThreadId['t-upload']
- .find(message => message.id === 'user:r-upload');
+ .thread.messagesByThreadId['t-upload'].find(message => message.id === 'user:r-upload');
expect(persisted?.content).toBe('look');
expect(JSON.stringify(persisted?.attachments)).toContain('opaque-upload');
expect(JSON.stringify(persisted)).not.toMatch(/base64|\[(ATTACHMENT|IMAGE|FILE):/i);
@@ -1069,7 +1063,9 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
});
expect(store.getState().queue.pendingFollowupsByThread['t-fup']).toHaveLength(1);
expect(
- vi.mocked(threadApi.appendMessage).mock.calls.some(([, message]) => message.sender === 'user')
+ vi
+ .mocked(threadApi.appendMessage)
+ .mock.calls.some(([, message]) => message.sender === 'user')
).toBe(false);
await act(async () => {
@@ -1114,7 +1110,9 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
});
});
- expect(store.getState().queue.pendingFollowupsByThread['t-fup-failed-reload']).toHaveLength(1);
+ expect(store.getState().queue.pendingFollowupsByThread['t-fup-failed-reload']).toHaveLength(
+ 1
+ );
});
it('stamps the assistant answer with the producing turn requestId on chat_done', async () => {
diff --git a/app/src/providers/__tests__/useOpenHumanExternalStore.quote.test.tsx b/app/src/providers/__tests__/useOpenHumanExternalStore.quote.test.tsx
index b5e0cdc6b2..5dd058e1eb 100644
--- a/app/src/providers/__tests__/useOpenHumanExternalStore.quote.test.tsx
+++ b/app/src/providers/__tests__/useOpenHumanExternalStore.quote.test.tsx
@@ -14,9 +14,9 @@ import type { ReactNode } from 'react';
import { Provider } from 'react-redux';
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { editMessage } from '../../services/chatService';
import type { ContentPart } from '../../services/chatWire';
import chatRuntimeReducer from '../../store/chatRuntimeSlice';
-import { editMessage } from '../../services/chatService';
import threadReducer, { loadThreadMessages } from '../../store/threadSlice';
import { registerChatSurface } from '../chatSurfaceHandlers';
import { useOpenHumanExternalStore } from '../useOpenHumanExternalStore';
@@ -61,9 +61,9 @@ function withQuote(text: string): AppendMessage {
} as unknown as Partial<AppendMessage>);
}
-function mount(store = configureStore({
- reducer: { thread: threadReducer, chatRuntime: chatRuntimeReducer },
-})) {
+function mount(
+ store = configureStore({ reducer: { thread: threadReducer, chatRuntime: chatRuntimeReducer } })
+) {
const wrapper = ({ children }: { children: ReactNode }) => (
<Provider store={store}>{children}</Provider>
);
diff --git a/app/src/store/queueSlice.test.ts b/app/src/store/queueSlice.test.ts
index f81e0b7c1a..d5fc1f8ebf 100644
--- a/app/src/store/queueSlice.test.ts
+++ b/app/src/store/queueSlice.test.ts
@@ -159,10 +159,7 @@ describe('queueSlice — chat runtime lifecycle', () => {
expect(state.itemsByThread.t1).toBeUndefined();
expect(state.pendingFollowupsByThread.t1).toHaveLength(1);
expect(state.itemsByThread.t2).toBeDefined();
- state = reducer(
- state,
- pendingFollowupCompleted({ threadId: 't1', requestId: 'm1' })
- );
+ state = reducer(state, pendingFollowupCompleted({ threadId: 't1', requestId: 'm1' }));
expect(state.pendingFollowupsByThread.t1).toBeUndefined();
});
diff --git a/app/src/store/queueSlice.ts b/app/src/store/queueSlice.ts
index eff8d58f16..df5d52e3e5 100644
--- a/app/src/store/queueSlice.ts
+++ b/app/src/store/queueSlice.ts
@@ -158,7 +158,12 @@ const queueSlice = createSlice({
const { threadId, message, text, attachments = [] } = action.payload;
const requestId = action.payload.requestId ?? message.id;
const bucket = state.pendingFollowupsByThread[threadId] ?? [];
- bucket.push({ message, attachments, requestId, preview: clipQueuePreview(text, attachments) });
+ bucket.push({
+ message,
+ attachments,
+ requestId,
+ preview: clipQueuePreview(text, attachments),
+ });
state.pendingFollowupsByThread[threadId] = bucket;
},
},
diff --git a/app/src/types/threadWire.generated.ts b/app/src/types/threadWire.generated.ts
index 0160383673..ea25cf8ba9 100644
--- a/app/src/types/threadWire.generated.ts
+++ b/app/src/types/threadWire.generated.ts
@@ -33,16 +33,8 @@ export type ToolTimelineStatus = 'running' | 'success' | 'error';
* inline "Agentic task insights" thoughts survive a settled turn / reload.
*/
export type SubagentTranscriptItem =
- | {
- iteration?: number | null;
- kind: 'thinking';
- text: string;
- }
- | {
- iteration?: number | null;
- kind: 'text';
- text: string;
- }
+ | { iteration?: number | null; kind: 'thinking'; text: string }
+ | { iteration?: number | null; kind: 'text'; text: string }
| {
callId: string;
detail?: string | null;
@@ -67,12 +59,7 @@ export type SubagentTranscriptItem =
* the row's status/label live in exactly one place.
*/
export type TranscriptItem =
- | {
- kind: 'narration';
- round: number;
- seq: number;
- text: string;
- }
+ | { kind: 'narration'; round: number; seq: number; text: string }
| {
endedAt?: number | null;
kind: 'thinking';
@@ -81,12 +68,7 @@ export type TranscriptItem =
startedAt?: number | null;
text: string;
}
- | {
- callId: string;
- kind: 'toolCall';
- round: number;
- seq: number;
- };
+ | { callId: string; kind: 'toolCall'; round: number; seq: number };
/**
* Provider-neutral ordered inbound content.
*/
@@ -99,12 +81,7 @@ export type ContentPart =
markdownDialect?: string | null;
text: string;
}
- | {
- altText: string | null;
- caption: string | null;
- kind: 'image';
- media: MediaReference;
- }
+ | { altText: string | null; caption: string | null; kind: 'image'; media: MediaReference }
| {
caption: string | null;
durationMs: number | null;
@@ -120,16 +97,8 @@ export type ContentPart =
title: string | null;
transcript: string | null;
}
- | {
- caption: string | null;
- fileName: string | null;
- kind: 'file';
- media: MediaReference;
- }
- | {
- kind: 'voice_note';
- voiceNote: VoiceNote;
- }
+ | { caption: string | null; fileName: string | null; kind: 'file'; media: MediaReference }
+ | { kind: 'voice_note'; voiceNote: VoiceNote }
| {
altText: string | null;
emoji: string | null;
@@ -154,10 +123,7 @@ export type ContentPart =
organization: string | null;
phoneNumbers: ContactMethod[];
}
- | {
- kind: 'buttons';
- rows: ButtonAction[][];
- }
+ | { kind: 'buttons'; rows: ButtonAction[][] }
| {
closesAtUnixMs: number | null;
kind: 'poll';
@@ -166,15 +132,8 @@ export type ContentPart =
providerPollId: string | null;
question: string;
}
- | {
- blocks: any;
- kind: 'presentation';
- }
- | {
- data: any;
- kind: 'native';
- provider: string;
- };
+ | { blocks: any; kind: 'presentation' }
+ | { data: any; kind: 'native'; provider: string };
/**
* Origin of voice transcript enrichment.
*/
@@ -253,9 +212,7 @@ export interface AgentRun {
/**
* Inline resumable checkpoint state, if small enough to store directly.
*/
- checkpoint: {
- [k: string]: any;
- };
+ checkpoint: { [k: string]: any };
/**
* Filesystem path to a resumable checkpoint for this run, if persisted
* out-of-band from `checkpoint`.
@@ -286,9 +243,7 @@ export interface AgentRun {
/**
* Arbitrary caller-supplied metadata.
*/
- metadata: {
- [k: string]: any;
- };
+ metadata: { [k: string]: any };
/**
* The run that spawned this one, if any.
*/
@@ -591,9 +546,7 @@ export interface SubagentToolCall {
* call row, and the frontend grafts it onto the matching transcript item
* by `call_id` when it rehydrates.
*/
- args?: {
- [k: string]: any;
- };
+ args?: { [k: string]: any };
callId: string;
/**
* Server-computed contextual detail (e.g. the path / recipient).
@@ -645,9 +598,7 @@ export interface ConversationMessageRecord {
attachments?: ContentPart[];
content: string;
createdAt: string;
- extraMetadata: {
- [k: string]: any;
- };
+ extraMetadata: { [k: string]: any };
id: string;
sender: string;
type: string;
@@ -777,9 +728,7 @@ export interface RunEvent {
/**
* Arbitrary event payload.
*/
- payload: {
- [k: string]: any;
- };
+ payload: { [k: string]: any };
runId: string;
/**
* Per-run monotonically increasing sequence number; the primary key
diff --git a/crates/openhuman-core/src/channels/routes.rs b/crates/openhuman-core/src/channels/routes.rs
index fcd2a34440..742fa3c42b 100644
--- a/crates/openhuman-core/src/channels/routes.rs
+++ b/crates/openhuman-core/src/channels/routes.rs
@@ -258,7 +258,6 @@ where
Ok::<_, tinybus::module::ModuleCallError>(response)
}
.await;
- eprintln!("DBG operation={:?}", operation.as_ref().map(|_| ()).map_err(|e| e.to_string()));
let (reply, next_route, clear_history) = match operation {
Ok(ChannelControlResult::Route {
reply,
diff --git a/crates/openhuman-core/src/channels/runtime/startup.rs b/crates/openhuman-core/src/channels/runtime/startup.rs
index 77452b714f..4229439d75 100644
--- a/crates/openhuman-core/src/channels/runtime/startup.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup.rs
@@ -94,7 +94,17 @@ impl ChannelHandle {
Self::Module(channel) => channel.capabilities(),
Self::Relay(_) => tinychannels_bus::ChannelCapabilities::unknown(),
#[cfg(test)]
- Self::Test(_channel) => tinychannels_bus::ChannelCapabilities::unknown(),
+ Self::Test(channel) => {
+ // A test channel stands in for a chat provider: the module only
+ // parses remote commands for channels that advertise them.
+ let mut capabilities = tinychannels_bus::ChannelCapabilities::unknown();
+ capabilities.remote_control = true;
+ capabilities.chat_approvals = true;
+ capabilities.history_key_ignores_thread =
+ tinychannels_bus::provider_id(&channel.name) == "telegram";
+ capabilities.reactions = channel.supports_reactions;
+ capabilities
+ }
}
}
diff --git a/crates/openhuman-core/src/mcp/server/tools/params.rs b/crates/openhuman-core/src/mcp/server/tools/params.rs
index ab6370da89..4fc0bbb460 100644
--- a/crates/openhuman-core/src/mcp/server/tools/params.rs
+++ b/crates/openhuman-core/src/mcp/server/tools/params.rs
@@ -224,8 +224,8 @@ async fn validate_tool_arguments(
log::warn!("[mcp][params] argument validation unavailable: {error:?}");
ToolCallError::Internal("MCP argument validation is unavailable".into())
})?;
- let client = crate::mcp::module_client::McpConfiguredClient::for_config(&config)
- .map_err(|error| {
+ let client =
+ crate::mcp::module_client::McpConfiguredClient::for_config(&config).map_err(|error| {
log::warn!("[mcp][params] argument validation unavailable: {error:?}");
ToolCallError::Internal("MCP argument validation is unavailable".into())
})?;
diff --git a/crates/openhuman-core/src/mcp/server/tools_tests_dispatch_tests.rs b/crates/openhuman-core/src/mcp/server/tools_tests_dispatch_tests.rs
index 6b9e86da2c..c9ed484371 100644
--- a/crates/openhuman-core/src/mcp/server/tools_tests_dispatch_tests.rs
+++ b/crates/openhuman-core/src/mcp/server/tools_tests_dispatch_tests.rs
@@ -10,8 +10,7 @@ struct AmbientStorage {
impl AmbientStorage {
fn install() -> Self {
- let fixture =
- crate::storage::test_support::sqlite_backend().expect("SQLite test backend");
+ let fixture = crate::storage::test_support::sqlite_backend().expect("SQLite test backend");
let guard = crate::storage::test_support::install_for_test(
&fixture.url,
std::sync::Arc::clone(&fixture.backend),
diff --git a/crates/openhuman-core/src/modules/storage_host_cdylib_stream_tests.rs b/crates/openhuman-core/src/modules/storage_host_cdylib_stream_tests.rs
index caede353ee..2b7dc40865 100644
--- a/crates/openhuman-core/src/modules/storage_host_cdylib_stream_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_host_cdylib_stream_tests.rs
@@ -31,9 +31,7 @@ async fn a_blob_over_the_bus_frame_round_trips_through_a_peer_bound_stream() {
let rig = rig("tinyjuice").await;
// 20 MiB: over the 16 MiB frame no inline call could carry.
let len = 20 * MIB;
- let stored = rig
- .member("StreamPut", ("juice/ccr/streamed", len))
- .await;
+ let stored = rig.member("StreamPut", ("juice/ccr/streamed", len)).await;
assert_eq!(stored["ok"]["len"], len, "{stored}");
// It is in the module's own scope, byte for byte.
let handle = rig.backend.for_scope(&rig.scope("tinyjuice")).unwrap();
@@ -91,9 +89,7 @@ async fn a_streamed_blob_is_still_bound_by_the_grant_and_the_length() {
"{denied_get}"
);
// The module keeps working after a refusal.
- let after = rig
- .member("StreamPut", ("juice/ccr/after", 3 * MIB))
- .await;
+ let after = rig.member("StreamPut", ("juice/ccr/after", 3 * MIB)).await;
assert_eq!(after["ok"]["len"], 3 * MIB, "{after}");
}
@@ -123,9 +119,7 @@ async fn an_inline_blob_no_frame_can_carry_fails_fast_instead_of_hanging() {
.await
.unwrap()
.is_none());
- let after: Value = rig
- .member("PutBlob", ("juice/ccr/after", 2048usize))
- .await;
+ let after: Value = rig.member("PutBlob", ("juice/ccr/after", 2048usize)).await;
assert!(
after.get("ok").is_some(),
"the module keeps working: {after}"
@@ -247,10 +241,7 @@ async fn a_second_module_cannot_read_or_take_the_first_modules_streams() {
.peer_proxy(0, "Blobs")
.call(
"PutStream",
- (
- json!({"key": "juice/ccr/hijacked", "len": MIB}),
- reference,
- ),
+ (json!({"key": "juice/ccr/hijacked", "len": MIB}), reference),
)
.await;
assert!(
diff --git a/crates/openhuman-core/src/web_chat/event_bus_surface_tests.rs b/crates/openhuman-core/src/web_chat/event_bus_surface_tests.rs
index c0564c77b8..6c391e834c 100644
--- a/crates/openhuman-core/src/web_chat/event_bus_surface_tests.rs
+++ b/crates/openhuman-core/src/web_chat/event_bus_surface_tests.rs
@@ -1,5 +1,5 @@
-use super::*;
use super::tests::find_agent_web_event;
+use super::*;
use crate::web_chat::{QueueItemPayload, ScopedWebEvent, WebChannelEvent, WebEventContext};
use tokio::sync::broadcast;