feat(plans): implement ThreeWayMergeEngine for subplan result integration #11101

Closed
HAL9000 wants to merge 3 commits from bugfix/9608-three-way-merge-engine into master

3 Commits

Author SHA1 Message Date
CleverAgents Bot e78be87a92 ci: stop master workflow on PR updates
CI / lint (pull_request) Failing after 35s
CI / typecheck (pull_request) Successful in 58s
CI / build (pull_request) Successful in 35s
CI / helm (pull_request) Successful in 28s
CI / push-validation (pull_request) Successful in 30s
CI / quality (pull_request) Successful in 1m11s
CI / security (pull_request) Successful in 1m28s
CI / integration_tests (pull_request) Failing after 2m42s
CI / e2e_tests (pull_request) Successful in 3m57s
CI / unit_tests (pull_request) Failing after 4m17s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 3s
Remove the stale pull_request trigger from master.yml so PR branch commits do not launch the master workflow.

Maintenance patch for PR #11101.
2026-06-10 20:18:11 -04:00
HAL9000 1b11e295da fix(merge): resolve ThreeWayMergeEngine conflict detection and merge regressions
CI / lint (pull_request) Failing after 1m20s
CI / benchmark-publish (pull_request) Has been skipped
CI / quality (pull_request) Successful in 55s
CI / security (pull_request) Successful in 1m44s
CI / typecheck (pull_request) Successful in 2m12s
CI / push-validation (pull_request) Successful in 38s
CI / helm (pull_request) Successful in 42s
CI / build (pull_request) Successful in 50s
CI / benchmark-regression (pull_request) Failing after 1m9s
CI / integration_tests (pull_request) Failing after 3m53s
CI / e2e_tests (pull_request) Failing after 6m15s
CI / unit_tests (pull_request) Failing after 8m29s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 3s
Fixes six blocking issues from PR review:

1. CRITICAL: _merge_subplan_status() now records MergeConflict objects
   when both current and incoming diverge from base with different statuses.
   The conflict-raise path was dead code — ThreeWayMergeError never fired
   because the conflict field on SubplanStatusMergeResult was never populated.

2. REGRESSION: SubplanService accidentally dropped from _LAZY_IMPORTS in
   __init__.py when new three-way merge entries were inserted, breaking all
   runtime getattr(services, "SubplanService") calls.

3. CONTRIBUTORS.md line 27 had a malformed "<<*" partial conflict marker
   artifact that would corrupt the file and fail lint checks.

4. _merge_cost_metadata subplan_costs parameter was missing type annotation
   (contributed list[tuple[str, CostMetadata]]). Zero-tolerance rule per
   CONTRIBUTING.md. Updated docstring to accurately describe accumulating
   base_cost + parent delta + subplans.

5. Step decorator "@given" was missing "the " prefix for the feature text
   "And the subplan _S1 has error..." — Behave would raise StepNotImplemented.

6. step_merge_empty scenario was passing non-empty current/subplan lists,
   so ValueError guard never fired. Now uses all-empty status lists.

Also improves:
- Cost metadata now properly accumulates base_cost + parent delta + subplans
  (previously silently dropped base cost data)
- Budget remaining correctly uses min across all three sides
- step_current_changes uses getattr() for AttributeError safety
- Sequential merge assertion now verifies both S1=APPLIED and S2=COMPLETE

Closes #9557
2026-05-16 13:44:46 +00:00
HAL9000 d4d0f3f158 feat(plans): implement ThreeWayMergeEngine for subplan result integration (#9608)
CI / benchmark-publish (pull_request) Has been skipped
CI / push-validation (pull_request) Successful in 41s
CI / lint (pull_request) Failing after 1m2s
CI / helm (pull_request) Successful in 1m3s
CI / build (pull_request) Successful in 1m9s
CI / benchmark-regression (pull_request) Failing after 1m20s
CI / typecheck (pull_request) Successful in 1m33s
CI / quality (pull_request) Successful in 1m40s
CI / security (pull_request) Successful in 1m57s
CI / integration_tests (pull_request) Failing after 4m15s
CI / e2e_tests (pull_request) Successful in 4m39s
CI / unit_tests (pull_request) Failing after 6m43s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 4s
Implements a three-way merge engine that safely integrates subplan
execution results back into the parent plan state. The engine handles
merging of ancestor (base), parent (current), and subplan (incoming)
states with automatic application of non-conflicting changes and
validation before committing.

Changes:
- Added ThreeWayMergeEngine class in
  src/cleveragents/application/services/three_way_merge_engine.py
- Implemented merge logic for plan-specific fields: subplan statuses,
  cost metadata accumulation, skeleton metadata preservation, error
  state propagation, and timestamp advancement
- Added domain models in three_way_merge_models.py (value objects,
  type aliases, exception)
- Added comprehensive BDD tests in features/three_way_merge_engine.feature
- Added step definitions for Given/When/Then Behave scenarios
- Added Robot integration tests with CLI helper
- Registered service symbols for lazy loading in __init__.py

Based on:
    - docs/specification.md (subplan merge strategies)
    - ADR-006 (Plan Lifecycle)
    - Forgejo issue #9557

ISSUES CLOSED: #9557
2026-05-09 14:41:19 +00:00