π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(agent-runtime): arm bounded verify when async-tool parent state is missing (#16393)
Arvin Xu633084cd75c3
diff --git a/apps/server/src/services/agentRuntime/AgentRuntimeService.test.ts b/apps/server/src/services/agentRuntime/AgentRuntimeService.test.tsindex 93dc620a499..7a00fb7691c 100644--- a/apps/server/src/services/agentRuntime/AgentRuntimeService.test.ts+++ b/apps/server/src/services/agentRuntime/AgentRuntimeService.test.ts@@ -1857,6 +1857,52 @@ describe('AgentRuntimeService', () => {expect(mockQueueService.scheduleMessage).not.toHaveBeenCalled();});+ it('arms a verify when the parent state is missing/expired and scheduleVerifyOnHold is set', async () => {+ // Redis read replica hasn't seen the park yet, or the child outran the+ // parent's park. A missing state must retry, not strand on the first miss.+ mockCoordinator.loadAgentState.mockResolvedValue(null);+ const casSpy = vi.spyOn(AgentOperationModel.prototype, 'tryResumeFromAsyncTool');++ const won = await service.tryResumeParentFromAsyncTool(+ { parentOperationId: parentOpId },+ { scheduleVerifyOnHold: true },+ );++ expect(won).toBe(false);+ expect(casSpy).not.toHaveBeenCalled();+ expect(mockQueueService.scheduleMessage).toHaveBeenCalledWith(+ expect.objectContaining({+ operationId: parentOpId,+ payload: { asyncToolVerifyAttempt: 1, verifyAsyncToolBarrier: true },+ // No state to read stepCount from β falls back to 0.+ stepIndex: 0,+ }),+ );+ });++ it('does not arm a verify on missing state when scheduleVerifyOnHold is not set', async () => {+ // The clean-done bridge path resumes without opting into the watchdog;+ // a missing state there must stay a silent no-op, not schedule a re-check.+ mockCoordinator.loadAgentState.mockResolvedValue(null);++ const won = await service.tryResumeParentFromAsyncTool({ parentOperationId: parentOpId });++ expect(won).toBe(false);+ expect(mockQueueService.scheduleMessage).not.toHaveBeenCalled();+ });++ it('stops re-arming on missing state once the bounded attempts are exhausted', async () => {+ mockCoordinator.loadAgentState.mockResolvedValue(null);++ const won = await service.tryResumeParentFromAsyncTool(+ { parentOperationId: parentOpId },+ { scheduleVerifyOnHold: true, verifyAttempt: 6 },+ );++ expect(won).toBe(false);+ expect(mockQueueService.scheduleMessage).not.toHaveBeenCalled();+ });+it('schedules a finish step when the parked tool requests onComplete=finish (skipCallSupervisor / delegate)', async () => {mockCoordinator.loadAgentState.mockResolvedValue({pendingToolsCalling: [{ id: 'tc1' }],diff --git a/apps/server/src/services/agentRuntime/AgentRuntimeService.ts b/apps/server/src/services/agentRuntime/AgentRuntimeService.tsindex e210a3cfa8a..b89304f2e7a 100644--- a/apps/server/src/services/agentRuntime/AgentRuntimeService.ts+++ b/apps/server/src/services/agentRuntime/AgentRuntimeService.ts@@ -1765,11 +1765,16 @@ export class AgentRuntimeService {const state = await this.coordinator.loadAgentState(parentOperationId);if (!state) {- // State expired (Redis TTL) or never persisted β nothing left to resume.- // Surface it: a missing state at completion time is how a parent silently- // strands. There is no stepCount/status to arm a verify against.- log('[%s] async-tool resume: parent state missing/expired, cannot resume', parentOperationId);+ // State expired (Redis TTL) or never persisted. A missing state at+ // completion time is a classic way a parent silently strands β but it is+ // often transient: a read replica that hasn't seen the park yet, or the+ // child outrunning the parent's park before its snapshot lands. Arm the+ // bounded verify so a later re-check can resume once the state is visible,+ // instead of giving up on the first miss. A genuinely-gone parent just+ // exhausts the attempt cap (verify_exhausted) rather than stranding here.+ log('[%s] async-tool resume: parent state missing/expired, arming verify', parentOperationId);asyncToolResumeCounter.add(1, { outcome: 'no_state' });+ await this.maybeScheduleAsyncToolVerify(parentOperationId, null, options);return false;}@@ -1868,12 +1873,16 @@ export class AgentRuntimeService {*/private async maybeScheduleAsyncToolVerify(parentOperationId: string,- state: AgentState,+ state: AgentState | null,options?: { scheduleVerifyOnHold?: boolean; verifyAttempt?: number },): Promise<void> {if (!options?.scheduleVerifyOnHold || !this.queueService) return;- const status = state.status as string;+ // `state` is null when the parked snapshot is missing/expired at completion+ // time (no_state). We can't read a status to skip a terminal op, but the+ // bounded attempt cap below keeps a genuinely-gone parent from re-arming+ // forever, so it's safe to retry instead of stranding on a transient miss.+ const status = state?.status as string | undefined;if (status === 'done' || status === 'error' || status === 'interrupted') return;const attempt = options.verifyAttempt ?? 1;@@ -1885,7 +1894,7 @@ export class AgentRuntimeService {'[%s] async-tool barrier verify exhausted after %d attempts, giving up (status: %s)',parentOperationId,ASYNC_TOOL_VERIFY_MAX_ATTEMPTS,- status,+ status ?? 'missing',);asyncToolResumeCounter.add(1, { outcome: 'verify_exhausted' });return;@@ -1898,7 +1907,7 @@ export class AgentRuntimeService {attempt,ASYNC_TOOL_VERIFY_MAX_ATTEMPTS,delay,- status,+ status ?? 'missing',);try {@@ -1909,7 +1918,7 @@ export class AgentRuntimeService {operationId: parentOperationId,payload: { asyncToolVerifyAttempt: attempt, verifyAsyncToolBarrier: true },priority: 'high',- stepIndex: state.stepCount,+ stepIndex: state?.stepCount ?? 0,});} catch (error) {log(