Skip to content

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

Merged
chrisknvidia merged 4 commits into
NVIDIA:mainfrom
Afloat16:perf/index-claude-tool-results
Nov 19, 2026
Merged

chrisknvidia merged 4 commits into
NVIDIA:mainfrom
Afloat16:perf/index-claude-tool-results

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Summary

Claude Code log recovery currently searches every preceding step and its tool calls for each tool result. A large batch of calls makes that repeated search quadratic.

Index the latest preceding assistant step by normalized call ID and attach results directly. Preserve delayed/out-of-order results, repeated results, reused IDs, orphan handling and observation order. The index holds references to existing steps and uses O(unique call IDs) additional entries.

Verification

  • python -m pytest tests/tier3/test_claude_tool_result_pairing.py tests/tier3/test_log_converters.py tests/test_harbor_collector_runtime_failures.py -q — 217 passed.
  • Four new regression cases cover delayed and out-of-order results, error evidence, reused IDs within/across steps, results before calls, orphan/empty IDs and both directions of a 256-call batch.
  • Compared complete old/new output dictionaries for 500 seeded mixed streams of 1–120 events; all were identical.
  • Whole-parser local benchmark, median of three runs per case (Python 3.12.14, synthetic public fixtures):
Batched tool calls Before After
500 0.004534 s 0.001034 s
2,000 0.053320 s 0.004523 s
5,000 0.353296 s 0.012363 s

The interleaved call/result control has small index overhead: 5,000 calls measured 0.030563 s before and 0.033816 s after. The gain is for batched/delayed results that previously required repeated long searches; these fixtures do not measure live model execution.

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Updated documentation for user-visible changes (Unreleased changelog)
  • Ran make lint equivalent: python -m ruff check src tests
  • Full make test did not complete successfully in this environment (see below)
  • Ran make build equivalent: python -m build (wheel and sdist)
  • Did not add credentials, private datasets, or proprietary benchmark content

The unchanged base 8fe9723, tested with python -m pytest -x -q, stops after 456 passed and 19 deselected at tests/ci/test_gateway_benchmark_workflows.py::test_gitlab_enriched_tier1_applies_the_keyless_job_baselines[extra0-expected0]. The sandbox has no /tmp, while that workflow fixture explicitly invokes mktemp -d /tmp/skillevaluator-enriched-tier1.XXXXXX. The same test fails for the same reason on the retry branch. No full-suite pass is claimed.

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I checked this two ways. First, equivalence: I ran the old and new Claude parser over 3000 randomly generated streams (mixed call/result order, repeated and reused IDs, empty and unknown IDs, string vs list results, error flags, string-only assistant messages, garbage lines) and the output dictionaries were identical every time. Second, timing: 5000 batched calls went from about 0.39 s to 0.016 s here, reversed order the same, and the interleaved case stayed flat, matching your table.

The new tests pass on main as well, which is what you want for a refactor like this; they pin the pairing rules rather than catch a bug, and that is fine. Two notes, neither blocking: this adds a line directly above the loop that #729 changes, so whichever lands second needs a small rebase; and a non-object JSON line still raises in both the old and new code, which #728 handles separately.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, @Afloat16. Reviewed afc218af51a0; no new actionable defects found. The call-ID index preserves chronological pairing, delayed/batched result order, reused IDs, unknown/empty IDs, and error metadata. Tool results still attach to the latest preceding matching step.

Validation: All 4 new pairing tests and 28 existing converter tests passed; 3,000 seeded random streams produced trajectories identical to the base parser.

The prior notes about adjacent parser work describe separate changes or pre-existing behavior; I found no regression introduced by this index.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Afloat16 for this contribution! I reviewed afc218af51. I reproduced the problem on main, confirmed this change fixes it, and ran the new and related tests on this head (all pass). I left 1 inline comment (1 P3); please take a look.

Comment thread CHANGELOG.md Resolved
Merge current main while retaining this change and the published release notes.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@Afloat16

Copy link
Copy Markdown
Contributor Author

Addressed in 03ac3b0: the tool-result indexing note is now in a new ### Changed subsection under ## Unreleased, with main's published release notes preserved. This PR's existing production and regression-test changes are preserved; the review follow-up is limited to changelog placement and the main merge. git diff --check passes. Hosted workflows remain awaiting maintainer approval.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Afloat16 for this contribution and for addressing the earlier review! I re-checked dc5f8e8b5f: all 1 earlier comment is resolved in the code, the tests pass, and I found nothing new. Approving.

@chrisknvidia
chrisknvidia merged commit f7c174e into NVIDIA:main Nov 19, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants