mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Add message-count batching to the Guardian v3 housekeeper (#65028)
## What changed
Set `batch_limit = { mode = "messages", limit = 9 }` in the housekeeper
configuration to route up to nine new evidence records per batch. Each tool
call and each tool result counts separately. In this mode, batches can exceed
the default 100,000 estimated tokens while still fitting within the routing
model's input limit.
## Testing
Add a housekeeping test that routes nine large records in the first batch
and defers the tenth to the next batch.
GitOrigin-RevId: 99fdfc71f432007958c793a46b251f2e32a3e8ba
This commit is contained in:
@@ -2595,6 +2595,28 @@
|
||||
"mode"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"description": "Number of new evidence records, counting each tool call and result separately.",
|
||||
"properties": {
|
||||
"limit": {
|
||||
"format": "uint32",
|
||||
"minimum": 1.0,
|
||||
"type": "integer"
|
||||
},
|
||||
"mode": {
|
||||
"enum": [
|
||||
"messages"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"limit",
|
||||
"mode"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -167,9 +167,14 @@ impl Housekeeper {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let token_limit = match self.batch_limit {
|
||||
None => 100_000,
|
||||
Some(GuardianV3HousekeeperBatchLimit::Tokens(limit)) => limit.get() as usize,
|
||||
let (token_limit, max_sources) = match self.batch_limit {
|
||||
None => (100_000, pending.len()),
|
||||
Some(GuardianV3HousekeeperBatchLimit::Tokens(limit)) => {
|
||||
(limit.get() as usize, pending.len())
|
||||
}
|
||||
Some(GuardianV3HousekeeperBatchLimit::Messages(limit)) => {
|
||||
(self.sampler.input_limit, limit.get() as usize)
|
||||
}
|
||||
};
|
||||
let policy = TruncationPolicy::Tokens(token_limit.min(self.sampler.input_limit));
|
||||
let input_budget = policy.byte_budget();
|
||||
@@ -181,7 +186,7 @@ impl Housekeeper {
|
||||
// adds its serialized bytes and, after the first, one separating comma.
|
||||
let mut input_bytes = to_json_string_bounded(&empty_input, input_budget)?.len();
|
||||
let mut texts = Vec::new();
|
||||
for source in pending {
|
||||
for source in pending.iter().take(max_sources) {
|
||||
// Preserve the existing board's post-size limit, including source metadata.
|
||||
let text = to_json_string_bounded(source, 64 * 1024)?;
|
||||
// Every valid batch must route the first original to at least one channel.
|
||||
|
||||
@@ -93,6 +93,7 @@ use board_host::board_host;
|
||||
enum RoutingCase {
|
||||
Success,
|
||||
DefaultBatchLimit,
|
||||
MessageBatchLimit,
|
||||
RetryExhausted,
|
||||
WindowPressure,
|
||||
InstructionsExceedWindow,
|
||||
@@ -108,6 +109,7 @@ enum RoutingCase {
|
||||
|
||||
#[test_case::test_case(RoutingCase::Success; "transient_failures_route_each_original_once")]
|
||||
#[test_case::test_case(RoutingCase::DefaultBatchLimit; "default_token_limit_groups_large_originals")]
|
||||
#[test_case::test_case(RoutingCase::MessageBatchLimit; "message_count_splits_batches_above_the_default_token_limit")]
|
||||
#[test_case::test_case(RoutingCase::RetryExhausted; "exhausted_retries_leave_the_batch_pending")]
|
||||
#[test_case::test_case(RoutingCase::WindowPressure; "splits_batches_to_fit_routing_instructions_and_evicts_completed_batches")]
|
||||
#[test_case::test_case(RoutingCase::InstructionsExceedWindow; "budgets_configured_routing_instructions")]
|
||||
@@ -171,6 +173,13 @@ async fn routes_captured_originals_and_updates_descriptions(
|
||||
let (first_batch_size, later_text, batch_limit) = match case {
|
||||
// Eight 44 KiB originals fit the default 400,000-byte batch. The ninth starts another.
|
||||
RoutingCase::DefaultBatchLimit => (8, "x".repeat(44 * 1024), None),
|
||||
RoutingCase::MessageBatchLimit => (
|
||||
9,
|
||||
"x".repeat(44 * 1024),
|
||||
Some(GuardianV3HousekeeperBatchLimit::Messages(
|
||||
NonZeroU32::new(9).expect("positive limit"),
|
||||
)),
|
||||
),
|
||||
RoutingCase::WindowPressure => (
|
||||
2,
|
||||
"The later message is outside this capture.".repeat(50),
|
||||
@@ -270,6 +279,7 @@ async fn routes_captured_originals_and_updates_descriptions(
|
||||
RoutingCase::InvalidResponse => r#"{"private-evidence-canary":true}"#,
|
||||
RoutingCase::Success
|
||||
| RoutingCase::DefaultBatchLimit
|
||||
| RoutingCase::MessageBatchLimit
|
||||
| RoutingCase::RetryExhausted
|
||||
| RoutingCase::WindowPressure
|
||||
| RoutingCase::InstructionsExceedWindow
|
||||
@@ -385,6 +395,7 @@ async fn routes_captured_originals_and_updates_descriptions(
|
||||
case,
|
||||
RoutingCase::Success
|
||||
| RoutingCase::DefaultBatchLimit
|
||||
| RoutingCase::MessageBatchLimit
|
||||
| RoutingCase::WindowPressure
|
||||
| RoutingCase::DuplicateDestination
|
||||
) {
|
||||
|
||||
@@ -382,6 +382,8 @@ pub struct GuardianV3HousekeeperConfigToml {
|
||||
pub enum GuardianV3HousekeeperBatchLimit {
|
||||
/// Estimated tokens in the serialized channel catalog and new evidence.
|
||||
Tokens(NonZeroU32),
|
||||
/// Number of new evidence records, counting each tool call and result separately.
|
||||
Messages(NonZeroU32),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
|
||||
Reference in New Issue
Block a user