Skip to content

🀯 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.

πŸ› fix: recall on every success-like completion, not just done (#17613)

Tsukid22f50a8b5ab
diff --git a/apps/server/src/services/agentRuntime/CompletionLifecycle.ts b/apps/server/src/services/agentRuntime/CompletionLifecycle.ts
index 532d970e4f9..489a19a7f3a 100644
--- a/apps/server/src/services/agentRuntime/CompletionLifecycle.ts
+++ b/apps/server/src/services/agentRuntime/CompletionLifecycle.ts
@@ -631,32 +631,39 @@ export class CompletionLifecycle {
await hookDispatcher.dispatch(operationId, 'onComplete', event, metadata._hooks);
+ // Recall the user when a run finishes with a deliverable while they may be
+ // away (push / inbox). Fires on every success-like terminal β€” `done` plus
+ // the step/cost caps, which still produce a reply worth recalling β€” to
+ // match the desktop completion notification, which notifies on any clean
+ // (non-abort, non-error) terminal. Fire-and-forget through the
+ // `@/business` slot; the default implementation is a no-op. Sub-agent /
+ // group-member completions are internal steps of a parent run, never a
+ // user-facing recall β€” in-group members carry `orchestrationRole: 'member'`
+ // WITHOUT `isSubAgent` (see execAgentMember), so guard both.
+ if (
+ isSuccessLikeCompletionReason(reason) &&
+ metadata?.isSubAgent !== true &&
+ metadata?.orchestrationRole !== 'member'
+ ) {
+ void notifyAgentRunCompleted({
+ agentId: event.agentId || undefined,
+ duration: event.duration,
+ lastAssistantContent: event.lastAssistantContent,
+ operationId,
+ topicId: event.topicId,
+ userId: metadata?.userId || this.userId,
+ // Personal runs leave this undefined β‡’ bare deep link; workspace
+ // runs carry the id so the business slot can slug-prefix the URL.
+ workspaceId: this.workspaceId,
+ }).catch((error) =>
+ log('[%s] Completion notification failed (non-fatal): %O', operationId, error),
+ );
+ }
+
// Delivery checker: on a successful completion, run the confirmed verify
// plan against the deliverable. Fire-and-forget and self-guarded β€” a run
// without an opted-in plan is a no-op, and failures never affect the run.
if (reason === 'done') {
- // Recall the user when a long run finishes cleanly while they may be
- // away (push / inbox). Fire-and-forget through the `@/business` slot β€”
- // the default implementation is a no-op. Sub-agent / group member
- // completions are internal steps of a parent run, never a user-facing
- // recall β€” in-group members carry `orchestrationRole: 'member'`
- // WITHOUT `isSubAgent` (see execAgentMember), so guard both.
- if (metadata?.isSubAgent !== true && metadata?.orchestrationRole !== 'member') {
- void notifyAgentRunCompleted({
- agentId: event.agentId || undefined,
- duration: event.duration,
- lastAssistantContent: event.lastAssistantContent,
- operationId,
- topicId: event.topicId,
- userId: metadata?.userId || this.userId,
- // Personal runs leave this undefined β‡’ bare deep link; workspace
- // runs carry the id so the business slot can slug-prefix the URL.
- workspaceId: this.workspaceId,
- }).catch((error) =>
- log('[%s] Completion notification failed (non-fatal): %O', operationId, error),
- );
- }
-
// The task's verify plan is instantiated fire-and-forget at run start; a
// fast or no-op run can reach completion before it settles. Await the
// in-flight instantiation (if any) so the gate sees the confirmed plan
diff --git a/apps/server/src/services/agentRuntime/__tests__/CompletionLifecycle.test.ts b/apps/server/src/services/agentRuntime/__tests__/CompletionLifecycle.test.ts
index f519d2e9359..d024920a5fc 100644
--- a/apps/server/src/services/agentRuntime/__tests__/CompletionLifecycle.test.ts
+++ b/apps/server/src/services/agentRuntime/__tests__/CompletionLifecycle.test.ts
@@ -709,7 +709,25 @@ describe('CompletionLifecycle.dispatchHooks β€” completion notification', () =>
expect(mockNotifyAgentRunCompleted).not.toHaveBeenCalled();
});
- it('does not notify on non-done terminals', async () => {
+ it.each(['max_steps', 'cost_limit'])(
+ 'notifies on the success-like capped terminal %s (still produced a deliverable)',
+ async (reason) => {
+ const lifecycle = buildLifecycle();
+ stubSideEffects(lifecycle);
+
+ const doneState = {
+ createdAt: new Date(Date.now() - 90_000).toISOString(),
+ messages: [{ content: 'final reply', role: 'assistant' }],
+ metadata: { _hooks: [], agentId: 'agt_1', topicId: 'tpc_1' },
+ status: 'done',
+ };
+ await lifecycle.dispatchHooks('op-1', doneState, reason);
+
+ expect(mockNotifyAgentRunCompleted).toHaveBeenCalledTimes(1);
+ },
+ );
+
+ it('does not notify on error / aborted terminals', async () => {
const lifecycle = buildLifecycle();
stubSideEffects(lifecycle);