Skip to content

refactor: delete the dead and repeated code in fourteen over-gate functions - #2024

Merged
ZhengGong-amd merged 25 commits into
mainfrom
lean/shafeng/cc20-hyperloom-misc
Oct 21, 2026
Merged

ZhengGong-amd merged 25 commits into
mainfrom
lean/shafeng/cc20-hyperloom-misc

Conversation

@fengshaoyi-amd

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

Copy link
Copy Markdown
Contributor

What this does

Fourteen functions across the multi-node launcher, the decision trace, the Langfuse backfill, the critic's decision reviewer, research hints, the session manifest, two hyperloom.common helpers, the KB collector and the quantization driver were over the code-metrics gate. This PR brings each one under every limit it broke, mostly by deleting code: a health wait its only caller always switched off, a second copy of the kill escalation, coercions of values the only caller already passes as numbers, decision-trace rows rebuilt after they were built, span-time and score fallbacks the producer never needs, a KB prior lookup written out twice, and manifest fields read once from the env and again from args.

Production code: +384 / −637 (net −253) across 12 files. The code-metrics baseline loses 21 entries and gains none. The cleanup continues in #2026 and #2052.

How to read it. This branch was opened before the rework, so its history keeps the first pass (helpers extracted from these functions) and 8925eee2a, which returns all of it to main's code. Review the overall diff, or the commits from 0bd299e05 on: each changes one module, and its message lists what it deleted and why that is safe.

Commit Module Production lines Baseline entries removed
0bd299e drop the dead health wait, share the kill escalation (and 141cac8) multi_node/scripts/launch_infera_node.py, multi_node/_internal/infera_support.py +59 / −148 4
0f114ef build each decision-trace row once trace/decision_trace.py +87 / −114 2
6fac249 drop dead span-time fallbacks from the Langfuse backfill tools/backfill_langfuse.py +77 / −94 2
21dcebe one KB prior lookup loop and one advice pass in the reviewer agents/critic/runtime/decision_reviewer.py +31 / −72 3
cf45cc1 one positive-number rule for target gaps baseline_comparison/research_hints.py +40 / −61 2
69bd6ab read each manifest field once from args or env session/manifest.py +35 / −54 2
914f359 derive the conc-pair summary from the rows it reports common/gain_math.py +19 / −44 1
95b556e one prefix table for unified-diff body lines common/unified_diff.py +6 / −12 1
7dc78a2 skip a failing unit where it is prepared hyperloom_kb/collect/engine.py +17 / −22 2
d14d9a7 set operations for the mapping call head check hyperloom_kb/collect/expressions.py +3 / −3 1
db9911c one manifest guard and a step table in classify_attempt agents/quantization/driver/assessment.py +10 / −13 1

multi_node/, trace/, tools/, baseline_comparison/ and session/ are under src/hyperloom/inference_optimizer/; agents/ and common/ under src/hyperloom/; hyperloom_kb/ is src/hyperloom_kb/.

Gate numbers per function

Measured with the gate's own tools (ruff C901, complexipy, function lines), base → head. Limits are 20, 30 and 80; a value at a limit passes. Bold values were over the limit at base.

Function Cyclomatic Cognitive Lines
launch_infera_node.main 17 → 13 32 → 22 126 → 79
_kill_prior 15 → 5 40 → 8 52 → 25
_reap_stale_engines_by_cmdline 15 → 9 32 → 17 45 → 30
write_decision_trace 17 → 5 53 → 12 151 → 62
backfill_langfuse.ingest 13 → 9 44 → 19 148 → 70
prepare_review 12 → 6 29 → 12 119 → 49
_commit_coordinator_inbox 16 → 13 34 → 30 83 → 76
gap_analysis 14 → 6 50 → 30 83 → 59
build_manifest 10 → 3 45 → 21 105 → 80
conc_pair_comparison 7 → 4 29 → 23 100 → 79
parse_unified_diff 15 → 12 36 → 30 49 → 43
collect (KB collector) 15 → 12 31 → 27 89 → 79
_compile_call 13 → 13 34 → 30 58 → 58
classify_attempt 20 → 17 36 → 30 73 → 70

