Skip to content

fix(agents): Implementer commits a dummy Python file instead of editing actual repo files #52

Description

@archittmittal

Summary

The implementer_node in backend/agents.py hardcodes the commit path to feature_issue_{issue_number}.py (line 607). This means the agent always creates a brand-new throwaway script in the target repository, regardless of what the Architect's directive or the issue description says. It never reads existing files, never applies a patch, and never makes a meaningful change to the actual codebase.


Affected Code

# backend/agents.py:607  (current — broken behaviour)
path = f"feature_issue_{issue_number}.py"

And the LLM prompt reinforces this broken pattern:

# backend/agents.py:559-560
system_prompt = "You are the Implementer Agent. Write a tiny python script that implements
                 the core logic of the idea. Keep it very short. Output ONLY the Python script."
user_prompt = f"Write code for: {idea}"

The agent is instructed to write a generic script, not to modify any specific file in the repository.


Steps to Reproduce

  1. Run AutoMaintainer against any target repository with a real open issue.
  2. Watch the Implementer commit its "code".
  3. Check the resulting PR in the target repository — it will contain a single new file called feature_issue_N.py containing a short standalone Python script that has no relation to the actual codebase structure.

Impact

Expectation Actual Behaviour
Agent reads the target file identified by the Architect ❌ Agent never fetches any existing file
Agent patches the correct lines in the correct file ❌ Agent creates a new unrelated feature_issue_N.py
Merged PR improves the target repository ❌ Merged PR adds a useless throwaway script
Self-correcting loop fixes real bugs ❌ Maintainer reviews a script with no context

This is the single most critical functional bug in the system — it makes the entire agentic loop produce zero value.


Root Cause

The Architect directive contains precise file and line references (e.g. "Modify agents.py:54-76 to add retry logic"), but the Implementer node never parses this directive. It ignores the file path entirely and writes free-form code to a hardcoded new file.


Proposed Fix

The Implementer node needs to be rewritten to:

  1. Parse the Architect directive to extract the target file path and line range.
  2. Fetch the current file contents from GitHub using gh_repo.get_contents(file_path).
  3. Prompt the LLM with the existing code as context, asking it to produce a targeted patch/replacement for the specified lines only.
  4. Commit only the modified file (not a new feature_issue_N.py).
# backend/agents.py — proposed implementer_node logic sketch

# 1. Extract target file from directive
import re
match = re.search(r'([\w/.-]+\.\w+):(\d+)-(\d+)', directive)
if match:
    target_file = match.group(1)
    start_line, end_line = int(match.group(2)), int(match.group(3))
else:
    target_file = None

# 2. Fetch current file from GitHub
if target_file:
    try:
        file_obj = gh_repo.get_contents(target_file, ref=default_branch)
        original_content = file_obj.decoded_content.decode('utf-8')
    except Exception:
        original_content = ""

# 3. Ask LLM to patch specific lines
system_prompt = (
    "You are the Implementer Agent. You will receive the full contents of a source file "
    "and a directive specifying which lines to change and why. Output ONLY the complete "
    "modified file contents — no explanations, no markdown fences."
)
user_prompt = (
    f"Directive: {idea}\n\n"
    f"File: {target_file}\n"
    f"Lines to change: {start_line}{end_line}\n\n"
    f"Current file contents:\n{original_content}"
)

# 4. Commit the modified target file (not a new file)
path = target_file  # ← use the actual file path

Files to Change

  • backend/agents.py:
    • Lines 556–560: Update implementer_node system/user prompts to include existing file context.
    • Line 607: Replace hardcoded path = f"feature_issue_{issue_number}.py" with dynamic path parsed from the Architect directive.
    • Lines 618–623: Update create_file to update_file when the target file already exists.

Acceptance Criteria

  • When the Architect directive references a specific file (e.g. agents.py:54-76), the Implementer fetches and modifies that exact file.
  • The PR diff shows changes to an existing repository file, not a new feature_issue_N.py.
  • The Implementer falls back to creating a new file only when no target file can be extracted from the directive.
  • The Maintainer review prompt includes the original file content alongside the proposed changes for proper context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions