refactor: collapse dual stat buckets, prune unused params, kill dead helpers
Tracer:
- Collapse the ``live`` / ``completed`` LLM stat buckets into one
flat dict. The ``completed`` bucket was only ever written by tests
— production never moved stats across, and ``get_total_llm_stats``
always summed both for display.
- Drop ``record_llm_usage(agent_id=...)``: argument was unused, and
the per-call ``bucket=`` knob is gone with the buckets.
run_config_factory:
- Drop unused ``parallel_tool_calls``, ``tool_choice`` parameters
from ``make_run_config`` — no caller ever overrode them.
- Drop ``agent_name`` from ``make_agent_context`` — set into the
context dict but no consumer ever read it; the bus's ``names`` map
is the source of truth.
Wire reasoning_effort through:
- ``Config.get("strix_reasoning_effort")`` is now actually plumbed
to ``make_run_config`` from ``entry.py``. Previously the env var
was advertised but never consumed.
Multi-agent graph tools:
- Replace six copies of
``inner = ctx.context if isinstance(ctx.context, dict) else {}``
with a single ``_ctx(ctx)`` helper.
Todo tools:
- Lift the duplicated ``priority_order`` / ``status_order`` dicts
to module-level ``_PRIORITY_RANK`` / ``_STATUS_RANK`` and replace
both inline sort lambdas with ``_todo_sort_key``.
Notes tools:
- Delete ``append_note_content`` (and its test): docstring claimed
it was for an "agents-graph wiki-update hook on agent_finish" that
was never wired up. Pure dead public API.
Style:
- Drop the ``del ctx`` no-ops from notes / reporting / web_search
tools. ``ARG001`` is already silenced project-wide for tool
modules; the ``del`` was cargo-culted.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -258,32 +258,26 @@ def test_events_with_agent_id_include_agent_name(
|
||||
assert chat_event["actor"]["agent_name"] == "Root Agent"
|
||||
|
||||
|
||||
def test_get_total_llm_stats_aggregates_live_and_completed(
|
||||
def test_get_total_llm_stats_aggregates_recordings(
|
||||
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
tracer = Tracer("cost-rollup")
|
||||
set_global_tracer(tracer)
|
||||
|
||||
# Live agent (still running).
|
||||
tracer.record_llm_usage(
|
||||
agent_id="root-agent",
|
||||
input_tokens=1_000,
|
||||
output_tokens=250,
|
||||
cached_tokens=100,
|
||||
cost=0.12345,
|
||||
requests=2,
|
||||
bucket="live",
|
||||
)
|
||||
# Completed agents (finalized — moved by on_agent_end hook).
|
||||
tracer.record_llm_usage(
|
||||
agent_id="child-1",
|
||||
input_tokens=2_000,
|
||||
output_tokens=500,
|
||||
cached_tokens=400,
|
||||
cost=0.54321,
|
||||
requests=3,
|
||||
bucket="completed",
|
||||
)
|
||||
|
||||
stats = tracer.get_total_llm_stats()
|
||||
|
||||
@@ -107,7 +107,6 @@ def test_max_turns_default_is_300() -> None:
|
||||
tool_server_host_port=None,
|
||||
caido_host_port=None,
|
||||
agent_id="root",
|
||||
agent_name="root",
|
||||
parent_id=None,
|
||||
tracer=None,
|
||||
)
|
||||
@@ -124,7 +123,6 @@ def test_make_agent_context_full_shape() -> None:
|
||||
tool_server_host_port=48081,
|
||||
caido_host_port=48080,
|
||||
agent_id="agent-1",
|
||||
agent_name="root",
|
||||
parent_id=None,
|
||||
tracer="not-a-real-tracer",
|
||||
is_whitebox=True,
|
||||
@@ -154,7 +152,6 @@ def test_make_agent_context_is_whitebox_defaults_false() -> None:
|
||||
tool_server_host_port=None,
|
||||
caido_host_port=None,
|
||||
agent_id="r",
|
||||
agent_name="root",
|
||||
parent_id=None,
|
||||
tracer=None,
|
||||
)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from strix.telemetry.tracer import Tracer, get_global_tracer, set_global_tracer
|
||||
from strix.tools.notes import tools as notes_actions
|
||||
|
||||
@@ -9,7 +11,9 @@ def _reset_notes_state() -> None:
|
||||
notes_actions._loaded_notes_run_dir = None
|
||||
|
||||
|
||||
def test_wiki_notes_are_persisted_and_removed(tmp_path: Path, monkeypatch) -> None:
|
||||
def test_wiki_notes_are_persisted_and_removed(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
_reset_notes_state()
|
||||
|
||||
@@ -48,10 +52,12 @@ def test_wiki_notes_are_persisted_and_removed(tmp_path: Path, monkeypatch) -> No
|
||||
assert wiki_path.exists() is False
|
||||
finally:
|
||||
_reset_notes_state()
|
||||
set_global_tracer(previous_tracer) # type: ignore[arg-type]
|
||||
set_global_tracer(previous_tracer)
|
||||
|
||||
|
||||
def test_notes_jsonl_replay_survives_memory_reset(tmp_path: Path, monkeypatch) -> None:
|
||||
def test_notes_jsonl_replay_survives_memory_reset(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
_reset_notes_state()
|
||||
|
||||
@@ -108,10 +114,10 @@ def test_notes_jsonl_replay_survives_memory_reset(tmp_path: Path, monkeypatch) -
|
||||
assert listed_after_delete["total_count"] == 0
|
||||
finally:
|
||||
_reset_notes_state()
|
||||
set_global_tracer(previous_tracer) # type: ignore[arg-type]
|
||||
set_global_tracer(previous_tracer)
|
||||
|
||||
|
||||
def test_get_note_returns_full_note(tmp_path: Path, monkeypatch) -> None:
|
||||
def test_get_note_returns_full_note(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
_reset_notes_state()
|
||||
|
||||
@@ -136,44 +142,11 @@ def test_get_note_returns_full_note(tmp_path: Path, monkeypatch) -> None:
|
||||
assert result["note"]["content"] == "entrypoints and sinks"
|
||||
finally:
|
||||
_reset_notes_state()
|
||||
set_global_tracer(previous_tracer) # type: ignore[arg-type]
|
||||
|
||||
|
||||
def test_append_note_content_appends_delta(tmp_path: Path, monkeypatch) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
_reset_notes_state()
|
||||
|
||||
previous_tracer = get_global_tracer()
|
||||
tracer = Tracer("append-note-run")
|
||||
set_global_tracer(tracer)
|
||||
|
||||
try:
|
||||
created = notes_actions._create_note_impl(
|
||||
title="Repo wiki",
|
||||
content="base",
|
||||
category="wiki",
|
||||
tags=["repo:demo"],
|
||||
)
|
||||
assert created["success"] is True
|
||||
note_id = created["note_id"]
|
||||
assert isinstance(note_id, str)
|
||||
|
||||
appended = notes_actions.append_note_content(
|
||||
note_id=note_id,
|
||||
delta="\n\n## Agent Update: worker\nSummary: done",
|
||||
)
|
||||
assert appended["success"] is True
|
||||
|
||||
loaded = notes_actions._get_note_impl(note_id=note_id)
|
||||
assert loaded["success"] is True
|
||||
assert loaded["note"]["content"] == "base\n\n## Agent Update: worker\nSummary: done"
|
||||
finally:
|
||||
_reset_notes_state()
|
||||
set_global_tracer(previous_tracer) # type: ignore[arg-type]
|
||||
set_global_tracer(previous_tracer)
|
||||
|
||||
|
||||
def test_list_and_get_note_handle_wiki_repersist_oserror_gracefully(
|
||||
tmp_path: Path, monkeypatch
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
_reset_notes_state()
|
||||
@@ -195,7 +168,7 @@ def test_list_and_get_note_handle_wiki_repersist_oserror_gracefully(
|
||||
|
||||
_reset_notes_state()
|
||||
|
||||
def _raise_oserror(*_args, **_kwargs) -> None:
|
||||
def _raise_oserror(*_args: object, **_kwargs: object) -> None:
|
||||
raise OSError("disk full")
|
||||
|
||||
monkeypatch.setattr(notes_actions, "_persist_wiki_note", _raise_oserror)
|
||||
@@ -211,4 +184,4 @@ def test_list_and_get_note_handle_wiki_repersist_oserror_gracefully(
|
||||
assert fetched["note"]["content"] == "initial wiki content"
|
||||
finally:
|
||||
_reset_notes_state()
|
||||
set_global_tracer(previous_tracer) # type: ignore[arg-type]
|
||||
set_global_tracer(previous_tracer)
|
||||
|
||||
Reference in New Issue
Block a user