Repository navigation
feat(tier3): split measured agent time into LLM and tool seconds - #344
Merged
Merged
Conversation
Add trajectory_timing(), which splits one ATIF trajectory's time into LLM seconds and tool seconds and tags the result with its source. Native ATIF timing extras win when present (source atif). Otherwise the split is inferred from step timestamps plus the Wall time header that Codex writes for its shell tools and apply_patch, or the duration_seconds Harbor keeps in their tool metadata (source step_timestamps). Each timestamp gap counts once, parallel calls count their longest call, and each Harbor step of a merged multi-step trajectory is timed on its own. Unmeasured tools, untrusted or inconsistent evidence leave the trial unmeasured instead of zero. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Record each single-row trial's trajectory timing and extend resource_comparison with llm_seconds, tool_seconds and llm_ms_per_token, under the existing complete-arm and matching-case rules. The resources object also lists the timing sources per arm and flags mixed_timing_sources. The HTML Measured Agent Resources table gets the new rows and a timing-source line per agent. Scores, verdicts and gates do not change. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
rng1995
commented
Nov 5, 2026
rng1995
left a comment
Collaborator
Author
There was a problem hiding this comment.
Automated review: 3 findings (0 P1, 0 P2, 3 P3); 2 posted inline.
Findings outside the diff or about the description:
/Users/nraghavan/work/se-port-2026-10-28/prs/W64.md:50: P3: The PR text still has an unfilled template placeholder. Line 50 reads '- On the branch: TEST_SUMMARY', so the ## Tests section of public PR #344 has no exact count for the branch run, which the W47 style requires. The other count claims are correct: 50 tests in test_trajectory_timing.py, +22 in test_resource_usage.py (40 vs 18 on main), +3 in test_resource_comparison.py, and the fail-before results reproduce.
Suggested fix: Replace the placeholder with the measured result, for example '- On the branch: the three changed test files pass (95 passed), and 29 test files that touch resources, load_agent_data or _normalize_trials pass.' Then update the #344 body from this file.
Steps marked is_copied_context repeat work from an earlier trajectory. Timing them counted their tool time again, counted the gap after a copied step as LLM time, and summed copied native llm_duration_ms twice. Drop each Harbor step's copied prefix before choosing a timing source, and leave the trial unmeasured when a copied step follows new work or a Harbor step has only copied steps. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the CHANGELOG.md conflict by keeping the new main entries and this branch's entry in the existing Unreleased > Added subsection. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
rng1995
marked this pull request as ready for review
November 5, 2026 18:29
rng1995
requested review from
chrisknvidia,
mosheabr and
rmalani-nv
as code owners
November 5, 2026 18:29
…t starts with an agent step After a Harbor step's is_copied_context prefix is dropped, its first new step starts the timing. When that step is an agent response, no new timestamp shows when the model started it, so the model time of the first response was silently left out while the trial was still reported as measured. Inferred timing now leaves the trial unmeasured in that case. A new user or system step after the copied steps still starts the timing, and native llm_duration_ms timing is unaffected because it does not depend on step gaps. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the docs/reports.mdx conflict: keep this PR's LLM and tool timing table and notes at the end of "Measured agent resources", followed by main's new "Failure reasons and per-trial rows" section (#305). Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Narendran Raghavan <[email protected]>
rng1995
enabled auto-merge (squash)
November 5, 2026 22:25
rng1995
added a commit
that referenced
this pull request
Nov 6, 2026
The bridge_services fixture probes /healthz until the bridge answers. The probe's server worker can still be finishing after urllib has read the response, so under CI load a test could start with one worker already active. test_slow_drip_request_line_and_headers_obey_an_absolute_deadline then counted that worker next to its own connection and failed with 'assert 2 == 1' (seen on PRs #306 and #344). Wait for the bridge's workers to drain before yielding the fixture. Signed-off-by: Narendran Raghavan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Nov 6, 2026
Collaborator
Author
|
Post-merge review: 2 finding(s) (P3). Follow-up PR: #365.
🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
skillevaluator/tier3/harbor/trajectory_timing.py.trajectory_timing(trajectory)returns{"llm_seconds", "tool_seconds", "source"}for one Harbor ATIF trajectory, orNone. It uses one of two sources and never mixes them within a trajectory:atif(native timing extras): LLM time is the sum ofstep.extra.llm_duration_ms, only when every agent step has it. Tool time is the union oftool_calls[].extrastarted_at/ended_atintervals, so overlapping calls count once, plusduration_msfor calls without an interval, only when every call is timed. When any native extra is present, nothing is inferred.step_timestamps(inferred): each gap between consecutive step timestamps is counted once. Tool time for a step is the wall time of its calls, and parallel calls count their longest. The rest of the gap is LLM time, which then also includes harness and queue time. Call wall time comes from theWall time: N secondsline that Codex writes in the header of its shell tool output (exec_command,write_stdin,wait,wait_command,shell,shell_command) andapply_patchoutput, or from theduration_secondsthat Harbor keeps in the structured tool metadata of those calls.Output:line, so command output cannot supply a duration. A header with twoWall timelines, a wall time over 24 hours, a duplicate call id, tool time longer than the gap after its step, missing or naive (no UTC offset) or backwards timestamps, or a trailing tool step all leave the trial unmeasured. A call to any other tool (update_plan, web search, MCP tools, Claude CodeBash...) has no measured duration, so the whole trial stays unmeasured. A trajectory with no tool calls measures 0 tool seconds.extra.harbor_step_nameand each Harbor step is timed on its own, so verifier and setup time between steps is never counted.is_copied_contextrepeat earlier work, so each Harbor step's copied prefix is dropped before the timing source is chosen, as the collector already skips copied agent steps. A copied step after new steps, or a Harbor step with only copied steps, leaves the trial unmeasured. Copied timestamps do not show when the first new response started, so inferred timing also leaves the trial unmeasured when the new steps after a copied prefix start with an agent step. A new user or system step after the copied steps starts the timing as usual. Nativellm_duration_mstiming does not depend on step gaps, so it is not affected.load_agent_datacomputes the timing from the trialtrajectory.jsonit already loads for token counts, and_normalize_trialsrecords it astrial["timing"]for single-row trials.resource_comparisonaddsllm_seconds,tool_secondsandllm_ms_per_token(1000 × LLM seconds / (prompt + completion tokens), from complete arm totals with a positive token count) next totokensandagent_seconds. It also addstiming_sources(the sources each arm used),caveats(mixed_timing_sourceswhen an agent's trials mix native and inferred timing) and atiming_definitionstring. Totals are rounded to milliseconds.docs/reports.mdxdocuments the measures, sources, coverage rules and sign convention under "Measured agent resources".docs/tier3-live-evaluation.mdxpoints to it. CHANGELOG entry under Unreleased > Added.Why
The resources table shows whether a skill changes total tokens and agent execution seconds, but not whether the time went to the model or to tools. No Harbor 0.24 agent converter writes native ATIF timing extras. The Harbor 0.24 Codex converter does keep an ISO timestamp on every step and pairs each tool output with its call by
source_call_id, and Codex writes each call's wall time in its own output header. Inferring from those gives the default Codex agent real numbers. Native extras still take priority for agents that write them.Coverage is partial by design. A Codex trial that also calls
update_plan, web search or an MCP tool has no duration for that call, so it showsN/Arather than a guess. Claude Code trajectories with tool calls stayN/A. Timing is diagnostic only: scores, verdicts and gates do not change.Kept from public
resource_comparison's gating applies to the new measures unchanged: deltas only for complete arms with identicalentry_idcounts, JSON-safe finite non-negative values, and measured/total trial counts per arm. Missing timing staysnull(N/A), never zero.agent_secondsstill comes from Harbor'sresult.jsonagent_executionphase (timezone-aware, setup and verifier excluded) and remains the whole-agent wall time. The new timestamp parsing also rejects naive timestamps._load_bounded_jsonload of the redacted trialtrajectory.json. Redaction keeps step timestamps and theWall timeheader (tested). Trials whose trajectory was skipped (too large, or redaction or validation failed) have no timing, as the docs say._trajentry stays out ofraw_trial_rewards, and report-budget compaction of the embedded payload is unchanged. The per-trialtimingobject is three small fields.resourcesJSON object; no second latency section. CLI, Markdown andBENCHMARK.mdoutput are unchanged.Tests
tests/tier3/test_trajectory_timing.py(60 tests):Bashcall without a header, and a non-Codex tool with a Codex-style header, not inferredupdate_plan, web search, an MCP-style tool,execandview_imageleave the trial unmeasuredapply_patchwith a header counted; a bareapply_patchresult unmeasuredfunctions.shell_command) andwait_commandmeasuredwrite_stdinwith and without a Codex exec headertool_metadataduration_secondsused; a non-finite value rejectedgpt-5-mini), covering bundled steps withsource_call_id, parallel calls,shellmetadata and a free-formapply_patchcall; timing is the same after_redacted_trajectory_data, and removing one call's metadata leaves the trial unmeasured_merged_step_trajectory, timed per Harbor step; a continuation step does not count the gap before it; every Harbor step must be timedllm_duration_msand tool durations are not counted twice; native extras only on copied steps do not block inference; each Harbor step of a merged trial drops its own copied prefix; a copied step after new work, or only copied steps, give no timingtests/tier3/test_resource_usage.py(+22 test cases): timing validation and source tags; arm pairing and ms per token; millisecond rounding; tool totals require every trial; timing deltas without token counters; no deltas for partial or mismatched arms; missing timing is not zero; a measured zero is kept; mixed sources across and within arms flagged; consistent sources not flagged; invalid values (True,-1,"1.0", NaN, infinity, 10**1000,None) stay unavailable.tests/reporting/test_resource_comparison.py(+3 tests): realtrajectory.jsonfiles flow throughagent_eval_result_from_directorytotrial["timing"],resources, JSON and HTML (rows, deltas with percentages, timing-source line); an unmeasured arm showsN/Awith no delta; mixed sources show the caveat.origin/mainsrc,test_resource_comparison.pyhas 3 failed, 2 passed (KeyError: 'timing'andKeyError: 'llm_seconds'), andtest_trajectory_timing.pyandtest_resource_usage.pyfail at import (trajectory_timingmodule andnormalized_trial_timingmissing). Before the copied-context fix, the 6 copied-context tests failed (for example 3601.0 LLM and 2.0 tool seconds instead of 4.0 and 1.0). Before the agent-first fix,test_new_work_that_starts_with_an_agent_step_after_copied_context_is_unmeasuredfailed (4.0 LLM and 1.0 tool seconds instead of no timing; 13.0 and 2.0 for the merged trial) and the other 59 passed.main: the three changed test files pass (105 passed). The 31 test files that mentionresources,load_agent_data,_normalize_trials,is_copied_contextor the new timing code give 2335 passed, 4 skipped and 2 failed (-n 8); the 2 failures aretest_sidecar_retains_*intests/test_harbor_secure_docker_environment.py, which fail the same way onmainin this local environment.ruff checkandruff format --checkare clean on the changed Python files.scripts/check_oss_boundary.pypassed.🤖 Generated with Claude Code