Skip to content

Adaptive codex timeout based on PR size and media proofs — large PRs with videos consistently time out #272

@scotthuang

Description

@scotthuang

Problem

The default codex_timeout_ms of 600,000ms (10 minutes) is too short for large PRs, especially those with video proofs. External contributors have no way to override this timeout — the repository_dispatch payload
in dispatchItemReview() never includes codex_timeout_ms, so it always falls through to the hard default.

Concrete example

PR #91093 (openclaw/openclaw#91093) in openclaw/openclaw:

┌───────────────┬────────────────────────────────────────┐
│ Metric │ Value │
├───────────────┼────────────────────────────────────────┤
│ Files changed │ 71 │
├───────────────┼────────────────────────────────────────┤
│ Lines added │ +4,176 │
├───────────────┼────────────────────────────────────────┤
│ Commits │ 18 │
├───────────────┼────────────────────────────────────────┤
│ Video proofs │ 2 (.mov files in PR body) │
├───────────────┼────────────────────────────────────────┤
│ Codex result │ spawnSync codex ETIMEDOUT (repeatedly) │
└───────────────┴────────────────────────────────────────┘

This PR is also tagged size: XL.

Why this happens

  1. Large diff context: 71 files × up to 2,000 chars per file patch = ~140KB of diff alone, plus PR body, 18 commits, timeline events, review comments, and the 760-line static prompt template.
  2. Video preprocessing eats into the wall-clock budget: prepareMediaProofArtifacts() runs before codex and for each video:
  • curl download (up to 90s per video via --max-time 90)
  • ffprobe metadata extraction
  • ffmpeg contact sheet generation

Two videos could consume up to 180s just in download, plus ffmpeg processing time — all before codex even starts. This time counts against the same outer shell timeout in sweep.yml.
3. No adaptive scaling: pr-surface-stats.ts already classifies files by type and counts additions/deletions, but this data is never used to adjust the timeout. Every PR gets the same 10 minutes regardless of 5
files or 80 files.

Suggested fixes

Option A (quick): Add codex_timeout_ms to the dispatchItemReview() client_payload, derived from PR surface stats (e.g., file count × baseline, capped at some max). This lets the workflow pick the right timeout
without any manual config.

Option B (more thorough): Factor video preprocessing time into the timeout separately — if N video proofs are detected, add N * 120s to the codex timeout budget.

Option C (architectural): Run video proof preprocessing in a separate, earlier step (e.g., in the plan job or a dedicated media job), so the review shard starts with preprocessed artifacts and the codex timeout
only covers the review itself.

Related code

  • prepareMediaProofArtifacts() — src/clawsweeper.ts:6101
  • proofVideoUrlsFromContext() — src/clawsweeper.ts:6059 (scans entire context JSON for .mov/.mp4/.m4v/.webm/.avi/.mkv, up to 4 URLs)
  • dispatchItemReview() — src/repair/comment-webhook.ts:662 (no codex_timeout_ms in payload)
  • sweep.yml:886 — timeout fallback chain, client_payload.codex_timeout_ms is always undefined for external repos
  • pr-surface-stats.ts — has file classification and counts, unused for timeout decisions

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Urgent regression or broken agent/channel workflow affecting real users now.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopThis issue is about crashes, hangs, restart loops, or process-level availability.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions