loops: reorder history collapsed under the progress pill
ci / gates (push) Successful in 7s
ci / frontend (push) Successful in 26s
ci / rust (push) Failing after 1m14s
ci / e2e (push) Has been skipped
ci / publish (push) Has been skipped

Completes the reorder rationale loop — the previous commit captured
REORDER: markers server-side but nothing surfaced them. Now the loops
sidebar renders a small "N reorders ▸" button under the progress pill
whenever the loop has any reorder events. Click expands to a
newest-first list of "iter <n> · <rationale>" lines so a reviewer can
see, at a glance, when the plan was adjusted and why.

Backend:
- LoopProgress DTO gains recent_reorders: Vec<Value> — newest-first,
  capped at 5 so the card stays compact. Full history remains on the
  loop row's reorder_events column.
- cm_db::repo::loops::recent_reorders — reads the jsonb array, returns
  the last N in newest-first order.
- list_progress populates it per loop.

Frontend:
- LoopReorderEvent + recent_reorders on LoopProgress type.
- LoopsList tracks openHistoryId per-loop (one open at a time).
- Card renders history button + expanded panel styled to match the
  progress pill above.

Notes:
- The event object schema is {run_id, iteration, text, ts}. Fields are
  optional in the TS type so future schema tweaks don't break the
  render.
- 5-item cap chosen so the sidebar card doesn't grow unbounded. If a
  loop accumulates a lot of reorders, follow-up UI can render the full
  history on the loop detail page.
This commit is contained in:
Omar Sobh
2026-07-09 19:00:39 -07:00
parent 0c17de52dd
commit ce111273bb
4 changed files with 106 additions and 0 deletions
+8
View File
@@ -363,6 +363,10 @@ pub struct LoopProgress {
pub consumed_count: usize,
pub total_int_count: usize,
pub current_int_index: i32,
/// Recent coordinator-issued reorders on this loop — newest first,
/// capped at 5 so the sidebar card stays compact. Full history is
/// on the loop row's reorder_events column.
pub recent_reorders: Vec<serde_json::Value>,
}
/// `GET /api/loops/progress` — bulk progress read for every loop in the
@@ -418,6 +422,9 @@ pub async fn list_progress(
cached
}
};
let recent = cm_db::repo::loops::recent_reorders(&state.pool, l.id, 5)
.await
.unwrap_or_default();
out.push(LoopProgress {
loop_id: l.id,
source_topic_id: topic_id,
@@ -426,6 +433,7 @@ pub async fn list_progress(
consumed_count: consumed.len(),
total_int_count: total,
current_int_index: current_idx,
recent_reorders: recent,
});
}
Ok(Json(out))