-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Move token usage/context information to session level #3221
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
Conversation
Replace EventMsg::TokenCount(Option<TokenUsageInfo>) with EventMsg::TokenCount(TokenCountEvent) and update all sites and consumers to use the new struct. Remove ZDR documentation/config references no longer in use.
codex-rs/core/src/codex.rs
Outdated
.send(Event { | ||
id: sub_id.to_string(), | ||
msg: EventMsg::TokenCount(crate::protocol::TokenCountEvent { | ||
info: info.clone(), |
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.
Why cloning the info ?
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.
No good reason.
@@ -521,12 +521,54 @@ pub struct TaskStartedEvent { | |||
#[derive(Debug, Clone, Deserialize, Serialize, Default)] | |||
pub struct TokenUsage { | |||
pub input_tokens: u64, | |||
pub cached_input_tokens: Option<u64>, | |||
pub cached_input_tokens: u64, |
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.
General comment: we should not used unsigned int for this kind of thing. Unsigned arithmetic is not as good as signed one, it can fail gracefully in a lot of ways etc
This is a good reading on the topic (TLDR; this is not because it must be non-negative that we should use unsigned ints)
https://hamstergene.github.io/posts/2021-10-30-do-not-use-unsigned-for-nonnegativity/
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.
Good to know! I won't churn this PR but make sure to avoid unsigned where possible.
Move context information into the main loop so it can be used to interrupt the loop or start auto-compaction.