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
4 changes: 2 additions & 2 deletions crates/goose/src/context_mgmt/auto_compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ mod tests {
id: "test_session".to_string(),
working_dir: PathBuf::from(working_dir),
description: "Test session".to_string(),
created_at: "2024-01-01T00:00:00Z".to_string(),
updated_at: "2024-01-01T00:00:00Z".to_string(),
created_at: Default::default(),
updated_at: Default::default(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could cause flakiness in tests. probably they would catch something then though

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it? DateTime::default() returns unix epoch 0, not now()

schedule_id: Some("test_job".to_string()),
recipe: None,
total_tokens: Some(100),
Expand Down
18 changes: 5 additions & 13 deletions crates/goose/src/session/legacy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::conversation::Conversation;
use crate::session::Session;
use anyhow::Result;
use chrono::NaiveDateTime;
use chrono::{DateTime, Local, NaiveDateTime, TimeZone, Utc};
use std::fs;
use std::io::{self, BufRead};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -65,9 +65,9 @@ pub fn load_session(session_name: &str, session_path: &Path) -> Result<Session>
if let Some(obj) = metadata_json.as_object_mut() {
obj.entry("id").or_insert(serde_json::json!(session_name));
obj.entry("created_at")
.or_insert(serde_json::json!(format_timestamp(created_time)?));
.or_insert(serde_json::json!(DateTime::<Utc>::from(created_time)));
obj.entry("updated_at")
.or_insert(serde_json::json!(format_timestamp(modified_time)?));
.or_insert(serde_json::json!(DateTime::<Utc>::from(modified_time)));
obj.entry("extension_data").or_insert(serde_json::json!({}));
obj.entry("message_count").or_insert(serde_json::json!(0));

Expand Down Expand Up @@ -97,17 +97,9 @@ pub fn load_session(session_name: &str, session_path: &Path) -> Result<Session>
Ok(session)
}

fn format_timestamp(time: SystemTime) -> Result<String> {
let duration = time.duration_since(std::time::UNIX_EPOCH)?;
let timestamp = chrono::DateTime::from_timestamp(duration.as_secs() as i64, 0)
.unwrap_or_default()
.format("%Y-%m-%d %H:%M:%S")
.to_string();
Ok(timestamp)
}

fn parse_session_timestamp(session_name: &str) -> Option<SystemTime> {
NaiveDateTime::parse_from_str(session_name, "%Y%m%d_%H%M%S")
.ok()
.map(|dt| SystemTime::from(dt.and_utc()))
.and_then(|dt| Local.from_local_datetime(&dt).single())
.map(SystemTime::from)
}
13 changes: 7 additions & 6 deletions crates/goose/src/session/session_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::providers::base::{Provider, MSG_COUNT_FOR_SESSION_NAME_GENERATION};
use crate::recipe::Recipe;
use crate::session::extension_data::ExtensionData;
use anyhow::Result;
use chrono::{DateTime, Utc};
use etcetera::{choose_app_strategy, AppStrategy};
use rmcp::model::Role;
use serde::{Deserialize, Serialize};
Expand All @@ -27,8 +28,8 @@ pub struct Session {
#[schema(value_type = String)]
pub working_dir: PathBuf,
pub description: String,
pub created_at: String,
pub updated_at: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub extension_data: ExtensionData,
pub total_tokens: Option<i32>,
pub input_tokens: Option<i32>,
Expand Down Expand Up @@ -279,8 +280,8 @@ impl Default for Session {
id: String::new(),
working_dir: std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")),
description: String::new(),
created_at: String::new(),
updated_at: String::new(),
created_at: Default::default(),
updated_at: Default::default(),
extension_data: ExtensionData::default(),
total_tokens: None,
input_tokens: None,
Expand Down Expand Up @@ -510,8 +511,8 @@ impl SessionStorage {
.bind(&session.id)
.bind(&session.description)
.bind(session.working_dir.to_string_lossy().as_ref())
.bind(&session.created_at)
.bind(&session.updated_at)
.bind(session.created_at)
.bind(session.updated_at)
.bind(serde_json::to_string(&session.extension_data)?)
.bind(session.total_tokens)
.bind(session.input_tokens)
Expand Down
23 changes: 8 additions & 15 deletions crates/goose/src/temporal_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,25 +851,18 @@ impl TemporalScheduler {
if let Some(session_info) =
all_sessions.iter().find(|s| s.id == session_id)
{
// Parse the updated_at timestamp from the database
if let Ok(modified_dt) = DateTime::parse_from_str(
&session_info.updated_at,
"%Y-%m-%d %H:%M:%S UTC",
) {
let modified_utc = modified_dt.with_timezone(&Utc);
let now = Utc::now();
let time_diff = now.signed_duration_since(modified_utc);

// Increased tolerance to 5 minutes to reduce false positives
if time_diff.num_minutes() < 5 {
has_active_session = true;
tracing::debug!(
let now = Utc::now();
let time_diff = now.signed_duration_since(session_info.updated_at);

// Increased tolerance to 5 minutes to reduce false positives
if time_diff.num_minutes() < 5 {
has_active_session = true;
tracing::debug!(
"Found active session for job '{}' modified {} minutes ago",
job.id,
time_diff.num_minutes()
);
break;
}
break;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/goose/tests/test_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub fn create_test_session_metadata(message_count: usize, working_dir: &str) ->
id: "".to_string(),
working_dir: PathBuf::from(working_dir),
description: "Test session".to_string(),
created_at: "".to_string(),
created_at: Default::default(),
schedule_id: Some("test_job".to_string()),
recipe: None,
total_tokens: Some(100),
Expand All @@ -392,7 +392,7 @@ pub fn create_test_session_metadata(message_count: usize, working_dir: &str) ->
accumulated_input_tokens: Some(50),
accumulated_output_tokens: Some(50),
extension_data: Default::default(),
updated_at: "".to_string(),
updated_at: Default::default(),
conversation: None,
message_count,
}
Expand Down
6 changes: 4 additions & 2 deletions ui/desktop/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,8 @@
"nullable": true
},
"created_at": {
"type": "string"
"type": "string",
"format": "date-time"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this not require client side changes

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just an openapi annotation. If it changed the generated code we'd see that in this diff, but it seems that it does not: https://github.com/block/goose/blob/12f7ef5900be42a48445e757bc2a444a193f6b86/ui/desktop/src/api/types.gen.ts#L712-L713

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, you'd think it would turn into js Dates though those have their own issues I remember

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
"description": {
"type": "string"
Expand Down Expand Up @@ -3633,7 +3634,8 @@
"nullable": true
},
"updated_at": {
"type": "string"
"type": "string",
"format": "date-time"
},
"working_dir": {
"type": "string"
Expand Down