Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/local/auto-fix-loop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ describe('runWithAutoFix', () => {
it('uses the persona repair path even when the debugger recommends guided repair', async () => {
const runSingleAttempt = vi
.fn()
.mockResolvedValueOnce(blockerResponse('MISSING_ENV_VAR', 'run-1', 'runtime-launch'))
.mockResolvedValueOnce(blockerResponse('INVALID_ARTIFACT', 'run-1', 'runtime-launch'))
.mockResolvedValueOnce(successResponse('run-2'));
const workflowRepairer = vi.fn().mockResolvedValue(workflowRepair('guided repair workflow'));

Expand All @@ -375,6 +375,40 @@ describe('runWithAutoFix', () => {
expect(result.ok).toBe(true);
});

it('does not auto-repair missing environment prerequisites', async () => {
const runSingleAttempt = vi
.fn()
.mockResolvedValue(blockerResponse('MISSING_ENV_VAR', 'run-1', 'runtime-launch'));
const workflowRepairer = vi.fn().mockResolvedValue(workflowRepair('should not run'));

const result = await runWithAutoFix(baseRequest, {
maxAttempts: 7,
runSingleAttempt,
classifyFailure: fakeClassification,
debugWorkflowRun: guidedDebugger,
workflowRepairer,
artifactWriter: vi.fn().mockResolvedValue(undefined),
});

expect(runSingleAttempt).toHaveBeenCalledTimes(1);
expect(workflowRepairer).not.toHaveBeenCalled();
expect(result.ok).toBe(false);
expect(result.auto_fix).toMatchObject({
max_attempts: 7,
final_status: 'blocker',
resumed: false,
attempts: [
expect.objectContaining({
attempt: 1,
blocker_code: 'MISSING_ENV_VAR',
fix_error: 'external setup blocker; no safe automatic workflow repair',
}),
],
});
expect(result.auto_fix?.escalation?.summary).toContain('environment or credentials prerequisite');
expect(result.nextActions.join('\n')).toContain('Set TEST_TOKEN before retrying.');
});

it('routes semantic workflow failures to persona repair instead of deterministic repair', async () => {
const artifactPath = 'workflows/demo-persona-repair/semantic-contract.ts';
const artifactContent = await readFile(new URL('../../workflows/demo-persona-repair/semantic-contract.ts', import.meta.url), 'utf8');
Expand Down
26 changes: 26 additions & 0 deletions src/local/auto-fix-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,28 @@ export async function runWithAutoFix(
};
attempts.push(attemptSummary);

if (isExternalSetupBlocker(blockerCode)) {
attemptSummary.fix_error = 'external setup blocker; no safe automatic workflow repair';
const classification = classifyFailure(evidence);
const debuggerResult = debugWorkflowRun({ evidence, classification });
const escalated = withAutoFix(response, maxAttempts, attempts, attemptSummary.status, warnings, trackingRunId);
escalated.nextActions = [
...escalated.nextActions,
debuggerResult.summary,
...debuggerResult.recommendation.steps.map((step) => step.description),
];
attachEscalationOptions(escalated, {
request: currentRequest,
response,
debuggerResult,
reason: 'The blocker is an environment or credentials prerequisite outside Ricky\'s safe auto-fix scope.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify the escalation reason text for WORKDIR_DIRTY.

The current reason mentions only environment/credentials prerequisites, but WORKDIR_DIRTY is also classified here and can make the message misleading for users.

Suggested wording update
-        reason: 'The blocker is an environment or credentials prerequisite outside Ricky\'s safe auto-fix scope.',
+        reason: 'The blocker is an external setup prerequisite (environment, credentials, or dirty workdir) outside Ricky\'s safe auto-fix scope.',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
reason: 'The blocker is an environment or credentials prerequisite outside Ricky\'s safe auto-fix scope.',
reason: 'The blocker is an external setup prerequisite (environment, credentials, or dirty workdir) outside Ricky\'s safe auto-fix scope.',
🤖 Prompt for 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.

In `@src/local/auto-fix-loop.ts` at line 145, Update the escalation reason string
that currently reads "The blocker is an environment or credentials prerequisite
outside Ricky's safe auto-fix scope." to explicitly include WORKDIR_DIRTY so
users aren’t misled; locate the mapping or constant where WORKDIR_DIRTY is
assigned this reason (symbol WORKDIR_DIRTY and the surrounding object/variable
in auto-fix-loop.ts) and change the message to mention "environment/credentials
prerequisites or a dirty working directory (WORKDIR_DIRTY) outside Ricky's safe
auto-fix scope," keeping proper escaping for the apostrophe.

trackingRunId,
artifactPath: resolveArtifactPath(currentRequest, response),
...(failedStep ? { failedStep } : {}),
});
return escalated;
}

if (attempt >= maxAttempts) {
return withAutoFix(response, maxAttempts, attempts, attemptSummary.status, warnings, trackingRunId);
}
Expand Down Expand Up @@ -304,6 +326,10 @@ function isV1DirectBlocker(code: string | undefined): boolean {
return code === 'MISSING_BINARY' || code === 'NETWORK_TRANSIENT';
}

function isExternalSetupBlocker(code: string | undefined): boolean {
return code === 'MISSING_ENV_VAR' || code === 'CREDENTIALS_REJECTED' || code === 'WORKDIR_DIRTY';
}

async function defaultWorkflowRepairer(input: WorkflowRepairInput): Promise<WorkflowRepairResult> {
const deterministicRepair = repairWorkflowDeterministically(input);
if (deterministicRepair) {
Expand Down