Remove the 4,000-byte prompt limit for thread/sample (#62378)

## What changed

Allow prompts longer than 4,000 bytes to pass `thread/sample` request
validation. Both `expectedTurnId` and `prompt` must still be nonblank.

GitOrigin-RevId: 59b97d351e2a02378b83aa9f2d4e649dd57169af
This commit is contained in:
Keyan Zhang
2026-11-18 22:40:41 +00:00
committed by copyberry
parent b967993f35
commit 8e9746b19d
2 changed files with 5 additions and 16 deletions
+4 -9
View File
@@ -55,8 +55,6 @@ use tokio_util::sync::CancellationToken;
use tokio_util::task::TaskTracker;
const SAMPLE_TIMEOUT: Duration = Duration::from_secs(30);
// Bytes conservatively bound tokens, including for byte-fallback tokenizers.
const MAX_PROMPT_BYTES: usize = 4_000;
const MAX_OUTPUT_BYTES: usize = 64 * 1024;
const THREAD_SNAPSHOT_NOTE: &str = concat!(
"\nThis snapshot is a copy of the source thread’s history taken while its turn was still running. ",
@@ -85,13 +83,10 @@ pub(crate) async fn generate_sample(
rpc_gate: Arc<ConnectionRpcGate>,
) -> SampleResult {
let deadline = Instant::now() + SAMPLE_TIMEOUT;
if task.params.expected_turn_id.trim().is_empty()
|| task.params.prompt.trim().is_empty()
|| task.params.prompt.len() > MAX_PROMPT_BYTES
{
return Err(invalid_request(format!(
"thread/sample requires expectedTurnId and a prompt of at most {MAX_PROMPT_BYTES} bytes",
)));
if task.params.expected_turn_id.trim().is_empty() || task.params.prompt.trim().is_empty() {
return Err(invalid_request(
"thread/sample requires a nonblank expectedTurnId and prompt",
));
}
let (sender, receiver) = oneshot::channel();
let originator = AuthStorageOriginator::current();
@@ -1319,13 +1319,7 @@ async fn sample_rejects_invalid_sources_and_prompts() -> Result<()> {
"Predict".to_string(),
"latest finished turn",
),
(parent.clone(), turn.clone(), String::new(), "prompt"),
(
parent.clone(),
turn.clone(),
"x".repeat(4_001),
"at most 4000 bytes",
),
(parent, turn, String::new(), "prompt"),
] {
let id = client
.send_raw_request(