--- phase: 10-workflow-modularization plan: 03 subsystem: workflow tags: [n8n, sub-workflow, container-actions, modularization] # Dependency graph requires: - phase: 10-01 provides: Clean workflow baseline (246 nodes, 0 orphan nodes) - phase: 10-02 provides: Container update sub-workflow pattern provides: - Container actions sub-workflow (start/stop/restart) - Main workflow integration with executeWorkflow nodes affects: [10-04, batch-operations] # Tech tracking tech-stack: added: [] patterns: [Execute Sub-workflow for action consolidation] key-files: created: [n8n-container-actions.json] modified: [n8n-workflow.json] key-decisions: - "Environment variable for workflow ID reference ($env.CONTAINER_ACTIONS_WORKFLOW_ID)" - "httpRequest nodes instead of curl for cleaner error handling in sub-workflow" - "Confirmation dialogs remain in main workflow per plan requirements" patterns-established: - "Action sub-workflow pattern: Prepare Input -> Execute Sub-workflow -> Handle Result" # Metrics duration: 6min completed: 2026-02-04 --- # Phase 10 Plan 3: Container Actions Sub-workflow Summary **Extracted container start/stop/restart actions into dedicated sub-workflow (209 nodes, +9 integration nodes)** ## Performance - **Duration:** 6 min - **Started:** 2026-02-04T18:05:50Z - **Completed:** 2026-02-04T18:11:40Z - **Tasks:** 3 (create sub-workflow, wire main workflow, deploy) - **Files created:** 1 (n8n-container-actions.json) - **Files modified:** 1 (n8n-workflow.json) ## Accomplishments - Created container-actions sub-workflow with 8 nodes - Input contract: containerId, containerName, action, chatId, messageId, responseMode - Output contract: success, message, action, containerName, containerId, chatId, messageId, responseMode - Added 9 nodes to main workflow for sub-workflow integration - Wired 3 action paths through sub-workflow: - Text command path (single match) - Inline keyboard path (start/restart) - Confirmed stop path - Used environment variable pattern for workflow ID reference ## Task Commits Each task was committed atomically: 1. **Task 1: Create container-actions sub-workflow** - `35705a7` (feat) 2. **Task 2: Wire main workflow to use sub-workflow** - `d07932f` (feat) **Task 3: Deploy and verify** - Requires n8n access (see User Setup Required) ## Files Created/Modified - `n8n-container-actions.json` - New sub-workflow (8 nodes, 303 lines) - `n8n-workflow.json` - Added 9 integration nodes (+234 lines) ## Decisions Made **1. Environment variable for workflow ID:** - Using `$env.CONTAINER_ACTIONS_WORKFLOW_ID` for sub-workflow reference - Matches pattern established in 10-02 with CONTAINER_UPDATE_WORKFLOW_ID - Allows easy ID update without editing workflow JSON **2. httpRequest nodes in sub-workflow:** - Sub-workflow uses n8n-nodes-base.httpRequest instead of curl commands - Cleaner JSON response handling with statusCode - onError: continueRegularOutput for graceful error handling **3. Confirmation dialogs in main workflow:** - Stop confirmation dialog remains in main workflow (not extracted) - Batch stop confirmation remains in main workflow - Only the action execution after confirmation moves to sub-workflow ## Deviations from Plan None - plan executed as written. ## Issues Encountered **n8n API not accessible from execution environment:** - WSL cannot resolve n8n.berger.work - Task 3 (deploy and verify) requires manual user action - All local verification passed successfully ## User Setup Required **To complete deployment:** 1. **Import container-actions sub-workflow:** - Open n8n web UI - Import `n8n-container-actions.json` - Note the assigned workflow ID 2. **Set environment variable:** - In n8n Settings > Variables, add: - `CONTAINER_ACTIONS_WORKFLOW_ID` = (workflow ID from step 1) 3. **Import/update main workflow:** - Import `n8n-workflow.json` (or update existing workflow) - Activate the workflow 4. **Verify functionality:** - Test text command: "start " - Test text command: "stop " (should work directly) - Test text command: "restart " - Test inline keyboard: Start/Stop/Restart buttons - Test stop confirmation flow via inline keyboard ## Verification Results | Check | Status | |-------|--------| | n8n-container-actions.json valid | PASS | | Has executeWorkflowTrigger with schema | PASS | | Input schema has 6 fields | PASS | | Main workflow has executeWorkflow nodes | PASS | | 3 action paths use sub-workflow | PASS | | Confirmation dialogs in main workflow | PASS | | Text command actions work | Pending deployment | | Inline keyboard actions work | Pending deployment | | Stop confirmation works | Pending deployment | ## Architecture ``` Main Workflow (n8n-workflow.json) | |-- Text Command Path: | Check Match Count -> Prepare Text Action Input | -> Execute Container Action (sub) -> Handle Text Action Result | -> Send Action Result | |-- Inline Keyboard Path (start/restart): | Route Action Type -> Prepare Immediate Action -> Get Container For Action | -> Prepare Inline Action Input -> Execute Inline Action (sub) | -> Handle Inline Action Result -> Send Immediate Result | |-- Inline Keyboard Path (stop): | Route Action Type -> Build Stop Confirmation -> Send Stop Confirmation | [User confirms] | Route Confirm Action -> Prepare Confirmed Stop -> Get Container For Stop | -> Prepare Confirmed Stop Input -> Execute Confirmed Stop Action (sub) | -> Handle Confirmed Stop Result -> Send Confirmed Stop Result Container Actions Sub-workflow (n8n-container-actions.json) | When executed by another workflow -> Route Action (switch: start/stop/restart) -> Start Container (httpRequest) -> Stop Container (httpRequest) -> Restart Container (httpRequest) -> Format [Start|Stop|Restart] Result -> Return to caller ``` ## Next Phase Readiness **Ready for Phase 10-04 (if applicable):** - Container actions consolidated in sub-workflow - Pattern established for additional sub-workflow extraction - Batch operations still use curl approach (not extracted to sub-workflow) **Blockers for full verification:** - Requires n8n deployment access - User must set CONTAINER_ACTIONS_WORKFLOW_ID environment variable --- *Phase: 10-workflow-modularization* *Completed: 2026-02-04*