From 67dd75db623d6f4b56f9a839d4ace4877c4edab4 Mon Sep 17 00:00:00 2001 From: Eilen Shin <136898293+Eilen6316@users.noreply.github.com> Date: Wed, 24 Jun 2026 09:21:50 +0800 Subject: [PATCH] chore: remove unused private helper functions (dead code) (#3749) These three module-private helpers have no callers anywhere in the repo (verified by a repo-wide identifier scan + direct greps; each appears only at its own definition): - agents/memory/updater.py: _create_empty_memory (a no-caller wrapper around storage.create_empty_memory, which is used directly elsewhere) - runtime/runs/worker.py: _extract_human_message (also drops the now-unused HumanMessage TYPE_CHECKING import and TYPE_CHECKING from typing) - sandbox/tools.py: _looks_like_unsafe_cwd_target (cwd safety is enforced via _is_allowed_local_bash_absolute_path) Underscore-prefixed = module-internal, so zero references is conclusive. Route handlers and @compiles-registered functions were excluded as false positives. Public-surface candidates are noted in the issue, not touched here. Fixes #3748. --- .../harness/deerflow/agents/memory/updater.py | 5 ---- .../harness/deerflow/runtime/runs/worker.py | 30 +------------------ .../harness/deerflow/sandbox/tools.py | 6 ---- 3 files changed, 1 insertion(+), 40 deletions(-) diff --git a/backend/packages/harness/deerflow/agents/memory/updater.py b/backend/packages/harness/deerflow/agents/memory/updater.py index 2ad9003fd..f51a3dd78 100644 --- a/backend/packages/harness/deerflow/agents/memory/updater.py +++ b/backend/packages/harness/deerflow/agents/memory/updater.py @@ -38,11 +38,6 @@ _SYNC_MEMORY_UPDATER_EXECUTOR = concurrent.futures.ThreadPoolExecutor( atexit.register(lambda: _SYNC_MEMORY_UPDATER_EXECUTOR.shutdown(wait=False)) -def _create_empty_memory() -> dict[str, Any]: - """Backward-compatible wrapper around the storage-layer empty-memory factory.""" - return create_empty_memory() - - def _save_memory_to_file(memory_data: dict[str, Any], agent_name: str | None = None, *, user_id: str | None = None) -> bool: """Backward-compatible wrapper around the configured memory storage save path.""" return get_memory_storage().save(memory_data, agent_name, user_id=user_id) diff --git a/backend/packages/harness/deerflow/runtime/runs/worker.py b/backend/packages/harness/deerflow/runtime/runs/worker.py index 204c74e4c..8948354ae 100644 --- a/backend/packages/harness/deerflow/runtime/runs/worker.py +++ b/backend/packages/harness/deerflow/runtime/runs/worker.py @@ -22,13 +22,10 @@ import logging import os from dataclasses import dataclass, field from functools import lru_cache -from typing import TYPE_CHECKING, Any, Literal, cast +from typing import Any, Literal, cast from langgraph.checkpoint.base import empty_checkpoint -if TYPE_CHECKING: - from langchain_core.messages import HumanMessage - from deerflow.config.app_config import AppConfig from deerflow.runtime.serialization import serialize from deerflow.runtime.stream_bridge import StreamBridge @@ -642,31 +639,6 @@ def _extract_llm_error_fallback_message(value: Any) -> str | None: return walk(value) -def _extract_human_message(graph_input: dict) -> HumanMessage | None: - """Extract or construct a HumanMessage from graph_input for event recording. - - Returns a LangChain HumanMessage so callers can use .model_dump() to get - the checkpoint-aligned serialization format. - """ - from langchain_core.messages import HumanMessage - - messages = graph_input.get("messages") - if not messages: - return None - last = messages[-1] if isinstance(messages, list) else messages - if isinstance(last, HumanMessage): - return last - if isinstance(last, str): - return HumanMessage(content=last) if last else None - if hasattr(last, "content"): - content = last.content - return HumanMessage(content=content) - if isinstance(last, dict): - content = last.get("content", "") - return HumanMessage(content=content) if content else None - return None - - def _unpack_stream_item( item: Any, lg_modes: list[str], diff --git a/backend/packages/harness/deerflow/sandbox/tools.py b/backend/packages/harness/deerflow/sandbox/tools.py index 3440b7b52..8d322ae1a 100644 --- a/backend/packages/harness/deerflow/sandbox/tools.py +++ b/backend/packages/harness/deerflow/sandbox/tools.py @@ -855,12 +855,6 @@ def _validate_local_bash_cwd_target(command_name: str, target: str | None, allow raise PermissionError(f"Unsafe working directory change in command: {command_name} {target}. Use paths under {VIRTUAL_PATH_PREFIX}") -def _looks_like_unsafe_cwd_target(target: str | None) -> bool: - if target is None: - return False - return target == "-" or target.startswith(("$", "`", "~", "/", "..")) or _has_dotdot_path_segment(target) - - def _validate_local_bash_root_path_args(command_name: str, tokens: list[str], start_index: int) -> None: if command_name not in _LOCAL_BASH_ROOT_PATH_COMMANDS: return