Skip to content

refactor(orchestrator): remove duplicated writeback, autosubmit and config-env branches - #1877

Merged
chaojhou merged 15 commits into
mainfrom
lean/shafeng/cc-writeback-config-env
Oct 17, 2026
Merged

chaojhou merged 15 commits into
mainfrom
lean/shafeng/cc-writeback-config-env

Conversation

@fengshaoyi-amd

@fengshaoyi-amd fengshaoyi-amd commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor
  • Description: what and why

Implements the cyclomatic/cognitive-complexity findings for the writeback/promotion path and the config/env plumbing. Each finding is a mechanism that either existed twice or could never fire. The change deletes the copy or the dead branch, and the complexity falls as a consequence. There is one commit per finding, each self-contained and each tightening the baseline for what it shrank.

  • Writeback. handle_unpromotable_result saved behind an any_changed flag that every path had already set (the action failure is always recorded first), so it now saves directly. lift_to_current_best guarded each field of the winning variant with isinstance(bv, dict), but every caller builds that variant as a dict, as the signature says. The guards on the previous current_best are untouched.
  • Kernel attempt summary. build_kernel_optimization_summary took a schema_version keyword defaulting to 2. Its only caller never passes it, so the version-1 branch was unreachable. It is gone.
  • Framework autosubmit. maybe_autosubmit_specialist_patches and maybe_autosubmit_framework_config each carried a full copy of the synthetic integrate_patch review submission: the settled/in-flight gate, patch name, provenance, candidate/batch forwarding, enablement marker, carriers and merged setup commands, proposal, observation and save. It now lives once, in _submit_integrate_review / _integrate_review_params, and each bridge keeps only what decides its deliverable. Re-checked against feat(predictor): ask PrimaTune for optimization proposals in FRAMEWORK_AGENT #1798 after merging main: both bridges seed provenance="specialist" before _forward_integrate_source, before and after this change, so a domain-less predictor-mandate dispatch keeps its label through either bridge.
  • Recipe KB tags. The journal's tag collector and the T0 trace extras each read the workload shape off SharedState with their own EP-env fallback and PP-env read, and the T0 prefer hints kept a third copy of the field list. knowledge/workload_tags.py now owns the list and the reader.
  • trace-analyze argv. _build_trace_analyze_cmd guarded each optional flag with its own if value: cmd += [flag, value] and hand-rolled the same positive-int parse twice. Main's trace-splitter cleanup (Cleanup trace splitter code #1612) folded four of those guards into an inline loop of its own. Every optional flag now comes from ordered (flag, value) tables through _optional_flags, which absorbs that loop, and the splitter hints come from one loop, which still forwards a zero hint. Both parses use optional_positive_int. Cleanup trace splitter code #1612's argv is kept as it is: no --skip-split, --split-llm-inference and the hints only for a non-scriptable TraceLens run, and --steady-state-mode generic for a scriptable one.
  • Executors. baseline.py re-exported default_baseline_config under an underscore alias that only its own _resolve_default_config and one test module used, and resolve_reference_base only dropped the third element of resolve_reference_launch. Callers now use the canonical names. Main's Use Magpie's native AgentX contract for optimization #1922 already removed the second alias, _materialize_config_with_envs.
  • Test isolation. The workload-env golden-lock snapshots read the host's session state through resolve_reference_launch. On a host whose workspace holds a session with a reference recipe, its server args and envs leaked into three goldens. _isolate now stubs that seam, as test_workload_envs_branches_unit already does.

Superseded on main: the specialist-dispatch commit (93642f651). main's bdf43087a moved warm_specialist_params onto two tables and dropped the same duplicated framework export. The merge takes main's dispatch.py, so this PR no longer changes it.

Not included: normalizing a non-dict current_best once at SharedState.from_dict and deleting the guards downstream of it. That moves a persisted-state boundary and is scoped separately, in #1883.

  • Linked issue(s): none

  • Tests: added/updated? commands run?

Added:

  • test_autosubmit_patch_survives_a_non_dict_first_proposal: a malformed first proposal costs the review its patch name, not the review.
  • A framework_agent_authoring assertion on the config bridge in test_autosubmit_config_enablement_propagates_marker_and_setup.
  • test_splitter_forwards_zero_workload_hints: a zero conc/osl/random_range_ratio is still forwarded. No existing case passed a falsy-but-present hint.

Updated:

  • test_profile_and_kernel_handlers.py imports default_baseline_config from _workload_envs instead of the deleted alias.
  • test_workload_envs_golden_lock.py::_isolate stubs resolve_reference_launch.

Before syncing with main, ran locally on Windows:

  • ruff check . and ruff format --check ..
  • PYTHONPATH=src lint-imports --no-cache: 7 kept, 0 broken.
  • python scripts/code_metrics.py --base-ref origin/main: PASSED.
  • mypy on the changed source files: 98 errors against 99 on origin/main for the same files, none new.
  • pytest over the blast radius, 22 files: the feat(predictor): ask PrimaTune for optimization proposals in FRAMEWORK_AGENT #1798 predictor suites plus the framework/autosubmit, promote, KB-write, recipe, grid-runner, trace-analyze, workload-env and baseline suites. 1485 passed, 29 failed. Every one of the 29 also fails on this host without this branch (checked against clean exports of origin/main and of the pre-branch base), each for a Windows-only reason: symlink privileges, \ in expected POSIX paths, the cp1252 default encoding, drive-letter colons, TraceLens not installed, or process teardown.

After merging origin/main at a17939e68:

  • ruff check and ruff format --check on the changed files: clean.
  • The code-metrics gate vs origin/main: PASSED, with 16 files judged.
  • pytest over 16 files covering the modules both sides changed: workload envs, the baseline executor, the grid runner, the kernel request handlers, framework autosubmit, and Use Magpie's native AgentX contract for optimization #1922's AgentX contract and native-launch replay. 1091 passed. The 18 failures fail identically on a clean export of origin/main at a17939e68 on this host: Windows paths and venv layout, git patch line endings, the cp1252 default encoding, and process teardown.

The full suite is left to Linux CI.

  • Size/complexity triggers crossed: none.

The four new units (_submit_integrate_review, _integrate_review_params, workload_shape_tags, _optional_flags) are under every threshold, and every touched unit shrinks.

Leaving the baseline:

  • _build_trace_analyze_cmd: cyclomatic 23, cognitive 45.
  • maybe_autosubmit_specialist_patches: cyclomatic 24, cognitive 58.
  • maybe_autosubmit_framework_config: cognitive 43, 138 lines.
  • _build_t0_trace_extras: cognitive 31.
  • The 58 duplicated lines in phases/framework.py.

Lowered:

  • lift_to_current_best: cognitive 213 → 148, cyclomatic 51 → 44.
  • build_kernel_optimization_summary: cognitive 63 → 59, cyclomatic 23 → 21.
  • _collect_workload_tags: cognitive 42 → 37.
  • maybe_autosubmit_specialist_patches: 170 → 102 lines.
  • _build_trace_analyze_cmd: 104 → 87 lines.

The units still above a ceiling were already above it.

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

Removed:

  • an always-true flag;
  • impossible per-field guards;
  • an unreachable schema branch;
  • the second copy of the integrate-review submission;
  • two extra copies of the workload-tag reader and its EP/PP env reads;
  • per-flag argv guards and two hand-rolled int parses;
  • a re-export alias and a forwarding function.

Each of the four new names replaces at least two copies.

Preserved, and pinned by:

  • the synthetic integrate_patch params: test_coordinator_async_batch2_unit.py, test_framework_agent_selection_audit.py;

  • the KB tag key sets and key order: test_coordinator_kb_writes.py, and main's whole-dict pin in test_coordinator_sync_helpers_coverage_unit.py;

  • the trace-analyze argv, including flag order: TestBuildTraceAnalyzeCmd in test_kernel_request_handlers_units.py, and Cleanup trace splitter code #1612's framework-kind gating in test_trace_splitting.py;

  • the workload-env goldens, byte for byte: test_workload_envs_golden_lock.py.

  • Observable effect:

