Proposal: improve ca-implementer-sonnet/opus — add code insertion safety guidance #3780

Open
opened 2026-04-06 06:17:00 +00:00 by freemo · 1 comment
Owner

Agent Improvement Proposal

Pattern Detected

Type: prompt_improvement
Affected Agents: ca-implementer-sonnet, ca-implementer-opus
Evidence: PR #3774 iterative failure pattern (7+ fix attempts over ~7 hours)

Detailed Evidence

PR #3774 ("fix: Update for Click 8.2+ compatibility and fix quality gates") shows a clear, repeated pattern of the implementer agent inserting code at incorrect locations in Python files:

  1. Comment #127225: "Reverted Breaking Change" — "The previous attempt accidentally inserted the helper function in the wrong locations (inside YAML strings), breaking Python syntax."

  2. Comment #127227: "Fixed incorrect usage of get_combined_output helper" — The helper function was called with context.result.output instead of context.result, showing the agent didn't verify the function signature before using it.

  3. Comment #127231: "Final fix completed" — "The previous attempt accidentally inserted the helper function in the wrong locations (inside YAML strings), breaking Python syntax. All affected files have been restored." Also: "The key lesson learned: When adding helper functions to test files, be very careful about where they're inserted — never inside string literals or in the middle of multi-line imports!"

This pattern resulted in:

  • 10+ commits including reverts (violating the "no fix-up commits" rule)
  • ~7 hours of iterative fixing for what should have been a straightforward change
  • Multiple syntax-breaking changes that had to be reverted

Proposed Change

Add a "Code Insertion Safety" section to both ca-implementer-sonnet.md and ca-implementer-opus.md agent definitions. The new section would instruct the implementer to:

  1. Read surrounding context before inserting code: Always read at least 30 lines around the intended insertion point to understand the syntactic context (are we inside a string literal? a multi-line expression? a decorator chain?).

  2. Verify insertion scope: Before inserting a function/import/constant, confirm the insertion point is at the correct scope level — module level for top-level functions, class level for methods, etc. Never insert inside string literals, docstrings, YAML embedded in Python, or multi-line expressions.

  3. Validate syntax after changes: After modifying a Python file, verify the file's syntax is still valid by checking with python -c "import ast; ast.parse(open('<file>').read())" or equivalent. If syntax is broken, revert and retry with a corrected insertion point.

  4. Prefer appending over inserting: When adding helper functions, prefer appending them after all imports (for module-level helpers) rather than trying to insert them at a specific line. This reduces the risk of inserting inside an existing construct.

Expected Impact

  • Fewer broken commits: Implementers will catch insertion errors before committing
  • Faster PR turnaround: Eliminates the multi-cycle fix-revert-fix pattern seen in PR #3774
  • Cleaner git history: Fewer reverts and fix-up commits
  • Reduced review burden: Reviewers won't need to flag syntax errors

Risk Assessment

  • Low risk: This is additive guidance — it doesn't change any existing behavior, only adds safety checks
  • Potential downside: Slightly slower implementation due to extra verification steps, but this is far outweighed by the time saved from avoiding broken commits
  • Both agents affected: The change applies to both Sonnet and Opus tiers, ensuring consistent behavior regardless of escalation level

This is a proposal from the agent evolver. A human must approve this issue before the change will be implemented. To approve: remove the needs feedback label, add State/Verified, or comment with approval.


Automated by CleverAgents Bot
Supervisor: Agent Evolver | Agent: ca-agent-evolver

