Preserve conversation context and separate next actions in recaps (#45090)

## Why

The 900-byte recap prompt limit leaves little room for completed progress, unresolved caveats, and recent corrections. Recaps need this context to distinguish completed work from pending requests.

## What changed

- Introduce a shared `RecapPrompt` with a 32 KiB ceiling for instructions and history, using an 8,192-token estimate. Instruct summaries to retain the broader goal, completed outcomes, and unresolved availability or validation caveats.
- Select up to eight answered exchanges plus a pending request, preserving adjacent steering and progress messages. Drop older whole exchanges before excerpting both ends of oversized messages, while retaining the newest answer and pending correction.
- Require a `summary` and nullable `next_action`, bounded to 700 and 200 characters respectively. Reject malformed or oversized responses and display an optional, separately styled `Next:` line.

## Testing

Add coverage for UTF-8 prompt bounds, exchange selection, pending corrections, excerpt boundaries, strict response parsing, and next-action rendering. Extend the recap generation integration test to verify bounded history and the structured response schema.

GitOrigin-RevId: 6c6a84bc602a168418c1952feb1d286ec0cb9e28
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-09-12 18:16:17 +00:00
1 parent f16c2237a5
commit 8d3c6cc13d
9 files changed
+544 -141

No files matched your search

@@ -62,7 +62,7 @@ async fn recap_generation_uses_bounded_structured_request_and_inserts_result() -
ev_response_created("recap-response"),
ev_assistant_message(
"recap-message",
r#"{"recap":"Finished parsing. Next: run focused tests."}"#,
r#"{"summary":"Finished parsing.","next_action":"Run focused tests."}"#,
),
ev_completed("recap-response"),
]
@@ -118,6 +118,22 @@ stream_max_retries = 0
while app_event_rx.try_recv().is_ok() {}
prepare_eligible_recap(&mut app, thread_id).await;
app.transcript_cells
.push(Arc::new(crate::history_cell::AgentMarkdownCell::new(
format!(
"Parser fix implemented. {} What should empty input do?",
"progress ".repeat(/*n*/ 5_000)
),
std::path::Path::new("."),
)));
app.transcript_cells
.push(Arc::new(crate::history_cell::UserHistoryCell {
message: "Keep follow-up work queued.".to_string(),
spoken: false,
text_elements: Vec::new(),
local_image_paths: Vec::new(),
remote_image_urls: Vec::new(),
}));
app.handle_event(
&mut tui,
@@ -169,7 +185,8 @@ stream_max_retries = 0
.collect::<Vec<_>>(),
vec![
"Conversation recap",
"Finished parsing. Next: run focused tests.",
"Finished parsing.",
"Next: Run focused tests.",
]
);
@@ -188,7 +205,20 @@ stream_max_retries = 0
"prompt: {prompt}\nrequest: {request}"
);
assert!(prompt.len() <= recap::RECAP_PROMPT_MAX_BYTES);
assert!(prompt.contains("Assistant: Parser fix implemented."));
assert!(prompt.contains("What should empty input do?"));
assert!(prompt.contains("[... excerpted ...]"));
assert_eq!(
prompt
.matches("Pending user request: Keep follow-up work queued.")
.count(),
1
);
assert_eq!(request["text"]["format"]["type"], "json_schema");
assert_eq!(
request["text"]["format"]["schema"]["required"],
serde_json::json!(["summary", "next_action"])
);
assert_eq!(request["tools"], serde_json::json!([]));
app_server.shutdown().await?;