Repository navigation
fix: retain actionable finding mutation diagnostics #651
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
efraespada
merged 6 commits into
develop
from
bugfix/646-bug-bugbot-persists-a-review-then-fails-reconciliation-with-opaque-provider-unavailable
Oct 21, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0b19fe4
fix: preserve actionable finding mutation diagnostics
efraespada 890b926
Merge develop into bugfix/646-bug-bugbot-persists-a-review-then-fails…
vypbot 5e637f9
fix: diagnose only the submitted finding batch
efraespada 38b5eb4
Merge develop into bugfix/646-bug-bugbot-persists-a-review-then-fails…
vypbot cb82695
fix: retain transient recovery for HTTP 408 and 425
efraespada 14169d6
fix: preserve the issue publication error boundary
efraespada 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
Large diffs are not rendered by default.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Large diffs are not rendered by default.
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
36 changes: 36 additions & 0 deletions
36
src/application/errors/__tests__/bugbot_mutation_error.test.ts
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 { BugbotMutationError, bugbotMutationError } from '../bugbot_mutation_error'; | ||
| import { PullRequestReviewOperationError, toPullRequestReviewOperationError } from '../../ports/pull_request_review_errors'; | ||
|
|
||
| it.each([ | ||
| [401, 'authorization.credential-invalid'], [403, 'authorization.denied'], [404, 'provider.not-found'], | ||
| [409, 'provider.conflict'], [422, 'provider.contract-invalid'], [429, 'provider.rate-limited'], | ||
| [408, 'provider.unavailable'], [425, 'provider.unavailable'], | ||
| [503, 'provider.unavailable'], | ||
| ])('preserves safe HTTP %s metadata and classifies recovery as %s', (status, code) => { | ||
| const cause = new PullRequestReviewOperationError('resolve-thread', { providerStatus: status, providerReference: 'AB12:34CD' }); | ||
| const error = bugbotMutationError(cause, 'resolution', ['backend/Dockerfile:20:healthcheck-requires-curl'], 'mark-resolved'); | ||
| expect(error).toMatchObject({ code, diagnostic: { stage: 'resolution', operation: 'resolve-thread', | ||
| providerStatus: `http-${status}`, providerReference: 'AB12:34CD' } }); | ||
| expect(JSON.stringify(error)).not.toMatch(/private-/); | ||
| if (status === 408 || status === 425) expect(error.retryable).toBe(true); | ||
| }); | ||
|
|
||
| it('drops malformed provider status/reference and unsafe finding markup', () => { | ||
| const cause = new PullRequestReviewOperationError('publish-comments', { providerStatus: 400.5, providerReference: '@team\nsecret' }); | ||
| const error = bugbotMutationError(cause, 'publication', ['@team<script>'], 'publish-comments'); | ||
| expect(error.diagnostic).toMatchObject({ findingId: 'unavailable', providerStatus: 'http-unavailable', providerReference: 'unavailable' }); | ||
| }); | ||
|
|
||
| it('retains a typed mutation error unchanged across application boundaries', () => { | ||
| const error = bugbotMutationError(new Error('private'), 'publication', [], 'publish-comments'); | ||
| expect(error).toBeInstanceOf(BugbotMutationError); | ||
| expect(bugbotMutationError(error, 'resolution', ['other'], 'mark-resolved')).toBe(error); | ||
| expect(JSON.stringify(error)).not.toContain('private'); | ||
| }); | ||
|
|
||
|
|
||
| it.each([null, 'private provider prose'])('does not retain non-object provider errors', cause => { | ||
| const error = bugbotMutationError(toPullRequestReviewOperationError(cause, 'update-comment'), 'publication', ['f1'], 'publish-comments'); | ||
| expect(error.diagnostic.providerStatus).toBe('http-unavailable'); | ||
| expect(error.message).not.toContain('private'); | ||
| }); |
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,37 @@ | ||
| import { ApplicationError, type ApplicationErrorCode } from './application_error'; | ||
| import { PullRequestReviewOperationError, type PullRequestReviewOperation } from '../ports/pull_request_review_errors'; | ||
|
|
||
| export interface BugbotMutationDiagnostic { | ||
| readonly stage: 'publication' | 'resolution'; | ||
| readonly operation: PullRequestReviewOperation; | ||
| readonly findingId: string; | ||
| readonly affectedCount: number; | ||
| readonly providerStatus: string; | ||
| readonly providerReference: string; | ||
| readonly errorCode: ApplicationErrorCode; | ||
| } | ||
|
|
||
| export class BugbotMutationError extends ApplicationError { | ||
| constructor(readonly diagnostic: BugbotMutationDiagnostic) { | ||
| super(diagnostic.errorCode, `Bugbot ${diagnostic.stage} failed: operation=${diagnostic.operation}; finding=${diagnostic.findingId}; affected=${diagnostic.affectedCount}; ${diagnostic.providerStatus}; provider-reference=${diagnostic.providerReference}. Completed effects are retained; correct the named cause and recheck the same target.`); | ||
| } | ||
| } | ||
|
|
||
| export function bugbotMutationError(cause: unknown, stage: BugbotMutationDiagnostic['stage'], findingIds: readonly string[], fallback: PullRequestReviewOperation, affectedCount = findingIds.length): BugbotMutationError { | ||
| if (cause instanceof BugbotMutationError) return cause; | ||
| const provider = cause instanceof PullRequestReviewOperationError ? cause : undefined; | ||
| const status = provider?.providerStatus; | ||
| const errorCode = status === 401 ? 'authorization.credential-invalid' : status === 403 ? 'authorization.denied' | ||
| : status === 404 ? 'provider.not-found' : status === 409 ? 'provider.conflict' | ||
| : status === 429 ? 'provider.rate-limited' | ||
| : status === 408 || status === 425 ? 'provider.unavailable' | ||
| : status && status < 500 ? 'provider.contract-invalid' : 'provider.unavailable'; | ||
| const first = findingIds[0]; | ||
| return new BugbotMutationError(Object.freeze({ | ||
| stage, operation: provider?.operation ?? fallback, | ||
| findingId: typeof first === 'string' && /^[A-Za-z0-9_./:-]{1,200}$/.test(first) ? first : 'unavailable', | ||
| affectedCount: Math.min(affectedCount, 10_000), | ||
| providerStatus: status ? `http-${status}` : 'http-unavailable', | ||
| providerReference: provider?.providerReference ?? 'unavailable', errorCode, | ||
| })); | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.