Private
Public Access
0
0

refactor(ai_client): rename send_result to send (the impl, TDD red moment)

The TDD red moment. The implementation is renamed but the call sites
in src/, tests/, and docs still use send_result. Subsequent commits
rename the call sites and progressively move the test suite back to
green.

10 references renamed in src/ai_client.py:
- 4 'Called by: send_result' docstring tags in private provider helpers
- 1 function definition (def send_result -> def send)
- 1 [C: ...] SDM tag referencing test function names
- 2 monitor component names (start_component / end_component)
- 2 error source strings (CONFIG + INTERNAL)

Also adds scripts/tier2/apply_t1_1_edits.py - the helper script that
applied the 10 edits. Kept in scripts/tier2/ as a record of the
mechanical change pattern.

Refs: conductor/tracks/send_result_to_send_20260616/
This commit is contained in:
2026-06-17 00:23:16 -04:00
parent c1d9a966d7
commit 5351389fc0
2 changed files with 95 additions and 10 deletions
+85
View File
@@ -0,0 +1,85 @@
"""Apply the 10 send_result -> send edits to src/ai_client.py.
This is a one-shot script for Task 1.1. Idempotent: re-running is a no-op
if the rename is already complete.
"""
from __future__ import annotations
import sys
from pathlib import Path
FILE = Path("src/ai_client.py")
EDITS: list[tuple[str, str]] = [
(
" Immediate-Mode DAG / Thread Context:\n Called by: send_result\n Calls: _ensure_grok_client",
" Immediate-Mode DAG / Thread Context:\n Called by: send\n Calls: _ensure_grok_client",
),
(
" Immediate-Mode DAG / Thread Context:\n Called by: send_result\n Calls: _ensure_minimax_client",
" Immediate-Mode DAG / Thread Context:\n Called by: send\n Calls: _ensure_minimax_client",
),
(
" Immediate-Mode DAG / Thread Context:\n Called by: send_result\n Calls: _ensure_qwen_client",
" Immediate-Mode DAG / Thread Context:\n Called by: send\n Calls: _ensure_qwen_client",
),
(
" Immediate-Mode DAG / Thread Context:\n Called by: send_result\n Calls: _send_llama_native",
" Immediate-Mode DAG / Thread Context:\n Called by: send\n Calls: _send_llama_native",
),
(
"def send_result(\n md_content: str,",
"def send(\n md_content: str,",
),
(
"[C: tests/test_ai_client_result.py:test_send_result_public_api_returns_result, tests/test_ai_client_result.py:test_send_result_preserves_errors, tests/test_deprecation_warnings.py:test_send_result_does_not_emit_deprecation]",
"[C: tests/test_ai_client_result.py:test_send_public_api_returns_result, tests/test_ai_client_result.py:test_send_preserves_errors, tests/test_deprecation_warnings.py:test_send_does_not_emit_deprecation]",
),
(
'if monitor.enabled: monitor.start_component("ai_client.send_result")',
'if monitor.enabled: monitor.start_component("ai_client.send")',
),
(
'source="ai_client.send_result")])',
'source="ai_client.send")])',
),
(
'source="ai_client.send_result", original=exc)',
'source="ai_client.send", original=exc)',
),
(
'if monitor.enabled: monitor.end_component("ai_client.send_result")',
'if monitor.enabled: monitor.end_component("ai_client.send")',
),
]
def main() -> int:
with FILE.open("r", encoding="utf-8", newline="") as f:
content = f.read()
has_crlf = "\r\n" in content
nl = "\r\n" if has_crlf else "\n"
normalized_edits = [
(old.replace("\n", nl), new.replace("\n", nl)) for old, new in EDITS
]
new_content = content
applied = 0
for old, new in normalized_edits:
if old in new_content:
new_content = new_content.replace(old, new, 1)
applied += 1
else:
print(f"NOT FOUND: {old[:80]!r}", file=sys.stderr)
if applied != len(EDITS):
print(f"Only applied {applied}/{len(EDITS)} edits. ABORTING.", file=sys.stderr)
return 1
with FILE.open("w", encoding="utf-8", newline="") as f:
f.write(new_content)
remaining = new_content.count("send_result")
print(f"Applied {applied}/{len(EDITS)} edits. Remaining send_result: {remaining}")
print(f"Line endings: {'CRLF' if has_crlf else 'LF'}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+10 -10
View File
@@ -2342,7 +2342,7 @@ def _send_grok(md_content: str, user_message: str, base_dir: str,
Result[str]: Wrap of string response and potential errors. Result[str]: Wrap of string response and potential errors.
Immediate-Mode DAG / Thread Context: Immediate-Mode DAG / Thread Context:
Called by: send_result Called by: send
Calls: _ensure_grok_client, _get_deepseek_tools, get_capabilities, run_with_tool_loop Calls: _ensure_grok_client, _get_deepseek_tools, get_capabilities, run_with_tool_loop
SSDL: SSDL:
@@ -2426,7 +2426,7 @@ def _send_minimax(md_content: str, user_message: str, base_dir: str,
Result[str]: Wrap of string response and potential errors. Result[str]: Wrap of string response and potential errors.
Immediate-Mode DAG / Thread Context: Immediate-Mode DAG / Thread Context:
Called by: send_result Called by: send
Calls: _ensure_minimax_client, _repair_minimax_history, _get_deepseek_tools, Calls: _ensure_minimax_client, _repair_minimax_history, _get_deepseek_tools,
get_capabilities, run_with_tool_loop get_capabilities, run_with_tool_loop
@@ -2581,7 +2581,7 @@ def _send_qwen(md_content: str, user_message: str, base_dir: str,
Result[str]: Wrap of string response and potential errors. Result[str]: Wrap of string response and potential errors.
Immediate-Mode DAG / Thread Context: Immediate-Mode DAG / Thread Context:
Called by: send_result Called by: send
Calls: _ensure_qwen_client, _dashscope_call Calls: _ensure_qwen_client, _dashscope_call
SSDL: SSDL:
@@ -2666,7 +2666,7 @@ def _send_llama(md_content: str, user_message: str, base_dir: str,
Result[str]: Wrap of string response and potential errors. Result[str]: Wrap of string response and potential errors.
Immediate-Mode DAG / Thread Context: Immediate-Mode DAG / Thread Context:
Called by: send_result Called by: send
Calls: _send_llama_native, _ensure_llama_client, _get_deepseek_tools, Calls: _send_llama_native, _ensure_llama_client, _get_deepseek_tools,
get_capabilities, run_with_tool_loop get_capabilities, run_with_tool_loop
@@ -2935,7 +2935,7 @@ def get_token_stats(md_content: str) -> dict[str, Any]:
} }
return _add_bleed_derived(stats, sys_tok=total_tokens) return _add_bleed_derived(stats, sys_tok=total_tokens)
def send_result( def send(
md_content: str, md_content: str,
user_message: str, user_message: str,
base_dir: str = ".", base_dir: str = ".",
@@ -2989,10 +2989,10 @@ def send_result(
Acquires the global _send_lock to synchronize provider calls. Safely called from any worker Acquires the global _send_lock to synchronize provider calls. Safely called from any worker
thread executing background tasks, preventing concurrent thread collisions on shared provider SDK states. thread executing background tasks, preventing concurrent thread collisions on shared provider SDK states.
[C: tests/test_ai_client_result.py:test_send_result_public_api_returns_result, tests/test_ai_client_result.py:test_send_result_preserves_errors, tests/test_deprecation_warnings.py:test_send_result_does_not_emit_deprecation] [C: tests/test_ai_client_result.py:test_send_public_api_returns_result, tests/test_ai_client_result.py:test_send_preserves_errors, tests/test_deprecation_warnings.py:test_send_does_not_emit_deprecation]
""" """
monitor = performance_monitor.get_monitor() monitor = performance_monitor.get_monitor()
if monitor.enabled: monitor.start_component("ai_client.send_result") if monitor.enabled: monitor.start_component("ai_client.send")
if rag_engine and getattr(rag_engine.config, "enabled", False) and "## Retrieved Context" not in user_message: if rag_engine and getattr(rag_engine.config, "enabled", False) and "## Retrieved Context" not in user_message:
chunks = rag_engine.search(user_message) chunks = rag_engine.search(user_message)
@@ -3053,10 +3053,10 @@ def send_result(
stream, pre_tool_callback, qa_callback, stream_callback, patch_callback stream, pre_tool_callback, qa_callback, stream_callback, patch_callback
) )
else: else:
res = Result(data="", errors=[ErrorInfo(kind=ErrorKind.CONFIG, message=f"unknown provider: {_provider}", source="ai_client.send_result")]) res = Result(data="", errors=[ErrorInfo(kind=ErrorKind.CONFIG, message=f"unknown provider: {_provider}", source="ai_client.send")])
except Exception as exc: except Exception as exc:
res = Result(data="", errors=[ErrorInfo(kind=ErrorKind.INTERNAL, message=str(exc), source="ai_client.send_result", original=exc)]) res = Result(data="", errors=[ErrorInfo(kind=ErrorKind.INTERNAL, message=str(exc), source="ai_client.send", original=exc)])
if monitor.enabled: monitor.end_component("ai_client.send_result") if monitor.enabled: monitor.end_component("ai_client.send")
return res return res
def _add_bleed_derived(d: dict[str, Any], sys_tok: int = 0, tool_tok: int = 0) -> dict[str, Any]: def _add_bleed_derived(d: dict[str, Any], sys_tok: int = 0, tool_tok: int = 0) -> dict[str, Any]: