refactor: dedupe `_dump` helper, collapse retry-policy plumbing, scrub test scars

Tools:
- Add a single ``dump_tool_result`` helper in ``tools/_decorator.py``
  and remove the eight identical ``_dump`` definitions from
  ``proxy/tools.py``, ``file_edit/tools.py``, ``python/tool.py``,
  ``terminal/tool.py``, ``todo/tools.py``, ``browser/tool.py``,
  ``notes/tools.py``, ``agents_graph/tools.py``. Imports trimmed.
  Net -50 LoC across the tool modules.

run_config_factory:
- Inline the four retry-policy plumbing pieces
  (``_RETRYABLE_HTTP_STATUSES``, ``_DEFAULT_MAX_RETRIES``,
  ``_DEFAULT_BACKOFF``, ``_default_retry_policy()``) into a single
  module-level ``_DEFAULT_RETRY`` ``ModelRetrySettings`` literal. The
  inputs were never overridden and the helper had one caller.

Tests:
- Drop migration scars from ``tests/test_run_config_factory.py``
  (``Phase 1`` / ``C1`` / ``C11`` / ``C21`` / ``HARNESS_WIKI`` / ``AUDIT``
  references). Replace the ``_RETRYABLE_HTTP_STATUSES``-touching test
  with a ``retry.policy is not None`` smoke check now that the constant
  has been inlined.
This commit is contained in:
0xallam
2026-04-25 12:54:44 -07:00
parent 43ebb786a2
commit ecbd92ce2c
11 changed files with 114 additions and 164 deletions
+6 -10
View File
@@ -23,7 +23,7 @@ if TYPE_CHECKING:
from agents import RunContextWrapper
from strix.tools._decorator import strix_tool
from strix.tools._decorator import dump_tool_result, strix_tool
logger = logging.getLogger(__name__)
@@ -36,10 +36,6 @@ _loaded_notes_run_dir: str | None = None
_DEFAULT_CONTENT_PREVIEW_CHARS = 280
def _dump(result: dict[str, Any]) -> str:
return json.dumps(result, ensure_ascii=False, default=str)
def _get_run_dir() -> Path | None:
try:
from strix.telemetry.tracer import get_global_tracer
@@ -441,7 +437,7 @@ async def create_note(
category: One of the categories above. Default ``"general"``.
tags: Optional free-form tags.
"""
return _dump(
return dump_tool_result(
await asyncio.to_thread(_create_note_impl, title, content, category, tags),
)
@@ -472,7 +468,7 @@ async def list_notes(
include_content: When False (default) entries have a preview;
when True the full ``content`` is included.
"""
return _dump(
return dump_tool_result(
await asyncio.to_thread(
_list_notes_impl,
category=category,
@@ -490,7 +486,7 @@ async def get_note(ctx: RunContextWrapper, note_id: str) -> str:
Args:
note_id: Note id from ``create_note`` or a ``list_notes`` entry.
"""
return _dump(await asyncio.to_thread(_get_note_impl, note_id))
return dump_tool_result(await asyncio.to_thread(_get_note_impl, note_id))
@strix_tool(timeout=30)
@@ -513,7 +509,7 @@ async def update_note(
content: New content, or ``None`` to keep.
tags: New tags list, or ``None`` to keep.
"""
return _dump(
return dump_tool_result(
await asyncio.to_thread(
_update_note_impl,
note_id=note_id,
@@ -531,4 +527,4 @@ async def delete_note(ctx: RunContextWrapper, note_id: str) -> str:
Args:
note_id: Note id to delete.
"""
return _dump(await asyncio.to_thread(_delete_note_impl, note_id))
return dump_tool_result(await asyncio.to_thread(_delete_note_impl, note_id))