Skip to content

fix: wait for new PipelineRun before reporting build complete#51

Merged
vtz merged 2 commits into
mainfrom
fix/download-wait-for-new-run
May 21, 2026
Merged

fix: wait for new PipelineRun before reporting build complete#51
vtz merged 2 commits into
mainfrom
fix/download-wait-for-new-run

Conversation

@vtz
Copy link
Copy Markdown
Owner

@vtz vtz commented May 21, 2026

Summary

  • Fixes a bug where bob build -d would immediately download artifacts from a stale build when the BuildJob was already in Succeeded phase from a previous run
  • The CLI now records the PipelineRun name at trigger time and waits until it changes before treating terminal phases as final
  • Falls back to downloading existing artifacts after a 2-minute startup timeout (covers the edge case where the operator doesn't create a new run)

Reproduction

# Build completes as run24
bob build body-ecu-nucleo

# Trigger again with -d — previously this would download run24's artifacts instantly
# without waiting for the new run25 to finish
bob build body-ecu-nucleo -d ./out

Test plan

  • go build ./cmd/bob/ compiles
  • go test ./cmd/bob/ all tests pass
  • Manual: bob build <name> -d ./out waits for the new PipelineRun to complete
  • Manual: if no new run appears within 2 min, falls back to existing artifacts

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of build status detection and artifact downloading by better handling edge cases where builds are already completed.
    • Enhanced startup behavior with optimized polling to reduce unnecessary delays and system overhead.
    • Strengthened error handling for build status checks to provide clearer feedback.

Review Change Stack

The -d flag would immediately download artifacts from a previous run if
the BuildJob was already in Succeeded phase. Now the CLI records the
PipelineRun at trigger time and waits until it changes (indicating the
operator started the new run) before considering terminal phases. Falls
back after a 2-minute timeout if no new run appears.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

The change modifies the build wait logic in waitAndDownload to fetch initial build status once, record the current pipeline state, and defer phase reporting until a new run is detected or a startup timeout expires. A buildStarted flag gates polling to avoid unnecessary phase transitions before the build truly begins.

Changes

Build startup polling control

Layer / File(s) Summary
Build startup timeout constant
cmd/bob/wait.go
New buildStartupTimeout constant is defined to control how long to wait for a new PipelineRun before proceeding with a completed build.
Initial build status fetch and startup state
cmd/bob/wait.go
Function initialization now performs a single fetch of current build status to record the prior PipelineRun, sets up a buildStarted gate, and wraps the initial status retrieval with error handling.
Gated polling logic for startup detection
cmd/bob/wait.go
Polling loop now checks if PipelineRun has changed; if the build is already in a terminal phase, it waits up to the startup timeout for a new run before proceeding, using continue to defer phase reporting until the build is truly ready.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit waits with watchful eyes,
For pipelines to awaken, rise,
First peek to catch the startup phase,
Then polling loops at measured pace—
No false alarms, just true dispatch! 🐰⏳

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and accurately describes the main bug fix: preventing artifact download until a new PipelineRun appears, which is the primary change in the modified wait.go file.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/download-wait-for-new-run

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86c2768c2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/bob/wait.go Outdated
Comment on lines +59 to +63
if build.PipelineRun != previousRun {
buildStarted = true
fmt.Printf(" New PipelineRun: %s\n", build.PipelineRun)
} else if build.Phase == "Succeeded" || build.Phase == "Failed" {
if time.Since(start) > buildStartupTimeout {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detect already-switched PipelineRun as build start

In waitAndDownload, startup is only recognized when build.PipelineRun != previousRun, but previousRun is captured from an immediate Get done after triggering. If the controller has already switched CurrentPipelineRun by that first read, the new run's name equals previousRun, so buildStarted never flips until a terminal phase plus the 2-minute timeout. In that case successful/failed builds are reported at least 2 minutes late (and the fallback path is taken unnecessarily), which regresses the normal bob build ... -d flow from cmd/bob/build.go.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/bob/wait.go`:
- Around line 35-39: The polling logic in waitAndDownload captures previousRun
once (previousRun := initial.PipelineRun) so if initial already has the new
PipelineRun the loop never sees a change and buildStarted stays false until
buildStartupTimeout elapses; fix by initializing previousRun to nil/empty and/or
immediately detecting a non-nil current PipelineRun on the first poll: in
waitAndDownload, after the initial c.Get(ctx, name) and inside the polling loop
re-read build := c.Get(...) (or use the existing variable) and set buildStarted
= true when build.PipelineRun != nil && build.PipelineRun != previousRun (or
when previousRun is nil and build.PipelineRun != nil), update previousRun each
iteration, and ensure the logic that prints phase output and triggers download
uses the updated buildStarted and current build state instead of relying on a
single captured previousRun variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 092516cd-bc9b-4871-a834-d0385dc98848

📥 Commits

Reviewing files that changed from the base of the PR and between 6c66e05 and 86c2768.

📒 Files selected for processing (1)
  • cmd/bob/wait.go

Comment thread cmd/bob/wait.go
If the operator updates PipelineRun before our initial Get, previousRun
already matches the new run. Treat Running/Pending phases as proof the
build has started, avoiding a 2-minute stall before downloading.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vtz vtz merged commit db5d0d6 into main May 21, 2026
3 checks passed
@vtz vtz deleted the fix/download-wait-for-new-run branch May 21, 2026 15:07
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