Repository navigation
fix(optimization): compact result.json with transcripts referenced by hash - #610
Conversation
|
This change shouldn't affect search behaviors but the evaluation reports no longer hold actual trajectory. Users also need the transcript folder to be able to see them. Is this a valid trade-off? |
360a182 to
7a5ab1b
Compare
7a5ab1b to
bb7e047
Compare
|
Rebased onto Hashes come from each record's own transcript. #608 keeps a pointer ( New public method: Behavior changes: as described, except that the optimizer is now on Tests:
|
bb7e047 to
cd04d34
Compare
… hash result.json held every trial's trajectory again: each row of OptimizationResult.reports inlined the trial's Session (or list) in actual_trajectory, once per evaluator, although the run directory already stores each trajectory once in transcripts/<hash>.json. It was also indented, which roughly doubles the size of nested span data. On a 1,728-trial scripted run the file was 7.4 MB; it is now 2.0 MB. Report rows now have actual_trajectory=None and a transcript tag holding the same hash as the case rows, read through one helper so the two views agree. Both views name a transcript only when the trial record they show holds a trajectory: after a resume, a trial's last event can be a killed iteration's successful re-run while the record kept is the failed one. save_result and OptimizationResult.to_file write compact JSON. from_file needs no change; results written before this change still load.
cd04d34 to
0dd05f7
Compare
|
Assessment: Comment This review covers head Review Categories
The new tests are thorough, especially the resume and moved-folder cases. |
|
Re-review of Compared with |
|
Re-review of The duplicated-decoding comment is fixed: both readers now call one
As before, I reviewed this by reading the code; I couldn't run tests or lint here. |
Description
<run>/result.jsonholds the wholeOptimizationResult. Two things make it much larger than the data it carries:result.reports[candidate][split].casesfor each completed trial is itsEvaluationDatadump, and itsactual_trajectoryinlines the trial's whole trajectory (aSessionof spans, or the list a rollout returned). There is one row per evaluator per trial, so each trajectory is written once per evaluator. The run directory already stores each trajectory once intranscripts/<hash>.json, and the case rows (result.to_rows("case")) already name that file in theirtranscriptcolumn.save_resultandOptimizationResult.to_filepretty-print withindent=2, which roughly doubles the size of the nested span data.On a run of a real
Agentwith a scripted model (1,728 trials, one evaluator, 10 iterations),result.jsonwas 7.4 MB. Written compact it would be 3.7 MB, of which 1.75 MB is the inlinedSessiontrajectories. Longer conversations and more evaluators make the inlined copies a larger share of the file.This PR:
actual_trajectory=Noneand adds atranscripttag besideevaluator,evaluator_typeandrun_index. The tag holds the same hash as the case row for that trial, or None when the trial record holds no trajectory. Both views get the hash from the same helper, so they always agree;trialevent for a trial can be a killed iteration's successful re-run, while the record the resumed run keeps is the failed one from the closed iterations;result.json(RunDirectory.save_result) andOptimizationResult.to_fileas compact JSON.run.json,effects.jsonand the.values.jsonfiles stay indented, since they are small and meant to be read by people.The same run's
result.jsonis now 2.0 MB. What remains grows with the number of report rows (trials times evaluators), not with the length of the trajectories. Each row still repeats the case input, the output, and any interactions and environment state; this PR does not change that.Behavior changes (the optimizer has not been released yet; it is only on
workstream/optimizer-workflow):result.reportsno longer carries trajectories, either in the returned result or afterfrom_file. A trajectory is read fromrun_dir / "transcripts" / f"{row['transcript']}.json", so reading one needs the run folder.EvaluationReport.display(include_actual_trajectory=True)on these reports shows None.transcriptkey.result.jsonandto_fileoutput are a single line of compact JSON.OptimizationResult.from_fileneeds no change. It loads the new files, still loads a result written before this change (indented, trajectories inline), and still needs no run folder.Related Issues
Part of #442. The result and its reports were added in #535.
Documentation PR
None
Type of Change
Bug fix
Testing
New
test_the_result_names_each_trajectory_by_its_transcript_hash_and_is_written_compactruns with two evaluators and two runs per case, with a rollout that returns a distinct list trajectory per trial, raises on one case and returns no trajectory on another. It checks thatresult.jsonholds no trajectory text and is compact, thatto_filewrites the same bytes, that every report row has no inline trajectory and carries the case row's hash (None for the crashed and the bare case), that each named file holds that trial's trajectory, thatfrom_filegives back an equal result, and that an indented result with inline trajectories still loads.New
test_a_finished_run_resumed_rewrites_the_same_transcript_hasheschecks that resuming the finished run rewritesresult.jsonwith the same reports.New
test_a_failed_record_kept_on_resume_names_no_transcript_of_a_killed_rerunkills a run after a step re-ran a candidate's failed trials and resumes it with a different proposal. That candidate's failed rows name no transcript in either view.New smoke scenario
test_the_result_names_each_session_transcript_by_its_hashruns a realAgenton a scripted model and checks that noSessionis inlined inresult.jsonand that each report row's transcript file holds that trial'sSession.test_reports_match_what_experiment_returns_for_the_same_trialsnow also drops the newtranscripttag before comparing withExperiment's rows, and checks that the tag is None when the rollout saves no trajectory.test_effects_diffs_and_the_result_are_writtennow checks the exact compact textsave_resultwrites.All of the above fail on the base branch.
pytest tests/strands_evals/optimization tests/strands_evals/types/optimizationgives 1,460 passed and 1 xfailed (1,456 passed and 1 xfailed on the base branch).ruff checkandruff format --checkon the changed files pass.mypy -p strands_evals.optimizationreports no errors in the optimization modules; the 23 errors it reports elsewhere are the same on the base branch.I ran
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.