Skip to content

fix(auto-fix): repair lead plan marker gates#58

Merged
khaliqgant merged 2 commits into
mainfrom
codex/fix-lead-plan-marker-repair
May 7, 2026
Merged

fix(auto-fix): repair lead plan marker gates#58
khaliqgant merged 2 commits into
mainfrom
codex/fix-lead-plan-marker-repair

Conversation

@khaliqgant

Copy link
Copy Markdown
Member

Summary

  • Add a bounded deterministic auto-fix for generated lead-plan marker gate failures.
  • Rewrite the generated lead-plan-gate so retries can append missing required sections to lead-plan.md before validating.
  • Cover the captured Non-goals failure path and resume behavior in auto-fix tests.

Validation

  • npm run typecheck
  • npx vitest run src/local/auto-fix-loop.test.ts
  • npm test

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f8180306-8e64-4b86-a320-62deb6426f97

📥 Commits

Reviewing files that changed from the base of the PR and between bca8100 and 82e48d7.

📒 Files selected for processing (2)
  • src/local/auto-fix-loop.test.ts
  • src/local/auto-fix-loop.ts

📝 Walkthrough

Walkthrough

Adds a deterministic repair that recognizes lead-plan-gate failures for missing required markers, injects a self-healing block into the workflow artifact to append missing sections (Non-goals, Routing contract, Implementation contract), and resumes the workflow with retry metadata after rewriting the artifact.

Changes

Lead-Plan Marker Deterministic Repair

Layer / File(s) Summary
Test Fixtures
src/local/auto-fix-loop.test.ts
leadPlanMarkerBlockerResponse() provides a mocked LocalResponse for an INVALID_ARTIFACT at lead-plan-gate; leadPlanMarkerWorkflowContent() returns the deterministic workflow source used by the test.
Repair Detection and Injection
src/local/auto-fix-loop.ts
repairLeadPlanRequiredMarkerGate scans failure evidence for the lead-plan missing-marker pattern and, when applicable, injects leadPlanGateSelfHealingBlock into the workflow source via safe string replacement; leadPlanGateSelfHealingBlock generates the appended-section-and-verify code.
Deterministic Repair Pipeline
src/local/auto-fix-loop.ts
repairWorkflowDeterministically calls the new lead-plan repair stage immediately after missing-file alignment and before other deterministic repairs, aggregating any produced change descriptions.
Test Verification
src/local/auto-fix-loop.test.ts
New runWithAutoFix test asserts the deterministic repair rewrites the workflow artifact (twice with expected substrings), resumes the workflow from the failed gate with previousRunId/retryOfRunId and startFromStep, and records a deterministic auto-fix attempt with blocker/failed-step details.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • AgentWorkforce/ricky#58: Makes the same deterministic auto-fix changes for lead-plan marker gate failures (adds repairLeadPlanRequiredMarkerGate / leadPlanGateSelfHealingBlock and tests).
  • AgentWorkforce/ricky#47: Modifies the auto-fix loop in src/local/auto-fix-loop.ts and touches deterministic repair orchestration.
  • AgentWorkforce/ricky#49: Adds deterministic repair handlers and tests within the same auto-fix machinery.

Poem

🐰 A marker lost in dusty code,
I hop and stitch the missing node.
Non-goals, routes, and contracts sewn,
The lead-plan wakes, the gate is shown. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(auto-fix): repair lead plan marker gates' directly and specifically describes the main change: adding a deterministic auto-fix for lead-plan marker gate failures.
Description check ✅ Passed The description is related to the changeset, covering the main objectives (bounded deterministic auto-fix, rewriting lead-plan-gate, test coverage) and includes validation steps performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-lead-plan-marker-repair

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bca810038b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/local/auto-fix-loop.ts Outdated
'const appendLeadPlanSection = (heading, lines) => {',
" const section = ['', '## ' + heading, '', ...lines].join('\\n');",
" if (body.includes('GENERATION_LEAD_PLAN_READY')) {",
" body = body.replace(/\\n*GENERATION_LEAD_PLAN_READY\\s*$/, section + '\\n\\nGENERATION_LEAD_PLAN_READY');",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle ready markers that are not final

When a lead plan contains GENERATION_LEAD_PLAN_READY but has any trailing text after it, this branch is taken but the anchored replace does not match, so body is written back unchanged and the final Non-goals/Routing/Implementation checks still fail on the retry. The previous gate only required body.includes(...), so this malformed-but-possible plan reaches the new self-healing path; append to the end or detect the no-op instead of assuming the marker is final.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
src/local/auto-fix-loop.test.ts (1)

