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
1 change: 1 addition & 0 deletions crates/minimal2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ async fn cmd_activate(global: &GlobalArgs, args: ActivateArgs) -> Result<(), ()>
project_path: abs_path,
network: args.network.into(),
policy,
status: Default::default(),
attrs: Default::default(),
};

Expand Down
1 change: 1 addition & 0 deletions crates/minimald/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ mod tests {
project_path: HostAbsPath::try_new("/tmp").unwrap(),
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
})
Expand Down
6 changes: 6 additions & 0 deletions crates/minimald/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ mod tests {
project_path: HostAbsPath::try_new("/tmp").unwrap(),
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
})
Expand Down Expand Up @@ -620,6 +621,7 @@ mod tests {
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
})
Expand Down Expand Up @@ -674,6 +676,7 @@ mod tests {
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: NetworkMode::OwnIp,
policy: SessionPolicy::new(Some(egress.clone()), None),
status: Default::default(),
attrs: Default::default(),
},
})
Expand Down Expand Up @@ -704,6 +707,7 @@ mod tests {
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
})
Expand All @@ -722,6 +726,7 @@ mod tests {
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
})
Expand Down Expand Up @@ -753,6 +758,7 @@ mod tests {
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: NetworkMode::HostNet,
policy: SessionPolicy::new(Some(egress), None),
status: Default::default(),
attrs: Default::default(),
},
})
Expand Down
1 change: 1 addition & 0 deletions crates/minimald/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ mod tests {
project_path: HostAbsPath::try_new("/uwu").unwrap(),
network: Default::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
})
Expand Down
1 change: 1 addition & 0 deletions crates/minimald/src/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ mod tests {
project_path: HostAbsPath::try_new("/proj").unwrap(),
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/minimald/src/sftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ mod tests {
project_path: HostAbsPath::try_new("/tmp").unwrap(),
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
})
Expand Down
1 change: 1 addition & 0 deletions crates/minvmd/examples/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ async fn run_session_exec(
.map_err(|e| format!("project_path: {e}"))?,
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
};
Expand Down
1 change: 1 addition & 0 deletions crates/minvmd/tests/minimald_session_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ async fn run_session_exec(
.map_err(|e| format!("project_path: {e}"))?,
network: sessions::NetworkMode::default(),
policy: Default::default(),
status: Default::default(),
attrs: Default::default(),
},
};
Expand Down
58 changes: 57 additions & 1 deletion crates/sessions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,34 @@ impl fmt::Display for SessionId {
}
}

/// Lifecycle status of a [`Record`].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SessionStatus implies its the state machine for the session- given its more the loadout vibes, do we want to call it Loadout or LoadoutStatus ?

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 it is actually part of the session lifecycle itself. A session is created as a Draft once the client sends the CreateSession request, along with the loadout information, and then it becomes active once the client gets back to it with the verdict on package and project contributions. It's not really a loadout specific thing.

///
/// `Draft` covers a session whose composition is still in flight —
/// an id has been allocated and a stub record persisted, but the
/// composition pipeline hasn't yet produced a finalized
/// `Composition`. `Active` is the finalized, ready-to-use state.
///
/// Defaults to `Active` so on-disk records predating this field
/// (which were always finalized at create time) deserialize
/// correctly.
///
/// The store layer doesn't enforce transitions between states — it
/// records the status verbatim. State-machine rules (e.g. "only
/// the composition pipeline can promote `Draft` → `Active`") live
/// in the manager actor.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "snake_case")]
pub enum SessionStatus {
/// Composition is in flight; the record is a stub awaiting the
/// `SubmitVerdict` round-trip to finalize.
Draft,
/// Composition complete; the record is ready to apply.
#[default]
Active,
}

/// The on-disk row/record pertaining to a session.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Record {
/// Unique ID describing this session.
#[serde(default = "SessionId::nil")]
Expand Down Expand Up @@ -295,6 +321,12 @@ pub struct Record {
#[serde(default)]
pub policy: SessionPolicy,

/// Lifecycle status. Defaults to [`SessionStatus::Active`] for
/// on-disk records predating this field — those records were
/// always finalized at create time.
#[serde(default)]
pub status: SessionStatus,

/// Free-form attributes.
pub attrs: BTreeMap<String, String>,
}
Expand Down Expand Up @@ -410,6 +442,7 @@ mod tests {
project_path: HostAbsPath::try_new("/p").unwrap(),
network,
policy,
status: SessionStatus::default(),
attrs: BTreeMap::new(),
}
}
Expand Down Expand Up @@ -673,4 +706,27 @@ mod tests {
);
assert!(record.validate_policy().is_ok());
}

/// On-disk records that predate the `status` field must
/// deserialize as `Active`. This guarantees existing session
/// stores keep working after the schema change.
#[test]
fn record_without_status_field_deserializes_as_active() {
// Build a JSON document deliberately missing the `status`
// field, with the rest of the fields set to plausible values.
let raw = serde_json::json!({
"id": SessionId::nil(),
"name": null,
"username": null,
"project_path": "/p",
"attrs": {},
});
let parsed: Record = serde_json::from_value(raw).expect("deserialize");
assert_eq!(parsed.status, SessionStatus::Active);
}

#[test]
fn session_status_default_is_active() {
assert_eq!(SessionStatus::default(), SessionStatus::Active);
}
}
Loading
Loading