mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-06-11 09:55:59 +00:00
fix(middleware): address Copilot review feedback on sandbox externalization
- Make get_sandbox_provider() lookup best-effort in _budget_content: only query when outputs_path or sandbox is available, and fall back to inline truncation if provider initialization raises rather than propagating the error. A resolved sandbox instance is sufficient on its own to take the non-mounted externalization branch. - Strict-match the sandbox post-write validation echo (check.strip() == 'OK') to avoid false positives if execute_command ever surfaces unrelated stdout/stderr containing 'OK' as a substring. Refs: #3417
This commit is contained in:
+7
-4
@@ -181,7 +181,7 @@ def _externalize_to_sandbox(
|
|||||||
# to create the directory, and write_file backends differ. Refuse to
|
# to create the directory, and write_file backends differ. Refuse to
|
||||||
# hand the model an unreadable read_file path.
|
# hand the model an unreadable read_file path.
|
||||||
check = sandbox.execute_command(f"test -s {shlex.quote(virtual_path)} && echo OK || echo MISSING")
|
check = sandbox.execute_command(f"test -s {shlex.quote(virtual_path)} && echo OK || echo MISSING")
|
||||||
if not isinstance(check, str) or "OK" not in check:
|
if not isinstance(check, str) or check.strip() != "OK":
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Sandbox externalize validation failed: path=%s, check=%r",
|
"Sandbox externalize validation failed: path=%s, check=%r",
|
||||||
virtual_path,
|
virtual_path,
|
||||||
@@ -340,8 +340,13 @@ def _budget_content(
|
|||||||
|
|
||||||
if threshold > 0 and len(content) > threshold:
|
if threshold > 0 and len(content) > threshold:
|
||||||
virtual_path: str | None = None
|
virtual_path: str | None = None
|
||||||
|
provider = None
|
||||||
|
if outputs_path or sandbox is not None:
|
||||||
|
try:
|
||||||
provider = get_sandbox_provider()
|
provider = get_sandbox_provider()
|
||||||
if getattr(provider, "uses_thread_data_mounts", False):
|
except Exception:
|
||||||
|
logger.exception("Failed to get sandbox provider for tool-output externalization; falling back to inline truncation")
|
||||||
|
if provider is not None and getattr(provider, "uses_thread_data_mounts", False):
|
||||||
# Host-mounted sandbox: the host outputs path is bind-mounted into
|
# Host-mounted sandbox: the host outputs path is bind-mounted into
|
||||||
# the sandbox at the same virtual path, so writing host-side is
|
# the sandbox at the same virtual path, so writing host-side is
|
||||||
# equivalent to writing sandbox-side. Preserve the original
|
# equivalent to writing sandbox-side. Preserve the original
|
||||||
@@ -355,8 +360,6 @@ def _budget_content(
|
|||||||
storage_subdir=config.storage_subdir,
|
storage_subdir=config.storage_subdir,
|
||||||
)
|
)
|
||||||
elif sandbox is not None:
|
elif sandbox is not None:
|
||||||
# Non-mounted (remote) sandbox: write into the sandbox itself so
|
|
||||||
# the model's read_file tool can read it back. Issue #3416.
|
|
||||||
virtual_path = _externalize_to_sandbox(
|
virtual_path = _externalize_to_sandbox(
|
||||||
content,
|
content,
|
||||||
tool_name=tool_name,
|
tool_name=tool_name,
|
||||||
|
|||||||
Reference in New Issue
Block a user