Repository navigation
refactor(orchestrator-state): delete the duplicated grading, profile-identity and trace-analyze paths - #2020
Conversation
…ze profile identity in one place No observable change: internal structure only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… status snapshot in named steps No observable change: internal structure only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…e snapshot in named steps Drops the dead RooflineBreakdown placeholder that the computed breakdown overwrote on the next line. No observable change: internal structure only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
No observable change: internal structure only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Code metrics gate: PASSEDJudged: the 4 files this change touches. Files it does not touch never fail it; anything found there is listed under Outside this change for information.
60 findings in files this change does not touchOutside this change (informational): 60
...and 35 more; the job log lists every row.
Thresholds and sources: |
|
Requesting changes: equivalence holds (differential runs on base vs head are byte-identical), but the split grows production code by 361 lines and creates a second helper directory next to Production code: +1089/−728 (net +361), with 4 new modules (708 lines) and 6 new types/constants ( Blocking
Simplify instead of relocate
Also fix the stale |
…state # Conflicts: # scripts/code_metrics_baseline.txt
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…nstead of swallowing them The saturation-telemetry and snapshot-history handlers around record_trace_analyze returned without a trace, so a defect in the helpers they call left no evidence and no failing test. Both now log with exc_info; neither changes what the caller sees. The hot-kernel sidecar merge catches the errors reading and projecting a JSON file can raise rather than everything. gaps trimming sorts with _shared_state.gap_rows.recency_key, which already computed the same key. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Merged current main into the branch (merge commit, so the review history stays attached) and worked through the list. Blocking 1 — baseline conflict. Resolved; Done
Not done, with reasons
Checked and clean: no Net production figure. +1086 / -729, net +357 (was +361). |
…longer need BLE001 accepts a broad handler that logs, so the suppression became dead once both handlers reported. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
PR #2020 -- refactor(orchestrator-state): split SharedState's grading, profile-identity, trace-analyze and gap paths into named stepsWhat it does: Ten functions in Blocking issues: none Checked: LGTM |
|
Production code is still too large. The net growth is +357 lines (it was +361), and it needs to keep shrinking before this can merge. I classified every changed line in the touched production files with an AST pass (merge-base vs head
Functions go from 108 to 157, record types from 2 to 7, and total parameters from 138 to 228. Of the 58 new definitions, 34 are referenced exactly once in The logic barely changed (+9). The growth is the scaffolding around single-use units: their signatures, docstrings, fields and spacing (about +359 lines). That is the same control flow in more places, not a simpler one (AGENTS.md Simplify by removing a mechanism). The parameter-count and tuple-return limits in Cut next:
Target: production net ≤ 0, or name each remaining new type in the description with what it removes. |
…state # Conflicts: # scripts/code_metrics_baseline.txt # src/hyperloom/orchestrator/state/shared_state.py
… summary lines The Args:/Returns: blocks on the helpers this branch adds go; the sentences stating a constraint from outside the file stay. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…of sidecar read #2049 settled this handler's types on main; the extracted helper carried an extra TypeError the inline code never caught. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…stale Merging origin/main shortened the module, so its recorded module-lines entry no longer matches the tree and the gate reports the baseline as out of date. Lowered to the value CI measured; nothing else changed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…state Resolve scripts/code_metrics_baseline.txt with resolve_baseline.py: two hunks, 13 entries retired. shared_state.py auto-merged; main's promoted-runtime comment on framework_repo_path is preserved. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
This PR adds +310 net production lines (+1007/−697, 4 new modules, 53 new functions, 5 NamedTuples). A delete-first reference implementation brings the same seven functions under every threshold at −140 net lines, with 3 new functions, 1 new constant, no new modules or types, and byte-identical output on 656 valid-input cases. Please rework the PR along these lines before merge. Targets (at merge-base): Delete
Change
Keep: Watch out
This gets every target to cc ≤ 8 / cog ≤ 28 / ≤ 80 lines with net ≤ 0 production lines. After rebasing, regenerate the baseline with |
…en over-gate functions repeated Round-3 rework of the CC20 state scope, delete-first. The four `state/_*.py` modules this branch added are gone and their contents are back in the single caller; `current_profile_workload_context`, `_langfuse_status_summary` and `GapRefreshCollaborator._extract_gaps_from_attempts` are back at their merge-base shape, having been over no repo threshold. Deleted rather than relocated: - `_rocprof_roofline_sidecar`, which re-parsed the file `_read_session_roofline_report` had already parsed; `record_trace_analyze` now hands the parsed payload to `_build_hot_kernel_summaries`. - the `keep_count > 0` branch in `upsert_gap`, unreachable because `_GAPS_MAX_ENTRIES` is 50; the trim is now a slice and sorts on the repo's own `gap_rows.recency_key`. - the `TYPE_CHECKING` block and its "import cycle" note, stale: importing `perf_metric`, `gain_math` or `grading` loads no orchestrator module, so those three now import at module top. - `_build_explore_search`'s private control-field normalizer, which repeated `phase_state._control_fields`. - `profile_workload_context`'s four "direct else base_*" ternaries, its two env loops and its ten key literals, which repeated `_STACK_BASE_FIELDS`, `_normalize_envs`, `to_str_list` and `to_int`; the eight overridable keys are one constant that `PROFILE_WORKLOAD_IDENTITY_KEYS` derives from. - the dead `RooflineBreakdown(0.0, 0.0, 0.0, "unknown")` stores. Behaviour: `to_str_list` and `to_int` are stricter than the hand-rolled coercions they replace -- `True` reads as 0 rather than 1, a non-finite float as 0 rather than raising, and a bare scalar or dict as its string rather than being dropped. These land in `last_profile_workload`, which decides whether a profile trace is reused. Net production lines against the merge base: -140. Every target is at cyclomatic <= 8 and under every repo threshold; 11 baseline entries retire. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Reworked delete-first on Where the seven targets land
New: Delete
Reverted to base as asked: Change
Kept: One target did not reach the external Cmetrics ceilingOur scope also has to measure < 20 on Cmetrics, which counts every For the same reason three reverted functions sit above 20 on Cmetrics while being byte-identical to One thing I could not doYou asked for the |
|
Follow-up on Re-measured against the new merge base:
The Cmetrics picture is unchanged, and so is the one blocker: Nothing else changed: no PR description edit, no |
…state Two of main's changes landed in code this branch had moved, so the merge is resolved by hand on the branch's shape: - #2060 replaced profile_workload_context's shlex round-trip with normalize_server_args, but the branch had lifted that computation above the context literal. The import merged and the call did not; the branch's joined_args now goes through normalize_server_args, so a JSON server-arg value survives the profile context, and `import shlex` is gone. - #2055 deleted the rocprof roofline enrichment, whose merge the branch had moved into the module-level _hot_kernel_row. _hot_kernel_row loses its rocprof_by_kernel_id argument and its rocprof_roofline field, _ROOFLINE_SIGNAL_KEYS loses that key, and _build_hot_kernel_summaries takes only the result, as on main. last_kernel_opt, kernel_opt_task_attempts, the kernel_opt_attempts accessors, kernel_opt_attempts_count, the _resolve_kernel_patch_identity shim and resolve_kernel_opt_max_failures stay deleted; none is read anywhere in the tree. SharedState.record_trace_analyze is untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
chaojhou
left a comment
There was a problem hiding this comment.
PR #2020 -- refactor(orchestrator-state): delete the duplicated grading, profile-identity and trace-analyze paths
What it does: Shrinks seven over-trigger bodies in orchestrator/state/shared_state.py and state/gaps.py by deleting logic other owners already provide: winners-history controls now come from phase_state._control_fields, gap trimming from gap_rows.recency_key, profile runtime fields from _STACK_BASE_FIELDS with coerce.to_int/to_str_list, and the hot-kernel row and bottleneck-saturation bookkeeping become _hot_kernel_row and _record_bottleneck_saturation. Production code is 134 lines smaller. A base-vs-head differential run over generated inputs gave identical output for valid inputs. Output differs only on the malformed-input coercions the description names, plus two it does not (see below; not blocking).
Blocking issues: 1
- [V5] The PR now conflicts with main, and the conflict is in the hot-kernel row this PR moved [verified]
Problem: #2087 merged into main at 4371269 (2026-10-22 03:31Z), after this branch's last merge of main. It added"call_count"and"duration_us"to the hot-kernel summary row inside_build_hot_kernel_summaries. This PR moved that same row into_hot_kernel_rowat src/hyperloom/orchestrator/state/shared_state.py:291, so the PR's copy lacks both keys.gh pr view 2020reportsmergeable: CONFLICTING.git merge-tree main b0969ef4conflicts inshared_state.py(that block) and inscripts/code_metrics_baseline.txt, where main'smodule-lines ... shared_state.pyis 2548 and this PR's is 2425.
Impact: The PR cannot merge. A resolution that keeps the PR side of the block silently removescall_count/duration_usfromlast_trace_analyze.hot_kernels_top15and undoes #2087's report fix.
Action: Merge current main. Add"call_count": entry.get("call_count")and"duration_us": entry.get("duration_us")to_hot_kernel_rowaftergpu_pct. Regenerate the baseline withscripts/code_metrics.py --update-baseline. Then confirm #2087'stest_record_trace_analyze_disk_recovery.py::test_discovered_kernel_rows_carry_call_count_and_durationpasses on the merged head.
SKIPPED: V4 -- # PARTIAL: lines for #1869, #1276, #1154, #1032 in openprs.txt; overlap with those PRs is unchecked.
Checked: shared_state.py at base bb2da63 vs head b0969ef for every moved/split unit: resolve_graded_comparison (both axes), profile_workload_context, current_profile_workload_context key swap, _build_explore_search vs phase_state._control_fields/_string_list, record_trace_analyze, _build_hot_kernel_summaries/_hot_kernel_row, _append_roofline_snapshot_history/_record_bottleneck_saturation/_saturation_delta, record_baseline_roofline_ceiling, append_stack_gain_entry; gaps.py upsert_gap vs gap_rows.recency_key; coerce.to_int/to_str_list, gain_math.gain_pct/gain_pct_or_zero, perf_metric.perf_snapshot_from_mapping/axis_of, roofline_snapshot.direction_saturation, roofline_ceiling.compute_roofline_breakdown_from_state; tree-wide grep of roofline_snapshots writers and of the callers of every reshaped function; main 4371269's _build_hot_kernel_summaries | Ran: differential harness on base and head src (6500 cases: 3000 profile_workload_context, 2000 resolve_graded_comparison, 1000 _build_explore_search, 200x60 upsert_gap, 300 record_trace_analyze) -> 0 diffs for grading/explore/gaps; profile diffs only on bool/inf/0/False/dict/scalar inputs; trace-analyze diffs only on a bool roofline_snapshot_id; head test_record_trace_analyze_lock.py run against base src (6 passed); ruff C901 head vs base on both files; fresh-interpreter import of gaps/grading/perf_metric/shared_state; gh pr view 2020 --json mergeable; git merge-tree main b0969ef; independent reader re-ran gh pr view and git merge-tree --write-tree origin/main(4371269) b0969ef | Base: bb2da63 | Head: b0969ef
…state # Conflicts: # scripts/code_metrics_baseline.txt # src/hyperloom/orchestrator/state/shared_state.py
…e made stale Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…state # Conflicts: # scripts/code_metrics_baseline.txt
chaojhou
left a comment
There was a problem hiding this comment.
PR #2020 -- refactor(orchestrator-state): delete the duplicated grading, profile-identity and trace-analyze paths
What it does: Shrinks seven over-trigger bodies in orchestrator/state/shared_state.py and state/gaps.py by deleting logic other owners already provide: winners-history controls now come from phase_state._control_fields, gap trimming from gap_rows.recency_key, profile runtime fields from _STACK_BASE_FIELDS with coerce.to_int/to_str_list, and the hot-kernel row and bottleneck-saturation bookkeeping become _hot_kernel_row and _record_bottleneck_saturation. Production code is 134 lines smaller. A base-vs-head differential run over generated inputs gave identical output for valid inputs. Output differs only on the malformed-input coercions the description names, plus two it does not (see below; not blocking).
Blocking issues: none
Checked: shared_state.py at base bb2da63 vs head b0969ef for every moved/split unit: resolve_graded_comparison (both axes), profile_workload_context, current_profile_workload_context key swap, _build_explore_search vs phase_state._control_fields/_string_list, record_trace_analyze, _build_hot_kernel_summaries/_hot_kernel_row, _append_roofline_snapshot_history/_record_bottleneck_saturation/_saturation_delta, record_baseline_roofline_ceiling, append_stack_gain_entry; gaps.py upsert_gap vs gap_rows.recency_key; coerce.to_int/to_str_list, gain_math.gain_pct/gain_pct_or_zero, perf_metric.perf_snapshot_from_mapping/axis_of, roofline_snapshot.direction_saturation, roofline_ceiling.compute_roofline_breakdown_from_state; tree-wide grep of roofline_snapshots writers and of the callers of every reshaped function; main 4371269's _build_hot_kernel_summaries | Ran: differential harness on base and head src (6500 cases: 3000 profile_workload_context, 2000 resolve_graded_comparison, 1000 _build_explore_search, 200x60 upsert_gap, 300 record_trace_analyze) -> 0 diffs for grading/explore/gaps; profile diffs only on bool/inf/0/False/dict/scalar inputs; trace-analyze diffs only on a bool roofline_snapshot_id; head test_record_trace_analyze_lock.py run against base src (6 passed); ruff C901 head vs base on both files; fresh-interpreter import of gaps/grading/perf_metric/shared_state; gh pr view 2020 --json mergeable; git merge-tree main b0969ef; independent reader re-ran gh pr view and git merge-tree --write-tree origin/main(4371269) b0969ef | Re-review at 6045eb3: the earlier [V5] is resolved -- the branch merges main (incl. #2087) and git merge-tree with origin/main is clean; _hot_kernel_row keeps call_count and duration_us (shared_state.py:305-306); non-baseline diff against main has the same patch-id as at b2e5d2b and the body is unchanged; baseline only removes 8 entries and lowers shared_state.py module-lines; CI green | Base: bb2da63 | Head: 6045eb3
LGTM
What this does
Consolidates grading, profile identity construction, persisted winner controls, and trace-analysis projection in
orchestrator/state/shared_state.py. Profile override names come fromPROFILE_OVERRIDABLE_KEYS; the identity-key tuple derives from it. Winner controls reuse_control_fields, and gap trimming reusesgap_rows.recency_keyinstead of a local sorter. Hot-kernel row projection and bottleneck saturation bookkeeping become named helpers. No module or type is added.Relative to main
bb2da63332dcbc46bdf10702c516ef43eb80a016, production code is 134 lines smaller:shared_state.py+258/-382 andgaps.py+10/-20. Including the test and metrics baseline, the complete PR is 115 lines smaller.The existing
size-exceptioncovers 670 changed production lines, counting additions plus deletions. The canonical trace-analysis projection, its history and saturation update, and the grading/profile values read from that state are reviewed together so the persisted contracts remain aligned.SharedStateretains ownership of its serialized fields and canonical writes; the module's remaining size debt is lowered rather than redistributed into modules that would duplicate that ownership.Observable effect
Valid numeric workload fields, valid trace-analysis envelopes, and KEEP/REVERT decisions retain their existing contracts. Canonical
last_trace_analyzeis still written before history is appended, and history failures still propagate after that write. Snapshot history retains the first baseline anchor and compares bottleneck saturation against the previous macro cycle when available.Some malformed-input coercions change. Profile integers and the previous roofline snapshot id use
to_int, which rejects booleans and non-finite numbers; such profile values become zero, and an invalid snapshot id restarts at one. Profile removal/unset lists useto_str_list, whose scalar fallback produces a stripped string instead of raising while attempting to iterate a scalar. These changes do not mean arbitrary malformed persisted state is accepted. The grading helper's zero fallback does not bypass the positive P50 gain threshold or the comparability and constraint gates.Complexity and validation
Measured with ruff 0.16.2 and complexipy 8.0.1 against the main commit above; lines are physical spans from
defthrough the last statement:record_trace_analyze_append_roofline_snapshot_historyprofile_workload_contextThe baseline diff removes 8 entries, lowers the
shared_state.pymodule-lines allowance 2549→2425, and adds none. This describes the changed units and does not claim the whole module has no existing size or complexity debt.Validation: 92 tests passed in
test_record_trace_analyze_lock.py,test_graded_comparison.py, andtest_gaps_field.pyunder Linux/Python 3.10. This includes canonical-write/history-failure ordering, history capping, previous-cycle saturation, grading and gap merge behavior. Ruff lint and format checks passed for both production files. The head already contains the main commit named above.