Skip to content

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

feat(threads): add thread pinning support

Steven Enamakele1d22b22c5eb
diff --git a/app/src/features/conversations/threadList/useThreadPins.test.ts b/app/src/features/conversations/threadList/useThreadPins.test.ts
new file mode 100644
index 0000000000..efab706a71
--- /dev/null
+++ b/app/src/features/conversations/threadList/useThreadPins.test.ts
@@ -0,0 +1,64 @@
+import { act, renderHook, waitFor } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import type { Thread } from '../../../types/thread';
+import { PINNED_THREAD_LABEL } from './groupThreads';
+import { useThreadPins } from './useThreadPins';
+
+const updateLabels = vi.fn();
+const dispatch = vi.fn();
+
+vi.mock('../../../services/api/threadApi', () => ({
+ threadApi: { updateLabels: (...args: unknown[]) => updateLabels(...args) },
+}));
+vi.mock('../../../store/hooks', () => ({ useAppDispatch: () => dispatch }));
+vi.mock('../../../store/threadSlice', () => ({
+ loadThreads: () => ({ type: 'thread/loadThreads' }),
+}));
+
+const THREAD: Thread = {
+ id: 't1',
+ title: 'One',
+ chatId: null,
+ isActive: true,
+ messageCount: 1,
+ lastMessageAt: '2026-10-06T12:00:00Z',
+ createdAt: '2026-10-06T12:00:00Z',
+ labels: ['general'],
+};
+
+describe('useThreadPins', () => {
+ beforeEach(() => {
+ updateLabels.mockReset();
+ dispatch.mockReset();
+ });
+
+ it('writes the pinned label, reloads threads and drops the override', async () => {
+ let resolveUpdate: () => void = () => {};
+ updateLabels.mockReturnValue(new Promise<void>(resolve => (resolveUpdate = resolve)));
+ dispatch.mockReturnValue({ unwrap: () => Promise.resolve() });
+ const { result } = renderHook(() => useThreadPins());
+
+ act(() => result.current.togglePin(THREAD, true));
+ // Optimistic: pinned before the core answers.
+ expect(result.current.isPinned(THREAD)).toBe(true);
+ expect(updateLabels).toHaveBeenCalledWith('t1', ['general', PINNED_THREAD_LABEL]);
+
+ await act(async () => resolveUpdate());
+ await waitFor(() => expect(dispatch).toHaveBeenCalledWith({ type: 'thread/loadThreads' }));
+ // Override cleared: the (unchanged, mocked) thread record decides again.
+ await waitFor(() => expect(result.current.isPinned(THREAD)).toBe(false));
+ });
+
+ it('reverts when the label write fails', async () => {
+ updateLabels.mockRejectedValue(new Error('boom'));
+ const pinned = { ...THREAD, labels: [PINNED_THREAD_LABEL] };
+ const { result } = renderHook(() => useThreadPins());
+
+ act(() => result.current.togglePin(pinned, false));
+ expect(result.current.isPinned(pinned)).toBe(false);
+ expect(updateLabels).toHaveBeenCalledWith('t1', []);
+ await waitFor(() => expect(result.current.isPinned(pinned)).toBe(true));
+ expect(dispatch).not.toHaveBeenCalled();
+ });
+});
diff --git a/crates/openhuman-core/src/threads/ops/support.rs b/crates/openhuman-core/src/threads/ops/support.rs
index 7512de0d24..931ba66b4c 100644
--- a/crates/openhuman-core/src/threads/ops/support.rs
+++ b/crates/openhuman-core/src/threads/ops/support.rs
@@ -76,7 +76,7 @@ pub(super) fn thread_to_summary(thread: ConversationThread) -> ConversationThrea
parent_thread_id: thread.parent_thread_id,
labels: thread.labels,
personality_id: thread.personality_id,
- working_dir: None,
+ action_dir: thread.working_dir,
}
}
diff --git a/crates/openhuman-core/src/threads/rpc_models.rs b/crates/openhuman-core/src/threads/rpc_models.rs
index 3abe09fd05..e09b1265ca 100644
--- a/crates/openhuman-core/src/threads/rpc_models.rs
+++ b/crates/openhuman-core/src/threads/rpc_models.rs
@@ -17,6 +17,20 @@ pub struct CreateConversationThreadRequest {
pub labels: Option<Vec<String>>,
#[serde(default)]
pub personality_id: Option<String>,
+ /// Working folder the new thread's agent acts in. Absent or empty uses the
+ /// global `action_dir`.
+ #[serde(default)]
+ pub action_dir: Option<String>,
+}
+
+/// Request to bind or clear the working folder of a thread that has no
+/// messages yet.
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct UpdateConversationThreadWorkingDirRequest {
+ pub thread_id: String,
+ /// Absolute folder path; empty clears back to the global `action_dir`.
+ pub action_dir: String,
}
/// Summary information for a workspace-backed conversation thread.
@@ -37,6 +51,9 @@ pub struct ConversationThreadSummary {
pub labels: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub personality_id: Option<String>,
+ /// Working folder bound to this thread; absent means the global default.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub action_dir: Option<String>,
}
/// A single persisted conversation message.
diff --git a/crates/openhuman-core/src/threads/store/blocking.rs b/crates/openhuman-core/src/threads/store/blocking.rs
index 1c9d967371..f1a798694c 100644
--- a/crates/openhuman-core/src/threads/store/blocking.rs
+++ b/crates/openhuman-core/src/threads/store/blocking.rs
@@ -161,6 +161,19 @@ pub async fn update_thread_title(
.await
}
+/// [`store::update_thread_working_dir`] on the blocking pool.
+pub async fn update_thread_working_dir(
+ workspace_dir: PathBuf,
+ thread_id: String,
+ working_dir: Option<String>,
+ updated_at: String,
+) -> Result<ConversationThread, String> {
+ run("update_thread_working_dir", move || {
+ store::update_thread_working_dir(workspace_dir, &thread_id, working_dir, &updated_at)
+ })
+ .await
+}
+
/// [`store::update_thread_labels`] on the blocking pool.
pub async fn update_thread_labels(
workspace_dir: PathBuf,
diff --git a/crates/openhuman-core/src/threads/store/mod.rs b/crates/openhuman-core/src/threads/store/mod.rs
index 5e4c731aeb..ffa8e72682 100644
--- a/crates/openhuman-core/src/threads/store/mod.rs
+++ b/crates/openhuman-core/src/threads/store/mod.rs
@@ -35,7 +35,7 @@ pub use bus::register_conversation_persistence_subscriber;
pub use store::{
append_message, delete_messages_from, delete_thread, ensure_thread, get_messages,
is_deterministic_message_id, list_threads, purge_threads, reply_run_id, run_reply_message_id,
- update_message, update_thread_labels, update_thread_title, ConversationPurgeStats,
+ update_message, update_thread_labels, update_thread_title, update_thread_working_dir, ConversationPurgeStats,
ConversationStore, ConversationThread, CreateConversationThread, CrossThreadHit,
ThreadMessage as ConversationMessage, ThreadMessagePatch as ConversationMessagePatch,
};