Framework autosubmit:

  • A patch deliverable whose first proposal_set entry is not a dict is reviewed with an empty patch name, instead of raising AttributeError out of the patch bridge.
  • The framework_config_autosubmitted_for_review observation now carries patch_name, as the patch bridge's observation already did.
  • The patch bridge parses its companion levers before the settled/in-flight check, so a redelivered deliverable for an already-settled specialist can log a lever-parse warning it used to skip.
  • Both bridges log the same line when the post-submit save fails.

trace-analyze: a boolean or infinite num_denoise_steps, num_inference_steps or SharedState.tp is now omitted like any other non-positive value. Before, True became --num-denoise-steps 1 / --tensor-parallel-size 1, and an infinite float raised OverflowError out of the handler. Every integer, numeric string, zero, negative or unparsable value produces the same argv as before.

Unobservable: the writeback, kernel-summary, KB-tag, argv-table and executor-alias commits, and the test-only isolation fix. The emitted summary, tag dicts, argv and goldens are unchanged.

  • Breaking changes: no for operators. One Python signature narrows: build_kernel_optimization_summary (listed in its module's __all__) no longer accepts schema_version. Its only caller never passed it, and the emitted summary is unchanged. The removed baseline.py alias was underscore-private.

  • PR addresses single concern: no. It bundles the complexity findings for two areas, one commit per finding, each reviewable and revertible on its own. They are the same kind of change (delete a duplicated or unreachable mechanism, then tighten the baseline), and most are a few dozen lines. As separate PRs they would each spend a CI run and a review on very little.

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

fengshaoyi-amd and others added 11 commits October 14, 2026 13:36
Every path through handle_unpromotable_result records the action failure before the save check, so the any_changed flag was always true by then. Save directly and drop the flag.

Co-authored-by: Cursor <cursoragent@cursor.com>
…he winner

Every caller builds the winning variant as a dict (a literal or a dict()
copy), matching the bv: dict[str, Any] signature, so the per-field
isinstance(bv, dict) guards and their empty fallbacks could never fire.
Drop them. The guards on the previous current_best are untouched.

Co-authored-by: Cursor <cursoragent@cursor.com>
…mary

build_kernel_optimization_summary took a schema_version keyword that
defaulted to 2, and its only caller, the session report, never passes it,
so the version-1 branch was unreachable. Remove the parameter and always
build the version-2 shape: lane-summed totals, the overall lane outcome
and lane_totals. The emitted summary is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ntegrate review

maybe_autosubmit_specialist_patches and maybe_autosubmit_framework_config
each carried a copy of the synthetic integrate_patch submission: the
settled/in-flight gate, the patch name, provenance and candidate/batch
forwarding, the enablement marker, carriers and merged setup commands,
the proposal, the observation and the save. That now lives once, in
_submit_integrate_review, with the params built by
_integrate_review_params; each bridge keeps only what decides its
deliverable.

Observable effects:
- A patch deliverable whose first proposal_set entry is not a dict is
  reviewed with an empty patch name instead of raising AttributeError
  out of the patch bridge.
- The framework_config_autosubmitted_for_review observation now carries
  patch_name, as the patch bridge's observation already did.
- The patch bridge parses its companion levers before the
  settled/in-flight check, so a redelivered deliverable for a settled
  specialist can log a lever-parse warning it used to skip.
- Both bridges log the same line when the post-submit save fails.

Co-authored-by: Cursor <cursoragent@cursor.com>
…g reader

The recipe journal's tag collector and the T0 trace extras each read
tp/ep/conc/isl/osl/max_model_len off SharedState, with the same EP
environment fallback and PP environment read written out twice, and the
T0 prefer hints kept a third copy of the field list.
knowledge/workload_tags.py now owns the field list and the reader. The
journal adds precision ahead of it, so both tag dicts keep their keys
and their key order. No behaviour change.

Co-authored-by: Cursor <cursoragent@cursor.com>
warm_specialist_params set the framework default twice. The earlier
block already copies the stripped, non-empty SharedState.framework, so
the second setdefault could only fire for a whitespace-only framework.
It is removed and the earlier block is the single owner.

tp, conc, isl, osl and max_model_len now come from one loop instead of
five copies of the same positive-int guard. precision keeps its own
string default.

Observable effect: a whitespace-only SharedState.framework no longer
reaches the specialist params as that raw string. Nothing else changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ables

_build_trace_analyze_cmd grew one `if value: cmd += [flag, value]`
guard per optional flag. Both runs of those guards now go through one
_optional_flags helper fed with ordered (flag, value) pairs, and the
three splitter hints come from one loop over (flag, payload key,
workload key).

The splitter loop keeps its own `not in (None, "")` predicate and
.strip() renderer: a zero conc, osl or random_range_ratio is a real
workload value and is still forwarded. A new argv case pins that,
since no existing case passed a falsy-but-present hint.

Cyclomatic complexity falls from 24 to under the gate limit, so its
baseline entry is removed; cognitive complexity 45 -> 33.

No behaviour change: the argv, including flag order, and the returned
steady-state mode are unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ptional_positive_int

_build_trace_analyze_cmd hand-rolled the same positive-int parse twice,
each with its own try/except around int(). Both now use the shared
hyperloom.common.coerce.optional_positive_int and emit through
_optional_flags, which removes the function's last try blocks and takes
its cognitive complexity under the gate limit.

Observable effect: a boolean or infinite num_denoise_steps,
num_inference_steps or SharedState.tp is now omitted like any other
non-positive value. Before, True became `--num-denoise-steps 1` /
`--tensor-parallel-size 1` and an infinite float raised
OverflowError out of the handler. The argv for every integer, numeric
string, zero, negative or unparsable value is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
… forwarder

baseline.py re-exported default_baseline_config and
materialize_config_with_envs under underscore aliases. No production
caller used them; one test module did. That module now imports the
canonical names from _workload_envs, BaselineExecutor calls
default_baseline_config directly, and the two YAML comments that named
the alias point at the real function.

resolve_reference_base only dropped the third element of
resolve_reference_launch. Its two callers, the multi-node per-round
restart in BenchmarkRunExecutor and the multi-node branch of run_grid,
now unpack resolve_reference_launch themselves.

No behaviour change.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ion state

materialize_config_with_envs seeds the reference recipe from
resolve_reference_launch, which loads SharedState from session_dir().
The autouse fixture drops the session-dir pin, so session_dir() falls
back to workspace_root(): USER_DATA_PATH, or the default workspace.
On a host whose workspace holds a session with a reference recipe, its
server args and envs leaked into three golden snapshots.

_isolate now stubs resolve_reference_launch to an empty recipe, the
same seam test_workload_envs_branches_unit already uses. Clearing
USER_DATA_PATH instead would only move the read to the default
workspace, which is just as real and shared, and would trip the
process-wide one-shot USER_DATA_PATH warning for every later test in
the worker.

Test-only change.

Co-authored-by: Cursor <cursoragent@cursor.com>
…back-config-env

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	scripts/code_metrics_baseline.txt
@fengshaoyi-amd
fengshaoyi-amd requested a review from a team as a code owner October 14, 2026 09:27
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Code metrics gate: PASSED

Judged: the 16 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 Baseline out of date Baseline entries vs base
Cyclomatic complexity fails > 20 0 0 0 70 -2
Cognitive complexity fails > 30 0 0 0 276 -4
Function length (lines) fails > 80 0 0 0 442 -1
Nested block depth fails > 5 0 0 0 26 +0
Parameter count fails > 5 0 0 0 560 +0
Module length (lines) warns > 800, fails > 1200 0 0 0 53 +0
Duplicated lines per file fails > 0 0 0 0 117 -1
Dead code (vulture) fails > 0 0 0 0 2 +0
Check Findings Effect
Comments 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): 1

