Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/architecture/tui.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ scope stays equal to the room goal it was copied from.
EVERY poll path is degrade-guarded (`_ROOM_POLL_ERRORS`/`_SESSION_POLL_ERRORS`/
`_JOB_POLL_ERRORS`) — an unguarded read escapes the interval callback and kills
the app, so a store failure must show DEGRADED and keep the last good view.
One candidate that cannot be read is not a store failure: a `RoomError` from
that candidate's own row, artifact or round binding becomes its pane's text
("unreadable", never cached) while the room's other panes refresh. The
candidate cache key includes the round's binding (`RoomStore.round_room_id`),
so a round deleted or moved away after the candidate was shown is checked again.
`JobStore.control` likewise converts everything to `JobError` (its callers catch
only that): the manager can vanish between the poll and the keypress, taking the
token file and leaving a truncated socket reply.
Expand Down
18 changes: 17 additions & 1 deletion src/syncmill/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3339,8 +3339,20 @@ def room_candidates(room_id: str, repo: Path) -> None:
_, _, coordinator = _room_coordinator(repo)
try:
coordinator.store.get_room(room_id)
damaged = 0
for candidate in coordinator.store.list_candidates(room_id):
manifest = coordinator.store.load_candidate(candidate["id"])
try:
manifest = coordinator.store.load_candidate(candidate["id"])
except RoomError as exc:
# One unreadable candidate (its artifact, or its round
# binding) is reported on its own line; the rest still list,
# and the command fails at the end rather than passing silently.
damaged += 1
echo(
f"{_shown(candidate['id'])} {_shown(candidate['member_id']):10} "
f"damaged: {_shown(str(exc))}"
)
continue
# The read model's verdict: a candidate that never completed is
# "not run", and a null gate is "no gate report" — never one `n/a`.
gate = _gate_verdict(
Expand All @@ -3357,6 +3369,10 @@ def room_candidates(room_id: str, repo: Path) -> None:
f"patch:{_shown(manifest['patch_bytes'])}B"
+ (f" {usage}" if usage else "")
)
if damaged:
raise click.ClickException(
f"{damaged} candidate(s) in room {_shown(room_id)} could not be read"
)
# A pager/`head` exiting early raises BrokenPipeError (an OSError) out of
# click.echo — re-raise it so Click's own EPIPE handling silences it,
# instead of printing a spurious "Error: Broken pipe".
Expand Down
13 changes: 13 additions & 0 deletions src/syncmill/room_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,19 @@ def build_room_comparison(
for candidate in store.list_candidates(room_id):
by_round.setdefault(str(candidate["round_id"]), []).append(candidate)
candidate_rows[str(candidate["id"])] = candidate
# A candidate whose round is not one of this room's (gone, or another
# room's) belongs to no round group; say so rather than let it vanish.
room_round_ids = {str(round_row.get("id")) for round_row in rounds}
for candidate in candidate_rows.values():
if str(candidate["round_id"]) not in room_round_ids:
damaged.append(
{
"round_id": str(candidate["round_id"]),
"reason": (
f"candidate {candidate['id']} names a round outside this room"
),
}
)
members = room.get("members")
member_ids = (
[m["member_id"] for m in members if isinstance(m, dict) and "member_id" in m]
Expand Down
281 changes: 199 additions & 82 deletions src/syncmill/rooms.py

Large diffs are not rendered by default.

42 changes: 34 additions & 8 deletions src/syncmill/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ def _read_artifact_result(run_id: str, *, store: ArtifactStore) -> dict | None:
return value


def _unreadable_candidate(candidate_id: str, exc: Exception) -> str:
"""The candidate pane for a candidate that cannot be read."""
return (
f"Candidate {printable_name(candidate_id)} unreadable: "
f"{printable_name(str(exc))}"
)


def _one_line(value: object) -> str:
"""A stored value in a one-line field, as the CLI shows it."""
return printable_name(str(value))
Expand Down Expand Up @@ -2700,26 +2708,47 @@ def _stage_candidate(
)
assert candidate_id is not None
reset = view is None
row = self._rooms.store.get_candidate(candidate_id)
# A RoomError from reading the candidate itself (its row, artifact or
# round binding) is that candidate's damage: it is staged as this
# pane's text, so the room's other panes still refresh. Store failures
# (sqlite3.Error and the rest) still raise and degrade the whole room.
# The unreadable text is never cached (key None): a view change or a
# repair is read again on the next stage.
try:
row = self._rooms.store.get_candidate(candidate_id)
except RoomError as exc:
return None, _unreadable_candidate(candidate_id, exc), view or "output", pages, False
if view is None:
view = "diff" if row.get("state") == "completed" else "output"
# Candidates are immutable (digest-bound), so this key makes a
# poll tick a no-op instead of re-streaming the patch.
# poll tick a no-op instead of re-streaming the patch. The round's
# binding is part of it: a round deleted or moved to another room
# after the candidate was shown must be validated again.
key = (
candidate_id,
view,
pages,
row.get("patch_sha256"),
row.get("output_sha256"),
row.get("state"),
row.get("round_id"),
self._rooms.store.round_room_id(row.get("round_id")),
)
truncated = False if reset else self._diff_truncated
if key == self._candidate_detail_key:
return key, None, view, pages, truncated
try:
if view == "diff":
manifest = self._rooms.store.load_candidate_patch_head(
candidate_id, pages * _DIFF_DISPLAY_BYTES
)
else:
manifest = self._rooms.store.load_candidate_checkpoint(
candidate_id, _CANDIDATE_OUTPUT_BYTES
)
except RoomError as exc:
return None, _unreadable_candidate(candidate_id, exc), view, pages, False
if view == "diff":
manifest = self._rooms.store.load_candidate_patch_head(
candidate_id, pages * _DIFF_DISPLAY_BYTES
)
truncated = bool(manifest["patch_truncated"])
text = render_candidate_diff(
manifest,
Expand All @@ -2728,9 +2757,6 @@ def _stage_candidate(
binary=manifest.get("patch_binary"),
)
else:
manifest = self._rooms.store.load_candidate_checkpoint(
candidate_id, _CANDIDATE_OUTPUT_BYTES
)
text = render_candidate_output(manifest)
return key, text, view, pages, truncated

Expand Down
18 changes: 9 additions & 9 deletions tests/test_room_lessons.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def frozen(git_repo, tmp_path, monkeypatch):

def test_lessons_sit_after_the_untrusted_checkpoint_next_to_the_task(frozen):
coordinator, room_id = frozen
prompt, included, omitted = coordinator._checkpoint(room_id, "next", lessons=TEXTS)
plain, plain_included, _ = coordinator._checkpoint(room_id, "next")
prompt, included, omitted = coordinator._checkpoint(room_id, "next", round_number=3, lessons=TEXTS)
plain, plain_included, _ = coordinator._checkpoint(room_id, "next", round_number=3)
assert included == plain_included and not omitted
assert prompt.startswith(rooms_module._CHECKPOINT_PREAMBLE_WITH_LESSONS)
assert "Continue to follow only the task" not in prompt
Expand All @@ -91,19 +91,19 @@ def test_lessons_sit_after_the_untrusted_checkpoint_next_to_the_task(frozen):
def test_without_candidates_the_lessons_still_lead_the_task(frozen):
coordinator, room_id = frozen
prompt, included, omitted = coordinator._checkpoint(
room_id, "next", min_round_number=9, lessons=TEXTS
room_id, "next", round_number=3, min_round_number=9, lessons=TEXTS
)
assert (prompt, included, omitted) == (TAIL, [], False)
assert coordinator._checkpoint(room_id, "next", min_round_number=9) == ("next", [], False)
assert coordinator._checkpoint(room_id, "next", round_number=3, min_round_number=9) == ("next", [], False)


def test_the_checkpoint_makes_room_for_the_lessons(frozen, monkeypatch):
coordinator, room_id = frozen
full, every, _ = coordinator._checkpoint(room_id, "next")
full, every, _ = coordinator._checkpoint(room_id, "next", round_number=3)
# Room for the whole checkpoint, not for the checkpoint plus the lessons.
cap = len(full.encode()) + 10
monkeypatch.setattr(rooms_module, "_ROOM_PROMPT_MAX_BYTES", cap)
prompt, included, omitted = coordinator._checkpoint(room_id, "next", lessons=TEXTS)
prompt, included, omitted = coordinator._checkpoint(room_id, "next", round_number=3, lessons=TEXTS)
assert omitted and included == every[len(every) - len(included):]
assert len(included) < len(every)
assert len(prompt.encode()) <= cap
Expand All @@ -113,10 +113,10 @@ def test_the_checkpoint_makes_room_for_the_lessons(frozen, monkeypatch):
def test_multibyte_lessons_are_budgeted_in_bytes(frozen, monkeypatch):
coordinator, room_id = frozen
korean = ["작은 diff를 선호한다 " * 40, "벤더 코드는 고치지 않는다 " * 40]
full, _, _ = coordinator._checkpoint(room_id, "next")
full, _, _ = coordinator._checkpoint(room_id, "next", round_number=3)
cap = len(full.encode()) + 10
monkeypatch.setattr(rooms_module, "_ROOM_PROMPT_MAX_BYTES", cap)
prompt, _, omitted = coordinator._checkpoint(room_id, "next", lessons=korean)
prompt, _, omitted = coordinator._checkpoint(room_id, "next", round_number=3, lessons=korean)
assert omitted
assert len(prompt.encode()) <= cap # a character count would overshoot
assert prompt.endswith("--- CURRENT USER TASK ---\nnext")
Expand All @@ -143,7 +143,7 @@ def test_every_excerpt_fallback_keeps_the_lessons_and_the_task(frozen, monkeypat
)
with patch("_ROOM_PROMPT_MAX_BYTES", cap), patch("_prompt_arg_units", units):
assert round_lessons_fit("next", TEXTS)
prompt, included, omitted = coordinator._checkpoint(room_id, "next", lessons=TEXTS)
prompt, included, omitted = coordinator._checkpoint(room_id, "next", round_number=3, lessons=TEXTS)
# The excerpts are dropped together with their ids; eligible ones existed.
assert (prompt, included, omitted) == (TAIL, [], True)

Expand Down
Loading
Loading