Skip to content

Conversation

pakrym-oai
Copy link
Collaborator

@pakrym-oai pakrym-oai commented Sep 5, 2025

Move context information into the main loop so it can be used to interrupt the loop or start auto-compaction.

@pakrym-oai pakrym-oai changed the title Move token information to session Move token usage/context information to session level Sep 6, 2025
.send(Event {
id: sub_id.to_string(),
msg: EventMsg::TokenCount(crate::protocol::TokenCountEvent {
info: info.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why cloning the info ?

Copy link
Collaborator Author

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,
Copy link
Contributor

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/

Copy link
Collaborator Author

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.

@pakrym-oai pakrym-oai enabled auto-merge (squash) September 6, 2025 15:18
@pakrym-oai pakrym-oai merged commit 0269096 into main Sep 6, 2025
18 checks passed
@pakrym-oai pakrym-oai deleted the pakrym/move-token-information-to-session branch September 6, 2025 15:19
@github-actions github-actions bot locked and limited conversation to collaborators Sep 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants