forked from genewildish/Mainline
Epic: Pipeline Mutation API for Stage Hot-Swapping #35
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Epic Summary
Implement a high-level Pipeline Mutation API that provides safe, unified operations for dynamically adding, removing, and modifying pipeline stages at runtime.
Problem Statement
The current pipeline architecture has several limitations for hot-swapping stages:
remove_stage()doesn't rebuild execution order - Removing a stage only deletes it from the dict, but doesn't update_execution_orderor_capability_map. This can cause dependency resolution errors.No partial cleanup support - The
cleanup()method cleans up ALL stages. There's no way to clean up just one stage.Display/camera swapping requires manual resource management - Swapping display or camera stages requires calling
cleanup()on the old stage andinit()on the new stage, which is error-prone.No unified API for hot-swapping - Operations are scattered across different methods with inconsistent behavior.
User Story
As a developer, I want a simple, unified API for safely hot-swapping pipeline stages at runtime, so that I can:
Proposed Solution: PipelineMutation API
Create a new class
PipelineMutationthat provides a safe, high-level API for hot-swapping operations.API Structure
Enhanced Pipeline Methods
remove_stage_safe(name: str) -> bool- Remove and rebuild execution ordercleanup_stage(name: str) -> None- Clean up specific stage without removingAcceptance Criteria
PipelineMutationclass with add/remove/replace operationsremove_stage_safe()rebuilds execution order automaticallycleanup_stage()cleans up specific stagescan_hot_swap()checker for stage compatibilityPhased Implementation
Phase 1: Core API (High Priority)
PipelineMutationclass with basic operationsremove_stage_safe()to Pipelinecleanup_stage()to PipelinePhase 2: Stage Safety Analysis (Medium Priority)
can_hot_swap()checkerPhase 3: Integration (High Priority)
app.pyto use PipelineMutation for preset changesTechnical Details
Files to modify:
engine/pipeline/mutation.py(new file)engine/pipeline/controller.py(add remove_stage_safe, cleanup_stage)engine/app.py(use PipelineMutation)engine/display/backends/websocket.py(add mutation commands)engine/pipeline/ui.py(add mutation operations)Tests to add:
tests/test_pipeline_mutation.py(new file)Related Issues
Questions/Decisions Needed
Progress Update (2026-03-18)
We have partially implemented the Pipeline Mutation API. Here's what's been done:
Completed
The following methods have been added to
Pipelineclass inengine/pipeline/controller.py:add_stage(name, stage, initialize=True)- Now acceptsinitializeparameter to control whether the stage is initialized immediatelyremove_stage(name, cleanup=True)- Now calls cleanup on the removed stage and returns itreplace_stage(name, new_stage, preserve_state=True)- Replaces a stage with a new one, preserves stateswap_stages(name1, name2)- Swaps two stages in the pipelinemove_stage(name, after, before)- Moves a stage's position in execution orderenable_stage(name)/disable_stage(name)- Convenience methods for enabling/disablingget_stage_info(name)- Returns detailed information about a stageget_pipeline_info()- Returns comprehensive pipeline state_rebuild()- Internal method for rebuilding execution order after mutations_copy_stage_state()- Copies state from old stage to new during replacementNext Steps
on_preset_changed()inpipeline_runner.pyto use mutation API instead of full rebuildTesting
Need to add tests in
tests/test_pipeline_controller.pycovering:Would you like us to continue with the implementation?
Completed in Recent Commits
The following have been implemented:
Phase 1: Core API - COMPLETED
PipelineMutationclass with basic operations (in controller.py)remove_stage_safe()rebuilds execution order automaticallycleanup_stage()cleans up specific stagesadd_stage(),replace_stage(),swap_stages(),move_stage()enable_stage()/disable_stage()get_stage_info()/get_pipeline_info()Additional Work
See commits:
c57617b- Performance fix and CI improvements3a2138a- Benchmark coverage-aware thresholdsRelated to Issue #35 (Pipeline Mutation API)
The camera hot-swap capability in #35 will require:
These fixes enable dynamic camera switching during runtime.
Implementation Complete
The Pipeline Mutation API has been fully implemented with the following changes:
Implemented Features
1.
can_hot_swap()FunctionFalsefor stages that provide minimum capabilities as the sole providerTruefor swappable stagesengine/pipeline/controller.py:188-2112.
cleanup_stage()Methodengine/pipeline/controller.py:173-1843. Fixed
remove_stage()to Rebuild Execution Order_rebuild()after removing a stageengine/pipeline/controller.py:115-1174. WebSocket Integration
_handle_pipeline_mutation()function inpipeline_runner.pyremove_stage,swap_stages,move_stageenable_stage,disable_stage,cleanup_stage,can_hot_swap5. Documentation
AGENTS.mdwith comprehensive mutation API documentationAcceptance Criteria Status
can_hot_swap()checkercleanup_stage()methodremove_stage_safe()remove_stage()now rebuilds automaticallypipeline_runner.pyAGENTS.mdFiles Modified
engine/pipeline/controller.py- Addedcan_hot_swap(),cleanup_stage(), fixedremove_stage()engine/app/pipeline_runner.py- Added_handle_pipeline_mutation()functionengine/pipeline/ui.py- Updated docstrings for mutation commandstests/test_pipeline_mutation_commands.py- New integration test fileAGENTS.md- Added mutation API documentationTest Results