Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(threads): restore turn state mirroring on observe

Steven Enamakel9d002c44bc86
diff --git a/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs b/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs
index 60f5be2fae..8c98a4e48e 100644
--- a/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs
+++ b/crates/openhuman-core/src/threads/turn_state/mirror/observe.rs
@@ -456,21 +456,35 @@ impl TurnStateMirror {
/// Append a hidden-reasoning delta to the transcript, with the same
/// coalescing rule as [`Self::push_transcript_narration`].
+ ///
+ /// Stamps the block's first delta as `started_at` and every appended delta
+ /// as `ended_at` (epoch ms), which is what the "Thought for Ns" label reads.
fn push_transcript_thinking(&mut self, round: u32, delta: &str) {
- if let Some(TranscriptItem::Thinking { round: r, text, .. }) =
- self.state.transcript.last_mut()
+ let now = now_epoch_ms();
+ if let Some(TranscriptItem::Thinking {
+ round: r,
+ text,
+ ended_at,
+ ..
+ }) = self.state.transcript.last_mut()
{
if *r == round {
append_capped_transcript_text(text, delta);
+ *ended_at = Some(now);
return;
}
}
let seq = self.next_seq();
let mut text = String::new();
append_capped_transcript_text(&mut text, delta);
- self.state
- .transcript
- .push(TranscriptItem::Thinking { round, seq, text });
+ log::trace!("[turn_state] thinking block opened round={round} seq={seq}");
+ self.state.transcript.push(TranscriptItem::Thinking {
+ round,
+ seq,
+ text,
+ started_at: Some(now),
+ ended_at: Some(now),
+ });
}
/// Record a tool call in the transcript at the point it occurred, as a
@@ -566,3 +580,12 @@ impl TurnStateMirror {
});
}
}
+
+/// Wall-clock epoch milliseconds for transcript timing (0 if the clock is
+/// before the epoch, which only a broken system clock produces).
+fn now_epoch_ms() -> u64 {
+ std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .map(|d| u64::try_from(d.as_millis()).unwrap_or(u64::MAX))
+ .unwrap_or(0)
+}
diff --git a/crates/openhuman-core/src/threads/turn_state/types.rs b/crates/openhuman-core/src/threads/turn_state/types.rs
index 0e8058a385..5f4e0918ee 100644
--- a/crates/openhuman-core/src/threads/turn_state/types.rs
+++ b/crates/openhuman-core/src/threads/turn_state/types.rs
@@ -292,7 +292,19 @@ pub enum TranscriptItem {
/// The agent's visible assistant text between tool calls.
Narration { round: u32, seq: u32, text: String },
/// The agent's hidden reasoning (when the model emits it).
- Thinking { round: u32, seq: u32, text: String },
+ ///
+ /// `started_at` / `ended_at` are epoch milliseconds of the block's first
+ /// and latest delta, so the UI can show "Thought for 12s" after a reload.
+ /// Absent on rows written before timing was recorded.
+ Thinking {
+ round: u32,
+ seq: u32,
+ text: String,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ started_at: Option<u64>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ ended_at: Option<u64>,
+ },
/// A pointer to a tool row in [`TurnState::tool_timeline`].
ToolCall {
round: u32,