HANDOFF S138.9 URGENT Code Generation Not Saving
Documentation for Handoffs
HANDOFF S138.9 — URGENT: Generated Code Files Are NOT Being Saved
Date: 2026-02-23 Session: 138.9 Priority: CRITICAL / URGENT Type: Bug Fix + Architecture Requirement
The Problem in One Sentence
Pipeline B generates Angular code strings in memory, sends them over SSE, and then throws them away. The actual .ts, .html, .scss files are never written to disk. Every generation run produces empty folder skeletons with zero source files inside.
Evidence
What Pipeline A (old) produces — CORRECT:
modules/user-management/
├── project.json ← NX config
├── ng-package.json ← Angular packaging
├── tsconfig.json, tsconfig.lib.json ← TypeScript config
├── package.json ← Dependencies
├── README.md, SETUP_COMPLETE.md ← Docs
├── vite.config.mts ← Build config
├── __tests__/ ← Full test suite
│ ├── models/user.model.test.ts
│ ├── actions/create-user.action.test.ts
│ └── ...
└── src/lib/
├── user-management.module.ts
├── models/user.model.ts, user-api.model.ts, user-filters.model.ts
├── state/user.state.ts, user.actions.ts
├── mocks/user-mock-data.ts, user-mock-api.ts
└── components/
├── user-form/user-form.component.ts + .html + .scss
├── user-card/user-card.component.ts + .html + .scss
├── user-filters/user-filters.component.ts + .html + .scss
├── user-role-manager/*.component.ts + .html + .scss
├── user-delete-confirm/*.component.ts + .html + .scss
└── user-avatar/*.component.ts + .html + .scss
30+ real files. Full NX library. Ready to build.
What Pipeline B (current) produces — BROKEN:
modules/fitness-studio-member-management/
└── src/lib/
├── components/
│ ├── member-list/ ← EMPTY FOLDER
│ ├── member-detail/ ← EMPTY FOLDER
│ ├── member-form/ ← EMPTY FOLDER
│ └── member-card/ ← EMPTY FOLDER
├── actions/ ← EMPTY FOLDER
└── models/ ← EMPTY FOLDER
Zero files. No project.json, no tsconfig, no package.json, no source code. Just empty directories.
Same pattern for ALL 5 Fitness Studio modules and ALL 4 Kids Points modules.
Root Cause
Where the code IS generated (but never saved):
- EXECUTE phase (
execute.phase.ts) generates code strings via LLM prompts (implement.prompt.tsfor Path B) - The generated
.ts,.html,.scsscontent exists as strings inGeneratedFileSpec[]objects - These are bundled into
manifestJSONand sent over SSE to the frontend - The frontend receives them in
handleWorkflowComplete()but only uses the JSON schema (actions/embeddables/entities), not the code strings
Where the code SHOULD be saved (but isn't):
The file-writing service exists and works — it's in Pipeline A:
apis/backend-ai-api/src/app/workflow/generators/module-code-generator.service.ts
Line 373: writeFilesToDisk(files, moduleId, category)
→ const basePath = path.join(this.workspaceRoot, 'modules', moduleId);
→ await fs.mkdir(dir, { recursive: true });
→ await fs.writeFile(fullPath, file.content, 'utf-8');
Line 409: updatePathMappings()
→ Updates tsconfig.base.json with @module/{name} path aliases
→ Updates config/tsconfig-paths/modules/generated.paths.json
The disconnect:
- Pipeline A (
backend-ai-api/workflow/) callswriteFilesToDisk()after generation → FILES WRITTEN - Pipeline B (
backend-vitto-api/module-generation/) callspersistGeneratedModules()which only saves JSON schema to MongoDB → NO FILES WRITTEN - Pipeline B's DEPLOY phase sends module data to
backend-ai-apivia HTTPPOST /ai-api/modules, but this endpoint ONLY does a MongoDB upsert — it does NOT triggerwriteFilesToDisk() - Someone added directory scaffolding (
createManualStructure()) that creates the folder skeleton, but never calls the actual file writer
What Needs to Happen
Fix 1: Wire Pipeline B's DEPLOY Phase to Write Files (URGENT)
The DEPLOY phase must call writeFilesToDisk() for every generated module. The code strings already exist in the EXECUTE phase output — they just need to be passed through to the file writer.
Option A — Have backend-vitto-api call a new endpoint on backend-ai-api that triggers file writing:
POST /ai-api/modules/:moduleId/write-files
Body: { files: GeneratedFileSpec[], category: string }
Option B — Have backend-vitto-api write files directly (add its own file-writing service that mirrors ModuleCodeGeneratorService.writeFilesToDisk()).
Option C — After the MongoDB upsert in generated-modules.controller.ts, automatically trigger writeFilesToDisk() using the data from the upsert. This way any module persist also writes files.
Recommendation: Option A is cleanest — keeps file-writing responsibility in one place (backend-ai-api).
Fix 2: Also Write NX/Angular Config Files
Pipeline A writes these per module — Pipeline B doesn't:
| File | Purpose | Must Generate |
|---|---|---|
project.json |
NX project config | YES |
ng-package.json |
Angular library packaging | YES |
tsconfig.json |
Module-level TS config | YES |
tsconfig.lib.json |
Library build TS config | YES |
package.json |
Module dependencies | YES |
README.md |
Module documentation | NICE TO HAVE |
vite.config.mts |
Build tooling | IF NEEDED |
src/index.ts |
Barrel export | YES |
Fix 3: Update Path Mappings
After writing files, must update:
tsconfig.base.json→ add@module/{name}path aliasconfig/tsconfig-paths/modules/generated.paths.json→ same
Pipeline A does this in updatePathMappings() — Pipeline B doesn't.
Fix 4: Wire GitLab — Each Module/Platform Becomes a Repository
Why
Right now, generated modules live as local folders under /modules/. This means:
- No version control on generated code
- No way to track changes across generation runs
- No collaborative editing — can't PR, review, or merge module changes
- No CI/CD per module
- A single bad generation overwrites previous good code with no rollback
What We Need
Each generated module (or platform) should become its own GitLab repository that can be independently:
- Version controlled (git history per module)
- Modified by developers (PRs, code review)
- Rebuilt/deployed independently
- Rolled back to any previous generation
Proposed Architecture
Generation completes
│
├─ Write files to /modules/{module-name}/ (Fix 1 above)
│
├─ Create/update GitLab repo
│ └─ POST /api/v4/projects
│ name: "{space-slug}-{module-slug}"
│ e.g. "chrome-space-1-fitness-studio-member-management"
│
├─ Commit generated files
│ └─ git add . && git commit -m "Generated by modgen-{sessionId}"
│
├─ Push to remote
│ └─ git push origin main
│
└─ Store repo URL in generated-modules document
└─ { repoUrl: "https://gitlab.com/gograb/modules/..." }
Implementation Options
Option A — GitLab API Integration (Recommended):
- Add GitLab API client to
backend-ai-apiorbackend-vitto-api - Use GitLab's Repositories API to create repos and commit files programmatically
- Store GitLab access token in
.env.local - Each generation creates a new commit (not a new repo) — repo is created once per module
Option B — Git CLI:
- After writing files, run
git init,git remote add,git commit,git pushvia child process - Simpler but less robust
Option C — GitLab CI/CD Templates:
- Include a
.gitlab-ci.ymlin each generated module - Auto-runs linting, type-checking, and build on each push
- Catches generation errors before they hit production
Repo Naming Convention
Organization: gograb/modules/
Repo name: {space-slug}/{module-slug}
Example:
gograb/modules/chrome-space-1/fitness-studio-member-management
gograb/modules/chrome-space-1/fitness-studio-trainer-management
gograb/modules/chrome-space-1/fitness-studio-class-management
Or for platform-level repos (one repo per full generation):
gograb/platforms/chrome-space-1/fitness-studio
└── Contains all 5 modules as directories within one repo
What to Store in MongoDB
Add to generated-modules schema:
{
// existing fields...
git: {
repoUrl: string; // "https://gitlab.com/gograb/modules/..."
lastCommitSha: string; // "abc123..."
lastCommitDate: Date;
branch: string; // "main"
generationSessionId: string; // "modgen-9e2521fb" — links commit to generation
}
}
Files to Modify
| File | Change |
|---|---|
apis/backend-vitto-api/src/app/module-generation/phases/deploy.phase.ts |
Add file-writing call after MongoDB persist |
apis/backend-ai-api/src/app/workflow/generators/module-code-generator.service.ts |
Expose writeFilesToDisk() via new API endpoint |
apis/backend-ai-api/src/app/workflow/generated-modules.controller.ts |
Add POST /ai-api/modules/:id/write-files endpoint |
apis/backend-vitto-api/src/app/module-generation/module-gen-phase.executor.ts |
Pass code strings from EXECUTE through to DEPLOY |
apis/backend-ai-api/src/app/workflow/schemas/generated-module.schema.ts |
Add git field to schema |
NEW: apis/backend-ai-api/src/app/workflow/services/gitlab-integration.service.ts |
GitLab API client |
Priority Order
- IMMEDIATE: Fix file writing — Pipeline B must write actual
.ts/.html/.scssfiles to disk (not just empty folders) - IMMEDIATE: Write NX config files (
project.json,tsconfig.json, etc.) alongside source files - IMMEDIATE: Update
tsconfig.base.jsonpath mappings so modules are importable - HIGH: Wire GitLab integration — each module becomes a versionable repository
- MEDIUM: Add
.gitlab-ci.ymltemplate for auto-validation on push
Context: All Active Bugs
| Bug | Description | Priority |
|---|---|---|
| 13 | Generated code files not written to disk (THIS HANDOFF) | CRITICAL |
| 10 | Page Unresponsive at 100% completion (6 sync blocking ops) | CRITICAL |
| 12 | Backend DEPLOY may not persist to generated-modules | HIGH |
| 11 | Page refresh redirects to /landing instead of reconnecting | HIGH |
| 5 | Deploy to Universe (space_modules) — blocked by Bug 10 | BLOCKED |