wire types: use chrono DateTime<Utc> as the timestamp type throughout

This commit is contained in:
damocles 2026-07-03 20:54:33 +02:00 committed by mara
commit 2c5d9ed336
15 changed files with 108 additions and 190 deletions

View file

@ -231,9 +231,9 @@ impl Approvals {
agent: row.agent,
kind: kind_from_str(&row.kind)?,
commit_ref: row.commit_ref,
requested_at: hive_sh4re::wire_time::WireTime(row.requested_at),
requested_at: hive_sh4re::wire_time::from_secs(row.requested_at),
status: ApprovalStatus::Approved,
resolved_at: Some(hive_sh4re::wire_time::WireTime(resolved_at)),
resolved_at: Some(hive_sh4re::wire_time::from_secs(resolved_at)),
note: None,
fetched_sha: row.fetched_sha,
description: row.description,
@ -294,9 +294,9 @@ impl Approvals {
agent: row.agent,
kind: kind_from_str(&row.kind)?,
commit_ref: row.commit_ref,
requested_at: hive_sh4re::wire_time::WireTime(row.requested_at),
requested_at: hive_sh4re::wire_time::from_secs(row.requested_at),
status: ApprovalStatus::Cancelled,
resolved_at: Some(hive_sh4re::wire_time::WireTime(resolved_at)),
resolved_at: Some(hive_sh4re::wire_time::from_secs(resolved_at)),
note: Some(note),
fetched_sha: row.fetched_sha,
description: row.description,
@ -404,11 +404,11 @@ fn row_to_approval(row: &rusqlite::Row<'_>) -> rusqlite::Result<Approval> {
agent: row.get(1)?,
kind,
commit_ref: row.get(3)?,
requested_at: hive_sh4re::wire_time::WireTime(row.get(4)?),
requested_at: hive_sh4re::wire_time::from_secs(row.get(4)?),
status,
resolved_at: row
.get::<_, Option<i64>>(6)?
.map(hive_sh4re::wire_time::WireTime),
.map(hive_sh4re::wire_time::from_secs),
note: row.get(7)?,
fetched_sha: row.get(8)?,
description: row.get(9)?,

View file

@ -24,7 +24,8 @@ use std::sync::{Arc, Mutex, OnceLock};
use std::time::{SystemTime, UNIX_EPOCH};
use anyhow::{Context, Result};
use hive_sh4re::wire_time::WireTime;
use chrono::{DateTime, Utc};
use rusqlite::{Connection, params};
use serde::Serialize;
@ -90,7 +91,7 @@ impl AuditOutcome {
#[derive(Debug, Clone, Serialize)]
pub struct AuditEntry {
pub id: i64,
pub ts_unix: WireTime,
pub ts_unix: DateTime<Utc>,
/// Agent on whose behalf the action was taken.
pub agent: String,
/// What was done (e.g. `restart_infra`).
@ -159,7 +160,7 @@ impl AuditLog {
) {
Ok(_) => Some(AuditEntry {
id: conn.last_insert_rowid(),
ts_unix: hive_sh4re::wire_time::WireTime(now),
ts_unix: hive_sh4re::wire_time::from_secs(now),
agent: agent.to_owned(),
action: action.to_owned(),
target: target.to_owned(),
@ -252,7 +253,7 @@ pub fn spawn_vacuum(coord: &Arc<crate::coordinator::Coordinator>) {
fn row_to_entry(r: &rusqlite::Row) -> rusqlite::Result<AuditEntry> {
Ok(AuditEntry {
id: r.get(0)?,
ts_unix: hive_sh4re::wire_time::WireTime(r.get(1)?),
ts_unix: hive_sh4re::wire_time::from_secs(r.get(1)?),
agent: r.get(2)?,
action: r.get(3)?,
target: r.get(4)?,

View file

@ -7,7 +7,8 @@ use std::sync::Mutex;
use std::time::{SystemTime, UNIX_EPOCH};
use anyhow::{Context, Result};
use hive_sh4re::wire_time::WireTime;
use chrono::{DateTime, Utc};
use hive_sh4re::{InboxRow, Message};
use rusqlite::{Connection, OptionalExtension, params};
use serde::Serialize;
@ -75,8 +76,8 @@ pub struct PendingReminder {
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub file_path: Option<String>,
pub due_at: WireTime,
pub created_at: WireTime,
pub due_at: DateTime<Utc>,
pub created_at: DateTime<Utc>,
/// Most recent delivery failure for this row, if any. Cleared
/// to NULL on operator retry. Surfaced inline in the dashboard
/// so a stuck reminder doesn't just silently retry forever.
@ -925,8 +926,8 @@ impl Broker {
agent: row.get(1)?,
message: row.get(2)?,
file_path: row.get(3)?,
due_at: hive_sh4re::wire_time::WireTime(row.get(4)?),
created_at: hive_sh4re::wire_time::WireTime(row.get(5)?),
due_at: hive_sh4re::wire_time::from_secs(row.get(4)?),
created_at: hive_sh4re::wire_time::from_secs(row.get(5)?),
last_error: row.get(6)?,
attempt_count: u32::try_from(attempts).unwrap_or(0),
})

View file

@ -805,7 +805,7 @@ impl Coordinator {
approval_kind,
sha_short,
status,
resolved_at: hive_sh4re::wire_time::WireTime(resolved_at),
resolved_at: hive_sh4re::wire_time::from_secs(resolved_at),
note,
description,
});
@ -838,8 +838,8 @@ impl Coordinator {
question: question.to_owned(),
options: options.to_vec(),
multi,
asked_at: hive_sh4re::wire_time::WireTime(asked_at),
deadline_at: deadline_at.map(hive_sh4re::wire_time::WireTime),
asked_at: hive_sh4re::wire_time::from_secs(asked_at),
deadline_at: deadline_at.map(hive_sh4re::wire_time::from_secs),
target: target.map(str::to_owned),
question_refs,
});
@ -869,7 +869,7 @@ impl Coordinator {
id,
answer: answer.to_owned(),
answerer: answerer.to_owned(),
answered_at: hive_sh4re::wire_time::WireTime(answered_at),
answered_at: hive_sh4re::wire_time::from_secs(answered_at),
cancelled,
target: target.map(str::to_owned),
answer_refs,

View file

@ -27,7 +27,7 @@ use tokio_stream::{Stream, StreamExt};
use crate::container_view::{ContainerView, claude_has_session};
use crate::coordinator::Coordinator;
use crate::lifecycle::{self, MANAGER_NAME};
use hive_sh4re::wire_time::WireTime;
use chrono::{DateTime, Utc};
mod approvals;
mod build_logs;
@ -434,7 +434,7 @@ struct ApprovalHistoryView {
/// `approved` / `denied` / `failed`.
status: &'static str,
/// RFC 3339 UTC. Renders as a relative time on the dashboard.
resolved_at: WireTime,
resolved_at: DateTime<Utc>,
/// Operator-supplied deny reason (for `denied`) or build error
/// (for `failed`). None on `approved`.
#[serde(skip_serializing_if = "Option::is_none")]
@ -475,7 +475,7 @@ struct ApprovalView {
/// RFC 3339 UTC time the approval was queued. Rendered as a
/// relative time on the card so the operator can spot a stale
/// request.
requested_at: WireTime,
requested_at: DateTime<Utc>,
}
/// Replace silent `.unwrap_or_default()` on the data sources behind
@ -1100,7 +1100,7 @@ async fn dashboard_history(State(state): State<AppState>) -> Response {
from,
to,
body,
at: hive_sh4re::wire_time::WireTime(at),
at: hive_sh4re::wire_time::from_secs(at),
in_reply_to,
file_refs,
})
@ -1120,7 +1120,7 @@ async fn dashboard_history(State(state): State<AppState>) -> Response {
from,
to,
body,
at: hive_sh4re::wire_time::WireTime(at),
at: hive_sh4re::wire_time::from_secs(at),
in_reply_to,
file_refs,
})
@ -1375,7 +1375,7 @@ async fn api_operator_inbox(State(state): State<AppState>) -> Response {
"id": id,
"from": from,
"body": body,
"at": hive_sh4re::wire_time::WireTime(at),
"at": hive_sh4re::wire_time::from_secs(at),
"in_reply_to": in_reply_to,
"file_refs": file_refs,
}))

View file

@ -9,7 +9,7 @@ use serde::Serialize;
use crate::container_view::ContainerView;
use crate::dashboard::{MetaInputView, TombstoneView};
use crate::rebuild_queue::QueueEntry;
use hive_sh4re::wire_time::WireTime;
use chrono::{DateTime, Utc};
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "snake_case", tag = "kind")]
@ -39,7 +39,7 @@ pub enum DashboardEvent {
from: String,
to: String,
body: String,
at: WireTime,
at: DateTime<Utc>,
#[serde(default, skip_serializing_if = "Option::is_none")]
in_reply_to: Option<i64>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
@ -54,7 +54,7 @@ pub enum DashboardEvent {
from: String,
to: String,
body: String,
at: WireTime,
at: DateTime<Utc>,
#[serde(default, skip_serializing_if = "Option::is_none")]
in_reply_to: Option<i64>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
@ -96,7 +96,7 @@ pub enum DashboardEvent {
sha_short: Option<String>,
/// `"approved"` / `"denied"` / `"failed"`.
status: &'static str,
resolved_at: WireTime,
resolved_at: DateTime<Utc>,
note: Option<String>,
description: Option<String>,
},
@ -112,8 +112,8 @@ pub enum DashboardEvent {
question: String,
options: Vec<String>,
multi: bool,
asked_at: WireTime,
deadline_at: Option<WireTime>,
asked_at: DateTime<Utc>,
deadline_at: Option<DateTime<Utc>>,
target: Option<String>,
/// Verified file-path tokens that appear in `question`.
/// Same shape as broker `Sent`/`Delivered` events; the
@ -131,7 +131,7 @@ pub enum DashboardEvent {
id: i64,
answer: String,
answerer: String,
answered_at: WireTime,
answered_at: DateTime<Utc>,
cancelled: bool,
target: Option<String>,
/// Verified file-path tokens that appear in `answer`.
@ -332,7 +332,7 @@ mod tests {
from: "a".into(),
to: "b".into(),
body: String::new(),
at: hive_sh4re::wire_time::WireTime(0),
at: hive_sh4re::wire_time::from_secs(0),
in_reply_to: None,
file_refs: Vec::new(),
},
@ -342,7 +342,7 @@ mod tests {
from: "a".into(),
to: "b".into(),
body: String::new(),
at: hive_sh4re::wire_time::WireTime(0),
at: hive_sh4re::wire_time::from_secs(0),
in_reply_to: None,
file_refs: Vec::new(),
},
@ -363,7 +363,7 @@ mod tests {
approval_kind: "apply_commit",
sha_short: None,
status: "approved",
resolved_at: hive_sh4re::wire_time::WireTime(0),
resolved_at: hive_sh4re::wire_time::from_secs(0),
note: None,
description: None,
},
@ -374,7 +374,7 @@ mod tests {
question: String::new(),
options: Vec::new(),
multi: false,
asked_at: hive_sh4re::wire_time::WireTime(0),
asked_at: hive_sh4re::wire_time::from_secs(0),
deadline_at: None,
target: None,
question_refs: Vec::new(),
@ -384,7 +384,7 @@ mod tests {
id: 1,
answer: String::new(),
answerer: "a".into(),
answered_at: hive_sh4re::wire_time::WireTime(0),
answered_at: hive_sh4re::wire_time::from_secs(0),
cancelled: false,
target: None,
answer_refs: Vec::new(),
@ -447,7 +447,7 @@ mod tests {
seq: 1,
entry: crate::audit_log::AuditEntry {
id: 1,
ts_unix: hive_sh4re::wire_time::WireTime(0),
ts_unix: hive_sh4re::wire_time::from_secs(0),
agent: "atlas".into(),
action: "restart_infra".into(),
target: "hive-ci".into(),
@ -476,7 +476,7 @@ mod tests {
seq: 7,
entry: crate::audit_log::AuditEntry {
id: 42,
ts_unix: hive_sh4re::wire_time::WireTime(1_700_000_000),
ts_unix: hive_sh4re::wire_time::from_secs(1_700_000_000),
agent: "atlas".into(),
action: "restart_infra".into(),
target: "hive-gateway".into(),

View file

@ -70,7 +70,7 @@ pub fn for_agent(coord: &Coordinator, agent: &str) -> Result<Vec<LooseEnd>> {
agent: a.agent,
commit_ref: a.commit_ref,
description: a.description,
age_seconds: saturating_age(now, a.requested_at.secs()),
age_seconds: saturating_age(now, a.requested_at.timestamp()),
});
}
for q in coord.questions.pending_all()? {
@ -83,7 +83,7 @@ pub fn for_agent(coord: &Coordinator, agent: &str) -> Result<Vec<LooseEnd>> {
asker: q.asker,
target: q.target,
question: q.question,
age_seconds: saturating_age(now, q.asked_at.secs()),
age_seconds: saturating_age(now, q.asked_at.timestamp()),
});
}
for r in coord.broker.list_pending_reminders()? {
@ -95,7 +95,7 @@ pub fn for_agent(coord: &Coordinator, agent: &str) -> Result<Vec<LooseEnd>> {
owner: r.agent,
message: r.message,
due_at: r.due_at,
age_seconds: saturating_age(now, r.created_at.secs()),
age_seconds: saturating_age(now, r.created_at.timestamp()),
});
}
Ok(out)
@ -114,7 +114,7 @@ pub fn hive_wide(coord: &Coordinator) -> Result<Vec<LooseEnd>> {
agent: a.agent,
commit_ref: a.commit_ref,
description: a.description,
age_seconds: saturating_age(now, a.requested_at.secs()),
age_seconds: saturating_age(now, a.requested_at.timestamp()),
});
}
for q in coord.questions.pending_all()? {
@ -123,7 +123,7 @@ pub fn hive_wide(coord: &Coordinator) -> Result<Vec<LooseEnd>> {
asker: q.asker,
target: q.target,
question: q.question,
age_seconds: saturating_age(now, q.asked_at.secs()),
age_seconds: saturating_age(now, q.asked_at.timestamp()),
});
}
for r in coord.broker.list_pending_reminders()? {
@ -132,7 +132,7 @@ pub fn hive_wide(coord: &Coordinator) -> Result<Vec<LooseEnd>> {
owner: r.agent,
message: r.message,
due_at: r.due_at,
age_seconds: saturating_age(now, r.created_at.secs()),
age_seconds: saturating_age(now, r.created_at.timestamp()),
});
}
Ok(out)

View file

@ -497,7 +497,7 @@ fn spawn_broker_to_dashboard_forwarder(coord: Arc<Coordinator>) {
from,
to,
body,
at: hive_sh4re::wire_time::WireTime(at),
at: hive_sh4re::wire_time::from_secs(at),
in_reply_to,
file_refs,
});
@ -517,7 +517,7 @@ fn spawn_broker_to_dashboard_forwarder(coord: Arc<Coordinator>) {
from,
to,
body,
at: hive_sh4re::wire_time::WireTime(at),
at: hive_sh4re::wire_time::from_secs(at),
in_reply_to,
file_refs,
});

View file

@ -14,7 +14,8 @@ use std::sync::Mutex;
use std::time::{SystemTime, UNIX_EPOCH};
use anyhow::{Context, Result, bail};
use hive_sh4re::wire_time::WireTime;
use chrono::{DateTime, Utc};
use rusqlite::{Connection, OptionalExtension, params};
use serde::Serialize;
@ -75,12 +76,12 @@ pub struct OpQuestion {
pub question: String,
pub options: Vec<String>,
pub multi: bool,
pub asked_at: WireTime,
pub asked_at: DateTime<Utc>,
/// Deadline after which a watchdog auto-resolves the question with
/// answer `[expired]`. `None` = no expiry. Surfaced on the
/// dashboard as a remaining-time chip.
pub deadline_at: Option<WireTime>,
pub answered_at: Option<WireTime>,
pub deadline_at: Option<DateTime<Utc>>,
pub answered_at: Option<DateTime<Utc>>,
pub answer: Option<String>,
/// Recipient of the question. `None` = the operator (dashboard
/// path); `Some(<agent>)` = a peer agent asked via
@ -288,14 +289,14 @@ fn row_to_question(row: &rusqlite::Row<'_>) -> rusqlite::Result<OpQuestion> {
question: row.get(2)?,
options,
multi: multi != 0,
asked_at: hive_sh4re::wire_time::WireTime(row.get(5)?),
asked_at: hive_sh4re::wire_time::from_secs(row.get(5)?),
answered_at: row
.get::<_, Option<i64>>(6)?
.map(hive_sh4re::wire_time::WireTime),
.map(hive_sh4re::wire_time::from_secs),
answer: row.get(7)?,
deadline_at: row
.get::<_, Option<i64>>(8)?
.map(hive_sh4re::wire_time::WireTime),
.map(hive_sh4re::wire_time::from_secs),
target: row.get(9)?,
})
}

View file

@ -2018,8 +2018,8 @@ fn schedule_to_wire(s: crate::scheduled_prompts::Schedule) -> hive_sh4re::WireSc
owner: s.owner,
body: s.body,
interval_seconds: s.interval_seconds,
next_fire_at_unix: hive_sh4re::wire_time::WireTime(s.next_fire_at_unix),
created_at_unix: hive_sh4re::wire_time::WireTime(s.created_at_unix),
next_fire_at_unix: hive_sh4re::wire_time::from_secs(s.next_fire_at_unix),
created_at_unix: hive_sh4re::wire_time::from_secs(s.created_at_unix),
source: match s.source {
crate::scheduled_prompts::ScheduleSource::Operator => {
hive_sh4re::WireScheduleSource::Operator
@ -2028,16 +2028,16 @@ fn schedule_to_wire(s: crate::scheduled_prompts::Schedule) -> hive_sh4re::WireSc
hive_sh4re::WireScheduleSource::Approval { id }
}
},
cancelled_at_unix: s.cancelled_at_unix.map(hive_sh4re::wire_time::WireTime),
paused_at_unix: s.paused_at_unix.map(hive_sh4re::wire_time::WireTime),
cancelled_at_unix: s.cancelled_at_unix.map(hive_sh4re::wire_time::from_secs),
paused_at_unix: s.paused_at_unix.map(hive_sh4re::wire_time::from_secs),
description: s.description,
targets: s
.targets
.into_iter()
.map(|t| hive_sh4re::WireScheduleTarget {
target: t.target,
cancelled_at_unix: t.cancelled_at_unix.map(hive_sh4re::wire_time::WireTime),
last_fired_at_unix: t.last_fired_at_unix.map(hive_sh4re::wire_time::WireTime),
cancelled_at_unix: t.cancelled_at_unix.map(hive_sh4re::wire_time::from_secs),
last_fired_at_unix: t.last_fired_at_unix.map(hive_sh4re::wire_time::from_secs),
last_result: t.last_result,
})
.collect(),
@ -2131,8 +2131,8 @@ mod tests {
owner: "operator".to_owned(),
body: "ping".to_owned(),
interval_seconds: None,
next_fire_at_unix: hive_sh4re::wire_time::WireTime(0),
created_at_unix: hive_sh4re::wire_time::WireTime(0),
next_fire_at_unix: hive_sh4re::wire_time::from_secs(0),
created_at_unix: hive_sh4re::wire_time::from_secs(0),
source: hive_sh4re::WireScheduleSource::Operator,
cancelled_at_unix: None,
paused_at_unix: None,