**Context** When running `/compact`, `drain_to_completed` would throw an error if `token_usage` was `None` in `ResponseEvent::Completed`. This made the command fail even though everything else had succeeded. **What changed** - Instead of erroring, we now just check `if let Some(token_usage)` before sending the event. - If it’s missing, we skip it and move on. **Why** This makes `AgentTask::compact()` behave in the same way as `AgentTask::spawn()`, which also doesn’t error out when `token_usage` isn’t available. Keeps things consistent and avoids unnecessary failures. **Fixes** Closes #2417 --------- Co-authored-by: Ahmed Ibrahim <aibrahim@openai.com>
This commit is contained in:
committed by
GitHub
parent
e307040f10
commit
a6c346b9e1
@@ -2816,15 +2816,9 @@ async fn drain_to_completed(
|
|||||||
response_id: _,
|
response_id: _,
|
||||||
token_usage,
|
token_usage,
|
||||||
}) => {
|
}) => {
|
||||||
let token_usage = match token_usage {
|
// some providers don't return token usage, so we default
|
||||||
Some(usage) => usage,
|
// TODO: consider approximate token usage
|
||||||
None => {
|
let token_usage = token_usage.unwrap_or_default();
|
||||||
return Err(CodexErr::Stream(
|
|
||||||
"token_usage was None in ResponseEvent::Completed".into(),
|
|
||||||
None,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
sess.tx_event
|
sess.tx_event
|
||||||
.send(Event {
|
.send(Event {
|
||||||
id: sub_id.to_string(),
|
id: sub_id.to_string(),
|
||||||
@@ -2832,6 +2826,7 @@ async fn drain_to_completed(
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Ok(_) => continue,
|
Ok(_) => continue,
|
||||||
|
|||||||
Reference in New Issue
Block a user