Skip to content

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

fix(rpc): carry a per-call budget through the active transport; serialise the last shared-store case\n\nTwo CodeRabbit findings on the previous head.\n\n`callCoreRpc` handed a caller's `timeoutMs` to its own fetch path only. When\nan active transport is set (tunnel, LAN, cloud) the call went to\n`transport.call(method, params)` and the budget was dropped, so the 10-minute\nallowance for a memory source sync applied on localhost and nowhere else. The\n`CoreTransport` contract now takes `timeoutMs` in its call options, each of\nthe four transports applies it in place of its constructor default for that\none call (message and timer both), and the client forwards the clamped value\nonly when a caller supplied one, so a transport keeps its own default for\nordinary calls rather than inheriting the local client's. One case per\ntransport pins the override; three client cases pin forwarding, clamping and\nthe no-budget path.\n\n`memory_read_rpc_score_index_and_summary_helpers_cover_dashboard_paths` was\nthe one shared-store case in `memory_threads` without `env_lock`; under a\nparallel run another case's wipe could empty its rows before the reads. It\ntakes the lock like the rest.\n\nClaude-Session: https://claude.ai/code/session_01Ufhq47VCos7Tw9zCyYEXmR\n

Shanuf25543f1021a
diff --git a/app/src/services/__tests__/coreRpcClient.test.ts b/app/src/services/__tests__/coreRpcClient.test.ts
index d3415c7515..fae566d2b0 100644
--- a/app/src/services/__tests__/coreRpcClient.test.ts
+++ b/app/src/services/__tests__/coreRpcClient.test.ts
@@ -9,7 +9,9 @@ import {
classifyRpcError,
CoreRpcError,
isThreadNotFoundCoreRpcError,
+ setActiveCoreTransport,
} from '../coreRpcClient';
+import type { CoreTransport } from '../transport/CoreTransport';
vi.mock('@tauri-apps/api/core', () => ({ invoke: vi.fn(), isTauri: vi.fn(() => false) }));
vi.mock('../../lib/ai/localCoreAiMemory', () => ({
@@ -522,6 +524,68 @@ describe('coreRpcClient', () => {
expect(fetch).not.toHaveBeenCalled();
});
+ describe('active transport forwarding (#5820)', () => {
+ function fakeTransport(): CoreTransport & { call: ReturnType<typeof vi.fn> } {
+ return {
+ kind: 'lan-http',
+ call: vi.fn().mockResolvedValue({ requested: true }),
+ stream: vi.fn(),
+ isHealthy: vi.fn().mockResolvedValue(true),
+ close: vi.fn().mockResolvedValue(undefined),
+ } as unknown as CoreTransport & { call: ReturnType<typeof vi.fn> };
+ }
+
+ afterEach(() => {
+ setActiveCoreTransport(null);
+ });
+
+ test('forwards a caller-supplied per-call budget to the active transport', async () => {
+ // Tunnel and cloud requests used to ignore `timeoutMs` entirely, so a
+ // memory source sync was cut off at the transport's default while the
+ // core kept working.
+ const transport = fakeTransport();
+ setActiveCoreTransport(transport);
+
+ await callCoreRpc({
+ method: 'openhuman.memory_sources_sync',
+ params: { source_id: 'src_1' },
+ timeoutMs: 600_000,
+ });
+
+ expect(transport.call).toHaveBeenCalledWith(
+ 'openhuman.memory_sources_sync',
+ { source_id: 'src_1' },
+ { timeoutMs: 600_000 }
+ );
+ });
+
+ test('clamps the forwarded budget the same way the local path does', async () => {
+ const transport = fakeTransport();
+ setActiveCoreTransport(transport);
+
+ await callCoreRpc({ method: 'openhuman.memory_sources_sync', timeoutMs: 99_999_999 });
+
+ expect(transport.call).toHaveBeenCalledWith(
+ 'openhuman.memory_sources_sync',
+ {},
+ { timeoutMs: 10 * 60 * 1_000 }
+ );
+ });
+
+ test('leaves the transport on its own default when no budget is given', async () => {
+ const transport = fakeTransport();
+ setActiveCoreTransport(transport);
+
+ await callCoreRpc({ method: 'openhuman.memory_sources_sync' });
+
+ expect(transport.call).toHaveBeenCalledTimes(1);
+ const [method, params, opts] = transport.call.mock.calls[0] as [string, unknown, unknown];
+ expect(method).toBe('openhuman.memory_sources_sync');
+ expect(params).toEqual({});
+ expect(opts).toBeUndefined();
+ });
+ });
+
describe('testCoreRpcConnection', () => {
test('POSTs a core.ping JSON-RPC envelope to the supplied URL', async () => {
vi.resetModules();
diff --git a/app/src/services/coreRpcClient.ts b/app/src/services/coreRpcClient.ts
index 2dfd927991..70b6b2958e 100644
--- a/app/src/services/coreRpcClient.ts
+++ b/app/src/services/coreRpcClient.ts
@@ -694,7 +694,12 @@ export async function callCoreRpc<T>({
// Dispatch through active transport when one is set (e.g. tunnel / cloud).
if (_activeTransport) {
coreRpcLog('[transport] dispatching via %s method=%s', _activeTransport.kind, normalizedMethod);
- return _activeTransport.call<T>(normalizedMethod, params ?? {});
+ // A caller's per-call budget travels with the call; without one the
+ // transport keeps its own default rather than inheriting the local
+ // client's, since each transport sizes that for its own medium.
+ const transportOpts =
+ timeoutMs === undefined ? undefined : { timeoutMs: resolvePerCallTimeoutMs(timeoutMs) };
+ return _activeTransport.call<T>(normalizedMethod, params ?? {}, transportOpts);
}
const effectiveTimeoutMs = resolvePerCallTimeoutMs(timeoutMs);
diff --git a/app/src/services/transport/CloudHttpTransport.test.ts b/app/src/services/transport/CloudHttpTransport.test.ts
index 6096918d7e..e888678131 100644
--- a/app/src/services/transport/CloudHttpTransport.test.ts
+++ b/app/src/services/transport/CloudHttpTransport.test.ts
@@ -80,4 +80,24 @@ describe('CloudHttpTransport', () => {
const t = new CloudHttpTransport(URL);
await expect(t.isHealthy()).resolves.toBe(false);
});
+ it('a per-call timeoutMs replaces the transport default for that call', async () => {
+ // The RPC client forwards a caller's budget (a memory source sync runs for
+ // minutes); the transport must apply it instead of its own default.
+ const fetchMock = vi.fn().mockImplementation(
+ (_url: string, init?: RequestInit) =>
+ new Promise((_resolve, reject) => {
+ init?.signal?.addEventListener('abort', () => {
+ const e = new Error('aborted');
+ e.name = 'AbortError';
+ reject(e);
+ });
+ })
+ );
+ vi.stubGlobal('fetch', fetchMock);
+
+ const t = new CloudHttpTransport(URL);
+ await expect(t.call('openhuman.ping', {}, { timeoutMs: 30 })).rejects.toThrow(
+ /\[transport:cloud\] openhuman.ping timed out after 30ms/
+ );
+ });
});
diff --git a/app/src/services/transport/CloudHttpTransport.ts b/app/src/services/transport/CloudHttpTransport.ts
index 6637ffdcc0..90cf97d6d4 100644
--- a/app/src/services/transport/CloudHttpTransport.ts
+++ b/app/src/services/transport/CloudHttpTransport.ts
@@ -38,7 +38,11 @@ export class CloudHttpTransport implements CoreTransport {
log('[transport:cloud] created rpcUrl=%s token=%s', rpcUrl, bearerToken ? 'set' : 'none');
}
- async call<T>(method: string, params: unknown, opts?: { signal?: AbortSignal }): Promise<T> {
+ async call<T>(
+ method: string,
+ params: unknown,
+ opts?: { signal?: AbortSignal; timeoutMs?: number }
+ ): Promise<T> {
const id = _nextId++;
const payload: JsonRpcRequestBody = { jsonrpc: '2.0', id, method, params: params ?? {} };
@@ -49,8 +53,9 @@ export class CloudHttpTransport implements CoreTransport {
headers.Authorization = `Bearer ${this.bearerToken}`;
}
+ const timeoutMs = opts?.timeoutMs ?? this.timeoutMs;
const controller = new AbortController();
- const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
opts?.signal?.addEventListener('abort', () => controller.abort());
let response: Response;
@@ -63,7 +68,7 @@ export class CloudHttpTransport implements CoreTransport {
});
} catch (err) {
if (controller.signal.aborted) {
- throw new Error(`[transport:cloud] ${method} timed out after ${this.timeoutMs}ms`);
+ throw new Error(`[transport:cloud] ${method} timed out after ${timeoutMs}ms`);
}
throw err;
} finally {
diff --git a/app/src/services/transport/CoreTransport.ts b/app/src/services/transport/CoreTransport.ts
index dca1ede6b0..9e69d63414 100644
--- a/app/src/services/transport/CoreTransport.ts
+++ b/app/src/services/transport/CoreTransport.ts
@@ -14,7 +14,18 @@ export interface CoreTransport {
readonly kind: TransportKind;
/** Make a JSON-RPC call and return the result. */
- call<T>(method: string, params: unknown, opts?: { signal?: AbortSignal }): Promise<T>;
+ /**
+ * `timeoutMs`, when given, replaces the transport's own default deadline for
+ * this one call. The RPC client forwards a caller's per-call budget here so a
+ * request that legitimately runs for minutes (a memory source sync, a
+ * coding-session import) is not cut off at the transport's default while the
+ * core keeps working on it.
+ */
+ call<T>(
+ method: string,
+ params: unknown,
+ opts?: { signal?: AbortSignal; timeoutMs?: number }
+ ): Promise<T>;
/** Stream a JSON-RPC method that produces sequential chunks. */
stream<T>(method: string, params: unknown, opts?: { signal?: AbortSignal }): AsyncIterable<T>;
diff --git a/app/src/services/transport/LanHttpTransport.test.ts b/app/src/services/transport/LanHttpTransport.test.ts
index 5d550e2a1c..7b1adee2c3 100644
--- a/app/src/services/transport/LanHttpTransport.test.ts
+++ b/app/src/services/transport/LanHttpTransport.test.ts
@@ -105,4 +105,24 @@ describe('LanHttpTransport', () => {
const t = new LanHttpTransport(URL);
await expect(t.close()).resolves.toBeUndefined();
});
+ it('a per-call timeoutMs replaces the transport default for that call', async () => {
+ // The RPC client forwards a caller's budget (a memory source sync runs for
+ // minutes); the transport must apply it instead of its own default.
+ const fetchMock = vi.fn().mockImplementation(
+ (_url: string, init?: RequestInit) =>
+ new Promise((_resolve, reject) => {
+ init?.signal?.addEventListener('abort', () => {
+ const e = new Error('aborted');
+ e.name = 'AbortError';
+ reject(e);
+ });
+ })
+ );
+ vi.stubGlobal('fetch', fetchMock);
+
+ const t = new LanHttpTransport(URL, 30_000);
+ await expect(t.call('openhuman.ping', {}, { timeoutMs: 30 })).rejects.toThrow(
+ /\[transport:lan\] openhuman.ping timed out after 30ms/
+ );
+ });
});
diff --git a/app/src/services/transport/LanHttpTransport.ts b/app/src/services/transport/LanHttpTransport.ts
index 83d2f7633c..b18b4799de 100644
--- a/app/src/services/transport/LanHttpTransport.ts
+++ b/app/src/services/transport/LanHttpTransport.ts
@@ -37,14 +37,19 @@ export class LanHttpTransport implements CoreTransport {
log('[transport:lan] created rpcUrl=%s', rpcUrl);
}
- async call<T>(method: string, params: unknown, opts?: { signal?: AbortSignal }): Promise<T> {
+ async call<T>(
+ method: string,
+ params: unknown,
+ opts?: { signal?: AbortSignal; timeoutMs?: number }
+ ): Promise<T> {
const id = _nextId++;
const payload: JsonRpcRequestBody = { jsonrpc: '2.0', id, method, params: params ?? {} };
log('[transport:lan] → %s id=%d', method, id);
+ const timeoutMs = opts?.timeoutMs ?? this.timeoutMs;
const controller = new AbortController();
- const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
opts?.signal?.addEventListener('abort', () => controller.abort());
let response: Response;
@@ -57,7 +62,7 @@ export class LanHttpTransport implements CoreTransport {
});
} catch (err) {
if (controller.signal.aborted) {
- throw new Error(`[transport:lan] ${method} timed out after ${this.timeoutMs}ms`);
+ throw new Error(`[transport:lan] ${method} timed out after ${timeoutMs}ms`);
}
throw err;
} finally {
diff --git a/app/src/services/transport/LocalTransport.test.ts b/app/src/services/transport/LocalTransport.test.ts
index df3228e463..2287cc2fa8 100644
--- a/app/src/services/transport/LocalTransport.test.ts
+++ b/app/src/services/transport/LocalTransport.test.ts
@@ -87,6 +87,27 @@ describe('LocalTransport', () => {
await expect(t.call('openhuman.ping', {})).rejects.toThrow(/timed out after 30ms/);
});
+ it('a per-call timeoutMs replaces the constructor default for that call', async () => {
+ // The RPC client forwards a caller's budget (a memory source sync runs for
+ // minutes); the transport must apply it instead of its own default.
+ const fetchMock = vi.fn().mockImplementation(
+ (_url: string, init?: RequestInit) =>
+ new Promise((_resolve, reject) => {
+ init?.signal?.addEventListener('abort', () => {
+ const e = new Error('aborted');
+ e.name = 'AbortError';
+ reject(e);
+ });
+ })
+ );
+ vi.stubGlobal('fetch', fetchMock);
+
+ const t = new LocalTransport(getUrl, getToken(), 30_000);
+ await expect(t.call('openhuman.ping', {}, { timeoutMs: 30 })).rejects.toThrow(
+ /timed out after 30ms/
+ );
+ });
+
it('isHealthy + stream + close', async () => {
mockFetchOnce({ jsonrpc: '2.0', id: 1, result: 'pong' });
const t = new LocalTransport(getUrl, getToken());
diff --git a/app/src/services/transport/LocalTransport.ts b/app/src/services/transport/LocalTransport.ts
index 8a1b377fbc..1c91565aec 100644
--- a/app/src/services/transport/LocalTransport.ts
+++ b/app/src/services/transport/LocalTransport.ts
@@ -37,7 +37,11 @@ export class LocalTransport implements CoreTransport {
private readonly timeoutMs: number = 30_000
) {}
- async call<T>(method: string, params: unknown, opts?: { signal?: AbortSignal }): Promise<T> {
+ async call<T>(
+ method: string,
+ params: unknown,
+ opts?: { signal?: AbortSignal; timeoutMs?: number }
+ ): Promise<T> {
const id = _nextId++;
const payload: JsonRpcRequestBody = { jsonrpc: '2.0', id, method, params: params ?? {} };
@@ -49,8 +53,9 @@ export class LocalTransport implements CoreTransport {
headers.Authorization = `Bearer ${token}`;
}
+ const timeoutMs = opts?.timeoutMs ?? this.timeoutMs;
const controller = new AbortController();
- const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
// Merge caller signal with timeout signal.
opts?.signal?.addEventListener('abort', () => controller.abort());
@@ -65,7 +70,7 @@ export class LocalTransport implements CoreTransport {
});
} catch (err) {
if (controller.signal.aborted) {
- throw new Error(`[transport:local] ${method} timed out after ${this.timeoutMs}ms`);
+ throw new Error(`[transport:local] ${method} timed out after ${timeoutMs}ms`);
}
throw err;
} finally {
diff --git a/app/src/services/transport/TunnelTransport.test.ts b/app/src/services/transport/TunnelTransport.test.ts
index a15f49b67a..1c731e9364 100644
--- a/app/src/services/transport/TunnelTransport.test.ts
+++ b/app/src/services/transport/TunnelTransport.test.ts
@@ -450,4 +450,16 @@ describe('TunnelTransport', () => {
await transport.close();
});
+ it('a per-call timeoutMs replaces the tunnel default for that call', async () => {
+ // The RPC client forwards a caller's budget (a memory source sync runs for
+ // minutes); the tunnel must apply it instead of its own default.
+ const coreKp = generateKeypair();
+ const transport = new TunnelTransport('http://backend', 'CHAN_005', coreB64(coreKp), 'tok');
+ await connectTransport(transport);
+
+ const callP = transport.call('openhuman.ping', {}, { timeoutMs: 20 });
+ await expect(callP).rejects.toThrow(/\[tunnel\] openhuman.ping timed out after 20ms/);
+
+ await transport.close();
+ }, 10000);
});
diff --git a/app/src/services/transport/TunnelTransport.ts b/app/src/services/transport/TunnelTransport.ts
index d7e60325fb..79407bc7a9 100644
--- a/app/src/services/transport/TunnelTransport.ts
+++ b/app/src/services/transport/TunnelTransport.ts
@@ -340,8 +340,13 @@ export class TunnelTransport implements CoreTransport {
// -- CoreTransport ---------------------------------------------------------
- async call<T>(method: string, params: unknown, opts?: { signal?: AbortSignal }): Promise<T> {
+ async call<T>(
+ method: string,
+ params: unknown,
+ opts?: { signal?: AbortSignal; timeoutMs?: number }
+ ): Promise<T> {
await this.ensureConnected();
+ const timeoutMs = opts?.timeoutMs ?? this.callTimeoutMs;
const requestId = crypto.randomUUID();
const envelope: Envelope = { requestId, kind: 'request', seq: 0, payload: { method, params } };
@@ -349,8 +354,8 @@ export class TunnelTransport implements CoreTransport {
return new Promise<T>((resolve, reject) => {
const timeoutId = setTimeout(() => {
this.pending.delete(requestId);
- reject(new Error(`[tunnel] ${method} timed out after ${this.callTimeoutMs}ms`));
- }, this.callTimeoutMs);
+ reject(new Error(`[tunnel] ${method} timed out after ${timeoutMs}ms`));
+ }, timeoutMs);
opts?.signal?.addEventListener('abort', () => {
clearTimeout(timeoutId);
diff --git a/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs b/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
index 152d833dea..46fc92016b 100644
--- a/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/memory_threads_raw_coverage_e2e.rs
@@ -1835,6 +1835,10 @@ fn memory_tree_runtime_store_buffers_and_retrieval_wire_helpers() {
#[tokio::test]
async fn memory_read_rpc_score_index_and_summary_helpers_cover_dashboard_paths() {
+ // Serialised with every other case on the shared module store: a parallel
+ // run of this target would otherwise let another case's `wipe_shared_store`
+ // empty the rows seeded below before the reads assert on them.
+ let _lock = env_lock();
let tmp = TempDir::new().expect("tempdir");
let mut config = config_in(&tmp);
use_module_workspace(&mut config);