Repository navigation
feat(events): give a session an event envelope carrying run lifecycle #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justintime4tea
wants to merge
10
commits into
nightly
from
justingross/GH-778-run-events-carry-lifecycle-and-activity
+1,548
−59
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a153df9
feat(events): give a session an event envelope carrying run lifecycle
justintime4tea 58337b4
feat(events): refuse empty and nil identifiers
justintime4tea 1e7fd93
refactor(events): share timestamp, sequence number, and duration_ms
justintime4tea 5db77be
refactor(cli): use the shared duration_ms serde module
justintime4tea 2a25276
feat(events): read an unknown variant as unknown rather than failing
justintime4tea 778eaa4
fix(events): read a null liveness as the default
justintime4tea 53e19a1
doc(events): say what a false from follows() covers
justintime4tea fa9af6f
feat(events): let a start name the run it continues
justintime4tea 85f0a05
feat(events): carry usage on every terminal lifecycle event
justintime4tea 8c0a23f
doc(events): drop the claim that no second run id travels
justintime4tea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| //! Serializes a [`Duration`] as whole milliseconds, the unit every duration on | ||
| //! the wire is expressed in. Use it as | ||
| //! `#[serde(with = "aura_events::duration_ms")]`, or `duration_ms::option` for | ||
| //! an `Option<Duration>`. | ||
|
|
||
| use std::time::Duration; | ||
|
|
||
| use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
|
|
||
| pub fn serialize<S: Serializer>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error> { | ||
| u64::try_from(duration.as_millis()) | ||
| .unwrap_or(u64::MAX) | ||
| .serialize(serializer) | ||
| } | ||
|
|
||
| pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Duration, D::Error> { | ||
| u64::deserialize(deserializer).map(Duration::from_millis) | ||
| } | ||
|
|
||
| pub mod option { | ||
| use std::time::Duration; | ||
|
|
||
| use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
|
|
||
| pub fn serialize<S: Serializer>( | ||
| duration: &Option<Duration>, | ||
| serializer: S, | ||
| ) -> Result<S::Ok, S::Error> { | ||
| duration | ||
| .map(|d| u64::try_from(d.as_millis()).unwrap_or(u64::MAX)) | ||
| .serialize(serializer) | ||
| } | ||
|
|
||
| pub fn deserialize<'de, D: Deserializer<'de>>( | ||
| deserializer: D, | ||
| ) -> Result<Option<Duration>, D::Error> { | ||
| Ok(Option::<u64>::deserialize(deserializer)?.map(Duration::from_millis)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::time::Duration; | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
| use serde_json::json; | ||
|
|
||
| #[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
| struct Timed { | ||
| #[serde(with = "super")] | ||
| elapsed: Duration, | ||
| #[serde(with = "super::option")] | ||
| limit: Option<Duration>, | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_duration_is_whole_milliseconds() { | ||
| let timed = Timed { | ||
| elapsed: Duration::from_micros(1_500_999), | ||
| limit: Some(Duration::from_millis(30_000)), | ||
| }; | ||
| let json = serde_json::to_value(&timed).unwrap(); | ||
| assert_eq!(json, json!({ "elapsed": 1500, "limit": 30_000 })); | ||
| assert_eq!( | ||
| serde_json::from_value::<Timed>(json).unwrap(), | ||
| Timed { | ||
| elapsed: Duration::from_millis(1500), | ||
| limit: Some(Duration::from_millis(30_000)), | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn an_absent_duration_is_null() { | ||
| let timed = Timed { | ||
| elapsed: Duration::ZERO, | ||
| limit: None, | ||
| }; | ||
| let json = serde_json::to_value(&timed).unwrap(); | ||
| assert_eq!(json, json!({ "elapsed": 0, "limit": null })); | ||
| assert_eq!(serde_json::from_value::<Timed>(json).unwrap(), timed); | ||
| } | ||
|
|
||
| /// A duration too long for a u64 of milliseconds saturates rather than | ||
| /// failing to serialize. | ||
| #[test] | ||
| fn a_duration_past_u64_milliseconds_saturates() { | ||
| let timed = Timed { | ||
| elapsed: Duration::MAX, | ||
| limit: Some(Duration::MAX), | ||
| }; | ||
| assert_eq!( | ||
| serde_json::to_value(&timed).unwrap(), | ||
| json!({ "elapsed": u64::MAX, "limit": u64::MAX }) | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
Unknowncomment explains how serde reads and writes values.CLAUDE.mdrequires type comments to describe only what the value means, not runtime behavior. Remove the read/write clauses. The same wording appears onObserverKind::UnknownandLifecycleEvent::Unknown, with the pattern repeated elsewhere inrun.rs.This repository requirement must be satisfied before merging.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!