Module Lines Limit
src/hyperloom/orchestrator/kernel/attempt_summary.py 1003 warns > 800

Already over at the base (backlog, not this change's): 9

Unit Dimension Base Now
src/hyperloom/orchestrator/loop/writeback.py:3492 WritebackCollaborator.build_env_spec Cognitive complexity 37 37
src/hyperloom/orchestrator/actions/executors/_workload_envs.py:1243 materialize_config_with_envs Cyclomatic complexity 111 111
src/hyperloom/orchestrator/actions/executors/_workload_envs.py:1243 materialize_config_with_envs Function length (lines) 926 926
src/hyperloom/orchestrator/loop/writeback.py:3492 WritebackCollaborator.build_env_spec Function length (lines) 111 111
src/hyperloom/orchestrator/loop/writeback.py:4527 WritebackCollaborator.validate_geak_via_geak_harness Function length (lines) 187 187
src/hyperloom/orchestrator/actions/executors/_workload_envs.py:1 Module length (lines) 2183 2174
src/hyperloom/orchestrator/actions/executors/baseline.py:1 Module length (lines) 4274 4270
src/hyperloom/orchestrator/loop/writeback.py:1 Module length (lines) 4820 4791
src/hyperloom/orchestrator/phases/framework.py:1 Module length (lines) 3201 3159
84 findings in files this change does not touch

Outside this change (informational): 84

Unit Dimension Baseline Now
src/hyperloom/orchestrator/enablement/recipe/projections.py project_launch_evidence Cognitive complexity absent 36
src/hyperloom/orchestrator/state/shared_state.py resolve_graded_comparison Cognitive complexity absent 34
src/hyperloom_kb/collect/mapping.py _experience Cognitive complexity absent 31
src/hyperloom_kb/schema.py FieldDeclaration.__post_init__ Cognitive complexity absent 32
src/kernelforge/cli/forge_loop_command.py _prepare_measurement_driver Cognitive complexity absent 36
src/kernelforge/cli/forge_loop_command.py _read_kb_warm_start Cognitive complexity absent 40
src/kernelforge/loop/runner.py IterationLoop._collect_session_candidate Cognitive complexity absent 44
src/kernelforge/loop/runner.py IterationLoop._rule_on_attempt Cognitive complexity absent 38
src/hyperloom_kb/tests/test_cli.py Duplicated lines per file absent 18
src/hyperloom_kb/tests/test_global_identity_and_pull.py Duplicated lines per file absent 13
src/hyperloom_kb/tests/test_local_state.py Duplicated lines per file absent 18
src/hyperloom/inference_optimizer/cli/__init__.py _reexport_session_environment Function length (lines) absent 112
src/hyperloom/inference_optimizer/cli/__init__.py _resolve_agent_lineup Function length (lines) absent 89
src/hyperloom/inference_optimizer/cli/__init__.py _resolve_run_topology Function length (lines) absent 92
src/hyperloom/inference_optimizer/cli/__init__.py _resume_session Function length (lines) absent 171
src/hyperloom/inference_optimizer/cli/__init__.py _seed_fresh_session Function length (lines) absent 172
src/hyperloom/inference_optimizer/multi_node/cli.py _restart_multinode Function length (lines) absent 107
src/hyperloom/inference_optimizer/multi_node/scripts/launch_multinode.py _build_parser Function length (lines) absent 84
src/hyperloom/inference_optimizer/multi_node/scripts/launch_multinode.py _spawn_rank_actors Function length (lines) absent 90
src/hyperloom_kb/http_service.py RequestHandler._dispatch Function length (lines) absent 91
src/hyperloom_kb/sync.py GlobalSync.pull Function length (lines) absent 86
src/kernelforge/cli/forge_loop_command.py _RunReporter.build_result Function length (lines) absent 91
src/kernelforge/cli/forge_loop_command.py _prepare_measurement_driver Function length (lines) absent 140
src/kernelforge/cli/forge_loop_command.py _read_kb_warm_start Function length (lines) absent 154
src/kernelforge/loop/knowledge_integration.py _measure_warmstart_field Function length (lines) absent 83

...and 59 more; the job log lists every row.

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, ruff 0.16.2, vulture 2.16.

_mn_ref_envs: dict[str, str] = {}
if _mn_is_multi_node():
from ._workload_envs import resolve_reference_base
from ._workload_envs import resolve_reference_launch
@fengshaoyi-amd

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown

Automated review started for head e611a05. Progress: https://github.com/AMD-AGI/Hyperloom/actions/runs/38551842106

…back-config-env

main's warm_specialist_params tables cover the knob loop this branch
added, so dispatch.py takes main's version. _collect_workload_tags keeps
main's loop over the identity strings and reads the workload shape
through workload_shape_tags, which also serves the T0 trace extras.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown

Automated review: no verdict applied -- the PR head moved from e611a05 to 9d5abf5 during the review. Comment /review to retry. Run: https://github.com/AMD-AGI/Hyperloom/actions/runs/38551842106

PR #1877 -- refactor(orchestrator): remove duplicated writeback, autosubmit and config-env branches

What it does: Deletes duplicated or unreachable mechanisms on the writeback/promotion path and the config/env plumbing: an always-true any_changed save flag and impossible winner-side dict guards in loop/writeback.py, an unreachable schema_version < 2 branch in the kernel attempt summary, the second copy of the synthetic integrate_patch review submission in phases/framework.py (now one _submit_integrate_review / _integrate_review_params), three copies of the workload-shape tag reader (now knowledge/workload_tags.py), duplicated framework defaults and positive-int guards in specialist dispatch, per-flag argv guards and hand-rolled int parses in trace_analyze.py, and two re-export aliases plus a forwarder in the executors, with callers migrated to the canonical names. Each deletion is one self-contained commit and every touched unit's complexity falls.

Blocking issues: none

SKIPPED: V4 -- open PRs #1276 (1311 files), #1675 (161 files), #1032 (1075 files) and #1154 (1232 files) were only partially compared in openprs.txt, so overlap with those PRs' files past their first 100 is unchecked.

Checked: writeback.py handle_unpromotable_result / lift_to_current_best and all 10 production callers; phases/framework.py maybe_autosubmit_specialist_patches / maybe_autosubmit_framework_config / _submit_integrate_review / _integrate_review_params against both base copies; knowledge/workload_tags.py + _collect_workload_tags / _build_t0_trace_extras / _build_warm_prefer outputs run on both trees (byte-identical, including the EP env fallback and PP read); trace_analyze.py _build_trace_analyze_cmd run on both trees for 7 tp and 9 num_denoise value shapes; attempt_summary build_kernel_optimization_summary and its only caller; baseline.py / _grid_runner.py / _workload_envs.py removals swept tree-wide; ruff C901 at 20 on head and base copies of all changed src files; independent adversarial re-read of the card against the diff | Ran: ruff C901 head-vs-base complexity comparison; direct base/head execution of _build_trace_analyze_cmd, _collect_workload_tags, _build_t0_trace_extras; pytest (head tree) TestBuildTraceAnalyzeCmd (7 passed), splitter/tracelens selection (15 passed), test_workload_envs_golden_lock (10 passed), autosubmit selections in test_coordinator_async_batch2_unit (5 passed) and test_framework_agent_selection_audit (10 passed), test_coordinator_kb_writes (37 passed), test_kernel_attempt_summary (27 passed), test_profile_and_kernel_handlers (173 passed, 1 env-only failure reproduced identically on base) | Base: d755931 | Head: e611a05

…back-config-env

Brings in the phase-budget (#1873) and gemm-tune MoE routing (#1862)
fixes. The only conflict is the module-lines baseline: request_handlers.py
takes main's lower count, recipe_journal.py and recipe_kb_t0.py keep this
branch's measured counts.
@chaojhou

Copy link
Copy Markdown
Collaborator

PR #1877 -- refactor(orchestrator): remove duplicated writeback, autosubmit and config-env branches

What it does: Deletes mechanisms that existed twice or could never fire in the writeback/promotion path and the config/env plumbing. The always-true any_changed save flag and the per-field isinstance(bv, dict) guards in lift_to_current_best go, as does the unreachable schema_version branch of build_kernel_optimization_summary. The two specialist autosubmit bridges now share one integrate-review submission (_submit_integrate_review / _integrate_review_params), the recipe-KB workload-shape tags have one reader (knowledge/workload_tags.py), trace-analyze argv comes from ordered tables (_optional_flags, optional_positive_int), and the baseline.py aliases and the resolve_reference_base forwarder give way to the canonical names; the workload-env golden-lock tests stop reading the host's session state.

Blocking issues: none

Checked: diff of all 18 files; lift_to_current_best signature and the origin of bv at its 8 call sites (writeback.py, phases/kernel.py, phases/prelude.py); handle_unpromotable_result save path; _submit_integrate_review, _integrate_review_params, both autosubmit bridges, _forward_integrate_source, and every writer/reader of framework_agent_candidate_id; workload_shape_tags against _collect_workload_tags, _build_t0_trace_extras, _build_warm_prefer; _build_trace_analyze_cmd, optional_positive_int, to_int; build_kernel_optimization_summary callers; tree-wide references to the removed names; open PRs that overlap these blocks or add calls to the removed aliases (#1867, #1612, #1675, #1782) | Ran: python pr_tools/c901.py (ruff C901 counting; ruff is not installed here): _build_trace_analyze_cmd 24->9, maybe_autosubmit_specialist_patches 24->12, maybe_autosubmit_framework_config 19->8, lift_to_current_best 51->44, build_kernel_optimization_summary 23->21, new units 3-6; base-vs-head execution of _build_t0_trace_extras from git objects over 11664 state/env combinations: 0 mismatches; the head moved from 9d5abf5 to 5836d15 by a merge of main, and the PR's own hunks compare identical across it (only code_metrics_baseline.txt context lines differ) | Base: 7da6fd1 | Head: 5836d15

LGTM

@chaojhou

Copy link
Copy Markdown
Collaborator

Non-blocking suggestions. None of these blocks merging; each removes a defensive check or a mechanism rather than adding one.

  1. Validate proposal_set once at the intent boundary instead of in each consumer. protocol/intent.py:59 only requires the proposal_set key for SPECIALIST_DONE, so actions/executors/integrate_patch.py:4246, loop/conversation.py:854 and now _integrate_review_params (phases/framework.py:260) each re-check its shape, and a malformed first entry silently becomes patch_name="". A shape check in validate_envelope, next to _validate_review_verdict_payload, lets all three trust the list; test_autosubmit_patch_survives_a_non_dict_first_proposal then pins the wrong layer and can go.
  2. Finish the single workload-shape reader. _build_warm_prefer still loops over WORKLOAD_SHAPE_FIELDS itself, so the tags written to the KB carry the EP/PP env fallback while the warm-start prefer hints do not. The fallback re-reads a value the producer already has: cli/__init__.py:1351 exports EP from ep_resolved, so setting it on SharedState there would let workload_shape_tags read state only and drop its os.environ reads. Nothing in the tree sets PP.
  3. test_splitter_forwards_zero_workload_hints: only random_range_ratio=0.0 is a real workload value; conc=0 and osl=0 pin an accident, and slicing cmd[cmd.index("--split-conc"):] to the end also fails the day any flag is appended after the hints. Asserting that ["--split-r", "0.0"] appears keeps the guard against _optional_flags swallowing a zero. The new comment ("A zero hint is a real workload value and is forwarded") holds for workload zeros only: a payload split_r: 0 is still replaced by the workload value through payload.get(k) or workload.get(k) (pre-existing).
  4. _submit_integrate_review returns PendingProposal | None only so the config bridge can log a line whose facts the observation already records; dropping the return (or logging inside) removes that mechanism. Its deliverable argument also carries framework_agent_authoring, a provenance flag, while the docstring says it is what to apply.
  5. _integrate_review_params forwards framework_agent_candidate_id / framework_batch_id without the framework_agent_authoring condition the patch bridge used to apply. Every in-tree writer sets them together (phases/framework.py:1178, :1688), so nothing changes today; one line in the description would record it.
  6. lift_to_current_best is still cyclomatic 44 and 322 lines after the guards go, because one body builds both the stack entry and the new current_best. Extracting the stack-entry builder is the structural fix, for a later PR.
  7. Merge order: fix(agentx): serve the replay with its prefix cache, and stop reading an unmeasured round as a result #1867 adds overlaps_measured to the patch bridge's propose payload and a key to its observation, exactly the code this PR moves into _submit_integrate_review; Cleanup trace splitter code #1612 edits the splitter-hint block; feat(agentx) Use Magpie native AgentX for Hyperloom optimization #1675 and feat(gpu): support the Radeon AI PRO R9700 (gfx1201) with vLLM #1782 add test calls to the removed _materialize_config_with_envs / _default_baseline_config aliases. Whichever lands second carries the other side into the new structure (or renames to materialize_config_with_envs / default_baseline_config) rather than resolving the conflict by dropping it.

…back-config-env

_build_trace_analyze_cmd conflicted with the trace splitter cleanup
(#1612). Its behaviour is kept as main has it: no --skip-split, the
splitter hints behind --split-llm-inference for a non-scriptable
TraceLens run only, and the generic steady-state mode for a scriptable
TraceLens run. Its inline four-flag loop is the same rule as
_optional_flags and is folded into it; the two branches it gated with
"scriptable" and "not scriptable and not is_bypass" are one if/elif.

@chaojhou chaojhou 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.

PR #1877 -- refactor(orchestrator): remove duplicated writeback, autosubmit and config-env branches

What it does: deletes mechanisms that existed twice or could never fire on the writeback/promotion path and the config/env plumbing: the always-true any_changed save flag and the winner-side dict guards in lift_to_current_best, the unreachable schema_version branch of the kernel attempt summary, the second copy of the specialist autosubmit integrate review, three copies of the workload-shape tag reader, per-flag trace-analyze argv guards, and the baseline.py aliases and resolve_reference_base forwarder. The PR's own content is unchanged since the previous LGTM at 5836d15: every commit after it is a merge of main.

Blocking issues: 1

  1. [mergeable] The branch conflicts with main [verified]
    Problem: GitHub reports mergeable: CONFLICTING (mergeStateStatus: DIRTY); main has moved 24 commits past the last merge, including #1922. git merge-tree origin/main 794d477d3 conflicts in scripts/code_metrics_baseline.txt, assets/configs/baseline_atom.yaml, assets/configs/baseline_sglang.yaml, tests/test_profile_and_kernel_handlers.py and orchestrator/actions/executors/baseline.py. src/hyperloom/orchestrator/actions/executors/baseline.py:765
    Impact: the PR cannot merge, and #1883, stacked on this branch, inherits the same five conflicts.
    Action: merge or rebase onto main. In baseline.py, keep this PR's deletion of the _default_baseline_config alias (#1922 kept it on main, but nothing in the merged tree reads it; :3977 calls default_baseline_config()). In test_profile_and_kernel_handlers.py, #1922 already migrated 68 of the 70 alias uses; carry the remaining _default_baseline_config import on main's side to the canonical default_baseline_config. In the two baseline YAMLs, take main's comment (materialize_benchmark_config, the entry point after #1922) rather than materialize_config_with_envs. Regenerate code_metrics_baseline.txt with --update-baseline. Then grep the merged tree for _materialize_config_with_envs, _default_baseline_config and resolve_reference_base: there must be no reader left.

Checked: git log --no-merges 5836d152..794d477d3 (only main commits); the five conflict hunks in git merge-tree --write-tree origin/main 794d477d3; every reader of the three deleted names on origin/main and in the merged tree; the YAML comment on both sides | Ran: git merge-tree against origin/main; tree-wide git grep at origin/main and on the merged tree | Base: 0198f43 | Head: 794d477

…back-config-env

Main's AgentX contract change (#1922) renamed the entry point the profile
tests and the baseline YAML comments name, and re-exported
_default_baseline_config from baseline.py. The tests and comments follow
main; the alias stays removed, so the one test that used it imports
default_baseline_config from _workload_envs. The baseline keeps main's
entries, tightened with --update-baseline.

@chaojhou chaojhou 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.

Re-reviewed at 0cf8890: the merge of main resolves the five conflicts as advised (the _default_baseline_config alias stays deleted, the last test import moves to default_baseline_config, both baseline YAMLs take main's comment, and the code-metrics baseline only lowers or drops entries). No reader of _materialize_config_with_envs, _default_baseline_config or resolve_reference_base remains, the other 13 files carry the same change as the previous LGTM, and CI is green.

LGTM

@chaojhou
chaojhou merged commit b731bf3 into main Oct 17, 2026
42 checks passed
@chaojhou
chaojhou deleted the lean/shafeng/cc-writeback-config-env branch October 17, 2026 05:57
chaojhou added a commit that referenced this pull request Oct 17, 2026
#1877 landed on main as a squash whose tree equals this branch's merged
#1877 head, so the merge keeps this branch's tree unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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