208-255: ⚡ Quick win

Add a test variant exercising the plainOldBlock fallback path in repairLeadPlanRequiredMarkerGate.

The current fixture (leadPlanMarkerWorkflowContent) embeds the gate command using \\n escape sequences, which matches the escapedOldBlock branch (lines 741-748 in auto-fix-loop.ts). The plainOldBlock fallback (lines 750-757) — intended for workflow files where the gate command uses actual newlines — is not covered by any test. A regression in that path would go undetected.

🧪 Suggested additional test or repairWorkflowDeterministically assertion
+  it('deterministically repairs lead-plan marker gates with plain-newline command format', () => {
+    const plainContent = leadPlanMarkerWorkflowContent().replace(/\\n/g, '\n');
+    const evidence = localResponseToWorkflowRunEvidence_equivalent({
+      // Evidence text must match the trigger pattern:
+      failureText: 'lead plan missing required marker: Non-goals',
+    });
+    const repair = repairWorkflowDeterministically({
+      artifactPath: 'workflows/generated/lead-plan-marker.ts',
+      artifactContent: plainContent,
+      evidence: leadPlanMarkerEvidence(),
+    });
+
+    expect(repair).toMatchObject({
+      applied: true,
+      mode: 'deterministic',
+      summary: expect.stringContaining('lead-plan-gate append missing required plan markers'),
+    });
+    expect(repair?.content).toContain("appendLeadPlanSection('Non-goals'");
+    expect(repair?.content).toContain('Local execution must run through Agent Relay using the generated workflow artifact.');
+  });

Alternatively, a simpler inline assertion in the existing test:

   expect(result.ok).toBe(true);
+  // Verify the plain-newline fallback also produces a repaired artifact:
+  const plainRepair = repairWorkflowDeterministically({
+    artifactPath: 'workflows/generated/lead-plan-marker.ts',
+    artifactContent: leadPlanMarkerWorkflowContent().replace(/\\n/g, '\n'),
+    evidence: localResponseToWorkflowRunEvidence(firstFailure, 1),
+  });
+  expect(plainRepair).not.toBeNull();
+  expect(plainRepair?.content).toContain("appendLeadPlanSection('Non-goals'");
🤖 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 208 - 255, Add a test variant
that exercises the plainOldBlock fallback in repairLeadPlanRequiredMarkerGate by
providing a workflow fixture where the gate command uses real newlines (not
"\\n" escapes) — create a copy of leadPlanMarkerWorkflowContent with the gate
command written using actual newline characters, then call runWithAutoFix (using
the same runSingleAttempt/artifactWriter pattern) and assert that the
artifactWriter receives the repaired 'workflows/generated/lead-plan-marker.ts'
containing the multiline gate block and that result.auto_fix?.attempts[0] shows
the expected applied_fix summary and failed_step 'lead-plan-gate'; this will
ensure the plainOldBlock branch in repairLeadPlanRequiredMarkerGate (and not
only escapedOldBlock) is covered.
🤖 Prompt for all review comments with 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.

Nitpick comments:
In `@src/local/auto-fix-loop.test.ts`:
- Around line 208-255: Add a test variant that exercises the plainOldBlock
fallback in repairLeadPlanRequiredMarkerGate by providing a workflow fixture
where the gate command uses real newlines (not "\\n" escapes) — create a copy of
leadPlanMarkerWorkflowContent with the gate command written using actual newline
characters, then call runWithAutoFix (using the same
runSingleAttempt/artifactWriter pattern) and assert that the artifactWriter
receives the repaired 'workflows/generated/lead-plan-marker.ts' containing the
multiline gate block and that result.auto_fix?.attempts[0] shows the expected
applied_fix summary and failed_step 'lead-plan-gate'; this will ensure the
plainOldBlock branch in repairLeadPlanRequiredMarkerGate (and not only
escapedOldBlock) is covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c5e7c298-f199-4f25-8b2b-39c149975fd8

📥 Commits

Reviewing files that changed from the base of the PR and between 04950d0 and bca8100.

📒 Files selected for processing (2)
  • src/local/auto-fix-loop.test.ts
  • src/local/auto-fix-loop.ts

@khaliqgant khaliqgant merged commit 97173a0 into main May 7, 2026
1 check was pending
@khaliqgant khaliqgant deleted the codex/fix-lead-plan-marker-repair branch May 7, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant