mirror of
https://github.com/openai/codex.git
synced 2026-11-24 15:21:20 +00:00
1 parent
66d5edf825
commit
9483b09ea4
4 files changed
+23
-23
No files matched your search
@@ -20,7 +20,7 @@ pub struct GoalUpdate {
|
||||
pub expected_goal_id: Option<String>,
|
||||
}
|
||||
|
||||
pub enum ThreadGoalAccountingOutcome {
|
||||
pub enum GoalAccountingOutcome {
|
||||
Unchanged(Option<crate::ThreadGoal>),
|
||||
Updated(crate::ThreadGoal),
|
||||
}
|
||||
@@ -389,11 +389,11 @@ WHERE thread_id = ?
|
||||
token_delta: i64,
|
||||
mode: GoalAccountingMode,
|
||||
expected_goal_id: Option<&str>,
|
||||
) -> anyhow::Result<ThreadGoalAccountingOutcome> {
|
||||
) -> anyhow::Result<GoalAccountingOutcome> {
|
||||
let time_delta_seconds = time_delta_seconds.max(0);
|
||||
let token_delta = token_delta.max(0);
|
||||
if time_delta_seconds == 0 && token_delta == 0 {
|
||||
return Ok(ThreadGoalAccountingOutcome::Unchanged(
|
||||
return Ok(GoalAccountingOutcome::Unchanged(
|
||||
self.get_thread_goal(thread_id).await?,
|
||||
));
|
||||
}
|
||||
@@ -464,13 +464,13 @@ RETURNING
|
||||
let row = query.fetch_optional(self.pool.as_ref()).await?;
|
||||
|
||||
let Some(row) = row else {
|
||||
return Ok(ThreadGoalAccountingOutcome::Unchanged(
|
||||
return Ok(GoalAccountingOutcome::Unchanged(
|
||||
self.get_thread_goal(thread_id).await?,
|
||||
));
|
||||
};
|
||||
|
||||
let updated = thread_goal_from_row(&row)?;
|
||||
Ok(ThreadGoalAccountingOutcome::Updated(updated))
|
||||
Ok(GoalAccountingOutcome::Updated(updated))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,7 +808,7 @@ mod tests {
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
|
||||
let ThreadGoalAccountingOutcome::Unchanged(Some(goal)) = outcome else {
|
||||
let GoalAccountingOutcome::Unchanged(Some(goal)) = outcome else {
|
||||
panic!("stale goal version should not be updated");
|
||||
};
|
||||
assert_ne!(replacement.goal_id, original.goal_id);
|
||||
@@ -845,7 +845,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Updated(accounted) = outcome else {
|
||||
let GoalAccountingOutcome::Updated(accounted) = outcome else {
|
||||
panic!("active goal should account usage");
|
||||
};
|
||||
|
||||
@@ -1067,7 +1067,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Updated(goal) = outcome else {
|
||||
let GoalAccountingOutcome::Updated(goal) = outcome else {
|
||||
panic!("active goal should be updated");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::Active, goal.status);
|
||||
@@ -1085,7 +1085,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Updated(goal) = outcome else {
|
||||
let GoalAccountingOutcome::Updated(goal) = outcome else {
|
||||
panic!("budget crossing should update the goal");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::BudgetLimited, goal.status);
|
||||
@@ -1103,7 +1103,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Updated(goal) = outcome else {
|
||||
let GoalAccountingOutcome::Updated(goal) = outcome else {
|
||||
panic!("budget-limited goal should still account in-flight active usage");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::BudgetLimited, goal.status);
|
||||
@@ -1138,7 +1138,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Unchanged(Some(goal)) = outcome else {
|
||||
let GoalAccountingOutcome::Unchanged(Some(goal)) = outcome else {
|
||||
panic!("budget-limited goal should not be updated");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::BudgetLimited, goal.status);
|
||||
@@ -1186,7 +1186,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Updated(goal) = outcome else {
|
||||
let GoalAccountingOutcome::Updated(goal) = outcome else {
|
||||
panic!("stopped goal should account final usage");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::BudgetLimited, goal.status);
|
||||
@@ -1365,7 +1365,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Updated(budget_limited) = outcome else {
|
||||
let GoalAccountingOutcome::Updated(budget_limited) = outcome else {
|
||||
panic!("budget crossing should update the goal");
|
||||
};
|
||||
|
||||
@@ -1418,7 +1418,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Unchanged(Some(goal)) = active_only else {
|
||||
let GoalAccountingOutcome::Unchanged(Some(goal)) = active_only else {
|
||||
panic!("completed goal should not be updated by active-only accounting");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::Complete, goal.status);
|
||||
@@ -1436,7 +1436,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Updated(goal) = completing_turn else {
|
||||
let GoalAccountingOutcome::Updated(goal) = completing_turn else {
|
||||
panic!("completed goal should be updated for final accounting");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::Complete, goal.status);
|
||||
@@ -1485,7 +1485,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Unchanged(Some(goal)) = active_only else {
|
||||
let GoalAccountingOutcome::Unchanged(Some(goal)) = active_only else {
|
||||
panic!("paused goal should not be updated by active-only accounting");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::Paused, goal.status);
|
||||
@@ -1503,7 +1503,7 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.expect("usage accounting should succeed");
|
||||
let ThreadGoalAccountingOutcome::Updated(goal) = in_flight_turn else {
|
||||
let GoalAccountingOutcome::Updated(goal) = in_flight_turn else {
|
||||
panic!("stopped goal should be updated for in-flight accounting");
|
||||
};
|
||||
assert_eq!(crate::ThreadGoalStatus::Paused, goal.status);
|
||||
|
||||
Reference in new issue
Block a user