UAT: ContextAssemblyPipeline.assemble() completely reimplements parent ACMSPipeline.assemble() without calling super() — creates maintenance risk and code duplication #3750

Open
opened 2026-04-05 22:28:22 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/acms-context-pipeline-assemble-super
  • Commit Message: fix(acms): refactor ContextAssemblyPipeline.assemble() to delegate to super() and eliminate duplication
  • Milestone: Backlog (no milestone assigned)
  • Parent Epic: #396

Bug Report

Summary

ContextAssemblyPipeline.assemble() in src/cleveragents/application/services/acms_pipeline.py (lines 575–765) completely reimplements the full 10-stage pipeline logic from ACMSPipeline.assemble() in src/cleveragents/application/services/acms_service.py (lines 878–1009) without calling super().assemble().

Problems

  1. Code duplication: ~130 lines of pipeline logic are duplicated verbatim between the two assemble() methods. Any bug fix or enhancement to ACMSPipeline.assemble() must be manually replicated in ContextAssemblyPipeline.assemble().

  2. Maintenance risk: Future changes to ACMSPipeline.assemble() (e.g., adding new pipeline stages, changing budget enforcement logic, or fixing bugs) will not automatically propagate to ContextAssemblyPipeline. This has already happened — the skeleton compression logic added in the fix for #3563 had to be duplicated in both methods.

  3. Inline import: ContextAssemblyPipeline.assemble() contains an inline import at lines 600–601:

    import re
    from cleveragents.domain.models.core.context_fragment import ULID_PATTERN
    

    This is unusual and suggests the method was written independently rather than extending the parent.

  4. Duplicated ULID validation: The ULID validation at lines 604–606 is identical to the validation in ACMSPipeline.assemble() lines 904–906.

Expected Behaviour

ContextAssemblyPipeline.assemble() should call super().assemble() and only add the timing instrumentation and event emission that are specific to ContextAssemblyPipeline. The parent class handles all pipeline logic; the subclass adds observability.

Suggested Fix

Refactor ContextAssemblyPipeline.assemble() to:

  1. Call super().assemble() to execute the pipeline.
  2. Wrap the call with timing instrumentation (measuring total time).
  3. Emit the CONTEXT_BUILT event after the call.
  4. Store StageTimings on self._last_timings.

This requires either:

  • Refactoring ACMSPipeline.assemble() to expose per-stage timing hooks or accept a timing callback, or
  • Restructuring the pipeline so each stage is a separate method that can be overridden/timed individually.

Code Locations

File Lines Symbol
src/cleveragents/application/services/acms_pipeline.py 575–765 ContextAssemblyPipeline.assemble()
src/cleveragents/application/services/acms_service.py 878–1009 ACMSPipeline.assemble()

Subtasks

  • Audit both assemble() implementations and document all divergences
  • Refactor ACMSPipeline.assemble() to expose per-stage timing hooks or accept a timing callback (enabling subclass instrumentation without full reimplementation)
  • Refactor ContextAssemblyPipeline.assemble() to call super().assemble() and delegate all pipeline logic to the parent
  • Remove inline import re and from cleveragents.domain.models.core.context_fragment import ULID_PATTERN from ContextAssemblyPipeline.assemble() — move to module-level imports
  • Remove duplicated ULID validation from ContextAssemblyPipeline.assemble() (already handled by parent)
  • Retain timing instrumentation and CONTEXT_BUILT event emission in ContextAssemblyPipeline as the subclass-specific additions
  • Tests (Behave): Add/update scenarios verifying that ContextAssemblyPipeline.assemble() delegates to ACMSPipeline.assemble() and does not duplicate pipeline stages
  • Tests (Behave): Add scenario verifying timing instrumentation and CONTEXT_BUILT event are still emitted after refactor
  • Tests (Robot): Verify end-to-end ACMS pipeline behaviour is unchanged after refactor
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • ContextAssemblyPipeline.assemble() no longer contains duplicated pipeline logic — it calls super().assemble() and only adds subclass-specific observability.
  • No inline imports remain inside ContextAssemblyPipeline.assemble().
  • All nox sessions pass (lint, typecheck, unit_tests, integration_tests, coverage_report).
  • Coverage >= 97%.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Backlog note: This issue was discovered during autonomous operation
on milestone v3.4.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/acms-context-pipeline-assemble-super` - **Commit Message**: `fix(acms): refactor ContextAssemblyPipeline.assemble() to delegate to super() and eliminate duplication` - **Milestone**: Backlog (no milestone assigned) - **Parent Epic**: #396 --- ## Bug Report ### Summary `ContextAssemblyPipeline.assemble()` in `src/cleveragents/application/services/acms_pipeline.py` (lines 575–765) completely reimplements the full 10-stage pipeline logic from `ACMSPipeline.assemble()` in `src/cleveragents/application/services/acms_service.py` (lines 878–1009) **without calling `super().assemble()`**. ### Problems 1. **Code duplication**: ~130 lines of pipeline logic are duplicated verbatim between the two `assemble()` methods. Any bug fix or enhancement to `ACMSPipeline.assemble()` must be manually replicated in `ContextAssemblyPipeline.assemble()`. 2. **Maintenance risk**: Future changes to `ACMSPipeline.assemble()` (e.g., adding new pipeline stages, changing budget enforcement logic, or fixing bugs) will **not** automatically propagate to `ContextAssemblyPipeline`. This has already happened — the skeleton compression logic added in the fix for #3563 had to be duplicated in both methods. 3. **Inline import**: `ContextAssemblyPipeline.assemble()` contains an inline import at lines 600–601: ```python import re from cleveragents.domain.models.core.context_fragment import ULID_PATTERN ``` This is unusual and suggests the method was written independently rather than extending the parent. 4. **Duplicated ULID validation**: The ULID validation at lines 604–606 is identical to the validation in `ACMSPipeline.assemble()` lines 904–906. ### Expected Behaviour `ContextAssemblyPipeline.assemble()` should call `super().assemble()` and only add the timing instrumentation and event emission that are specific to `ContextAssemblyPipeline`. The parent class handles all pipeline logic; the subclass adds observability. ### Suggested Fix Refactor `ContextAssemblyPipeline.assemble()` to: 1. Call `super().assemble()` to execute the pipeline. 2. Wrap the call with timing instrumentation (measuring total time). 3. Emit the `CONTEXT_BUILT` event after the call. 4. Store `StageTimings` on `self._last_timings`. This requires either: - Refactoring `ACMSPipeline.assemble()` to expose per-stage timing hooks or accept a timing callback, **or** - Restructuring the pipeline so each stage is a separate method that can be overridden/timed individually. ### Code Locations | File | Lines | Symbol | |------|-------|--------| | `src/cleveragents/application/services/acms_pipeline.py` | 575–765 | `ContextAssemblyPipeline.assemble()` | | `src/cleveragents/application/services/acms_service.py` | 878–1009 | `ACMSPipeline.assemble()` | --- ## Subtasks - [ ] Audit both `assemble()` implementations and document all divergences - [ ] Refactor `ACMSPipeline.assemble()` to expose per-stage timing hooks or accept a timing callback (enabling subclass instrumentation without full reimplementation) - [ ] Refactor `ContextAssemblyPipeline.assemble()` to call `super().assemble()` and delegate all pipeline logic to the parent - [ ] Remove inline `import re` and `from cleveragents.domain.models.core.context_fragment import ULID_PATTERN` from `ContextAssemblyPipeline.assemble()` — move to module-level imports - [ ] Remove duplicated ULID validation from `ContextAssemblyPipeline.assemble()` (already handled by parent) - [ ] Retain timing instrumentation and `CONTEXT_BUILT` event emission in `ContextAssemblyPipeline` as the subclass-specific additions - [ ] Tests (Behave): Add/update scenarios verifying that `ContextAssemblyPipeline.assemble()` delegates to `ACMSPipeline.assemble()` and does not duplicate pipeline stages - [ ] Tests (Behave): Add scenario verifying timing instrumentation and `CONTEXT_BUILT` event are still emitted after refactor - [ ] Tests (Robot): Verify end-to-end ACMS pipeline behaviour is unchanged after refactor - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors --- ## Definition of Done This issue is complete when: - [ ] All subtasks above are completed and checked off. - [ ] `ContextAssemblyPipeline.assemble()` no longer contains duplicated pipeline logic — it calls `super().assemble()` and only adds subclass-specific observability. - [ ] No inline imports remain inside `ContextAssemblyPipeline.assemble()`. - [ ] All `nox` sessions pass (lint, typecheck, unit_tests, integration_tests, coverage_report). - [ ] Coverage >= 97%. - [ ] A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - [ ] The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - [ ] The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.4.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
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.

Blocks
#396 Epic: ACMS Context Pipeline
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3750
No description provided.