perf(workflow): cap final-patch timeout at 10s in all cases

Success runs used 30s, failure runs 10s. 30s is too long to block
terminal-event emission — git diff on a healthy workspace returns
well under a second; the timeout is a failsafe, not a common-case
budget. Users watching the stream shouldn't wait 30s for a degraded
case.

Unifying at 10s removes the status-dependent branch and the final_status
argument to compute_final_patch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-04-24 10:38:22 -04:00
parent bc06e2dbd5
commit 8057739c85
No known key found for this signature in database

View file

@ -178,19 +178,13 @@ pub async fn write_finalize_commit(
.await;
}
/// Failed and cancelled runs use a shorter diff timeout so a corrupted
/// workspace can't stall downstream consumers waiting on the terminal event.
async fn compute_final_patch(
run_options: &RunOptions,
services: &RunServices,
status: StageStatus,
) -> Option<String> {
/// Bounded to 10s so a corrupted or unresponsive workspace can't stall
/// downstream consumers waiting on the terminal event. Git diff on a
/// healthy workspace returns in well under a second; timeout is a failsafe,
/// not a common-case budget.
async fn compute_final_patch(run_options: &RunOptions, services: &RunServices) -> Option<String> {
let base_sha = run_options.git.as_ref().and_then(|g| g.base_sha.clone())?;
let timeout_ms = match status {
StageStatus::Success | StageStatus::PartialSuccess => 30_000,
_ => 10_000,
};
match git_diff_with_timeout(&*services.sandbox, &base_sha, timeout_ms).await {
match git_diff_with_timeout(&*services.sandbox, &base_sha, 10_000).await {
Ok(patch) if !patch.is_empty() => Some(patch),
Ok(_) => None,
Err(err) => {
@ -325,14 +319,14 @@ pub async fn finalize(retroed: Retroed, options: &FinalizeOptions) -> Result<Con
let conclusion = build_conclusion_from_parts(
checkpoint.as_ref(),
&stage_durations,
final_status.clone(),
final_status,
failure_reason,
duration_ms,
options.last_git_sha.clone(),
);
let (final_patch, ()) = tokio::join!(
compute_final_patch(&run_options, &services, final_status),
compute_final_patch(&run_options, &services),
write_finalize_commit(&run_options, &services.run_store, &conclusion),
);