Skip to content

Commit 1c984ab

Browse files
Kasper JungeRalphify
authored andcommitted
workspace: record reason alias inline in run_loop
Added coverage/engine.md noting the inline-alias refactor and the safety argument for the `state.status.reason` property access. Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent c5ce11d commit 1c984ab

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# `engine.py` coverage
2+
3+
Valid at: c5ce11d
4+
5+
## Recent changes
6+
7+
- c5ce11d — inlined the `reason = state.status.reason` local in
8+
`run_loop`. The alias was read exactly once on the next line as the
9+
`reason=` kwarg to `RunStoppedData(...)`. Inlined to
10+
`reason=state.status.reason` to match the chained-read style elsewhere
11+
(e.g. `_IterationPanel._apply_assistant`'s `raw.get("message", {}).get("usage")`
12+
after 52e0272). Same Phase 4 inline-alias shape as ce487d3 (`text`),
13+
52e0272 (`msg`), 497c028 (`agent`), fc5e1cb (`total_in`).
14+
Safe: the immediately-preceding `if state.status == RunStatus.RUNNING:
15+
state.status = RunStatus.COMPLETED` normalizes the status to a terminal
16+
value, so `RunStatus.reason`'s ValueError guard (non-terminal) cannot
17+
fire here.
18+
19+
## Structure notes
20+
21+
`run_loop` is the main loop orchestrator. Its control-flow helpers
22+
(`_handle_control_signals`, `_wait_for_resume`, `_run_iteration`,
23+
`_delay_if_needed`) are each short and single-purpose. `_run_iteration`
24+
splits into `_run_commands``_assemble_prompt``_run_agent_phase`.
25+
`_run_agent_phase` is the longest at ~80 lines but its branches map 1:1
26+
to the agent outcome tri-state (timed_out / success / failure) — no
27+
obvious extraction candidate without inventing synthetic abstractions.
28+
29+
## Potential future wins (not yet taken)
30+
31+
- None spotted. The locals that survive in `_run_agent_phase`
32+
(`duration`, `event_type`, `state_detail`, `ended_data`) all have
33+
multiple uses and good names. `_run_commands`'s `output` is mutated
34+
before use. `_run_iteration`'s `iteration` alias is used 4 times.

workspace/ralphs/improve-codebase/iterations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
One line per iteration: `<sha> <summary>`.
44

5+
c5ce11d refactor: inline `reason = state.status.reason` alias in `run_loop`'s `RUN_STOPPED` emit. The local was read exactly once as the `reason=` kwarg to `RunStoppedData(...)` on the next line; collapsing to `reason=state.status.reason` matches the inline-alias pattern from ce487d3 (`text`) / 52e0272 (`msg`) / 497c028 (`agent`) / fc5e1cb (`total_in`). Safe at this call site — the immediately-preceding `if state.status == RunStatus.RUNNING: state.status = RunStatus.COMPLETED` normalizes status to a terminal value (STOPPED / COMPLETED / FAILED), so the `RunStatus.reason` property's "non-terminal raises ValueError" guard cannot fire.
6+
57
3823019 refactor: narrow `line = escape_markup(data["line"])` scope past the early-return guard in `_on_agent_output_line` — the local was computed unconditionally inside `_console_lock` but only used on the `_IterationSpinner` branch; the `if not isinstance(target, _IterationSpinner): return` early-return path would have thrown the value away. Moving the binding below the guard preserves exactly the same output (same escape_markup call, same f-string, same add_scroll_line) while skipping the wasted work whenever target is None or an _IterationPanel. Same Phase 4 shape as 134078d (`name_col`), 7730dd4 (`secs`), ef176bf (`line_count`), 59b0e34 (`page`). Pinned by the raw-line handling tests in test_console_emitter.py.
68

79
ce487d3 refactor: inline `text` alias in `_output.py:collect_output` — the local was assigned from `ensure_str(stream)` and read exactly once on the next line as `parts.append(text)`. Same alias-inline shape as fc5e1cb / 497c028 / 52e0272 — the `ensure_str` helper name already documents the decode step, so the intermediate binding was pure noise. Tests in `test_output.py` cover the str, bytes, and stdout+stderr-newline-join paths.

0 commit comments

Comments
 (0)