## Why
Model request hooks need to correlate attempts belonging to the same generation across retries and model fallback.
## What changed
Add `request_id` and one-based `attempt_number` fields to `PreModelRequest` and `PostModelRequest` inputs and their generated schema. Keep the request ID stable across retries and increment the attempt number for each call to open a response stream.
## Testing
Extend hook tests to verify matching request IDs and increasing attempt numbers across retries. Extend the background compaction scenario to verify that its pre/post hooks share an ID distinct from the ordinary sampling request.
GitOrigin-RevId: 2d85ad6fd630505a89a712cebab6ca0f731610c9
## Why
A budget can be exhausted while another thread waits to start work. New requests, tools, and automatic turns must observe that stop without discarding an already-consumed response whose cost exhausted the budget.
## What changed
- Share a work gate across the rollout tree while preserving native and host accounting ownership.
- Recheck the budget before HTTP and WebSocket requests, hook execution, tool dispatch, and compaction. Prevent automatic wakeups and late input from restarting stopped work, leaving pending input queued.
- Record response costs without rejecting the consumed response solely because its bill exhausts the budget, and stop new work when enforced accounting overflows.
- Expose a thread-registration receipt that remains committed after unload.
## Testing
Extend rollout-budget coverage to verify that accepted response text remains in history after exhaustion and that waiting tools observe the shared stop while completed tools retain their results.
GitOrigin-RevId: e583d657c6f29e374d374cdb014bf23fd6c28614
## What changed
Allow successful synchronous `PostModelRequest` MCP hooks to return `extra_codex_rollout_budget_units` in `structuredContent`. Add these charges to rollout spending while preserving provider usage separately, including completed responses without token usage and incomplete responses with reported usage.
Validate prices as finite and nonnegative. Preserve valid sibling charges when another hook reports an invalid price, and surface accounting failures without retrying inference. Carry hook charges and overflow information through host accounting and enforce local budget limits.
## Testing
Extend coverage for hook-driven budget exhaustion, failed hooks, overflow, interrupted responses, and foreground and background compaction accounting.
GitOrigin-RevId: dc54ba53478d82848bcafb55ecef88215019d09f
## Why
Streaming can dispatch tools before a response finishes and its usage is accounted for. Allow callers to wait for completion and synchronous post-hooks so budget enforcement can block tools from the response that exhausts the budget.
## What changed
- Add `responses.process_mode = "after_complete_response"` to buffer response items and release them in order after completion, synchronous post-hooks, and usage accounting. Keep `streaming` as the default and deliver safety-buffering notifications immediately.
- Track whether response usage has already been charged to avoid duplicate accounting, including during compaction.
- Stop new tools across the agent tree when the rollout budget is exhausted. Coordinate steering with accounting and prevent buffered tool calls from dispatching after steering or cancellation.
- Bound buffered responses to 65,535 events and reject overflow.
## Testing
Add configuration coverage and extend integration tests for buffered output ordering, synchronous hooks, interrupted responses and resume, steering, invalid usage, and budget exhaustion preventing tool dispatch.
GitOrigin-RevId: bd06811cfd50cb701babe6353465c57dfed2a37a
## What changed
- Pair `PreModelRequest` and `PostModelRequest` hooks per sampling or compaction attempt, with distinct lifecycle IDs and cancellation reporting.
- Add `thread_id` and `kind` to hook inputs, distinguishing `sampling`, `foreground_compaction`, and `background_compaction`. Include the provider's `response_id` in post-hook inputs when available.
- Wait for synchronous post-hooks before releasing terminal response events, accounting for usage, or installing compaction results. Allow streaming output and tool execution to proceed before the hook finishes, and cancel synchronous post-hooks when their owning request is interrupted.
- Preserve incomplete-response, budget-exceeded, and hook-denied outcomes across sampling retries and compaction model fallback.
## Testing
Add coverage for streaming and tool ordering, interrupted post-hooks, per-attempt metadata, and foreground and background compaction accounting and installation ordering.
GitOrigin-RevId: 3e808c5b3bf2d5a6a326d9f5be5bbd0359b2d16e