The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): wake retired bots for group turns
Gille996417c385a5
diff --git a/apps/desktop/src/plugins/hermes-bots/group-test-utils.ts b/apps/desktop/src/plugins/hermes-bots/group-test-utils.tsindex f537265e3a8..af3600f40c9 100644--- a/apps/desktop/src/plugins/hermes-bots/group-test-utils.ts+++ b/apps/desktop/src/plugins/hermes-bots/group-test-utils.ts@@ -77,6 +77,8 @@ export interface RpcCall {params: Record<string, unknown>/** Socket refcount after this request released its own lease. */refcountAfter: number+ spawnPriority?: 'background' | 'foreground'+ timeoutMs?: number}export interface GatewayOptions {@@ -127,6 +129,8 @@ export interface ScriptedGateway {rpc: RpcCall[]/** Filter `rpc` by method. */rpcFor: (method: string) => RpcCall[]+ /** Route retentions acquired for explicit multi-RPC member turns. */+ retains: Array<{ spawnPriority?: 'background' | 'foreground' }>/** Live socket refcount — zero between turns, never zero during one. */refcount: () => number/** Sessions by stored id, so a test can pre-seed a finished transcript. */@@ -150,6 +154,7 @@ export function createGroupGateway(options: GatewayOptions = {}): ScriptedGatewaconst calls: PromptCall[] = []const attaches: AttachCall[] = []const rpc: RpcCall[] = []+ const retains: Array<{ spawnPriority?: 'background' | 'foreground' }> = []const timeline: string[] = []const storage = new Map<string, unknown>()const uiMeta: Record<string, unknown> = {}@@ -366,7 +371,13 @@ export function createGroupGateway(options: GatewayOptions = {}): ScriptedGatewanotify: vi.fn(),notifyError: vi.fn(),request: async (method: string, params: Record<string, unknown> = {}) => record(method, params),- requestProfile: async (_route: unknown, method: string, params: Record<string, unknown> = {}) => {+ requestProfile: async (+ _route: unknown,+ method: string,+ params: Record<string, unknown> = {},+ timeoutMs?: number,+ options?: { spawnPriority?: 'background' | 'foreground' }+ ) => {refcount += 1try {@@ -378,11 +389,12 @@ export function createGroupGateway(options: GatewayOptions = {}): ScriptedGatewadisposals += 1}- rpc.push({ method, params, refcountAfter: refcount })+ rpc.push({ method, params, refcountAfter: refcount, spawnPriority: options?.spawnPriority, timeoutMs })timeline.push(method)}},- retainProfile: async () => {+ retainProfile: async (_route: unknown, options?: { spawnPriority?: 'background' | 'foreground' }) => {+ retains.push({ spawnPriority: options?.spawnPriority })timeline.push('retain')refcount += 1let released = false@@ -417,6 +429,7 @@ export function createGroupGateway(options: GatewayOptions = {}): ScriptedGatewarefcount: () => refcount,rpc,rpcFor: (method: string) => rpc.filter(entry => entry.method === method),+ retains,sessions,storage,timeline,diff --git a/apps/desktop/src/plugins/hermes-bots/group-turns.test.ts b/apps/desktop/src/plugins/hermes-bots/group-turns.test.tsindex e7307366a5c..edcd4223ee1 100644--- a/apps/desktop/src/plugins/hermes-bots/group-turns.test.ts+++ b/apps/desktop/src/plugins/hermes-bots/group-turns.test.ts@@ -380,6 +380,17 @@ describe('per-turn socket lease', () => {expect(reply).toBe('routed reply')// The retain landed before the first session-scoped RPC on the route.expect(room.gateway.timeline[0]).toBe('retain')+ expect(room.gateway.retains).toEqual([{ spawnPriority: 'foreground' }])++ const resumes = room.gateway.rpcFor('session.resume')++ expect(resumes.length).toBeGreaterThan(0)++ for (const resume of resumes) {+ expect(resume).toMatchObject({ spawnPriority: 'foreground', timeoutMs: 180_000 })+ }++ expect(room.gateway.rpcFor('session.create')).toEqual([expect.objectContaining({ spawnPriority: 'foreground' })])// The socket was NEVER disposed mid-turn: after every per-request lease// released, the turn lease still held the refcount above zero.diff --git a/apps/desktop/src/plugins/hermes-bots/group-turns.ts b/apps/desktop/src/plugins/hermes-bots/group-turns.tsindex 649facf3550..362b40880a0 100644--- a/apps/desktop/src/plugins/hermes-bots/group-turns.ts+++ b/apps/desktop/src/plugins/hermes-bots/group-turns.ts@@ -165,6 +165,22 @@ interface GroupSessionSnapshot {session_key?: string}+/** Group turns are explicit user work. A member may be cold or retired when+ * its round begins, and session hydration can legitimately wait behind a+ * remote or WSL backend. Use the same three-minute budget as Desktop's+ * focused session hydration instead of the generic 30-second RPC deadline. */+const GROUP_SESSION_RESUME_OPTIONS = {+ spawnPriority: 'foreground',+ timeoutMs: 180_000+} as const++const GROUP_SESSION_BACKGROUND_RESUME_OPTIONS = { timeoutMs: 180_000 } as const+const GROUP_SESSION_CREATE_OPTIONS = { spawnPriority: 'foreground' } as const++function resumeGroupSession(member: GroupMember, params: Record<string, unknown>): Promise<GroupSessionSnapshot> {+ return requestForBot<GroupSessionSnapshot>(member, 'session.resume', params, GROUP_SESSION_RESUME_OPTIONS)+}+/** The error message of a RETAINED failed turn, else null. The gateway keeps* `{ status: 'error', error }` under `inflight` after a turn dies so a* reconnecting client can rebuild the error bubble; it is a tombstone of@@ -263,11 +279,11 @@ export async function ensureGroupChatSession(}try {- const res = (await requestForBot(member, 'session.resume', {+ const res = await resumeGroupSession(member, {session_id: target,profile: member.name,omit_messages: true- })) as GroupSessionSnapshot+ })if (!binding.isLive()) {return { runtime: null }@@ -322,18 +338,23 @@ export async function ensureGroupChatSession(return { runtime: null }}- const created = (await requestForBot(member, 'session.create', {- profile: member.name,- title,- // Room member sessions are plumbing — always hidden from the sidebar.- hidden: true,- // Explicit contracts (PR #97008): room plumbing sessions always rebuild- // from the member profile's CURRENT config on resume, never a stale- // stored model/provider pin. Older gateways ignore the unknown params;- // the server's hidden + "Group: " title fallback then covers legacy.- room_plumbing: true,- follow_profile_config: true- })) as { session_id?: string; stored_session_id?: string }+ const created = (await requestForBot(+ member,+ 'session.create',+ {+ profile: member.name,+ title,+ // Room member sessions are plumbing — always hidden from the sidebar.+ hidden: true,+ // Explicit contracts (PR #97008): room plumbing sessions always rebuild+ // from the member profile's CURRENT config on resume, never a stale+ // stored model/provider pin. Older gateways ignore the unknown params;+ // the server's hidden + "Group: " title fallback then covers legacy.+ room_plumbing: true,+ follow_profile_config: true+ },+ GROUP_SESSION_CREATE_OPTIONS+ )) as { session_id?: string; stored_session_id?: string }if (!binding.isLive()) {return { runtime: null }@@ -486,7 +507,7 @@ async function retainGroupTurnRoute(member: GroupMember): Promise<() => void> {}try {- const release = await host.retainProfile(route)+ const release = await host.retainProfile(route, { spawnPriority: 'foreground' })return typeof release === 'function' ? release : noop} catch {@@ -517,11 +538,11 @@ async function submitGroupTurnPrompt(throw error}- const res = (await requestForBot(member, 'session.resume', {+ const res = await resumeGroupSession(member, {session_id: stored,profile: member.name,omit_messages: true- })) as GroupSessionSnapshot+ })const fresh = res?.session_id@@ -994,10 +1015,10 @@ async function pollGroupMemberTurn(context: GroupTurnPollContext): Promise<nulllet state: GroupSessionSnapshot | null = nulltry {- state = (await requestForBot(member, 'session.resume', {+ state = await resumeGroupSession(member, {session_id: stored || liveRuntime,profile: member.name- })) as GroupSessionSnapshot+ })} catch {continue}@@ -1094,10 +1115,10 @@ async function prepareGroupTurnBaseline(const runtimeIds = new Set<string>([runtime])try {- const pre = (await requestForBot(member, 'session.resume', {+ const pre = await resumeGroupSession(member, {session_id: stored || runtime,profile: member.name- })) as GroupSessionSnapshot+ })snapshot = prebefore = Array.isArray(pre?.messages) ? pre.messages.length : pre?.message_count || 0@@ -1245,10 +1266,15 @@ export async function harvestStrandedGroupReply(group: string, member: GroupMembconst sessions = room.sessions || {}const scoped = sessions[groupSessionKey(strandedThread, member)]const stored = scoped || (hasThreadScopedGroupSession(sessions, memberKey) ? null : sessions[memberKey])- state = (await requestForBot(member, 'session.resume', {- session_id: stored || `Group: ${room.roomId || group} · ${strandedThread}`,- profile: member.name- })) as GroupSessionSnapshot+ state = await requestForBot<GroupSessionSnapshot>(+ member,+ 'session.resume',+ {+ session_id: stored || `Group: ${room.roomId || group} · ${strandedThread}`,+ profile: member.name+ },+ GROUP_SESSION_BACKGROUND_RESUME_OPTIONS+ )} catch (error: any) {// A session that genuinely no longer exists has nothing to harvest, and a marker that can// never resolve would keep the member out of every round; only unreachability keeps it.diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 07947fb0213..fc96d934ddf 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -1457,17 +1457,22 @@ export const host = {* a non-retained secondary socket closes at refcount 0 between calls — and* the gateway reaps any runtime session that socket minted, failing the* next RPC with 4001. Acquire before the first session-scoped RPC, release- * (idempotent) in a `finally`. Feature-detect: older hosts lack this. */- retainProfile: async (route: PluginProfileRoute | string): Promise<() => void> => {+ * (idempotent) in a `finally`. An explicit user action can mark the retain+ * foreground so a retired route takes the pool's reserved interactive+ * slot. Feature-detect: older hosts lack this. */+ retainProfile: async (+ route: PluginProfileRoute | string,+ options?: PluginProfileRequestOptions+ ): Promise<() => void> => {if (typeof route !== 'string') {if (!route.connectionId.trim() || !route.profile.trim()) {throw new Error('Profile route must include connectionId and profile')}- return retainGatewayForAgent(route.connectionId, route.profile)+ return retainGatewayForAgent(route.connectionId, route.profile, options)}- return retainGatewayForAgent(null, route.trim() || 'default')+ return retainGatewayForAgent(null, route.trim() || 'default', options)},/** Read persisted sessions from a profile's owning source without dialingdiff --git a/apps/desktop/src/sdk/profile-routing.test.ts b/apps/desktop/src/sdk/profile-routing.test.tsindex 2d6b1b53a6c..b29f6a6ae27 100644--- a/apps/desktop/src/sdk/profile-routing.test.ts+++ b/apps/desktop/src/sdk/profile-routing.test.ts@@ -118,6 +118,7 @@ vi.mock('@/store/gateway', async () => {params,profile})),+ retainGatewayForAgent: vi.fn(async () => vi.fn()),retireLocalProfileGateways: vi.fn()}})@@ -138,6 +139,7 @@ const {openGatewayForProfile,requestGatewayForAgent,requestGatewayForProfile,+ retainGatewayForAgent,retireLocalProfileGateways} = await import('@/store/gateway')@@ -573,6 +575,21 @@ describe('connection-aware plugin host APIs', () => {})})+ it('forwards foreground intent when a plugin retains a profile route', async () => {+ const route = {+ connectionId: 'source-a',+ mode: 'remote' as const,+ profile: 'remote-worker',+ targetProfile: 'backend-worker'+ }++ await host.retainProfile(route, { spawnPriority: 'foreground' })++ expect(retainGatewayForAgent).toHaveBeenCalledWith('source-a', 'remote-worker', {+ spawnPriority: 'foreground'+ })+ })+it('keeps the profile-only request overload as a legacy fallback', async () => {const result = await host.requestProfile('legacy-worker', 'profiles.list', { include_sessions: true })