Skip to content

Runs keep going while they make progress; a step's time never fails a run - #357

Merged
nambok merged 1 commit into
mainfrom
fix/runs-keep-going
Oct 29, 2026
Merged

nambok merged 1 commit into
mainfrom
fix/runs-keep-going

Conversation

@nambok

@nambok nambok commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

A new-feature run triaged, planned (about 6 minutes of plan review), built eight files and reached the generator check with 30 seconds of its 15 minute invocation left. The check declined to start a sandbox build and failed the run: "the generator couldn't run here to regenerate them (not enough time left)". No generator build ran during the whole run, because the coder never called run_codegen.

Now a step's time never fails a run. Every place that lacked time hands the run to a fresh step (a new queue message with its own 15 minutes) that resumes at exactly that point, and the worker runs generators itself right after the implement work. The fixed continuation bounds are replaced by a progress rule: a run keeps going while its steps make progress.

Changes

Steps and progress (services/worker/src/passes/steps.rs, new; mod.rs)

  • Resume points after implement: Gate::Verify (worker generator run, adversarial test, security audit), Gate::Generators and Gate::Checks (proof, links, test-fix and new-feature checks, then the PR). The gate and what the skipped stages carry (the security verdict and its parked round) live on the run's checkpoint item. The message carries only the run id and step number.
  • Bounds before: MAX_CONTINUATIONS = 3, MAX_CONTINUATION_WALL_SECS = 45 min (and the first step's time was not counted). After: no count or wall-clock cap. Each step compares the branch head and resume point with where the previous step started. Two steps in a row without progress stop the run, naming the steps, the commit and where it was stuck. The team's usage limit (check_budget_exceeded) stops it before the next step is queued, and every step still starts with that check. Cancelling still stops it (resume_run_to_running). MAX_RUN_STEPS = 50 is only a runaway ceiling and logs an error if it is ever hit.
  • try_auto_continue returns why it couldn't continue, sends a new message (never a retry or redelivery of the current one), writes "...: continuing in step N with its own time budget" to the run page, and records run_step and step_queued_at on the run.
  • A redelivery or model retry of the same step is not counted as a new step, because the progress mark records its step number.
  • The plan check's "this step changed nothing, stop now" is replaced by the two-stalled-steps rule.

Where time used to fail or cut a run (mod.rs run_passes, hand_off_at)

  • Generator gate: GateStop::NeedsTime hands off at Generators (it used to fail with "not enough time left").
  • Proof, link, test-fix and new-feature checks: these get a TimeBudget that remembers when it refused a fix round for time. A check that then blocks the PR hands off at Checks instead of failing.
  • Before the PR opens: with less than 150 s left, the run hands off at Checks.
  • After implement: with less than 4 minutes left, the run hands off at Verify (the adversarial test used to be skipped silently).
  • The test-fix and security-fix rounds get the step deadline, so they stop on their own and are not cut off.
  • Only a run that cannot continue (usage limit, ceiling, queue error) stops at these points, with that reason and the branch the work is kept on.

Generators run with the work (generators.rs)

  • after_step: when the branch changes files a detected generator reads, the worker runs it in the sandbox right after implement and commits the output. It does not depend on the coder calling run_codegen.
  • gate(.., fresh) only verifies, with no second build, when nothing the generator reads changed since that run.
  • Ran::OutOfTime / Pass::OutOfTime separate a step without runway from a real failure.
  • A codegen build that CodeBuild itself timed out (TIMED_OUT) is reported as a tooling failure (sandbox.rs).

Run record size (run_lists.rs, new)

  • Progress notes, including the per-tool notes from implement.rs, are appended with a size(progress_notes) < 250 condition.
  • At the bound, the oldest notes move to S3 (runs/<team>/<run>/notes/<ms>.json). The item keeps the newest 200 and counts the moved notes in notes_archived.
  • Notes are capped at 1,000 characters.
  • pass_history is bounded the same way (200, keeping 150).

Stuck-run sweep (lambda/stuck-run-cleanup/handler.py)

  • A running run whose next step is queued and hasn't started (step_queued_at after updated_at, for less than 6 h) is not swept.
  • A step that started and then died is swept as before.

Queues (infra/lib/api-stack.ts)

  • Tickets, CI fix, feedback and webhooks get a visibility timeout of 5,400 s (6x the 900 s function timeout) and maxReceiveCount 5, as AWS recommends for SQS sources of Lambda.
  • Because steps hand off before 900 s, the visibility only delays a redelivery after a crash. The sweep has failed such a run with a reason long before that.

Future options, not in this PR: Lambda durable functions (checkpointed long-running execution) and Lambda Managed Instances (longer invocations) could replace the self-continuation. Both are larger migrations.

Verification

  • cargo fmt --all --check: clean.
  • cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test --workspace: common 1281, gateway 605, worker 970, 2 more; 0 failed.
  • python3 -m unittest for the stuck-run sweep: 18 passed.
  • infra npm test: 78 passed.
  • New tests:
    • Progress keeps a run going past the old bounds: 20 steps.
    • Two stalled steps stop the run, and the reason names the steps, the commit and where it was stuck.
    • The usage limit is checked before the next step is sent and at every step start.
    • A 10-step run sends 10 distinct new messages, each received once, never near maxReceiveCount.
    • Continuations are sent, never redelivered.
    • A gate that lacks time hands off at that gate (generators, the four checks, PR open).
    • A continuation resumes at the gate, with the security carry, and the worker's generator run comes before test and security.
    • Implement writing generator inputs triggers the generator; a later change that doesn't touch its inputs only verifies.
    • Out-of-time versus CodeBuild TIMED_OUT.
    • 2,000 worst-case-length notes keep the item under 400 KB.
    • The sweep leaves a queued step alone.
    • Worker queues: 5,400 s visibility and redrive count 5.

Gaps:

  • A run across several repositories still has no fresh steps. Its generator gate now says that precisely instead of "not enough time left".
  • Feedback-round pass history (feedback.rs) is still appended unbounded (one entry per round).
  • The dashboard doesn't yet read archived notes from S3.

… run

A new-feature run triaged, planned, built eight files and reached the
generator check with 30 seconds of its 15 minute invocation left. The check
declined to start a sandbox build and the run failed "not enough time
left", with the work done and the generator never run (the coder had not
called run_codegen).

- Every place that lacked time hands off instead: the run continues in a
  fresh step (a new queue message, its own 15 minutes) at the exact point:
  after implement (generators, test, security), the generator check, or
  the checks before the pull request. The skipped stages' results (the
  security verdict and its parked round) travel on the checkpoint.
- The fixed bounds (3 continuations, 45 minutes) are replaced by a
  progress rule: a run continues while its steps move the branch head or
  reach a later gate; two steps in a row without progress stop it with
  what was stuck; the team's usage limit and cancelling still stop it; a
  50 step ceiling guards against a runaway loop only.
- The worker runs a generator itself right after the implement work when
  the work changed its inputs, and commits the output; the late generator
  gate verifies (no second build when nothing it reads changed since).
- A codegen build CodeBuild timed out is a tooling failure.
- The run record's progress notes and pass history are bounded under the
  400 KB item limit (older notes move to S3).
- The stuck-run sweep leaves a run alone while its next step is queued.
- Worker queues: visibility 5,400 s (6x the 900 s function timeout) and a
  redrive count of 5, as AWS asks for SQS sources of Lambda.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant