Skip to content

refactor(executors): stop copying files from outside a round into its run_dir; delete the leak harvest - #2927

Closed
ZhengGong-amd wants to merge 4 commits into
mainfrom
lean/zgong/leak-harvest
Closed

ZhengGong-amd wants to merge 4 commits into
mainfrom
lean/zgong/leak-harvest

Conversation

@ZhengGong-amd

@ZhengGong-amd ZhengGong-amd commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

refactor(executors): stop copying files from outside a round into its run_dir; delete the leak harvest

  • Description: what and why

    harvest_leaked_artifacts was written for a harness that could leave a round's server log, results and traces outside the round's workspace. Since feat(hyperloom): measure every round with InferenceSuite and remove Magpie #2614 every round runs on InferenceSuite, whose server, client, eval and profile all write below the round's run_dir, so there is nothing left to bring back. The harvest still ran. After every warmup and measured round of run_grid (explore, integrate, specialist rebench, concurrency sweep, multi-branch) it globbed the top level of /workspace, $INFERENCEX_PATH and $RESULT_DIR (or INFERENCE_OPTIMIZER_LEAK_ROOTS when set) and copied every server.log, gpu_metrics.csv, profile_*.trace.json.gz, inferencex_result*.json and results*.json modified since the round started into the round's run_dir. On a healthy host it found nothing. When another process wrote one of those names during the round, the copy replaced the round's own server.log, or put a foreign results*.json where the accuracy reader globs. The baseline, profile and roofline rounds never called it and have run without it since feat(hyperloom): measure every round with InferenceSuite and remove Magpie #2614.

    Removed:

    • harvest_leaked_artifacts and its helpers in executors/benchmark_result.py, its export from executors/__init__.py, and INFERENCE_OPTIMIZER_LEAK_ROOTS.
    • The measurement runner's call on its own work directory (measure/runner/run.py) and the leak root the local backend named for it (measure/local.py).
    • The leak-root pin that eleven test modules set only to keep the harvest from scraping the host.
    • The multi-node report injection the harvest ended with: _inject_gpu_monitor, _aggregate_gpu_samples_by_role, _row_to_gpu_sample, _MN_GPU_SAMPLE_CAP. It wrote gpu_monitor, pd and gpu_monitor_by_role into <round>/benchmark_report.json, a file no round has had since feat(hyperloom): measure every round with InferenceSuite and remove Magpie #2614, so it returned on its first line. The PD-disaggregation specialist prompt told the specialist to read gpu_monitor_by_role from the benchmark report; that sentence goes with it.
    • gpu/_gpu_metrics.write_gpu_metrics, the function that read benchmark_report.json from a workspace and wrote gpu_metrics.json from it. The harvest was its only production caller, and no round workspace has that file. gpu_metrics.json is still written exactly as before by RoundFolder.write_gpu_metrics → write_gpu_metrics_from_report, called from benchmark_run/launch.py (baseline arm) and grid/_round_report.py (grid arm); neither is changed.
    • Comments and docstrings that still described what is deleted: in gpu/_gpu_metrics.py and test_gpu_metrics.py, the ones that named _row_to_gpu_sample or called the pod-side sampler a producer of gpu_monitor; in telemetry/kv_record.py, the reference to _MN_GPU_SAMPLE_CAP; in breakdown/recorder/baseline_event.py, the warning cap's stated reason, "one per harvested artifact".

    Kept: harvest_mn_gpu_metrics still merges the pods' gpu_metrics_<host>.csv into <run_dir>/gpu_metrics.csv for every grid round that left a run_dir. It was called from inside the harvest; the grid now calls it where it reads the finished round (grid/_round_report._settled_measurement). The harvest wrapped that call in except (OSError, ValueError, csv.Error); the merge already handles OSError on its read and its write and raises no ValueError, so the one error that could arrive, a malformed pod file, is now caught where the file is read, with the same outcome (a warning, no gpu_metrics.csv). Nothing in the tree reads that file and the session package does not collect it, but writing it is an effect and there is no multi-node run to check it against, so it stays for the multi-node owner to decide.

    This is the first of two stacked PRs. The second deletes the result parsing that cannot run since feat(hyperloom): measure every round with InferenceSuite and remove Magpie #2614 (the benchmark_report.json mapper, the rescue path, the report settle loop) and has no observable effect on a round; this one is kept apart because it removes behaviour that still ran.

  • Linked issue(s): none.

  • Tests: added/updated? commands run? (if a test was replaced, where its assertions live now):

    Deleted with the code they pinned: the eleven test_harvest_* cases in test_benchmark_result.py, the harvest and _resolve_leak_roots cases in test_benchmark_result_branches_unit.py, the two harvest cases in test_gpu_metrics.py, and the two multi-node cases that asserted the removed injection.

    Carried across:

    • The failure policy of the gpu_metrics.json writer (the artifact's content, no artifact and no warning for a report without telemetry, a failed write is logged and never raises) was asserted through write_gpu_metrics; the tests now call write_gpu_metrics_from_report, which owns that policy. The two no-telemetry cases became the same call and are one test. The artifact's source is asserted with the value a round really writes in test_round_folder.py::test_gpu_metrics_are_written_from_the_report_into_the_round_dir_not_the_run_dir. The two cases specific to the deleted file reader (no benchmark_report.json, an unparseable one) are removed.
    • The multi-node CSV merge tests now assert the merged file's rows (host and role columns, the window filter) instead of the injected report fields.
    • measure/tests/test_local_backend.py: test_the_per_round_cap_comes_from_the_call no longer expects INFERENCE_OPTIMIZER_LEAK_ROOTS in the round's environment; two sample warning strings that named the removed warning are replaced.

    Added: test_round_folder.py::test_the_grid_merges_a_multi_node_rounds_pod_gpu_samples_into_its_run_dir. The merge is now reached through a call this PR moved, and no test went through it; this one reads a round as the grid does on a host that reports itself multi-node and asserts <run_dir>/gpu_metrics.csv.

    Run on Python 3.12 with PYTHONPATH=src, on this branch merged with main:

    • pytest -n 40 src/hyperloom/inference_optimizer/tests src/hyperloom/orchestrator src/inference_suite src/hyperloom/measure src/hyperloom_multibranch src/hyperloom/common/tests/test_round_measurement.py: 28326 passed, 82 skipped, 63 failed, 40 errors. All 103 failing test ids also fail on main on the same host: bubblewrap sandbox tests that cannot remount /, a torch import that cannot load a ROCm library in a subprocess, installer and gateway-catalog tests. None imports code this PR changes.
    • ruff check . and ruff format --check .: clean.
    • python scripts/code_metrics.py --base-ref origin/main: PASSED (30 files judged).
    • lint-imports: 17 contracts kept. python scripts/check_broad_suppress.py: clean.
    • python scripts/pr_hygiene.py size: 391 production Python lines changed.
  • Size/complexity triggers crossed: split, or why the shape is right:

    None. 391 production lines change (42 added, 349 deleted), below the 400-line review trigger. No function is added and none gains a branch (_settled_measurement gains the one merge call); grid/_grid_runner.py shrinks from 1,112 to 1,088 lines.

  • If this simplifies or refactors: which mechanism was removed, which contract was preserved, and the tests that show it:

    Removed: the post-round search for files outside the run_dir, its environment variable, the inert multi-node report injection and the second gpu_metrics.json writer. Preserved: a grid round's row, warnings other than the removed one, error classes and stop attribution (executors/tests/test_grid_suite_round.py, test_grid_callers_suite.py, test_suite_round.py, unchanged apart from dropping the leak-root pin); gpu_metrics.json beside every round (test_round_folder.py, test_gpu_metrics.py); the multi-node gpu_metrics.csv merge: the grid still writes it into a round's run_dir (test_round_folder.py) with the same rows (test_benchmark_result_branches_unit.py).

  • Observable effect: what an operator will now see, and what the old behaviour cost them (if none, why the change is unobservable):

    • After an explore, integrate, rebench, concurrency-sweep or multi-branch round, no server.log, gpu_metrics.csv, profile_*.trace.json.gz, inferencex_result*.json or results*.json from the top of /workspace, $INFERENCEX_PATH or $RESULT_DIR is copied into the round's run_dir. Before, a file another process wrote under one of those names during a round could overwrite the round's server.log or be picked up as its accuracy result.
    • The log line harvested N leaked artifact(s) and the harvested_leaked_artifact:<path> entry in a round's nonfatal_warnings are gone.
    • INFERENCE_OPTIMIZER_LEAK_ROOTS (never documented) is no longer read and is silently ignored.
    • The multi-branch measurement runner no longer copies those file names from the top of its work directory into the files it signs. Its harvest call also ran the multi-node CSV merge on that directory, so on a host that reports itself multi-node the signed files no longer get a merged gpu_metrics.csv at their top level; each round's run_dir still gets its own.
    • A multi-node round that left no run_dir no longer gets a merged gpu_metrics.csv in its variant or warmup directory; the harvest wrote one there, and the merge now runs only on a run_dir. The warning for a malformed pod CSV now names the file.
    • PD-disaggregated multi-node sessions: the specialist prompt no longer points at gpu_monitor_by_role, a report field that has not been written since feat(hyperloom): measure every round with InferenceSuite and remove Magpie #2614.
    • gpu_metrics.json, throughput, latency, accuracy and grading of a round that left nothing outside its run_dir are unchanged.

    docs/reference/upgrade.md ("Upgrading from 1.2.x") and the Unreleased release notes carry the entry.

  • Breaking changes: yes, for a setup that relied on the harvest: a benchmark script or wrapper that writes server.log, results*.json, inferencex_result*.json, gpu_metrics.csv or a profile trace outside the round's run_dir no longer has it copied in, and INFERENCE_OPTIMIZER_LEAK_ROOTS no longer redirects the search. No round on InferenceSuite writes there. In-tree API: harvest_leaked_artifacts leaves hyperloom.orchestrator.actions.executors and write_gpu_metrics leaves gpu/_gpu_metrics.py; their in-tree callers, including hyperloom.measure, are migrated here.

  • PR addresses single concern: yes — the leak harvest and what only it called.

  • Root cause is upstream (TraceLens/GEAK/IntelliKit/AgentKernelArena), ticket filed: no.

🤖 Generated with Claude Code

… run_dir; delete the leak harvest

harvest_leaked_artifacts was written for a harness that could leave a round's
server log, results and traces outside the round's workspace. Since #2614
every round runs on inference_suite, whose server, client, eval and profile
all write below the round's run_dir, so there is nothing left to bring back.
The harvest still ran: after every warmup and measured round of run_grid
(explore, integrate, rebench, concurrency sweep, multi-branch) it globbed the
top of /workspace, $INFERENCEX_PATH and $RESULT_DIR, or
INFERENCE_OPTIMIZER_LEAK_ROOTS when set, and copied any server.log,
gpu_metrics.csv, profile_*.trace.json.gz, inferencex_result*.json or
results*.json modified since the round started into the round's run_dir. A
file another process wrote under one of those names replaced the round's own
server.log, or became a candidate for the accuracy reader's results*.json
glob. The baseline, profile and roofline rounds never called it.

Removed:
- harvest_leaked_artifacts, its helpers and INFERENCE_OPTIMIZER_LEAK_ROOTS;
  the measurement runner's call on its own work directory and the leak root
  the local backend named for it; the leak-root pin eleven test modules set
  only to keep the harvest off the host.
- The multi-node report injection the harvest ended with
  (_inject_gpu_monitor, _aggregate_gpu_samples_by_role, _row_to_gpu_sample).
  It wrote gpu_monitor, pd and gpu_monitor_by_role into the round's
  benchmark_report.json, a file no round has had since #2614, so it returned
  on its first line. The specialist prompt sentence pointing at
  gpu_monitor_by_role goes with it.
- gpu/_gpu_metrics.write_gpu_metrics, which read benchmark_report.json and
  was called only by the harvest. gpu_metrics.json is still written by
  RoundFolder.write_gpu_metrics on both round arms, unchanged; the writer's
  failure-policy tests now call write_gpu_metrics_from_report.

Kept: harvest_mn_gpu_metrics still merges the pods' sampler CSVs into the
round's gpu_metrics.csv; the grid now calls it where it reads the finished
round.

Observable effect:
- No file from outside a round's run_dir is copied into it. The
  "harvested N leaked artifact(s)" log line and the
  harvested_leaked_artifact:<path> warning are gone.
- INFERENCE_OPTIMIZER_LEAK_ROOTS (never documented) is no longer read.
- The measurement runner's signed files hold nothing copied from the top of
  its work directory. On a host that reports itself multi-node the runner
  also no longer writes a merged gpu_metrics.csv at the top of those files;
  each round's run_dir still gets its own.
- Throughput, latency, accuracy and grading of a round that left nothing
  outside its run_dir are unchanged.

docs: upgrade.md and the release notes gain an entry.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Code metrics gate: PASSED

Judged: the 30 files this change touches. Files it does not touch never fail it; anything found there is listed under Outside this change for information.

Dimension Limit New Worse Improved Over the limit vs base
Cyclomatic complexity fails > 20 0 0 0 0 +0
Cognitive complexity fails > 30 0 0 0 0 +0
Function length (lines) fails > 60 0 0 0 0 +0
Nested block depth fails > 4 0 0 0 0 +0
Parameter count fails > 5 0 0 0 0 +0
Module length (lines) warns > 800, fails > 1200 0 0 0 0 +0
Duplicated lines per file fails > 0 0 0 0 0 +0
Dead code (vulture) fails > 0 0 0 0 0 +0
Directory size (entries) fails > 50 0 0 0 0 +0
Check Findings Effect
Comments 0
Broad catch without a reason 0
Broad catch that records nothing 0
English only 0
Production code imports test code 0
Repeated literals 0
A1 Private name of another package 0
A8 Flag argument 0
A9 Tuple return 0
A10 Raw vocabulary comparison 0
A11 Hidden global write 0
A12 Pure forwarder 0
A12 Single-implementation abstraction 0

Module length warning: over 800 lines, within the 1200-line failure limit (not failing): 4

Module Lines Limit
src/hyperloom/inference_optimizer/breakdown/recorder/baseline_event.py 921 warns > 800
src/hyperloom/measure/local.py 1057 warns > 800
src/hyperloom/orchestrator/actions/executors/grid/_grid_runner.py 1088 warns > 800
src/hyperloom/orchestrator/prompts/specialist_prompt_builder.py 974 warns > 800

Verdict computed by the gate scripts in /home/runner/work/_temp/code-metrics-gate, not by this tree's copy.

Thresholds and sources: [tool.hyperloom.code_metrics] in pyproject.toml. Tools: complexipy 8.0.1, jscpd 5.4.1, radon 6.0.1, ruff 0.16.2, vulture 2.16.

ZhengGong-amd and others added 2 commits November 27, 2026 02:31
…file; drop the last mentions of the leak harvest

Review follow-up to the leak-harvest removal.

- harvest_mn_gpu_metrics was called from the grid under
  `except (OSError, ValueError, csv.Error)`, a handler carried over from the
  deleted harvest. The merge already handles OSError on its read and its
  write and nothing in it raises ValueError, so only csv.Error could arrive.
  That one is now caught where the pod file is read, with the same outcome
  (a warning, no gpu_metrics.csv), and the grid calls the merge in one line
  without importing csv.
- The module docstring of gpu/_gpu_metrics.py still listed the pod-side
  sampler as a producer of `gpu_monitor`; the injection that made it one is
  gone. The comment on the baseline event's warning cap still gave "one per
  harvested artifact" as its reason.
- Tests: one entry-point test shows a multi-node grid round still gets
  gpu_metrics.csv in its run_dir, which no test covered after the call
  moved. Two test_gpu_metrics.py cases that had become the same call are
  merged, an assertion that only echoed its own argument is dropped (the
  round-folder test asserts the real source), and a docstring that pointed
  at the deleted row mapper is replaced.

No observable change.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@ZhengGong-amd
ZhengGong-amd marked this pull request as ready for review November 27, 2026 06:21
@ZhengGong-amd
ZhengGong-amd requested a review from a team as a code owner November 27, 2026 06:21
A pod CSV whose rows all fall outside the round's window, or that the csv
module refuses to parse, leaves no gpu_metrics.csv and does not fail the round.
The malformed-file branch moved into the merge with the leak harvest's removal
and had no test of its own.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@ZhengGong-amd

Copy link
Copy Markdown
Collaborator Author

Folded into #2928, which now targets main and carries this PR's commits unchanged together with the result-parsing removal that was stacked on it. The two were split only to stay under the diff budget; they delete the same pre-#2614 mechanism and are reviewed as one there.

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.

1 participant