fix: trigger agentStatusChanged hook and heartbeat even when framework yields no message

memeloopTaskAgentWorkerHandler yields { state } without a message field (worker-side
bindWorkerConversation handles message materialization). The old code gated hook dispatch
and heartbeat startup inside if (lastResult?.message), so they were never triggered for
memeloop agents. Extract hook + heartbeat into if (lastResult) so they run regardless of
whether the framework attached a message to the terminal yield.
This commit is contained in:
linonetwo 2026-04-03 15:44:54 +08:00 committed by lin onetwo
parent b6988c57db
commit 143496fdf2

View file

@ -997,8 +997,12 @@ export class AgentInstanceService implements IAgentInstanceService {
}
});
}
}
// Trigger agentStatusChanged hook with actual terminal state (completed, input-required, etc.)
if (lastResult) {
// Trigger agentStatusChanged hook with actual terminal state (completed, input-required, etc.).
// This must run even when the framework yields no message (e.g. memeloopTaskAgentWorkerHandler
// yields { state } without a message; worker-side updates handle message materialization).
const terminalState = (lastResult.state ?? 'completed') as 'working' | 'completed' | 'failed' | 'canceled' | 'input-required';
await frameworkHooks.agentStatusChanged.promise({
agentFrameworkContext: frameworkContext,