fix: handle init_config approval kind in row deserializer
row_to_approval matched only apply_commit + spawn, so any approvals row with kind=init_config (added by 80dd5bb's two-step spawn) failed to deserialize. pending() / recent_resolved() collect all-or-nothing via collect::<Result<Vec>>(), so one bad row errored the whole query; api_state's log_default then swallowed the error and returned an empty list — every pending approval vanished from the dashboard (issue #160). - add the missing init_config arm to row_to_approval - collect_lenient(): skip + log unparseable rows so a single bad row can never blank the whole approvals list again - dashboard: label init_config approvals 'init' (was mislabeled 'spawn' by the apply-vs-other fallthrough) closes #160
This commit is contained in:
parent
4539091f3c
commit
189fc587a4
2 changed files with 30 additions and 7 deletions
|
|
@ -273,7 +273,9 @@
|
||||||
for (const a of approvals) {
|
for (const a of approvals) {
|
||||||
if (seenApprovals.has(a.id)) continue;
|
if (seenApprovals.has(a.id)) continue;
|
||||||
seenApprovals.add(a.id);
|
seenApprovals.add(a.id);
|
||||||
const verb = a.kind === 'spawn' ? 'spawn approval' : 'config commit';
|
const verb = a.kind === 'spawn' ? 'spawn approval'
|
||||||
|
: a.kind === 'init_config' ? 'config-init approval'
|
||||||
|
: 'config commit';
|
||||||
NOTIF.show('◆ approval #' + a.id, `${verb} for ${a.agent}`,
|
NOTIF.show('◆ approval #' + a.id, `${verb} for ${a.agent}`,
|
||||||
'hyperhive:approval:' + a.id);
|
'hyperhive:approval:' + a.id);
|
||||||
}
|
}
|
||||||
|
|
@ -1227,6 +1229,7 @@
|
||||||
const ul = el('ul', { class: 'approvals' });
|
const ul = el('ul', { class: 'approvals' });
|
||||||
for (const a of pending) {
|
for (const a of pending) {
|
||||||
const isApply = a.kind === 'apply_commit';
|
const isApply = a.kind === 'apply_commit';
|
||||||
|
const isInit = a.kind === 'init_config';
|
||||||
const li = el('li', { class: 'approval-card' });
|
const li = el('li', { class: 'approval-card' });
|
||||||
|
|
||||||
// ── identity header ──────────────────────────────────────────
|
// ── identity header ──────────────────────────────────────────
|
||||||
|
|
@ -1235,7 +1238,7 @@
|
||||||
el('span', { class: 'id' }, '#' + a.id),
|
el('span', { class: 'id' }, '#' + a.id),
|
||||||
el('span', { class: 'agent' }, a.agent),
|
el('span', { class: 'agent' }, a.agent),
|
||||||
el('span', { class: 'kind' + (isApply ? '' : ' kind-spawn') },
|
el('span', { class: 'kind' + (isApply ? '' : ' kind-spawn') },
|
||||||
isApply ? 'apply' : 'spawn'),
|
isApply ? 'apply' : isInit ? 'init' : 'spawn'),
|
||||||
);
|
);
|
||||||
if (isApply && a.sha_short) head.append(el('code', {}, a.sha_short));
|
if (isApply && a.sha_short) head.append(el('code', {}, a.sha_short));
|
||||||
li.append(head);
|
li.append(head);
|
||||||
|
|
@ -1261,7 +1264,9 @@
|
||||||
body.append(drill);
|
body.append(drill);
|
||||||
} else {
|
} else {
|
||||||
body.append(el('span', { class: 'meta' },
|
body.append(el('span', { class: 'meta' },
|
||||||
'new sub-agent — container will be created on approve'));
|
isInit
|
||||||
|
? 'scaffold proposed config repo — manager customises agent.nix before spawn'
|
||||||
|
: 'new sub-agent — container will be created on approve'));
|
||||||
}
|
}
|
||||||
li.append(body);
|
li.append(body);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,7 @@ impl Approvals {
|
||||||
LIMIT ?1",
|
LIMIT ?1",
|
||||||
)?;
|
)?;
|
||||||
let rows = stmt.query_map([limit], row_to_approval)?;
|
let rows = stmt.query_map([limit], row_to_approval)?;
|
||||||
rows.collect::<rusqlite::Result<Vec<_>>>()
|
Ok(collect_lenient(rows))
|
||||||
.map_err(Into::into)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pending(&self) -> Result<Vec<Approval>> {
|
pub fn pending(&self) -> Result<Vec<Approval>> {
|
||||||
|
|
@ -150,8 +149,7 @@ impl Approvals {
|
||||||
ORDER BY id ASC",
|
ORDER BY id ASC",
|
||||||
)?;
|
)?;
|
||||||
let rows = stmt.query_map([], row_to_approval)?;
|
let rows = stmt.query_map([], row_to_approval)?;
|
||||||
rows.collect::<rusqlite::Result<Vec<_>>>()
|
Ok(collect_lenient(rows))
|
||||||
.map_err(Into::into)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, id: i64) -> Result<Option<Approval>> {
|
pub fn get(&self, id: i64) -> Result<Option<Approval>> {
|
||||||
|
|
@ -261,12 +259,32 @@ impl Approvals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Collect approval rows, dropping (and logging) any that fail to
|
||||||
|
/// deserialize. A single malformed / unknown-kind row must never blank
|
||||||
|
/// the whole list: `collect::<Result<Vec>>()` is all-or-nothing, so one
|
||||||
|
/// bad row used to make `pending()` / `recent_resolved()` error out
|
||||||
|
/// wholesale — the dashboard then rendered an empty approvals queue
|
||||||
|
/// (issue #160, an unhandled `init_config` kind poisoning every read).
|
||||||
|
fn collect_lenient(
|
||||||
|
rows: impl Iterator<Item = rusqlite::Result<Approval>>,
|
||||||
|
) -> Vec<Approval> {
|
||||||
|
rows.filter_map(|r| match r {
|
||||||
|
Ok(a) => Some(a),
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(error = ?e, "skipping unparseable approval row");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn row_to_approval(row: &rusqlite::Row<'_>) -> rusqlite::Result<Approval> {
|
fn row_to_approval(row: &rusqlite::Row<'_>) -> rusqlite::Result<Approval> {
|
||||||
// Column order: id, agent, kind, commit_ref, requested_at, status, resolved_at, note, fetched_sha, description.
|
// Column order: id, agent, kind, commit_ref, requested_at, status, resolved_at, note, fetched_sha, description.
|
||||||
let kind: String = row.get(2)?;
|
let kind: String = row.get(2)?;
|
||||||
let kind = match kind.as_str() {
|
let kind = match kind.as_str() {
|
||||||
"apply_commit" => ApprovalKind::ApplyCommit,
|
"apply_commit" => ApprovalKind::ApplyCommit,
|
||||||
"spawn" => ApprovalKind::Spawn,
|
"spawn" => ApprovalKind::Spawn,
|
||||||
|
"init_config" => ApprovalKind::InitConfig,
|
||||||
other => {
|
other => {
|
||||||
return Err(rusqlite::Error::FromSqlConversionFailure(
|
return Err(rusqlite::Error::FromSqlConversionFailure(
|
||||||
2,
|
2,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue