Add code-mode output truncation protocol contracts (#57272)

## What changed

Add session options for client- or server-owned output truncation and optional `max_output_tokens` budgets for wait and terminate observations. Introduce `TerminateRequest` and update session implementations and callers to use it.

Extend the stdio and gRPC schemas with optional truncation settings and budgets, and define the `bounded-output-v1` capability. Existing sessions retain client-side truncation; providers reject server mode by default. This change defines the contracts without enabling server-side truncation.

## Testing

Extend protocol serialization coverage for `outputTruncation: "server"` while preserving existing wire shapes when optional fields are absent.

GitOrigin-RevId: 22145897ea16d385c5ba9e7549109f7a669fceb4
This commit is contained in:
Sean Huang
2026-10-26 21:36:35 +00:00
committed by copyberry
parent 7077b1edb9
commit e963cab11a
38 changed files with 329 additions and 55 deletions
@@ -45,6 +45,14 @@ service CodeModeHost {
message OpenSessionRequest {
optional SessionCellExecutionLimits cell_execution_limits = 1;
// Absent preserves the legacy client-side truncation behavior.
optional OutputTruncation output_truncation = 2;
}
enum OutputTruncation {
OUTPUT_TRUNCATION_UNSPECIFIED = 0;
OUTPUT_TRUNCATION_CLIENT = 1;
OUTPUT_TRUNCATION_SERVER = 2;
}
message SessionCellExecutionLimits {
@@ -64,6 +72,8 @@ message SessionEvent {
message SessionOpened {
string session_id = 1;
// Absent (including from an older host) means the client owns truncation.
optional OutputTruncation output_truncation = 2;
}
message CloseSessionRequest {
@@ -182,6 +192,8 @@ message WaitRequest {
string cell_id = 2;
string wait_id = 3;
uint64 yield_time_ms = 4;
// Only set for a session that selected server-side output truncation.
optional uint64 max_output_tokens = 5;
}
message WaitResponse {
@@ -211,6 +223,8 @@ message YieldObservationResponse {}
message TerminateRequest {
string session_id = 1;
string cell_id = 2;
// The terminating observation has its own output budget.
optional uint64 max_output_tokens = 3;
}
message ExecutionOutcome {