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
50 changes: 50 additions & 0 deletions src/local/auto-fix-loop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,40 @@ describe('runWithAutoFix', () => {
}
});

it('does not treat a non-executable --spec-file path as a workflow artifact to repair', async () => {
// Regression: when `ricky --spec-file docs/foo.md` failed at the intake
// stage (e.g. unresolved clarification questions), `resolveArtifactPath`
// used to fall back to `request.specPath`, which pointed at the source
// spec markdown. Auto-fix then handed the markdown to the workflow
// repairer, re-fed the "repaired" content as source=workflow-artifact,
// and looped 7× while the natural-language intent detector misrouted the
// spec body to debug. With no executable workflow path available, there
// is nothing to repair and auto-fix should bail on attempt 1.
const specFileRequest: LocalInvocationRequest = {
...baseRequest,
spec: '# Some markdown spec\n\nUnresolved question?',
specPath: 'docs/some-spec.md',
};
const runSingleAttempt = vi.fn().mockResolvedValueOnce(generationOnlyFailureResponse());
const workflowRepairer = vi.fn().mockResolvedValue(workflowRepair('should-not-run'));
const artifactWriter = vi.fn().mockResolvedValue(undefined);

const result = await runWithAutoFix(specFileRequest, {
maxAttempts: 7,
runSingleAttempt,
classifyFailure: fakeClassification,
debugWorkflowRun: directDebugger,
workflowRepairer,
artifactWriter,
});

expect(runSingleAttempt).toHaveBeenCalledTimes(1);
expect(workflowRepairer).not.toHaveBeenCalled();
expect(artifactWriter).not.toHaveBeenCalled();
expect(result.ok).toBe(false);
expect(result.auto_fix?.attempts).toHaveLength(1);
});

});

describe('isSyntheticStageId', () => {
Expand Down Expand Up @@ -1061,6 +1095,22 @@ function successResponse(runId: string): LocalResponse {
};
}

function generationOnlyFailureResponse(): LocalResponse {
return {
ok: false,
artifacts: [],
logs: [],
warnings: ['routing: Spec has unresolved workflow authoring questions'],
nextActions: ['Clarify the local workflow request and retry.'],
generation: {
stage: 'generate',
status: 'needs_clarification',
error: 'routing: Spec has unresolved workflow authoring questions',
},
exitCode: 2,
};
}
Comment on lines +1098 to +1112
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

Align generation-only fixture exit code with real generation failures.

Line 1110 sets exitCode: 2, but this helper models a generation/intake failure (status: 'needs_clarification'). Using blocker exit code here can hide regressions in auto-fix behavior for non-runtime failures.

Suggested fix
 function generationOnlyFailureResponse(): LocalResponse {
   return {
@@
-    exitCode: 2,
+    exitCode: 1,
   };
 }
📝 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
function generationOnlyFailureResponse(): LocalResponse {
return {
ok: false,
artifacts: [],
logs: [],
warnings: ['routing: Spec has unresolved workflow authoring questions'],
nextActions: ['Clarify the local workflow request and retry.'],
generation: {
stage: 'generate',
status: 'needs_clarification',
error: 'routing: Spec has unresolved workflow authoring questions',
},
exitCode: 2,
};
}
function generationOnlyFailureResponse(): LocalResponse {
return {
ok: false,
artifacts: [],
logs: [],
warnings: ['routing: Spec has unresolved workflow authoring questions'],
nextActions: ['Clarify the local workflow request and retry.'],
generation: {
stage: 'generate',
status: 'needs_clarification',
error: 'routing: Spec has unresolved workflow authoring questions',
},
exitCode: 1,
};
}
🤖 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.test.ts` around lines 1098 - 1112, The helper
generationOnlyFailureResponse models a generation/intake failure
(generation.status 'needs_clarification') but sets a blocker exit code
(exitCode: 2); change the exitCode in generationOnlyFailureResponse to the
non-blocker failure value used for real generation failures (e.g., exitCode: 1)
so tests accurately reflect generation-only failures.


function blockerResponse(code: LocalClassifiedBlocker['code'], runId: string | undefined, failedStep: string): LocalResponse {
const blocker: LocalClassifiedBlocker = {
code,
Expand Down
11 changes: 10 additions & 1 deletion src/local/auto-fix-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ts from 'typescript';

import type { LocalInvocationRequest } from './request-normalizer.js';
import type { LocalClassifiedBlocker, LocalExecutionEvidence, LocalResponse } from './entrypoint.js';
import { isExecutableWorkflowPath } from './entrypoint.js';
import { classifyFailure as defaultClassifyFailure } from '../runtime/failure/classifier.js';
import type { FailureClassification } from '../runtime/failure/types.js';
import { debugWorkflowRun as defaultDebugWorkflowRun } from '../product/specialists/debugger/debugger.js';
Expand Down Expand Up @@ -1586,12 +1587,20 @@ async function resolveWorkflowRepairTarget(
}

function resolveArtifactPath(request: LocalInvocationRequest, response: LocalResponse): string | undefined {
// `request.specPath` is the LAST resort because for CLI invocations like
// `--spec-file docs/foo.md` it points at the source spec (markdown, etc.),
// not an executable workflow. Treating that as the "artifact to repair"
// makes auto-fix hand the markdown spec to the workflow repairer and then
// re-feed the result as source=workflow-artifact, which loses the original
// CLI intent and routes the spec body through natural-language intent
// detection — where failure-vocabulary keywords misroute it to debug.
// Only fall back to specPath when it actually names an executable workflow.
return (
response.execution?.execution.workflow_file ??
response.execution?.execution.artifact_path ??
response.generation?.artifact?.path ??
response.artifacts[0]?.path ??
request.specPath
(request.specPath && isExecutableWorkflowPath(request.specPath) ? request.specPath : undefined)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/local/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ function artifactPathOverrideFor(request: LocalInvocationRequest): string | unde
return typeof candidate === 'string' && candidate.trim() ? candidate : undefined;
}

function isExecutableWorkflowPath(path: string): boolean {
export function isExecutableWorkflowPath(path: string): boolean {
return /(?:^|\/)workflows\/.+\.(?:ts|js)$|\.workflow\.(?:ts|js|yaml|yml)$/i.test(path);
}

Expand Down
Loading