Skip to content

Commit 9cc0588

Browse files
Kasper JungeRalphify
authored andcommitted
workspace: record try/except/else refactor in _read_agent_stream
Co-authored-by: Ralphify <noreply@ralphify.co>
1 parent cf72fd9 commit 9cc0588

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

workspace/ralphs/improve-codebase/coverage/_agent.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
# `_agent.py` coverage
22

3-
Valid at: d8d5592
3+
Valid at: cf72fd9
44

55
## Recent changes
66

7+
- cf72fd9 — replaced the `parsed = None` sentinel in `_read_agent_stream`
8+
with a `try/except/else` block. The old code set `parsed = None` in
9+
the JSON-decode-except branch solely so the next line's
10+
`if isinstance(parsed, dict):` would fall through; restructuring with
11+
`try: ... except: pass; else: if isinstance(...):` makes the "only
12+
forward when parsing succeeded" intent structural instead of encoded
13+
through a sentinel value. The error path now skips the isinstance
14+
check entirely (dead work before), and the success path is unchanged.
15+
`parsed` is no longer bound when the except clause runs, which matches
16+
Python convention — the value was always meant to be ignored there.
17+
Pinned by `tests/test_agent.py::test_ignores_non_json_lines` and the
18+
broader stream-JSON coverage in that file.
719
- d8d5592 — gated the `"".join(...)` of `stream.stdout_lines` and
820
`stderr_lines` at the tail of `_run_agent_streaming` on
921
`log_dir is not None`. The joined strings were only consumed by

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+
cf72fd9 refactor: replace `parsed = None` sentinel with try/except/else in `_read_agent_stream` — the sentinel only existed so that `isinstance(parsed, dict)` on the next line would fall through on JSON-parse failure. Moving the dict-handling into the try/else branch expresses "only run when parse succeeded" structurally and drops both the sentinel assignment and the redundant isinstance check on the error path. Behavior preserved — valid-but-non-dict JSON (lists, numbers, strings) still skips forwarding via the inner isinstance guard. Same sentinel→structure shape as prior Phase 4 scope narrowings, applied one level up.
6+
57
a6f4c47 refactor: drop redundant BOM-startswith guard before `removeprefix` in `parse_frontmatter``str.removeprefix` already returns the string unchanged when the prefix is absent, so the `if text.startswith(_UTF8_BOM):` wrapper was dead defensive code. Behavior preserved — `test_utf8_bom_does_not_break_frontmatter` still pins the BOM-stripping path and every other test exercises the no-BOM path. Same "drop the guard when the operation already handles the no-match case" shape as 5337d88 (empty dict → `" · ".join([])`), 4ccfa9a (empty list → `" · ".join([])`), and 8cb0d47 (redundant `max(..., 1)` floor).
68

79
3a8908d refactor: use `next(reversed(...), None)` in `enter_fullscreen` history fallback — the compound `if initial_id is None and self._iteration_history:` guard mixed two concerns (only fall back when nothing is live, *and* avoid `next(reversed({}))` raising StopIteration). Switching to the `next(it, default)` sentinel idiom lets the standard default handle empty-dict case so the outer `if` only encodes the "fall back when nothing live" intent. Behavior preserved — the existing `if initial_id is None or panel_for(...) is None:` next branch still prints "no iterations yet" and returns False, covered by `test_enter_without_iteration_prints_hint`.

0 commit comments

Comments
 (0)