Architecture: How to fix Bug 13 (generated code files never written to dis...
Documentation for Sessions
🏗️ Architecture: How to fix Bug 13 (generated code files never written to dis...
Date: 2026-02-23
Time: 23:17:07 UTC
Session: gspace1-138.2
Agent: backend
Confidence: 95%
Status: ✅ Documented
📋 Decision Context
Question:
How to fix Bug 13 (generated code files never written to disk) and make the post-completion flow crash-proof?
Task: S138.9 fix post-completion crash + code file writing
🎯 Decision Made
Chosen:
Three fixes: (1) Added try-catch safeRun wrapper to deferPostCompletionWork() with increased timer delays (100/100/200ms) so any error in persist/register/autoSync is caught and logged instead of crashing. (2) Added POST /ai-api/modules/:moduleId/write-files endpoint to GeneratedModulesController that calls the existing ModuleCodeGeneratorService.writeFilesToDisk() + updatePathMappings(). (3) Wired Pipeline B's DEPLOY phase to call the write-files endpoint for each module that has code files, grouping files by moduleName.
Options Considered:
- Have backend-vitto-api write files directly (duplicates code)
- Add write-files endpoint to backend-ai-api and call from Pipeline B DEPLOY (reuses existing infrastructure)
💭 Reasoning
Bug 10 (crash at completion) persists because the deferred chain has no error boundaries — any throw in persistGenerationState(), registerGeneratedModuleManifest(), or autoSyncModulesToCanvas() kills the page. The safeRun wrapper catches and logs instead. Bug 13 (code not saved) exists because Pipeline B's DEPLOY phase only does MongoDB upsert, never calls writeFilesToDisk(). The write-files endpoint reuses Pipeline A's existing ModuleCodeGeneratorService (which already handles directory creation, file writing, tsconfig path mapping, and barrel exports). Pipeline B calls it via the BackendAiClientService HTTP bridge, maintaining clean separation. File writing only triggers when executeOutput.files has content (i.e., outputMode was 'code' or 'both'), so VISUAL-only mode is unaffected.
📁 Files Involved
libs/libs-structural/vibe-universe/src/lib/components/vibe-universe-generator/vibe-universe-generator.component.tsapis/backend-ai-api/src/app/workflow/generated-modules.controller.tsapis/backend-vitto-api/src/app/module-generation/phases/module-gen-phase.executor.ts
🔗 Related
- Decision ID:
dev_1771888627822_a4rjxgc - Session: 138
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation