BUG-HUNT: [concurrency] subplan_merge_service.py _sequential_apply never updates base_content — wrong merge decisions for all subplans after first #7499

Open
opened 2026-04-10 20:50:29 +00:00 by HAL9000 · 1 comment
Owner

Bug Report: Incorrect Logic — _sequential_apply Uses Wrong Base for All Merges After First

Severity Assessment

  • Impact: Subplan merge produces incorrect output — changes from earlier subplans not considered when merging later subplans; results may have incorrect conflict detection and content
  • Likelihood: High — triggered any time a file is modified by more than one subplan
  • Priority: High

Location

  • File: src/cleveragents/application/services/subplan_merge_service.py
  • Function: _sequential_apply
  • Lines: 223–231
  • Category: incorrect-logic

Description

The method docstring says "Apply changes sequentially (each becomes the new base)" but base_content is never updated inside the loop. The original pre-subplan file content is used as the base for every merge iteration. For a 3-way merge, the "base" is the common ancestor — using the original as base for every merge ignores the fact that each iteration's output should become the new common ancestor for the next.

Evidence

def _sequential_apply(self, path, base_content, contents, subplan_ids):
    current = base_content
    for content in contents:
        result: MergeResult = self._seq_merge.merge(base_content, current, content)
        #                                            ^^^^^^^^^^^
        #   base_content never changes — should advance to `current` each iteration
        current = result.content

For iteration 2: merge(ORIGINAL_BASE, output_of_iteration_1, subplan_2_content) — this is wrong. Should be: merge(output_of_iteration_1, output_of_iteration_1, subplan_2_content) or more correctly advancing base to previous output.

Expected Behavior

After each iteration, base_content should be updated to the output of the previous merge, so each merge correctly reflects the accumulated state.

Actual Behavior

All merges use the original base_content, causing incorrect 3-way merge decisions for subplans 2+ (differences between original and subplan N are incorrectly reported as conflicts).

Suggested Fix

def _sequential_apply(self, path, base_content, contents, subplan_ids):
    current = base_content
    base = base_content
    for content in contents:
        result: MergeResult = self._seq_merge.merge(base, current, content)
        base = current       # advance base to previous output
        current = result.content

Category

incorrect-logic

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_, and @tdd_expected_fail to prove the bug exists before fixing it.


Automated by CleverAgents Bot
Supervisor: Bug Detection Pool | Agent: bug-hunt-pool-supervisor

## Bug Report: Incorrect Logic — `_sequential_apply` Uses Wrong Base for All Merges After First ### Severity Assessment - **Impact**: Subplan merge produces incorrect output — changes from earlier subplans not considered when merging later subplans; results may have incorrect conflict detection and content - **Likelihood**: High — triggered any time a file is modified by more than one subplan - **Priority**: High ### Location - **File**: `src/cleveragents/application/services/subplan_merge_service.py` - **Function**: `_sequential_apply` - **Lines**: 223–231 - **Category**: incorrect-logic ### Description The method docstring says "Apply changes sequentially (each becomes the new base)" but `base_content` is **never updated** inside the loop. The original pre-subplan file content is used as the base for every merge iteration. For a 3-way merge, the "base" is the common ancestor — using the original as base for every merge ignores the fact that each iteration's output should become the new common ancestor for the next. ### Evidence ```python def _sequential_apply(self, path, base_content, contents, subplan_ids): current = base_content for content in contents: result: MergeResult = self._seq_merge.merge(base_content, current, content) # ^^^^^^^^^^^ # base_content never changes — should advance to `current` each iteration current = result.content ``` For iteration 2: `merge(ORIGINAL_BASE, output_of_iteration_1, subplan_2_content)` — this is wrong. Should be: `merge(output_of_iteration_1, output_of_iteration_1, subplan_2_content)` or more correctly advancing base to previous output. ### Expected Behavior After each iteration, `base_content` should be updated to the output of the previous merge, so each merge correctly reflects the accumulated state. ### Actual Behavior All merges use the original `base_content`, causing incorrect 3-way merge decisions for subplans 2+ (differences between original and subplan N are incorrectly reported as conflicts). ### Suggested Fix ```python def _sequential_apply(self, path, base_content, contents, subplan_ids): current = base_content base = base_content for content in contents: result: MergeResult = self._seq_merge.merge(base, current, content) base = current # advance base to previous output current = result.content ``` ### Category incorrect-logic ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it. --- **Automated by CleverAgents Bot** Supervisor: Bug Detection Pool | Agent: bug-hunt-pool-supervisor
HAL9000 added this to the v3.3.0 milestone 2026-04-10 21:38:48 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: High — Correctness bug in subplan/correction/merge logic that directly impacts M4 milestone functionality
  • Milestone: v3.3.0 (M4: Corrections + Subplans) — This component is core to the corrections and subplan execution features
  • Story Points: 3 (M) — Bug fix with clear reproduction path
  • MoSCoW: Must Have — Subplan and correction functionality must work correctly for M4 delivery
  • Type: Bug

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

Issue triaged by project owner: - **State**: Verified - **Priority**: High — Correctness bug in subplan/correction/merge logic that directly impacts M4 milestone functionality - **Milestone**: v3.3.0 (M4: Corrections + Subplans) — This component is core to the corrections and subplan execution features - **Story Points**: 3 (M) — Bug fix with clear reproduction path - **MoSCoW**: Must Have — Subplan and correction functionality must work correctly for M4 delivery - **Type**: Bug --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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#7499
No description provided.