Skip to content

Commit 95033db

Browse files
committed
feature-296-bugbot-autofix: Implement truncation for finding body comments exceeding 12000 characters to prevent prompt bloat, and update related tests to ensure functionality; also limit verify commands to 20 with appropriate logging.
1 parent 9dde42b commit 95033db

6 files changed

Lines changed: 75 additions & 9 deletions

File tree

build/cli/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54111,6 +54111,8 @@ const exec = __importStar(__nccwpck_require__(1514));
5411154111
const shellQuote = __importStar(__nccwpck_require__(7029));
5411254112
const project_repository_1 = __nccwpck_require__(7917);
5411354113
const logger_1 = __nccwpck_require__(8836);
54114+
/** Maximum number of verify commands to run to avoid excessive build times. */
54115+
const MAX_VERIFY_COMMANDS = 20;
5411454116
/**
5411554117
* Returns true if there are uncommitted changes (working tree or index).
5411654118
*/
@@ -54240,6 +54242,10 @@ async function runBugbotAutofixCommitAndPush(execution, options) {
5424054242
verifyCommands = [];
5424154243
}
5424254244
verifyCommands = verifyCommands.filter((cmd) => typeof cmd === "string");
54245+
if (verifyCommands.length > MAX_VERIFY_COMMANDS) {
54246+
(0, logger_1.logInfo)(`Limiting verify commands to ${MAX_VERIFY_COMMANDS} (configured: ${verifyCommands.length}).`);
54247+
verifyCommands = verifyCommands.slice(0, MAX_VERIFY_COMMANDS);
54248+
}
5424354249
if (verifyCommands.length > 0) {
5424454250
(0, logger_1.logInfo)(`Running ${verifyCommands.length} verify command(s)...`);
5424554251
const verify = await runVerifyCommands(verifyCommands);
@@ -54342,7 +54348,7 @@ class BugbotAutofixUseCase {
5434254348
success: true,
5434354349
executed: true,
5434454350
steps: [
54345-
`Bugbot autofix completed. OpenCode applied changes for findings: ${idsToFix.join(", ")}. Run verify commands and commit/push.`,
54351+
// `Bugbot autofix completed. OpenCode applied changes for findings: ${idsToFix.join(", ")}. Run verify commands and commit/push.`,
5434654352
],
5434754353
payload: { targetFindingIds: idsToFix, context },
5434854354
}));
@@ -54444,6 +54450,17 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
5444454450
exports.buildBugbotFixPrompt = buildBugbotFixPrompt;
5444554451
const opencode_project_context_instruction_1 = __nccwpck_require__(7381);
5444654452
const sanitize_user_comment_for_prompt_1 = __nccwpck_require__(3514);
54453+
/** Maximum characters for a single finding's full comment body to avoid prompt bloat and token limits. */
54454+
const MAX_FINDING_BODY_LENGTH = 12000;
54455+
const TRUNCATION_SUFFIX = "\n\n[... truncated for length ...]";
54456+
/**
54457+
* Truncates body to max length and appends indicator when truncated.
54458+
*/
54459+
function truncateFindingBody(body, maxLength) {
54460+
if (body.length <= maxLength)
54461+
return body;
54462+
return body.slice(0, maxLength - TRUNCATION_SUFFIX.length) + TRUNCATION_SUFFIX;
54463+
}
5444754464
/**
5444854465
* Builds the prompt for the OpenCode build agent to fix the selected bugbot findings.
5444954466
* Includes repo context, the findings to fix (with full detail), the user's comment,
@@ -54463,7 +54480,7 @@ function buildBugbotFixPrompt(param, context, targetFindingIds, userComment, ver
5446354480
if (!data)
5446454481
return null;
5446554482
const issueBody = context.issueComments.find((c) => c.id === data.issueCommentId)?.body ?? null;
54466-
const fullBody = issueBody?.trim() ?? "";
54483+
const fullBody = truncateFindingBody((issueBody?.trim() ?? ""), MAX_FINDING_BODY_LENGTH);
5446754484
if (!fullBody)
5446854485
return null;
5446954486
return `---\n**Finding id:** \`${id}\`\n\n**Full comment (title, description, location, suggestion):**\n${fullBody}\n`;
@@ -54692,7 +54709,7 @@ class DetectBugbotFixIntentUseCase {
5469254709
success: true,
5469354710
executed: true,
5469454711
steps: [
54695-
`Bugbot fix intent: isFixRequest=${isFixRequest}, targetFindingIds=${filteredIds.length} (${filteredIds.join(", ") || "none"}).`,
54712+
// `Bugbot fix intent: isFixRequest=${isFixRequest}, targetFindingIds=${filteredIds.length} (${filteredIds.join(", ") || "none"}).`,
5469654713
],
5469754714
payload: {
5469854715
isFixRequest,

build/github_action/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49200,6 +49200,8 @@ const exec = __importStar(__nccwpck_require__(1514));
4920049200
const shellQuote = __importStar(__nccwpck_require__(7029));
4920149201
const project_repository_1 = __nccwpck_require__(7917);
4920249202
const logger_1 = __nccwpck_require__(8836);
49203+
/** Maximum number of verify commands to run to avoid excessive build times. */
49204+
const MAX_VERIFY_COMMANDS = 20;
4920349205
/**
4920449206
* Returns true if there are uncommitted changes (working tree or index).
4920549207
*/
@@ -49329,6 +49331,10 @@ async function runBugbotAutofixCommitAndPush(execution, options) {
4932949331
verifyCommands = [];
4933049332
}
4933149333
verifyCommands = verifyCommands.filter((cmd) => typeof cmd === "string");
49334+
if (verifyCommands.length > MAX_VERIFY_COMMANDS) {
49335+
(0, logger_1.logInfo)(`Limiting verify commands to ${MAX_VERIFY_COMMANDS} (configured: ${verifyCommands.length}).`);
49336+
verifyCommands = verifyCommands.slice(0, MAX_VERIFY_COMMANDS);
49337+
}
4933249338
if (verifyCommands.length > 0) {
4933349339
(0, logger_1.logInfo)(`Running ${verifyCommands.length} verify command(s)...`);
4933449340
const verify = await runVerifyCommands(verifyCommands);
@@ -49431,7 +49437,7 @@ class BugbotAutofixUseCase {
4943149437
success: true,
4943249438
executed: true,
4943349439
steps: [
49434-
`Bugbot autofix completed. OpenCode applied changes for findings: ${idsToFix.join(", ")}. Run verify commands and commit/push.`,
49440+
// `Bugbot autofix completed. OpenCode applied changes for findings: ${idsToFix.join(", ")}. Run verify commands and commit/push.`,
4943549441
],
4943649442
payload: { targetFindingIds: idsToFix, context },
4943749443
}));
@@ -49533,6 +49539,17 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
4953349539
exports.buildBugbotFixPrompt = buildBugbotFixPrompt;
4953449540
const opencode_project_context_instruction_1 = __nccwpck_require__(7381);
4953549541
const sanitize_user_comment_for_prompt_1 = __nccwpck_require__(3514);
49542+
/** Maximum characters for a single finding's full comment body to avoid prompt bloat and token limits. */
49543+
const MAX_FINDING_BODY_LENGTH = 12000;
49544+
const TRUNCATION_SUFFIX = "\n\n[... truncated for length ...]";
49545+
/**
49546+
* Truncates body to max length and appends indicator when truncated.
49547+
*/
49548+
function truncateFindingBody(body, maxLength) {
49549+
if (body.length <= maxLength)
49550+
return body;
49551+
return body.slice(0, maxLength - TRUNCATION_SUFFIX.length) + TRUNCATION_SUFFIX;
49552+
}
4953649553
/**
4953749554
* Builds the prompt for the OpenCode build agent to fix the selected bugbot findings.
4953849555
* Includes repo context, the findings to fix (with full detail), the user's comment,
@@ -49552,7 +49569,7 @@ function buildBugbotFixPrompt(param, context, targetFindingIds, userComment, ver
4955249569
if (!data)
4955349570
return null;
4955449571
const issueBody = context.issueComments.find((c) => c.id === data.issueCommentId)?.body ?? null;
49555-
const fullBody = issueBody?.trim() ?? "";
49572+
const fullBody = truncateFindingBody((issueBody?.trim() ?? ""), MAX_FINDING_BODY_LENGTH);
4955649573
if (!fullBody)
4955749574
return null;
4955849575
return `---\n**Finding id:** \`${id}\`\n\n**Full comment (title, description, location, suggestion):**\n${fullBody}\n`;
@@ -49781,7 +49798,7 @@ class DetectBugbotFixIntentUseCase {
4978149798
success: true,
4978249799
executed: true,
4978349800
steps: [
49784-
`Bugbot fix intent: isFixRequest=${isFixRequest}, targetFindingIds=${filteredIds.length} (${filteredIds.join(", ") || "none"}).`,
49801+
// `Bugbot fix intent: isFixRequest=${isFixRequest}, targetFindingIds=${filteredIds.length} (${filteredIds.join(", ") || "none"}).`,
4978549802
],
4978649803
payload: {
4978749804
isFixRequest,

src/usecase/steps/commit/bugbot/__tests__/build_bugbot_fix_prompt.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,23 @@ describe("buildBugbotFixPrompt", () => {
7373
const prompt = buildBugbotFixPrompt(mockExecution(), mockContext(), ["find-1"], "fix", []);
7474
expect(prompt).toContain("Run any standard project checks");
7575
});
76+
77+
it("truncates finding body when it exceeds 12000 characters and appends truncation indicator", () => {
78+
const longBody = "x".repeat(15000);
79+
const context = mockContext({
80+
issueComments: [{ id: 1, body: longBody }],
81+
});
82+
const prompt = buildBugbotFixPrompt(
83+
mockExecution(),
84+
context,
85+
["find-1"],
86+
"fix",
87+
[]
88+
);
89+
expect(prompt).toContain("find-1");
90+
expect(prompt).toContain("[... truncated for length ...]");
91+
const xCount = (prompt.match(/x/g) ?? []).length;
92+
expect(xCount).toBeLessThan(15000);
93+
expect(xCount).toBeLessThanOrEqual(12000);
94+
});
7695
});

src/usecase/steps/commit/bugbot/bugbot_autofix_use_case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class BugbotAutofixUseCase implements ParamUseCase<BugbotAutofixParam, Re
8484
success: true,
8585
executed: true,
8686
steps: [
87-
`Bugbot autofix completed. OpenCode applied changes for findings: ${idsToFix.join(", ")}. Run verify commands and commit/push.`,
87+
// `Bugbot autofix completed. OpenCode applied changes for findings: ${idsToFix.join(", ")}. Run verify commands and commit/push.`,
8888
],
8989
payload: { targetFindingIds: idsToFix, context },
9090
})

src/usecase/steps/commit/bugbot/build_bugbot_fix_prompt.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import type { BugbotContext } from "./types";
33
import { OPENCODE_PROJECT_CONTEXT_INSTRUCTION } from "../../../../utils/opencode_project_context_instruction";
44
import { sanitizeUserCommentForPrompt } from "./sanitize_user_comment_for_prompt";
55

6+
/** Maximum characters for a single finding's full comment body to avoid prompt bloat and token limits. */
7+
const MAX_FINDING_BODY_LENGTH = 12000;
8+
9+
const TRUNCATION_SUFFIX = "\n\n[... truncated for length ...]";
10+
11+
/**
12+
* Truncates body to max length and appends indicator when truncated.
13+
*/
14+
function truncateFindingBody(body: string, maxLength: number): string {
15+
if (body.length <= maxLength) return body;
16+
return body.slice(0, maxLength - TRUNCATION_SUFFIX.length) + TRUNCATION_SUFFIX;
17+
}
18+
619
/**
720
* Builds the prompt for the OpenCode build agent to fix the selected bugbot findings.
821
* Includes repo context, the findings to fix (with full detail), the user's comment,
@@ -28,7 +41,7 @@ export function buildBugbotFixPrompt(
2841
const data = context.existingByFindingId[id];
2942
if (!data) return null;
3043
const issueBody = context.issueComments.find((c) => c.id === data.issueCommentId)?.body ?? null;
31-
const fullBody = issueBody?.trim() ?? "";
44+
const fullBody = truncateFindingBody((issueBody?.trim() ?? ""), MAX_FINDING_BODY_LENGTH);
3245
if (!fullBody) return null;
3346
return `---\n**Finding id:** \`${id}\`\n\n**Full comment (title, description, location, suggestion):**\n${fullBody}\n`;
3447
})

src/usecase/steps/commit/bugbot/detect_bugbot_fix_intent_use_case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class DetectBugbotFixIntentUseCase implements ParamUseCase<Execution, Res
144144
success: true,
145145
executed: true,
146146
steps: [
147-
`Bugbot fix intent: isFixRequest=${isFixRequest}, targetFindingIds=${filteredIds.length} (${filteredIds.join(", ") || "none"}).`,
147+
// `Bugbot fix intent: isFixRequest=${isFixRequest}, targetFindingIds=${filteredIds.length} (${filteredIds.join(", ") || "none"}).`,
148148
],
149149
payload: {
150150
isFixRequest,

0 commit comments

Comments
 (0)