Skip to content

SDLC implement phase fails: contract not populated, plan comment parsing broken #304

Closed

Description

@james-in-a-box

Problem

The SDLC pipeline's implement phase fails to execute, leaving the PR with only the contract file and no actual implementation. This was observed in PR #300 / workflow run for issue #262.

Root Causes

1. Bug in populate-contract-tasks.py — comment parsing breaks on multiline bodies

get_issue_comments() uses gh api --jq ".[].body" which outputs raw string values with embedded newlines. It then splits the output by "\n":

return [body for body in result.stdout.strip().split("\n") if body.strip()]

This breaks each multi-line comment body into individual lines. find_plan_comment() looks for a single entry containing both [TASK- and ## Phase:

def find_plan_comment(comments: list[str]) -> str | None:
    for comment in reversed(comments):
        if "[TASK-" in comment and ("## Phase" in comment or "Phase 1:" in comment):
            return comment
    return None

Since those markers are on different lines of the plan comment, no individual "line-comment" ever matches both conditions, so the plan is never found.

Fix: Use a JSON-aware approach to fetch comments (e.g., --jq '.[].body' | jq -Rs or fetch as JSON array and parse in Python).

2. Contract fields empty after plan phase — acceptance_criteria, phases, decisions not populated

The plan phase agent posts a structured plan as a markdown comment but does not update the contract JSON. The contract still shows:

{
  "acceptance_criteria": [],
  "phases": [],
  "decisions": []
}

These fields are supposed to be populated by populate-contract-tasks.py at the start of the implement phase, but due to bug #1 above, that never succeeds. Even if bug #1 is fixed, populate-contract-tasks.py only populates phases (with tasks) — it does not populate acceptance_criteria or decisions.

The plan phase should populate these contract fields before advancing to implement. At minimum, populate-contract-tasks.py should also extract acceptance criteria and decisions from the plan, or the plan phase itself should update the contract.

3. Implement step skipped entirely when populate-contract-tasks.py fails

The "Populate contract tasks from plan" step does not have continue-on-error: true. When it fails, the subsequent "Run egg implementer" step is skipped. The agent never gets a chance to implement anything.

Even if the populate step fails, the implementer should arguably still run (perhaps with a warning), rather than the entire implement phase being aborted.

4. PR only contains the contract file

Because the implement step never runs, the PR (#300) only contains .egg-state/contracts/262.json with empty fields. The PR description is also very sparse ("Draft PR for SDLC pipeline implementation") and doesn't reflect the actual planned work.

Expected Behavior

  1. Plan phase populates the contract: When the plan phase completes, the contract should have populated acceptance_criteria, phases (with tasks), and decisions fields.

  2. Implement phase runs the agent: The populate-contract-tasks.py script should correctly parse multi-line plan comments from the issue. If the contract already has phases/tasks (populated during the plan phase), it should skip population gracefully.

  3. PR includes actual implementation: After the implement phase, the PR should contain the code changes implementing the plan, not just the contract file.

  4. PR description reflects the work: The PR description should be updated to reflect the implemented changes, not remain as a generic placeholder.

Suggested Changes

action/populate-contract-tasks.py

  • Fix get_issue_comments() to correctly handle multi-line comment bodies (use JSON parsing instead of newline splitting)
  • Extract and populate acceptance_criteria from the plan comment
  • Handle the case where phases/tasks are already populated in the contract

action/build-sdlc-prompt.sh (plan phase)

  • Instruct the plan phase agent to update the contract with acceptance criteria, phases, and decisions using the contract CLI
  • Or: have the plan phase workflow step populate the contract from the plan comment before advancing

.github/workflows/sdlc-pipeline.yml (implement job)

  • Consider adding error handling so the implement step can still run even if contract population encounters issues
  • Ensure the PR description is updated with meaningful content after implementation

Reproduction

  1. Label an issue with egg-sdlc
  2. Approve through refine → plan phases
  3. Observe that the contract has empty acceptance_criteria, phases, decisions after plan approval
  4. Observe that the implement phase fails at "Populate contract tasks from plan" with "No plan document found in issue comments"
  5. The PR only contains the contract file

References

Activity

  1. added
    bug
    on Feb 8, 2026
  2. james-in-a-box commented on Feb 8, 2026

    @james-in-a-box
    ContributorAuthor

    Additional finding: PR created prematurely by init job

    The init job in sdlc-pipeline.yml (lines 211-257) creates a draft PR before the implement phase runs, whenever current_phase == 'implement'. At that point the branch only contains the contract JSON, so the PR is opened with just the contract file and a generic placeholder description.

    The implement step runs in a separate job after init — and in this case it failed entirely, leaving the PR with only the contract.

    If the intent is that the agent should open a PR only after implementation is complete, the "Create or find draft PR" step should be moved out of init and into a post-implementation step (or into the finalize-pr job). Alternatively, if a draft PR is intentionally created early as a landing spot, the description should be updated after implementation completes.

    — Authored by egg

  3. jwbron commented on Feb 8, 2026

    @jwbron
    Owner

    @james-in-a-box put together a plan of action for this issue and add it to this issue

  4. james-in-a-box commented on Feb 8, 2026

    @james-in-a-box
    ContributorAuthor

    Plan of Action

    Based on analysis of the codebase, here is the prioritized plan to fix the SDLC implement phase failures:


    Fix 1: Comment Parsing in populate-contract-tasks.py (P0 — Blocking)

    Problem: get_issue_comments() at line 50 splits on "\n", breaking multi-line comment bodies into individual lines. The find_plan_comment() function then fails because [TASK- and ## Phase markers are on different lines.

    Solution: Fetch comments as JSON and parse properly in Python.

    def get_issue_comments(repo: str, issue_number: str, token: str) -> list[str]:
        """Fetch all comments on a GitHub issue."""
        result = subprocess.run(
            [
                "gh", "api",
                f"repos/{repo}/issues/{issue_number}/comments",
                "--paginate",
                "--jq", "[.[].body]",  # Output as JSON array
            ],
            capture_output=True,
            text=True,
            env={**os.environ, "GH_TOKEN": token},
        )
        if result.returncode != 0:
            print(f"Failed to fetch comments: {result.stderr}", file=sys.stderr)
            sys.exit(1)
    
        import json
        try:
            # Concatenate paginated JSON arrays
            bodies = []
            for line in result.stdout.strip().split("\n"):
                if line.strip():
                    bodies.extend(json.loads(line))
            return bodies
        except json.JSONDecodeError as e:
            print(f"Failed to parse comments JSON: {e}", file=sys.stderr)
            sys.exit(1)

    Files: action/populate-contract-tasks.py:31-50


    Fix 2: Extract Acceptance Criteria in populate-contract-tasks.py (P1)

    Problem: populate-contract-tasks.py only populates phases with tasks. The acceptance_criteria and decisions fields remain empty.

    Solution: Extend the script to extract acceptance criteria from the plan comment. The plan template includes an exit criteria section per phase that can be used.

    Add after task population (around line 144):

    # Extract acceptance criteria from plan
    # Look for exit criteria patterns in the plan
    import re
    criteria_pattern = r'\*\*Exit criteria\*\*:\s*(.+?)(?=\n\n|\n###|\Z)'
    matches = re.findall(criteria_pattern, plan_content, re.DOTALL)
    if matches:
        contract["acceptance_criteria"] = [
            {"id": f"ac-{i+1}", "description": m.strip(), "met": False}
            for i, m in enumerate(matches)
        ]

    Files: action/populate-contract-tasks.py (add extraction logic around line 144)


    Fix 3: Graceful Degradation for Implement Phase (P1)

    Problem: The "Populate contract tasks from plan" step fails without continue-on-error, causing the entire implement phase to be skipped.

    Solution: Add error handling so the implementer still runs with a warning.

    In .github/workflows/sdlc-pipeline.yml around line 322:

    - name: Populate contract tasks from plan
      id: populate-tasks
      continue-on-error: true  # Allow implement to proceed with warning
      env:
        GH_TOKEN: ${{ steps.bot-token.outputs.token }}
        # ... rest of step

    Then add a warning step after:

    - name: Warn if task population failed
      if: steps.populate-tasks.outcome == 'failure'
      run: |
        echo "::warning::Task population failed. Implementer will run without structured task tracking."

    Files: .github/workflows/sdlc-pipeline.yml:322-340


    Fix 4: Defer PR Creation Until Implementation (P2)

    Problem: The init job creates a draft PR before implementation runs (lines 211-257), resulting in a PR with only the contract file when implement fails.

    Solution: Move PR creation from init to a post-implementation step. Two options:

    Option A (Recommended): Move PR creation to the implement job, after the agent runs successfully.

    Option B: Keep early PR creation but update the description to clarify it's a placeholder, and add a step in finalize-pr to update the PR body with implementation details.

    For Option A, remove lines 211-257 from init and add to implement job after the agent step:

    - name: Create draft PR
      if: steps.egg.outputs.exit-code == '0'
      env:
        GH_TOKEN: ${{ steps.bot-token.outputs.token }}
      run: |
        # Check for existing PR first
        EXISTING_PR=$(gh pr list --head "${BRANCH_NAME}" --state open --json number --jq '.[0].number // empty')
        if [[ -n "$EXISTING_PR" ]]; then
          echo "pr_number=${EXISTING_PR}" >> "$GITHUB_OUTPUT"
          exit 0
        fi
    
        # Create PR with meaningful description based on implemented changes
        PR_BODY="Implementation for #${ISSUE_NUMBER}..."
        gh pr create --draft --title "[SDLC] ${ISSUE_TITLE}" --body "$PR_BODY" --base main

    Files: .github/workflows/sdlc-pipeline.yml:211-257 (init), :342-357 (implement)


    Fix 5: Plan Phase Should Populate Contract (P2 — Enhancement)

    Problem: The plan phase posts a markdown comment but doesn't update the contract JSON. This creates a dependency on populate-contract-tasks.py working correctly.

    Solution: Add a step in the plan job to populate the contract after the agent posts the plan. This makes the implement phase more robust.

    After the plan agent runs (around line 928), add:

    - name: Populate contract from plan
      if: steps.egg.outputs.exit-code == '0' && steps.validate-plan.outputs.found == 'true'
      env:
        GH_TOKEN: ${{ steps.bot-token.outputs.token }}
      run: |
        pip install -q pyyaml pydantic
        PYTHONPATH="${GITHUB_WORKSPACE}/shared:${PYTHONPATH:-}" \
          python3 action/populate-contract-tasks.py || true
    
        if git diff --quiet ".egg-state/contracts/${ISSUE_NUMBER}.json" 2>/dev/null; then
          echo "Contract already up to date"
        else
          git add ".egg-state/contracts/${ISSUE_NUMBER}.json"
          git commit -m "Populate contract tasks from plan"
          git push origin "${BRANCH_NAME}"
        fi

    Files: .github/workflows/sdlc-pipeline.yml:929-950 (add after validate-plan step)


    Implementation Order

    1. Fix 1 — Critical: Without this, no plan comments are ever found
    2. Fix 3 — Important: Prevents total failure when edge cases occur
    3. Fix 2 — Important: Ensures contract has complete data for tracking
    4. Fix 4 — Improvement: Better PR lifecycle management
    5. Fix 5 — Improvement: Redundancy for robustness

    Testing Plan

    1. Create a test issue with egg-sdlc label
    2. Verify refine phase posts analysis
    3. Approve to plan phase, verify plan is posted with [TASK-X-Y] markers
    4. Verify contract JSON is populated after plan phase (Fix 5)
    5. Approve to implement phase
    6. Verify populate-contract-tasks.py correctly parses multi-line comments (Fix 1)
    7. Verify implementer runs and creates commits
    8. Verify PR is created with meaningful content (Fix 4)

    — Authored by egg

  5. james-in-a-box commented on Feb 8, 2026

    @james-in-a-box
    ContributorAuthor

    egg finished successfully. View run logs

  6. jwbron commented on Feb 8, 2026

    @jwbron
    Owner

    @james-in-a-box open a pr for each of these fixes: #304 (comment)

  7. added 6 commits that reference this issue on Feb 8, 2026
    e42631c
    7a87a5d
    a75881c
    cc0c7d4
    51e7d0a
    dc75376
  8. james-in-a-box commented on Feb 8, 2026

    @james-in-a-box
    ContributorAuthor

    PRs Created for Plan of Action

    I've created the following PRs to address the issues identified in the plan of action:

    Fix 1: Comment Parsing (P0 — Critical)

    PR #307: Fix multiline comment parsing in populate-contract-tasks.py

    Fixes the root cause where get_issue_comments() was splitting multiline comments on \n, breaking the find_plan_comment() function.

    Fix 2: Extract Acceptance Criteria (P1)

    PR #308: Extract acceptance criteria from plan document

    Extends populate-contract-tasks.py to extract and populate the acceptance_criteria field from exit criteria and test strategy sections.

    Fix 3: Graceful Degradation (P1)

    PR #309: Add graceful degradation for implement phase task population

    Adds continue-on-error: true to the task population step so the implementer still runs even if population fails.

    Fix 4: Defer PR Creation (P2)

    PR #311: Defer PR creation until after implementation succeeds

    Moves PR creation from the init job to the implement job, ensuring PRs contain actual implementation code.

    Fix 5: Plan Phase Populates Contract (P2)

    PR #312: Populate contract from plan comment in plan phase

    Adds a step to the plan job that populates the contract before advancing to implement, providing redundancy.


    Recommended Merge Order

    1. PR Fix comment parsing to handle multiline bodies #307 (Fix 1) — Must be merged first as other fixes depend on it
    2. PR Extract acceptance criteria from plan document #308 (Fix 2) — Builds on Fix comment parsing to handle multiline bodies #307
    3. PR Add graceful degradation for implement phase task population #309 (Fix 3) — Independent, can be merged anytime
    4. PR Defer PR creation until after implementation succeeds #311 (Fix 4) — Independent, can be merged anytime
    5. PR Populate contract from plan comment in plan phase #312 (Fix 5) — Works best after Fix comment parsing to handle multiline bodies #307 and Extract acceptance criteria from plan document #308

    — Authored by egg

  9. james-in-a-box commented on Feb 8, 2026

    @james-in-a-box
    ContributorAuthor

    egg finished successfully. View run logs

  10. added a commit that references this issue on Feb 8, 2026
    1cbce92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions