Skip to content

Commit 7d57055

Browse files
claude-nightshift[bot]Nightshift ScoutNightshift Scoutclaude
authored
[nightshift] 20260422 multi-cleanup (#5044)
> *dcebae8d — haiku* > Dead code falls away > Stale comments drift with the breeze > Logs hoist at module root ## Summary Nightshift cleanup sweep across `lib/iris` and `lib/zephyr`. Two scouts produced changes; two filed `no_change` with notes recorded below for follow-up. ### lib/iris/src/iris (applied — 7505fd9) - Hoisted the `from iris.rpc import logging_pb2` import and the `_STR_TO_ENUM` mapping in `iris/logging.py` out of the `str_to_log_level` function body to module scope. The deferred import had no corresponding circular dependency (`iris.rpc.logging_pb2` does not import `iris.logging`) and every file that imports `str_to_log_level` already imports `logging_pb2` directly. - Widened the `str_to_log_level` parameter type to `str | None` and folded the falsy-check into the function, allowing four call sites to drop their redundant `if level_name else 0` guards. - Fixed a stale code comment in `cluster/types.py` that pointed at `iris.logging` for `LevelPrefixFormatter` / `_LEVEL_PREFIX` — those helpers live in `rigging.log_setup`. ### lib/zephyr/src/zephyr (applied — a3d9e7c) - Removed the dead `scatter_manifest_dir` parameter from `_regroup_result_refs`, its two call sites, and the two local variables (`output_stage_name`, `join_output_stage_name`) that only existed to construct the now-unused path. The coordinator-side scatter manifest was removed in #4853 but this plumbing was left behind. ### lib/levanter/src/levanter (no_change — findings only) Scout flagged but could not commit (sandbox denied file writes): - **Correctness bug**: `levanter/schedule.py:value_at_step` iterates the schedule forward and returns the first entry whose `start <= step`, which always yields the earliest segment's value for any schedule with more than one `ScheduleStep`. The call site `levanter/trainer.py:batch_axis_at_step` depends on this, so a training run configuring `train_batch_size` as an `IntSchedule` gets the wrong batch size after the first segment boundary. Regressed in PR #887 / commit 83f3f34 (renamed `until` → `start` without reversing the iteration order). - `utils/stat_utils.py:RunningMean.add` recomputes `self.total + total` twice (harmless duplicate). - `shapes.py:conforms` appears unreferenced across `lib/`. - `utils/background_iterable.py:80-87` has tautological `except StopIteration: raise` / `except Exception as e: raise e` blocks flagged by the AGENTS.md LLM-pitfall list. ### lib/marin/src/marin (no_change — findings only) Scout identified dead code but was also blocked by the sandbox: - `asdict_excluding` in `utils.py` (~27 LOC + self-referential tests) — last real caller was removed when speedrun code was deleted in #4541. - `lib/marin/src/marin/cluster/ray.py` (959 LOC, entirely unused) — already being removed in open PR #5028, so not duplicated here. - `evaluation/utils.py` uses `print` instead of `logger` in `download_from_gcs` / `upload_to_gcs`. - `core/runtime.py` still calls `datetime.utcnow()` (deprecated in 3.12). ## Test plan - [x] `./infra/pre-commit.py --all-files --fix` — clean - [x] `uv run pytest -x lib/iris/tests/test_logging.py` — 19 passed - [x] `uv run pytest -x lib/zephyr/tests/test_execution.py` — 42 passed --------- Co-authored-by: Nightshift Scout <nightshift@example.com> Co-authored-by: Nightshift Scout <nightshift-scout@anthropic.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 53bf959 commit 7d57055

7 files changed

Lines changed: 22 additions & 28 deletions

File tree

lib/iris/src/iris/cluster/log_store/duckdb_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def get_logs(
525525
regular expression and matched with DuckDB's ``regexp_matches()``.
526526
Otherwise it is treated as an exact key lookup.
527527
"""
528-
min_level_enum = str_to_log_level(min_level) if min_level else 0
528+
min_level_enum = str_to_log_level(min_level)
529529
is_pattern = bool(REGEX_META_RE.search(key))
530530

531531
if not is_pattern:

lib/iris/src/iris/cluster/log_store/mem_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def get_logs(
103103
tail: bool = False,
104104
min_level: str = "",
105105
) -> LogReadResult:
106-
min_level_enum = str_to_log_level(min_level) if min_level else 0
106+
min_level_enum = str_to_log_level(min_level)
107107
is_pattern = bool(REGEX_META_RE.search(key))
108108

109109
if is_pattern:

lib/iris/src/iris/cluster/providers/k8s/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def _build_pod_manifest(
525525

526526
def _kubectl_log_line_to_log_entry(kll: KubectlLogLine, attempt_id: int) -> logging_pb2.LogEntry:
527527
level_name = parse_log_level(kll.data)
528-
level = str_to_log_level(level_name) if level_name else 0
528+
level = str_to_log_level(level_name)
529529
entry = logging_pb2.LogEntry(source=kll.stream, data=kll.data, attempt_id=attempt_id, level=level)
530530
entry.timestamp.CopyFrom(timestamp_to_proto(Timestamp.from_seconds(kll.timestamp.timestamp())))
531531
return entry

lib/iris/src/iris/cluster/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,9 @@ def to_proto(self) -> job_pb2.ResourceSpecProto:
481481
482482
# Reinitialize logging with the unified Iris format.
483483
# Uses single-letter level prefix: I=INFO, W=WARNING, E=ERROR, D=DEBUG, C=CRITICAL.
484-
# NOTE: This duplicates LevelPrefixFormatter and _LEVEL_PREFIX from iris.logging
484+
# NOTE: This duplicates LevelPrefixFormatter and _LEVEL_PREFIX from rigging.log_setup
485485
# because CALLABLE_RUNNER executes inside an isolated task container that may not
486-
# have the iris package installed (e.g. user-provided Docker images).
486+
# have the rigging package installed (e.g. user-provided Docker images).
487487
_LEVEL_PREFIX = {"DEBUG": "D", "INFO": "I", "WARNING": "W", "ERROR": "E", "CRITICAL": "C"}
488488
489489
class _LevelPrefixFormatter(logging.Formatter):

lib/iris/src/iris/cluster/worker/task_attempt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ def _monitor_loop(
898898
def _make_log_entry(self, *, source: str, data: str) -> logging_pb2.LogEntry:
899899
"""Build a LogEntry proto from a source/data pair, parsing the level prefix."""
900900
level_name = parse_log_level(data)
901-
level = str_to_log_level(level_name) if level_name else 0
901+
level = str_to_log_level(level_name)
902902
entry = logging_pb2.LogEntry(source=source, data=data, level=level)
903903
entry.timestamp.epoch_ms = Timestamp.now().epoch_ms()
904904
return entry

lib/iris/src/iris/logging.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@
88
retains only the functions that depend on ``iris.rpc.logging_pb2``.
99
"""
1010

11+
from iris.rpc import logging_pb2
1112

12-
def str_to_log_level(level_name: str) -> int:
13+
_STR_TO_ENUM = {
14+
"DEBUG": logging_pb2.LOG_LEVEL_DEBUG,
15+
"INFO": logging_pb2.LOG_LEVEL_INFO,
16+
"WARNING": logging_pb2.LOG_LEVEL_WARNING,
17+
"ERROR": logging_pb2.LOG_LEVEL_ERROR,
18+
"CRITICAL": logging_pb2.LOG_LEVEL_CRITICAL,
19+
}
20+
21+
22+
def str_to_log_level(level_name: str | None) -> int:
1323
"""Convert a canonical level name (e.g. "INFO") to the LogLevel proto enum value.
1424
15-
Returns LOG_LEVEL_UNKNOWN (0) for unrecognized names.
16-
Uses lazy import to avoid pulling in protobuf at module load time.
25+
Returns ``LOG_LEVEL_UNKNOWN`` (0) for ``None``, empty strings, and
26+
unrecognized names.
1727
"""
18-
from iris.rpc import logging_pb2
19-
20-
_STR_TO_ENUM = {
21-
"DEBUG": logging_pb2.LOG_LEVEL_DEBUG,
22-
"INFO": logging_pb2.LOG_LEVEL_INFO,
23-
"WARNING": logging_pb2.LOG_LEVEL_WARNING,
24-
"ERROR": logging_pb2.LOG_LEVEL_ERROR,
25-
"CRITICAL": logging_pb2.LOG_LEVEL_CRITICAL,
26-
}
27-
return (
28-
_STR_TO_ENUM.get(level_name.upper(), logging_pb2.LOG_LEVEL_UNKNOWN)
29-
if level_name
30-
else logging_pb2.LOG_LEVEL_UNKNOWN
31-
)
28+
if not level_name:
29+
return logging_pb2.LOG_LEVEL_UNKNOWN
30+
return _STR_TO_ENUM.get(level_name.upper(), logging_pb2.LOG_LEVEL_UNKNOWN)

lib/zephyr/src/zephyr/execution.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,6 @@ def run_pipeline(
866866

867867
# Build and submit tasks
868868
tasks = _compute_tasks_from_shards(shards, stage, aux_per_shard, stage_name=stage_label)
869-
output_stage_name = tasks[0].stage_name if tasks else stage_label
870869
logger.info("[%s] Starting stage %s with %d tasks", self._execution_id, stage_label, len(tasks))
871870
self._start_stage(stage_label, tasks, is_last_stage=(stage_idx == last_worker_stage_idx))
872871

@@ -881,7 +880,6 @@ def run_pipeline(
881880
len(shards),
882881
output_shard_count=stage.output_shards,
883882
is_scatter=stage_is_scatter,
884-
scatter_manifest_dir=f"{self._chunk_prefix}/{self._execution_id}/{output_stage_name}",
885883
)
886884

887885
# Flatten final results — each shard may involve I/O (unpickling from
@@ -923,7 +921,6 @@ def _compute_join_aux(
923921

924922
join_stage_label = f"join-right-{parent_stage_idx}-{i}-stage{stage_idx}"
925923
right_tasks = _compute_tasks_from_shards(right_refs, right_stage, stage_name=join_stage_label)
926-
join_output_stage_name = right_tasks[0].stage_name if right_tasks else join_stage_label
927924
self._start_stage(join_stage_label, right_tasks)
928925
self._wait_for_stage()
929926
raw = self._collect_results()
@@ -933,7 +930,6 @@ def _compute_join_aux(
933930
len(right_refs),
934931
output_shard_count=right_stage.output_shards,
935932
is_scatter=right_is_scatter,
936-
scatter_manifest_dir=f"{self._chunk_prefix}/{self._execution_id}/{join_output_stage_name}",
937933
)
938934

939935
if len(shard_refs) != len(right_refs):
@@ -1313,7 +1309,6 @@ def _regroup_result_refs(
13131309
input_shard_count: int,
13141310
output_shard_count: int | None = None,
13151311
is_scatter: bool = False,
1316-
scatter_manifest_dir: str = "",
13171312
) -> list[Shard]:
13181313
"""Regroup worker output refs by output shard index without loading data.
13191314

0 commit comments

Comments
 (0)