Across the 12 touched production files: C901 total 780 → 727 and cognitive total 1,398 → 1,226. Functions over a gate limit: cognitive 13 → 1 and length 9 → 0. The one left, _reap_stale_engine_ports (cognitive 51, already in the baseline), is a function this PR does not change.

New names

  • _term_then_kill (launcher): SIGTERM, wait, SIGKILL, wait, for a list of pids and an optional process group. _kill_prior and _reap_stale_engines_by_cmdline each wrote this loop out.
  • _parse_args (launcher): the launcher's argparse definition, out of main.
  • _keep_revert_decision and _dynamic_action_decision (decision trace): the row for one KEEP/REVERT entry and for one dynamic-action dispatch. write_decision_trace indexes the calls, builds the rows, attaches token rollups in time order and writes.
  • _emit_agent and _emit_recipe_audit (Langfuse backfill): one agent span with its generations, and the agent:recipe_kb subtree.
  • _fetch_kb_priors (decision reviewer): one loop over (msg_id, topic) pairs for the KB prior lookups prepare_review wrote out once for proposals and again for the decision. msg_id=None is the decision-level lookup, as the persisted kb_priors_trace request record already states it.
  • _gap_pct (research hints): the one rule both percent gaps share in both modes, a gap only when both sides are positive numbers.
  • _env_digits (manifest): an env var as an int when it is all digits, else None; five manifest fields use it. hyperloom.common.env.env_int is not a fit: it accepts negatives and raises on other text.

Removed: _wait_health, the --health-port and --health-wait-sec flags and INFERA_FRONTEND_PORT (launcher); _to_num, a forwarding wrapper around coerce.to_float (research hints); _norm_conc (conc-pair comparison).

Why the deletions are safe

Each one rests on a fact at the call site:

  • Health wait. build_node_launch_args, the only producer of the launcher's argv, always passed --health-wait-sec 0 (infera_support.py:139-140 at the merge base), so the wait never ran. The launcher is bundled with its caller and shipped on every launch (commands/infera.py:149), so the two cannot drift apart.
  • gap_analysis. Its only production caller, gap_for_state (research_hints.py:361), passes a positive number or None.
  • _norm_conc. The only production caller, conc_sweep's _point_from_variant, builds conc with int(envs.get("CONC", "0")) (conc_sweep.py:183).
  • The decision-level lookup in prepare_review. It is recognised by msg_id is None. Every proposal's msg_id is a non-empty string: parse_request requires it (request_models.py:162) and the inbox parser only matches [A-Za-z0-9_\-]+ (inbox_parser.py:24, :205).
  • collect's two error handlers. _prepare, the one place both errors are raised from and called only from collect (engine.py:495), now raises the skip itself with the same reason.
  • classify_attempt reading every step up front. ValidationSteps is a frozen dataclass (quantization/driver/result_collector.py:27-28), so the reads have no side effect.
  • The backfill's or [] and hand-copied score fields. build_plan always sets recipe_audit (backfill_langfuse.py:161), and decision_to_scores (trace/langfuse_mapping.py:253) builds every score with exactly name, value, data_type, comment and metadata.
  • The manifest's second reads. getattr on an argparse namespace has no side effect and build_provenance never writes os.environ, so reading each field once in a different order reads the same values.

Observable effect

Nothing an operator sees changes. Launches, kills, decision traces, Langfuse spans and scores, critic reviews, research hints, manifests, KB collection reports and log lines are the same for every input the repo's own callers produce.

The differences below are reachable only by input that no caller in the repo produces:

  • Launcher flags. A manual run of launch_infera_node.py with --health-port or --health-wait-sec now exits 2 with "unrecognized arguments". Nothing in the tree passes them.
  • Launcher pid file. The pid file is read without checking first that it is a regular file. A missing file or a directory still reads as no prior server; a FIFO at that path would now block the read. The path is always the launcher's own pid file.
  • gap_analysis. A synthetic competitor-target row with a negative interactivity no longer yields an interactivity gap; it is treated like a zero or missing value, as the AgentX mode already did. An accepted throughput that is negative, a bool or infinite no longer yields a throughput gap.
  • conc_pair_comparison. A point whose conc is a bool is keyed and reported as True/False instead of 1/0.
  • build_manifest. With --isl/--osl given, $ISL/$OSL is no longer parsed. That matters only for a value str.isdigit() accepts and int() rejects, such as "²", on which the base code raised even though the argument overrode it.

Checklist

  • Description: above.
  • Linked issue(s): none.
  • Tests:
    • test_to_num goes with _to_num, the forwarding wrapper it tested; gap_analysis keeps its existing tests. No other test changes.
    • The rework was run differentially against main's version of each module, with no difference outside the list above:
      • Decision trace: 3,000 random sessions, byte-identical decision_trace.jsonl and warnings.
      • Langfuse backfill: 1,500 sessions against a recording fake SDK.
      • Decision reviewer: 4,000 prepare requests and 4,000 inbox commits.
      • Unified diff, mapping call heads and classify_attempt: 9,000 inputs each.
      • Conc-pair comparison: 6,000 ladders, plus 3,000 with a bool conc.
      • KB collector and manifest: 3,000 each.
      • The launcher's kill escalation: 12,000 scenarios.
    • Linux CI on this PR is the authority: every test shard passes.
  • Size/complexity triggers crossed:
    • 1,021 changed production lines is over the 1,000-line budget, so this carries size-exception. Eleven modules share one review round, each rework commit changes one module and reads on its own, and the net is −253.
    • No added or changed function crosses a gate limit. build_manifest (80 lines) and _commit_coordinator_inbox, gap_analysis, parse_unified_diff, _compile_call and classify_attempt (cognitive 30 each) sit at a limit.
  • If this simplifies or refactors:
    • Mechanisms removed:
      • The disabled leader health wait, its two flags and the argv that fed them.
      • A second copy of the TERM-then-KILL escalation.
      • Coercion of values the caller already guarantees (_to_num, _norm_conc, the AgentX-only normalisation in gap_analysis).
      • A join-time rebuild of every decision-trace row, and five copies of one field-copy rule.
      • Span-time and score fallbacks the producer never needs.
      • A second KB prior lookup loop and a second pass over the critic's advice.
      • Manifest fields read from the env and then again from args.
    • Contract preserved: every in-repo caller and all persisted data.
    • Tests: as above.
  • Observable effect: see the section above.
  • Breaking changes: none for in-repo callers or persisted data. The removed launcher flags belong to the pod script hyperloom mn ships with each launch, and it never enabled them.
  • Single concern: bringing these fourteen functions under the gate.
  • Root cause upstream: not applicable.

Known merge interactions

Gate

scripts/code_metrics.py --base-ref origin/main passes: 0 new, 0 worse. Baseline: −21 entries, +0. ruff check and ruff format --check are clean on the touched files.

fengshaoyi-amd and others added 7 commits October 19, 2026 19:10
…d retrieval code ran inline

Each function below was over a cyclomatic complexity of 20, counting every
branch, loop, except handler, boolean operator, ternary and comprehension
clause. The extracted helper names the job the function did inline:

- _compile_call 25 -> 19: _call_head picks the call's one builtin head and
  rejects the keys that head does not accept.
- RetrievalConfiguration.__post_init__ 22 -> 12: _limits and _provider_refs
  validate the two per-capability maps.
- FieldDeclaration.__post_init__ 26 -> 17: _check_role holds the role rules.
- QueryView.from_dict 21 -> 16: _field_lookup_from_dict decodes field_lookup.
- collect 21 -> 19: _project_unit returns a unit's projection, or the
  SkippedUnit that says why there is none.

No behaviour change; every error message is unchanged. The code-metrics
baseline drops the two cognitive-complexity entries this clears and lowers
collect's function length from 86 to 82.

Co-authored-by: Cursor <cursoragent@cursor.com>
…equests ran inline

write_decision_trace now reads as the pipeline its docstring describes: group
the calls by decision key, build each KEEP/REVERT and dynamic_action row, then
lay the rows out in ts order with their token rollups. The proposer attribution
(component, provenance, scope, fingerprint) is one helper, the grouping the
journal entry itself gives those fields.

