Parallelize repeated `retrieve-repeat3` tool calls
3 repeated calls. Repeated tool calls may be candidates for concurrent execution. Verify output independence and shared-state safety before changing them.
- Investigation priority
- 8
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
+inferred evidencelow confidenceInvestigate repeated `retrieve-repeat3` tool calls
3 repeated calls. The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Investigation priority
- 8
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
"automatic_application_allowed": false,
"components": {
"confidence": {
"kind": "declared",
- "source_ref": "rule:parallelize_tools:1.1",
+ "source_ref": "rule:parallelize_tools:1.2",
"value": "low"
},
"cost": {
@@ -1288,7 +1288,7 @@ Longest recorded spans
Bottlenec
"validation_cost_usd",
"validation_effort_minutes"
]
-}- Finding ID
- al_parallelize_tools_21b66313a1f3
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- After verifying output independence and shared-state safety, use asyncio.gather or ThreadPoolExecutor and validate the change with replay.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat3, evt_quickstart_02-repeat3, evt_quickstart_03-repeat3
Estimator, assumptions, and observed inputs
{
+}- Finding ID
- al_parallelize_tools_21b66313a1f3
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat3, evt_quickstart_02-repeat3, evt_quickstart_03-repeat3
Estimator, assumptions, and observed inputs
{
"assumptions": [
"No call consumes another call's output.",
"Calls do not conflict through shared mutable state.",
@@ -1349,12 +1349,12 @@ Longest recorded spans
Bottlenec
"status": "ok"
}
]
-inferred evidencelow confidenceParallelize repeated `retrieve-repeat1` tool calls
3 repeated calls. Repeated tool calls may be candidates for concurrent execution. Verify output independence and shared-state safety before changing them.
- Investigation priority
- 9
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
+inferred evidencelow confidenceInvestigate repeated `retrieve-repeat1` tool calls
3 repeated calls. The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Investigation priority
- 9
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
"automatic_application_allowed": false,
"components": {
"confidence": {
"kind": "declared",
- "source_ref": "rule:parallelize_tools:1.1",
+ "source_ref": "rule:parallelize_tools:1.2",
"value": "low"
},
"cost": {
@@ -1446,7 +1446,7 @@ Longest recorded spans
Bottlenec
"validation_cost_usd",
"validation_effort_minutes"
]
-}- Finding ID
- al_parallelize_tools_2c1a691fb06a
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- After verifying output independence and shared-state safety, use asyncio.gather or ThreadPoolExecutor and validate the change with replay.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat1, evt_quickstart_02-repeat1, evt_quickstart_03-repeat1
Estimator, assumptions, and observed inputs
{
+}- Finding ID
- al_parallelize_tools_2c1a691fb06a
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat1, evt_quickstart_02-repeat1, evt_quickstart_03-repeat1
Estimator, assumptions, and observed inputs
{
"assumptions": [
"No call consumes another call's output.",
"Calls do not conflict through shared mutable state.",
@@ -1507,12 +1507,12 @@ Longest recorded spans
Bottlenec
"status": "ok"
}
]
-inferred evidencelow confidenceParallelize repeated `retrieve-repeat4` tool calls
3 repeated calls. Repeated tool calls may be candidates for concurrent execution. Verify output independence and shared-state safety before changing them.
- Investigation priority
- 10
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
+inferred evidencelow confidenceInvestigate repeated `retrieve-repeat4` tool calls
3 repeated calls. The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Investigation priority
- 10
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
"automatic_application_allowed": false,
"components": {
"confidence": {
"kind": "declared",
- "source_ref": "rule:parallelize_tools:1.1",
+ "source_ref": "rule:parallelize_tools:1.2",
"value": "low"
},
"cost": {
@@ -1604,7 +1604,7 @@ Longest recorded spans
Bottlenec
"validation_cost_usd",
"validation_effort_minutes"
]
-}- Finding ID
- al_parallelize_tools_4daf13a58672
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- After verifying output independence and shared-state safety, use asyncio.gather or ThreadPoolExecutor and validate the change with replay.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat4, evt_quickstart_02-repeat4, evt_quickstart_03-repeat4
Estimator, assumptions, and observed inputs
{
+}- Finding ID
- al_parallelize_tools_4daf13a58672
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat4, evt_quickstart_02-repeat4, evt_quickstart_03-repeat4
Estimator, assumptions, and observed inputs
{
"assumptions": [
"No call consumes another call's output.",
"Calls do not conflict through shared mutable state.",
@@ -1665,12 +1665,12 @@ Longest recorded spans
Bottlenec
"status": "ok"
}
]
-inferred evidencelow confidenceParallelize repeated `retrieve` tool calls
3 repeated calls. Repeated tool calls may be candidates for concurrent execution. Verify output independence and shared-state safety before changing them.
- Investigation priority
- 11
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
+inferred evidencelow confidenceInvestigate repeated `retrieve` tool calls
3 repeated calls. The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Investigation priority
- 11
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
"automatic_application_allowed": false,
"components": {
"confidence": {
"kind": "declared",
- "source_ref": "rule:parallelize_tools:1.1",
+ "source_ref": "rule:parallelize_tools:1.2",
"value": "low"
},
"cost": {
@@ -1762,7 +1762,7 @@ Longest recorded spans
Bottlenec
"validation_cost_usd",
"validation_effort_minutes"
]
-}- Finding ID
- al_parallelize_tools_6a08b742dfb3
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- After verifying output independence and shared-state safety, use asyncio.gather or ThreadPoolExecutor and validate the change with replay.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01, evt_quickstart_02, evt_quickstart_03
Estimator, assumptions, and observed inputs
{
+}- Finding ID
- al_parallelize_tools_6a08b742dfb3
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01, evt_quickstart_02, evt_quickstart_03
Estimator, assumptions, and observed inputs
{
"assumptions": [
"No call consumes another call's output.",
"Calls do not conflict through shared mutable state.",
@@ -1823,12 +1823,12 @@ Longest recorded spans
Bottlenec
"status": "ok"
}
]
-inferred evidencelow confidenceParallelize repeated `retrieve-repeat2` tool calls
3 repeated calls. Repeated tool calls may be candidates for concurrent execution. Verify output independence and shared-state safety before changing them.
- Investigation priority
- 12
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
+inferred evidencelow confidenceInvestigate repeated `retrieve-repeat2` tool calls
3 repeated calls. The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Investigation priority
- 12
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
"automatic_application_allowed": false,
"components": {
"confidence": {
"kind": "declared",
- "source_ref": "rule:parallelize_tools:1.1",
+ "source_ref": "rule:parallelize_tools:1.2",
"value": "low"
},
"cost": {
@@ -1920,7 +1920,7 @@ Longest recorded spans
Bottlenec
"validation_cost_usd",
"validation_effort_minutes"
]
-}- Finding ID
- al_parallelize_tools_7d06d1a068ee
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- After verifying output independence and shared-state safety, use asyncio.gather or ThreadPoolExecutor and validate the change with replay.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat2, evt_quickstart_02-repeat2, evt_quickstart_03-repeat2
Estimator, assumptions, and observed inputs
{
+}- Finding ID
- al_parallelize_tools_7d06d1a068ee
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat2, evt_quickstart_02-repeat2, evt_quickstart_03-repeat2
Estimator, assumptions, and observed inputs
{
"assumptions": [
"No call consumes another call's output.",
"Calls do not conflict through shared mutable state.",
@@ -1981,12 +1981,12 @@ Longest recorded spans
Bottlenec
"status": "ok"
}
]
-inferred evidencelow confidenceParallelize repeated `retrieve-repeat0` tool calls
3 repeated calls. Repeated tool calls may be candidates for concurrent execution. Verify output independence and shared-state safety before changing them.
- Investigation priority
- 13
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
+inferred evidencelow confidenceInvestigate repeated `retrieve-repeat0` tool calls
3 repeated calls. The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Investigation priority
- 13
- Test readiness
- needs evidence or review
- Why
- confidence weak or unknown; cost opportunity unavailable; evidence weak or unknown; missing input:quality risk; missing input:reversible; missing input:validation cost usd; missing input:validation effort minutes
Ranking components, input references and ordering
{
"automatic_application_allowed": false,
"components": {
"confidence": {
"kind": "declared",
- "source_ref": "rule:parallelize_tools:1.1",
+ "source_ref": "rule:parallelize_tools:1.2",
"value": "low"
},
"cost": {
@@ -2078,7 +2078,7 @@ Longest recorded spans
Bottlenec
"validation_cost_usd",
"validation_effort_minutes"
]
-}- Finding ID
- al_parallelize_tools_8542ede550f6
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- After verifying output independence and shared-state safety, use asyncio.gather or ThreadPoolExecutor and validate the change with replay.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat0, evt_quickstart_02-repeat0, evt_quickstart_03-repeat0
Estimator, assumptions, and observed inputs
{
+}- Finding ID
- al_parallelize_tools_8542ede550f6
- Estimated latency savings
- 360.000 ms
- Estimated cost savings
- $0.0000
- Proposed change
- The tool name repeats in the same scope. Compare inputs and check dependencies and shared state before changing the calls.
- Validation
- runtime decreases while tool outputs remain equivalent
Evidence spans: evt_quickstart_01-repeat0, evt_quickstart_02-repeat0, evt_quickstart_03-repeat0
Estimator, assumptions, and observed inputs
{
"assumptions": [
"No call consumes another call's output.",
"Calls do not conflict through shared mutable state.",
diff --git a/tests/test_parallelization_evidence.py b/tests/test_parallelization_evidence.py
index 0ee5eba..45b0964 100644
--- a/tests/test_parallelization_evidence.py
+++ b/tests/test_parallelization_evidence.py
@@ -8,6 +8,7 @@
from agentloop.findings import build_diagnosis, diagnosis_to_markdown
from agentloop.graph import ExecutionEdge, ExecutionGraph
from agentloop.optimizer import build_optimization_plan
+from agentloop.patches import build_patch_plan
from agentloop.plan_export import export_optimization_markdown
from agentloop.tracer import AgentTrace
@@ -51,6 +52,48 @@ def test_repeated_names_are_inferred_candidates_with_explicit_assumptions():
assert group["estimated_savings_ms"] == 200
assert "serial and independent" not in card["why"]
assert "appear independent" not in str(report["recommendations"])
+ assert card["title"] == "Investigate repeated `search` tool calls"
+ assert "Compare inputs" in card["rewrite_hint"]
+
+
+def test_declared_identical_read_only_work_prefers_request_local_reuse(tmp_path):
+ metadata = {"read_only": True, "tool_reuse_key": "opaque-test-key", "parallel_safe": True}
+ trace = _trace(intervals=[(100, 220), (0, 100), (220, 300)], metadata=[metadata] * 3)
+ card = trace.report()["finding_candidates"][0]
+ assert card["observations"]["recommended_action"] == "test_request_local_reuse"
+ assert card["observations"]["retained_span_id"] == "tool-1"
+ assert card["estimated_latency_savings_ms"] == 200
+ assert card["estimate"]["estimator_id"] == "request_local_tool_reuse"
+ assert card["estimate"]["inputs"]["retained_duration_ms"] == 100
+ assert card["estimate"]["formula"] == "sum_duration_ms - retained_duration_ms"
+ assert "opaque-test-key" not in str(card)
+ [patch] = build_patch_plan(trace, repo_path=tmp_path, allowed_root=tmp_path)["patch_plans"]
+ assert "reusing the first result" in patch["proposed_rewrite"]
+ assert "asyncio.gather" not in str(patch)
+
+
+@pytest.mark.parametrize(
+ "change",
+ [
+ {"read_only": False},
+ {"read_only": 1},
+ {"tool_reuse_key": "other"},
+ {"tool_reuse_key": " "},
+ {"tool_reuse_key": ["opaque"]},
+ ],
+)
+def test_uncertain_reuse_remains_an_investigation(change):
+ metadata = {"read_only": True, "tool_reuse_key": "opaque"}
+ trace = _trace(metadata=[metadata, metadata, {**metadata, **change}])
+ [card] = trace.report()["finding_candidates"]
+ assert card["observations"]["recommended_action"] == "inspect_repetition"
+
+
+def test_failed_call_does_not_support_result_reuse():
+ trace = _trace(metadata=[{"read_only": True, "tool_reuse_key": "opaque"}] * 3)
+ trace.events[0].status = "error"
+ [card] = trace.report()["finding_candidates"]
+ assert card["observations"]["recommended_action"] == "inspect_repetition"
def test_declared_concurrency_safety_is_distinct_from_verified_evidence():
diff --git a/tests/test_patch_plan.py b/tests/test_patch_plan.py
index 756ff33..8af2d54 100644
--- a/tests/test_patch_plan.py
+++ b/tests/test_patch_plan.py
@@ -26,7 +26,7 @@ def plan():
with trace_agent("patchable") as trace:
for _ in range(3):
- with trace_tool_call("read_source"):
+ with trace_tool_call("read_source", metadata={"parallel_safe": True}):
pass
repeated = "same stable instruction " * 100
with trace_model_call("plan", input_text=repeated, output_tokens=1):