-
Notifications
You must be signed in to change notification settings - Fork 18
fix(branch): survive a transient control-plane 502 while polling (v0.2.8) #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { getBranchApi } from '../../lib/api/platform.js'; | ||
| import { isTransientApiError } from '../../lib/errors.js'; | ||
| import type { Branch } from '../../types.js'; | ||
|
|
||
| /** | ||
| * Read a branch, retrying a bounded number of times on transient failures. | ||
| * | ||
| * Used for the read that decides a poll's FINAL verdict, where a single | ||
| * unlucky 502 is expensive: `branch create` would report a branch that just | ||
| * reached 'ready' as stuck in its last-seen state (and exit non-zero on a | ||
| * genuine success), and `branch reset` would have to give up on confirming an | ||
| * outcome it very nearly had. Inside the poll loop itself this is unnecessary — | ||
| * the loop's own interval already is the retry. | ||
| * | ||
| * A non-transient error is rethrown on the first attempt: it will answer the | ||
| * same way every time. After the last attempt the final transient error is | ||
| * rethrown for the caller to interpret. | ||
| */ | ||
| export async function readBranchWithRetry( | ||
| branchId: string, | ||
| apiUrl: string | undefined, | ||
| attempts: number, | ||
| delayMs: number, | ||
| ): Promise<Branch> { | ||
| let lastErr: unknown; | ||
| for (let attempt = 1; attempt <= attempts; attempt++) { | ||
| try { | ||
| return await getBranchApi(branchId, apiUrl); | ||
| } catch (err) { | ||
| if (!isTransientApiError(err)) throw err; | ||
| lastErr = err; | ||
| if (attempt < attempts) await new Promise(r => setTimeout(r, delayMs)); | ||
| } | ||
| } | ||
| throw lastErr; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The timeout fallback — a headline behavior of this change — has no test coverage.
pollUntilReadynow has an untested branch where the budget is exhausted, the finalgetBranchApiread fails transiently, and it returns the last observedlastBranchinstead of surfacing the API error; likewise theUNREACHABLE_STATEre-announce path is untested. The added tests only cover a single 502 that is immediately followed by a successful read (mid-poll skip), a terminal 404, and 5xx create adoption. None of them exhaust the poll budget while reads keep failing, so a regression that turns a timed-out branch back into an API error would pass CI. Add a test wheregetBranchApistays transient for the full budget and assert the last observed branch state is reported (non-zero exit for a non-'ready' state) rather than an error.Prompt for AI agents