stream_json_requests names the usage counters a row reports and whether the
per-request outputs add up to the result row's total.

No behaviour change. The two write_decision_trace baseline entries are removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
The keep_revert and dynamic_action rows of decision_trace.jsonl, and a
stream-json request that reports no usage, had no test of their own; the
code that builds them now lives in named helpers, so pin their contract.

Co-authored-by: Cursor <cursoragent@cursor.com>
…s ran inline

Bring DecisionReviewer.prepare_review, DecisionReviewer._commit_coordinator_inbox,
classify_attempt, conc_pair_comparison and parse_unified_diff to cyclomatic
complexity 20 or below by lifting each inline job into a private helper:

- decision_reviewer: the KB-read skip gates and the prior lookups (now one
  _PriorLookups trail) leave prepare_review; advice grouping, verdict
  validation and standalone advice intents leave _commit_coordinator_inbox.
- assessment: the MUST-have file gap and the validator report each map to
  an outcome in their own function, under one manifest guard.
- gain_math: the pair speedup, the guard-axis reading and the summary stats
  leave conc_pair_comparison; the pair counts derive from rows and speedups.
- unified_diff: filing one hunk body line leaves parse_unified_diff.

No behaviour change: messages, exception types, returned shapes and the
order of side effects are unchanged. The six code-metrics baseline entries
these functions no longer exceed are removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
Bring main, _kill_prior and _reap_stale_engines_by_cmdline in the Infera
pod launcher to cyclomatic complexity 20 or below by lifting each inline
job into a private helper in the same stdlib-only script:

- launch_infera_node: _kill_prior and _reap_stale_engines_by_cmdline
  share one SIGTERM-then-SIGKILL escalation helper, _term_then_kill,
  instead of each carrying its own copy of the loop; the /proc cmdline
  scan leaves the reaper as _stale_engine_pids; main hands off the
  argument parser, the rendezvous-leader choice, the shared server-log
  dir check (now made once instead of twice), the GPU sampler files and
  its optional start, the launch-argument validation, the ray node
  teardown and the leader health wait with its log tail.

No behaviour change: the CLI flags and defaults, exit codes, the stdout
JSON (key order included), log lines, the prior-server RuntimeError,
files written and the order of subprocess, signal and network calls are
unchanged. _kill_prior now sends signal.SIGTERM and signal.SIGKILL where
it sent 15 and 9; they are the same signal numbers. The four
code-metrics baseline entries these functions no longer exceed are
removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
Bring seed_native_geak_proxy, agentx_measurement, find_reference_rows,
gap_analysis, match_variants_to_priors, build_manifest, ingest and
_summary_line to cyclomatic complexity 20 or below by lifting each inline
job into a private helper:

- geak_proxy: assembling the proxy's runtime environment (explicit
  overrides, the executable's PATH entry, no device pinning) leaves
  seed_native_geak_proxy.
- report: converting the latency percentiles to milliseconds leaves
  agentx_measurement.
- inferencex_client: the single-node hardware filter and the fixed-shape
  filter become named predicates of find_reference_rows.
- research_hints: the three axis-gap formulas, the synthetic and AgentX
  primary-gap rules and the AgentX status fields leave gap_analysis;
  tokenizing the hints and a variant leaves match_variants_to_priors.
- manifest: the workload block, the run identity (one _RunIdentity) and
  the all-digits env read leave build_manifest, which also drops eight
  `args is not None` guards that only restated getattr's default.
- backfill_langfuse: one agent span with its generations, the recipe-KB
  audit subtree and the decision scores leave ingest.
- dump_session_breakdown: the GEAK keep count leaves _summary_line.

No behaviour change: messages, exception types, returned shapes and the
order of side effects are unchanged. The six code-metrics baseline entries
these functions no longer exceed are removed.

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

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Code metrics gate: PASSED

