Skip to content

Multi-tier framework for evaluating AI agent skills and plugins with quality gates, security scanning, harness compatibility checks, semantic overlap detection, synthetic evaluation dataset generation, and live agent evaluation that measures how skills affect agent behavior. Ships reusable CI templates that bring every check to any repository.

perf(tier3): index Claude tool results by call ID (#733)

Afloatf7c174ea460a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0cc97384..813033ca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@ All notable changes to SkillEvaluator are documented in this file.
## Unreleased
+### Changed
+
+- Claude Code log recovery pairs batched and delayed tool results without repeatedly
+ scanning earlier tool calls, reducing reconstruction time for long trajectories.
+
### Documentation
- Add a README badge linking to the reusable GitHub and GitLab CI templates,
diff --git a/src/skillevaluator/tier3/eval_core/log_converters.py b/src/skillevaluator/tier3/eval_core/log_converters.py
index 2effe9db..2e74e37c 100644
--- a/src/skillevaluator/tier3/eval_core/log_converters.py
+++ b/src/skillevaluator/tier3/eval_core/log_converters.py
@@ -55,26 +55,24 @@ def _stringify_tool_result_content(content: Any) -> str:
def _attach_tool_result(
- steps: list[dict[str, Any]], tool_use_id: str, content_text: str, *, is_error: bool = False
+ steps_by_call_id: dict[str, dict[str, Any]], tool_use_id: str, content_text: str, *, is_error: bool = False
) -> None:
- for step in reversed(steps):
- if step.get("source") != "agent":
- continue
- for tc in step.get("tool_calls") or []:
- if tc.get("tool_call_id") == tool_use_id:
- step.setdefault("observation", {"results": []})
- step["observation"].setdefault("results", [])
- result: dict[str, Any] = {"source_call_id": tool_use_id, "content": content_text}
- if is_error:
- # Match Harbor's native Claude Code ATIF result metadata.
- result["extra"] = {"tool_result_is_error": True}
- step["observation"]["results"].append(result)
- return
+ step = steps_by_call_id.get(tool_use_id)
+ if step is None:
+ return
+ step.setdefault("observation", {"results": []})
+ step["observation"].setdefault("results", [])
+ result: dict[str, Any] = {"source_call_id": tool_use_id, "content": content_text}
+ if is_error:
+ # Match Harbor's native Claude Code ATIF result metadata.
+ result["extra"] = {"tool_result_is_error": True}
+ step["observation"]["results"].append(result)
def synthetic_trajectory_from_claude_stream_jsonl(text: str) -> dict[str, Any] | None:
"""Parse Claude Code ``--output-format stream-json`` lines (tee'd to claude-code.txt)."""
steps: list[dict[str, Any]] = []
+ steps_by_call_id: dict[str, dict[str, Any]] = {}
for raw_line in text.splitlines():
line = raw_line.strip()
if not line:
@@ -145,6 +143,10 @@ def synthetic_trajectory_from_claude_stream_jsonl(text: str) -> dict[str, Any] |
"observation": {"results": []},
}
)
+ for call in tool_calls:
+ if call["tool_call_id"]:
+ # Reused IDs belong to the latest preceding step, as in the reverse scan.
+ steps_by_call_id[call["tool_call_id"]] = steps[-1]
elif et == "user":
msg = evt.get("message")
@@ -159,7 +161,7 @@ def synthetic_trajectory_from_claude_stream_jsonl(text: str) -> dict[str, Any] |
tid = str(block.get("tool_use_id") or "")
res_text = _stringify_tool_result_content(block.get("content"))
if tid:
- _attach_tool_result(steps, tid, res_text, is_error=block.get("is_error") is True)
+ _attach_tool_result(steps_by_call_id, tid, res_text, is_error=block.get("is_error") is True)
elif et == "result":
res = evt.get("result")
diff --git a/tests/tier3/test_claude_tool_result_pairing.py b/tests/tier3/test_claude_tool_result_pairing.py
new file mode 100644
index 00000000..20d6e1f3
--- /dev/null
+++ b/tests/tier3/test_claude_tool_result_pairing.py
@@ -0,0 +1,87 @@
+# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+
+"""Claude result lookup must preserve chronological pairing and evidence ordering."""
+
+import json
+
+import pytest
+
+from skillevaluator.tier3.eval_core.log_converters import synthetic_trajectory_from_claude_stream_jsonl
+
+
+def _message(role, content):
+ return {"type": role, "message": {"content": content}}
+
+
+def _call(call_id, path="file.md"):
+ return {"type": "tool_use", "id": call_id, "name": "Read", "input": {"file_path": path}}
+
+
+def _result(call_id, content, **extra):
+ return {"type": "tool_result", "tool_use_id": call_id, "content": content, **extra}
+
+
+def _trajectory(*events):
+ return synthetic_trajectory_from_claude_stream_jsonl("\n".join(json.dumps(event) for event in events))
+
+
+def test_delayed_out_of_order_and_repeated_results_keep_their_steps():
+ trajectory = _trajectory(
+ _message("assistant", [_call("a"), _call("b")]),
+ _message("assistant", "progress update"),
+ _message("assistant", [_call("c")]),
+ _message(
+ "user",
+ [
+ _result("b", "failed", is_error=True),
+ _result("c", [{"type": "text", "text": "third"}]),
+ _result("a", "first"),
+ _result("b", "retry result"),
+ ],
+ ),
+ {"type": "result", "result": "finished"},
+ )
+
+ steps = trajectory["steps"]
+ assert len(steps) == 4
+ assert steps[0]["observation"]["results"] == [
+ {"source_call_id": "b", "content": "failed", "extra": {"tool_result_is_error": True}},
+ {"source_call_id": "a", "content": "first"},
+ {"source_call_id": "b", "content": "retry result"},
+ ]
+ assert steps[1]["message"] == "progress update"
+ assert steps[1]["observation"]["results"] == []
+ assert steps[2]["observation"]["results"] == [{"source_call_id": "c", "content": "third"}]
+ assert steps[3]["message"] == "finished"
+ assert steps[3]["observation"]["results"] == []
+
+
+def test_reused_ids_attach_once_to_the_latest_preceding_step():
+ trajectory = _trajectory(
+ _message("user", [_result("same", "too early")]),
+ _message("assistant", [_call("same", "old.md"), _call("same", "duplicate.md")]),
+ _message("user", [_result("same", "old result")]),
+ _message("assistant", [_call("same", "new.md"), _call("")]),
+ _message("user", [_result("same", "new result"), _result("unknown", "orphan"), _result("", "empty")]),
+ )
+
+ first, second = trajectory["steps"]
+ assert len(first["tool_calls"]) == 2
+ assert first["observation"]["results"] == [{"source_call_id": "same", "content": "old result"}]
+ assert second["tool_calls"][0]["arguments"]["path"] == "new.md"
+ assert second["observation"]["results"] == [{"source_call_id": "same", "content": "new result"}]
+
+
[email protected]("reverse", [False, True])
+def test_batched_calls_keep_result_order(reverse):
+ ids = [f"call-{index}" for index in range(256)]
+ result_ids = list(reversed(ids)) if reverse else ids
+ trajectory = _trajectory(
+ _message("assistant", [_call(call_id) for call_id in ids]),
+ _message("user", [_result(call_id, f"result {call_id}") for call_id in result_ids]),
+ )
+
+ assert trajectory["steps"][0]["observation"]["results"] == [
+ {"source_call_id": call_id, "content": f"result {call_id}"} for call_id in result_ids
+ ]