## Agent Improvement Proposal ### Pattern Detected **Type**: prompt_improvement **Affected Agents**: `ca-implementer-sonnet`, `ca-implementer-opus` **Evidence**: PR #3774 iterative failure pattern (7+ fix attempts over ~7 hours) ### Detailed Evidence PR #3774 ("fix: Update for Click 8.2+ compatibility and fix quality gates") shows a clear, repeated pattern of the implementer agent inserting code at incorrect locations in Python files: 1. **Comment [#127225](https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/3774#issuecomment-127225)**: "Reverted Breaking Change" — *"The previous attempt accidentally inserted the helper function in the wrong locations (inside YAML strings), breaking Python syntax."* 2. **Comment [#127227](https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/3774#issuecomment-127227)**: "Fixed incorrect usage of get_combined_output helper" — The helper function was called with `context.result.output` instead of `context.result`, showing the agent didn't verify the function signature before using it. 3. **Comment [#127231](https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/3774#issuecomment-127231)**: "Final fix completed" — *"The previous attempt accidentally inserted the helper function in the wrong locations (inside YAML strings), breaking Python syntax. All affected files have been restored."* Also: *"The key lesson learned: When adding helper functions to test files, be very careful about where they're inserted — never inside string literals or in the middle of multi-line imports!"* This pattern resulted in: - 10+ commits including reverts (violating the "no fix-up commits" rule) - ~7 hours of iterative fixing for what should have been a straightforward change - Multiple syntax-breaking changes that had to be reverted ### Proposed Change Add a **"Code Insertion Safety"** section to both `ca-implementer-sonnet.md` and `ca-implementer-opus.md` agent definitions. The new section would instruct the implementer to: 1. **Read surrounding context before inserting code**: Always read at least 30 lines around the intended insertion point to understand the syntactic context (are we inside a string literal? a multi-line expression? a decorator chain?). 2. **Verify insertion scope**: Before inserting a function/import/constant, confirm the insertion point is at the correct scope level — module level for top-level functions, class level for methods, etc. Never insert inside string literals, docstrings, YAML embedded in Python, or multi-line expressions. 3. **Validate syntax after changes**: After modifying a Python file, verify the file's syntax is still valid by checking with `python -c "import ast; ast.parse(open('<file>').read())"` or equivalent. If syntax is broken, revert and retry with a corrected insertion point. 4. **Prefer appending over inserting**: When adding helper functions, prefer appending them after all imports (for module-level helpers) rather than trying to insert them at a specific line. This reduces the risk of inserting inside an existing construct. ### Expected Impact - **Fewer broken commits**: Implementers will catch insertion errors before committing - **Faster PR turnaround**: Eliminates the multi-cycle fix-revert-fix pattern seen in PR #3774 - **Cleaner git history**: Fewer reverts and fix-up commits - **Reduced review burden**: Reviewers won't need to flag syntax errors ### Risk Assessment - **Low risk**: This is additive guidance — it doesn't change any existing behavior, only adds safety checks - **Potential downside**: Slightly slower implementation due to extra verification steps, but this is far outweighed by the time saved from avoiding broken commits - **Both agents affected**: The change applies to both Sonnet and Opus tiers, ensuring consistent behavior regardless of escalation level --- *This is a proposal from the agent evolver. A human must approve this issue before the change will be implemented. To approve: remove the `needs feedback` label, add `State/Verified`, or comment with approval.* --- **Automated by CleverAgents Bot** Supervisor: Agent Evolver | Agent: ca-agent-evolver
Author
Owner

@HAL9000 Aspects of this ticket, including the title itself, no longer apply since the agent definitions have been significantly refactored. Re-evaluate the agent definitions in @.opencode/ and rewrite or replace this ticket based on the new code. If you are rewriting the ticket in place then tag me with a comment once its ready for re-review. If you are closing this ticket and starting a new one then just use the "needs feedback" label and I will see it.

@HAL9000 Aspects of this ticket, including the title itself, no longer apply since the agent definitions have been significantly refactored. Re-evaluate the agent definitions in @.opencode/ and rewrite or replace this ticket based on the new code. If you are rewriting the ticket in place then tag me with a comment once its ready for re-review. If you are closing this ticket and starting a new one then just use the "needs feedback" label and I will see it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#3780
No description provided.