Add Guardian context cost and request token telemetry (#44164)

## What changed

- Record per-section text bytes, estimated text tokens, image bytes, and image counts for synchronous reviews and asynchronous scoring without logging evidence payloads.
- Emit estimated request tokens through `codex.guardian.context.request_tokens`. Synchronous estimates include assembled history, instructions, tool definitions, and output format, and measure the full logical request before WebSocket delta generation. Asynchronous estimates cover the assembled input.
- Add shared context budgeting helpers, including conservative image token reservations independent of encoded payload size and model-aware input limit calculation.

## Testing

Add coverage for separate text and image accounting, image estimates independent of encoded size, and section estimates that bound delivered messages. Extend asynchronous scorer and app-server tests to verify cost metric emission.

GitOrigin-RevId: aed45ecd9c23706f88caa51f2a4f2c77872d3bdb
This commit is contained in:
felixxia-oai authored and copyberry committed 2026-09-09 14:48:08 +00:00
1 parent 73a1148c9c
commit d3ffbbed5a
13 files changed
+472 -9

No files matched your search

+1 -1
View File
@@ -270,7 +270,7 @@ impl ComposedContext {
}
}
fn user_message(content: Vec<ContentItem>) -> ResponseItem {
pub(super) fn user_message(content: Vec<ContentItem>) -> ResponseItem {
ResponseItem::Message {
id: None,
role: "user".to_owned(),