Judged: the 14 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 59 +0
Cognitive complexity fails > 30 0 0 0 233 -12
Function length (lines) fails > 80 0 0 0 382 -9
Nested block depth fails > 5 0 0 0 24 +0
Parameter count fails > 5 0 0 0 95 +0
Module length (lines) warns > 800, fails > 1200 0 0 0 50 +0
Duplicated lines per file fails > 0 0 0 0 97 +0
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
116 findings in files this change does not touch

Outside this change (informational): 116

Unit Dimension Baseline Now
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/cli/forge_loop_command.py forge_loop Cognitive complexity absent 31
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/inference_optimizer/cli/__init__.py _reexport_session_environment Function length (lines) absent 111
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 170
src/hyperloom/inference_optimizer/cli/__init__.py _seed_fresh_session Function length (lines) absent 170
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 84
src/hyperloom_kb/sync.py GlobalSync.pull Function length (lines) absent 84
src/kernelforge/cli/forge_loop_command.py _RunReporter.build_result Function length (lines) absent 92
src/kernelforge/cli/forge_loop_command.py _prepare_measurement_driver Function length (lines) absent 136
src/kernelforge/cli/forge_loop_command.py _read_kb_warm_start Function length (lines) absent 149
src/kernelforge/loop/runner.py IterationLoop._close_iteration Function length (lines) absent 117
src/kernelforge/loop/runner.py IterationLoop._collect_session_candidate Function length (lines) absent 185
src/kernelforge/loop/runner.py IterationLoop._implementer_history Function length (lines) absent 112
src/kernelforge/loop/runner.py IterationLoop._rule_on_attempt Function length (lines) absent 102
src/kernelforge/loop/runner.py IterationLoop._source_attempt Function length (lines) absent 175

...and 91 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.

@fengshaoyi-amd
fengshaoyi-amd marked this pull request as draft October 20, 2026 03:34
@fengshaoyi-amd

Copy link
Copy Markdown
Contributor Author

Back to draft while I rework this along the review guidance on the parallel complexity PRs: delete mechanisms instead of relocating them, keep production code net-negative, and touch only functions that were over the code-metrics gate thresholds. I will mark it ready again with the gate's own before/after numbers in the description.

fengshaoyi-amd and others added 11 commits October 20, 2026 11:38
The first pass split twenty-three functions into helpers without removing
a mechanism, so it moved code instead of shrinking it. Every file it
touched goes back to its origin/main content: the twenty-two source and
test files, the code-metrics baseline entries it added for the new
helpers, and test_decision_trace_rows.py, which only pinned helpers that
no longer exist.

The nine functions that only a cmetrics floor flagged (none of them is
over the code-metrics gate) stay at this version. The fourteen that are
over the gate are reworked deletion-first in the commits that follow.

Safe: these files are byte-identical to origin/main, so their behaviour
is main's.

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

Deleted the leader /health wait: _wait_health, the --health-port and
--health-wait-sec flags, INFERA_FRONTEND_PORT and the argv elements that
fed them. build_node_launch_args, the only producer of the launcher's
argv, always passed --health-wait-sec 0, so the wait, health_ok and
log_tail never ran. The launcher is bundled and shipped with its caller
on every launch, so the two cannot drift apart.

_kill_prior and _reap_stale_engines_by_cmdline each ran the same
SIGTERM, wait, SIGKILL, wait loop. _term_then_kill is that loop once,
with the optional process-group signal _kill_prior adds; kill order,
liveness probes, timeouts and log lines are unchanged.

_kill_prior also loses the is_file() pre-check (the read's OSError
handler already covers a missing pid file), the empty targets default
and its if (_proc_tree always includes the root) and the truthiness test
in front of pid > 0. main reads HYPERLOOM_MN_SERVER_LOG_DIR once instead
of evaluating the same check twice, calls _detach_launch once after the
framework branch, lets _start_gpu_sampler read its own interval as its
first statement, drops the `or ""` on an env value that is always a str,
and keeps its argparse definition in _parse_args.

Observable: a manual run that passes --health-port or --health-wait-sec
now exits 2 with "unrecognized arguments"; nothing in the tree passes
them. A non-regular file at the pid-file path is now read instead of
skipped; that path is always the launcher's own pid file.

Co-authored-by: Cursor <cursoragent@cursor.com>
Deleted _to_num, a forwarding wrapper around coerce.to_float; its callers
use to_float directly, and test_to_num goes with the wrapper it tested.

_gap_pct is the rule both percent gaps (throughput and interactivity)
share in both modes: a gap exists only when both sides parse as positive
numbers. It replaces the AgentX-only positive-or-None normalisation of
four inputs and the two inline gap conditions.

gap_analysis now computes, per mode, only the inputs, TPOT ratio and
primary-gap rule that mode uses; AgentX no longer computes the synthetic
inputs and rule and then overwrites them. The synthetic primary-gap
rule's two branches (with and without a throughput gap) are one
comparison against the throughput gap, or 0 when there is none.

Observable: a synthetic competitor-target row with a negative
interactivity no longer yields an interactivity gap; it is treated like
a zero or missing value, as AgentX already did. An accepted throughput
that is negative, boolean or infinite no longer yields a throughput gap;
gap_for_state, the only production caller, passes a positive number or
None.

Co-authored-by: Cursor <cursoragent@cursor.com>
Deleted from write_decision_trace:
- the intermediate row's "kind" entry, which nothing read;
- consumed_keys and its if/else: popping a key's calls out of
  calls_by_key hands them to the first decision, in time order, that
  names the key, exactly as the set did;
- the join-time rebuild of every row with `or ""` / `or {}` defaults:
  iso_z and phase_at always return a str and every row carries its
  decision dict, so the row built per source is the persisted row and
  the join only adds its tokens (the file is written with sort_keys, so
  key order does not change);
- the provenance conditional around proposer_for, which already maps ""
  to "orchestration";
- five copies of "copy the field when its text is non-empty" (kind,
  provenance, scope, fingerprint, variant_name), now one loop.

_keep_revert_decision and _dynamic_action_decision each build the row
for one decision source; write_decision_trace indexes the calls, builds
the rows, attaches token rollups in time order and writes.
write_session_decision_trace is untouched.

Safe: origin/main and this version wrote byte-identical
decision_trace.jsonl files and identical warnings for 3,000 randomly
generated sessions.

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

Deleted from ingest:
- `or a_lo` and `or p_lo` in the agent and phase end-time fallbacks:
  _time_bounds returns both bounds or neither and a datetime is always
  truthy, so those operands never decide anything. The fallback that
  remains is named once per phase (phase_start).
- the recipe-KB block's own min/max over parsed timestamps; it uses
  _time_bounds, which now reads ``ts`` with .get as audit rows need.
- `plan.get("recipe_audit") or []`: build_plan always sets the list.
- `score.get("metadata") or {}`, `score.get("comment") or ""` and the
  two hand-copied five-field kwargs lists: decision_to_scores builds
  every score with exactly name, value, data_type, comment (a str) and
  metadata (a dict), so the score is passed as it is.
- `span is not None` in front of hasattr(span, "score"), which is
  already False for None; the phase lookup uses lfmap.phase_of instead
  of a copy of it.
- `if p_hi is not None: last_end = p_hi`, now `p_hi or last_end`.

_emit_agent (one agent span with its generations) and _emit_recipe_audit
(the agent:recipe_kb subtree) each emit one subtree of the trace. The
langfuse import handler is untouched.

Safe: against a recording fake SDK, origin/main and this version made
identical span, end, score, create_score, flush and log calls for 1,500
randomly generated sessions.

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

prepare_review:
- the per-proposal and per-decision prior lookups were two copies of the
  same list_priors call, hit extraction, unreachable check and request
  record; one loop now runs over (msg_id, topic) pairs, where msg_id is
  None for the decision-level lookup exactly as the persisted request
  record already states it. Proposal.msg_id is always a non-empty str
  (parse_request and the inbox parser both guarantee it), so None
  identifies the decision lookup.
- the any_kb_unreachable flag is derived from the request records it
  duplicated.
- the read path (scope, lookups, audit trail, notes) is
  _fetch_kb_priors; prepare_review keeps the bundle setup and the four
  skip decisions.

_commit_coordinator_inbox:
- review["advice"] was read and filtered twice (dict with a body_md);
  it is filtered once and both the per-target inlining and the
  standalone advice intents read that list.
- the validated (item, target, verdict, intent) tuples are gone: the
  first pass validates every verdict and builds its intent, the second
  pass commits each item, reading target and verdict from items the
  first pass already checked. Nothing is committed unless every verdict
  validates, as before.

Safe: with recording fakes for the session memory and the KB writer,
origin/main and this version produced identical bundles, outcomes,
exceptions and call sequences for 4,000 random prepare requests and
4,000 random coordinator-inbox commits.

Co-authored-by: Cursor <cursoragent@cursor.com>
parse_unified_diff:
- the "@@" branch is gone: a hunk header starts with "@", which none of
  the body-line prefixes match, so it already fell through untouched.
- the three "+" / "-" / " " branches are one table from prefix to the
  FileChange list it feeds; the "+++" / "---" exclusion is one check.
- the "no leading diff --git" guard skips first and opens the section
  after, instead of an if/else around the open.

Safe: origin/main and this version produced identical FileChange lists
for 9,000 random patches built from header, hunk, body, "+++x"/"---x"
and empty lines.

Co-authored-by: Cursor <cursoragent@cursor.com>
_compile_call:
- the built-in heads are BUILTINS.intersection(node) and the rejected
  keys node.keys() - allowed, replacing two filtering comprehensions.
- str(heads[0]) is (head,) = heads: every BUILTINS member is already a
  str, and len(heads) == 1 was checked just above.

Safe: the error messages sort their keys, so set order never shows.
origin/main and this version compiled 9,000 random mapping nodes to
the same expression or the same MappingError text.

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

classify_attempt:
- steps (4) and (5) were guarded by the same
  "manifest_present and not manifest_parse_error" test twice in a row;
  they are one block, checked in the same order.
- the four "step == FAIL -> outcome" branches are a table walked in the
  same order, so the first failing step still decides the outcome.

Safe: ValidationSteps is a frozen dataclass, so reading every step up
front has no side effect. origin/main and this version classified
9,000 random attempt artefacts to the same OutcomeId.

Co-authored-by: Cursor <cursoragent@cursor.com>
conc_pair_comparison:
- the speedups list and the successful/failed counters duplicated what
  the rows already record; the summary derives them from the rows with
  a speedup.
- the best-rung search no longer re-filters with isinstance(float): a
  speedup is either None or ot / bt of two to_float results. max() over
  the paired rows keeps the first maximum, as the enumerate form did.
- the hand-rolled median is statistics.median, which averages the two
  middle values the same way.
- the "guard_axis and" checks and "if guard_axis else None" ternaries
  are gone: off the interactivity objective the axes dicts are already
  empty, so .get("") is None.
- _norm_conc is gone (see below).

Observable effect: a point whose "conc" is a bool now keys and reports
as True/False instead of 1/0. No in-tree producer emits one: the only
production caller, conc_sweep's _point_from_variant, builds conc with
int(envs.get("CONC", "0")).

Safe: origin/main and this version produced identical rows and
summaries for 6,000 random point ladders, and for 3,000 more with bool
conc values once conc is shown as int.

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

The kill escalation shared by the two kill paths kept their empty except clauses, which CodeQL reports as an empty except without an explanation; contextlib.suppress states the same rule without one.

Co-authored-by: Cursor <cursoragent@cursor.com>
@fengshaoyi-amd fengshaoyi-amd changed the title refactor: name the jobs twenty-three hyperloom functions ran inline refactor: delete the dead and repeated code in fourteen over-gate functions Oct 20, 2026
…erloom-misc

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

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown

Automated review started for head 88c2711. Progress: https://github.com/AMD-AGI/Hyperloom/actions/runs/39413612949

@github-actions

Copy link
Copy Markdown

Automated review: no verdict applied -- the review job ended with result 'failure'. Comment /review to retry. Run: https://github.com/AMD-AGI/Hyperloom/actions/runs/39413612949

…erloom-misc

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

@ZhengGong-amd ZhengGong-amd 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.

Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size-exception Waives the PR diff budget; added by a maintainer with a reason in the PR description

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants