diff --git a/comfy/distributed/distributed_prompt_queue.py b/comfy/distributed/distributed_prompt_queue.py index b4d6a6d2d..82b5504d1 100644 --- a/comfy/distributed/distributed_prompt_queue.py +++ b/comfy/distributed/distributed_prompt_queue.py @@ -204,7 +204,7 @@ class DistributedPromptQueue(AbstractPromptQueue): """ return False - def get_history(self, prompt_id: Optional[int] = None, max_items=None, offset=-1) \ + def get_history(self, prompt_id: Optional[int] = None, max_items=None, offset=None) \ -> Mapping[str, HistoryEntry]: return self._caller_history.copy(prompt_id=prompt_id, max_items=max_items, offset=offset) diff --git a/comfy/distributed/history.py b/comfy/distributed/history.py index 3306f8504..ae2e3d39b 100644 --- a/comfy/distributed/history.py +++ b/comfy/distributed/history.py @@ -19,12 +19,16 @@ class History: def copy(self, prompt_id: Optional[str | int] = None, max_items: Optional[int] = None, offset: Optional[int] = None) -> Dict[str, HistoryEntry]: - offset = offset or 0 + if offset is not None and offset < 0: + offset = max(len(self.history) + offset, 0) max_items = max_items or MAXIMUM_HISTORY_SIZE if prompt_id in self.history: return {prompt_id: copy.deepcopy(self.history[prompt_id])} else: - return dict(islice(self.history, offset, max_items)) + ordered_dict = OrderedDict() + for k in islice(self.history, offset, max_items): + ordered_dict[k] = copy.deepcopy(self.history[k]) + return ordered_dict def clear(self): self.history.clear()