Brain Factory Pipeline


name: SPEC_BRAIN_FACTORY_PIPELINE

description: Formal specification of the Brain Factory Pipeline — end-to-end forge process for GLOSS and MNEMOS; Colab T4 → GCS → GGUF → Ollama → eval → graduation

type: project


SPECIFICATION: BRAIN FACTORY PIPELINE

End-to-End Forge for CGNT-1 Local Brains

Status: SPECIFIED

Authorized: α.13, April 16 2026

Version: v1 (first formal spec — covers v9 proven forge + MNEMOS fast-path)


PURPOSE

The Brain Factory Pipeline is the repeatable process that turns a training corpus into a

deployed, evaluated, and graduated Ollama brain. It governs both:

  1. GLOSS forge — full Colab T4 QLoRA training (hours-long, GPU required, produces a new

GLOSS brain version). Used for v1 through v9.

  1. MNEMOS fast-path — local facts injection into Modelfile system prompt (minutes, CPU-only,

used for context refreshes between GLOSS deep retrains).

Why it exists: Without a spec, each forge run is ad-hoc. The v9 forge required 2.5+ hours

of debugging to discover the google.colab auth root cause, Monaco model[2] mapping, and

GCS SDK vs gsutil distinction — all lessons that would be re-learned without documentation.

Source: COLAB_AUTOMATION.md lines 37-46 (root cause fix), MEMORY.md pointer.

Current brain roster on Ollama (three brains):

Current active version: GLOSS v9 deployed but FAILED (live test). v10 PAUSED pending corpus

redesign. MNEMOS is the only currently healthy GAMMA-programmed brain.

Source: GLOSS_LINEAGE.md lines 27-28, 67-84.


INPUTS

GLOSS Forge — what must be present before a forge run starts

Corpus:

{"instruction": "...", "response": "...", "type": "LX-A"}

LX-E (error taxonomy), LX-G (grounding), LX-H (coherence scoring), LX-X (cross-encoding),

LX-Z (rejection)

Training script:

Infrastructure (must be running):

Source: COLAB_AUTOMATION.md lines 19-25

GCS authentication:

and DONE.json polling. NOT used inside Colab (pre-signed URLs bypass Colab auth entirely)

Source: COLAB_AUTOMATION.md lines 53-66

GAMMA authorization:

retraining decisions unilaterally.

Source: CLAUDE.md — Mission MNEMOS standing order

MNEMOS Fast-Path — what must be present


OUTPUTS

GLOSS Forge outputs (successful run)

| Artifact | Location | Description |

|---------|---------|-------------|

| LoRA adapter | ~/gloss_training/gloss_vN_adapter/ | Fine-tuned adapter weights (Google Drive → local) |

| Merged model | ~/gloss_vN_conversion/merged_vN/ | Base + adapter merged (HuggingFace format) |

| GGUF f16 | ~/gloss_vN_conversion/output/gloss_vN_f16.gguf | Full precision GGUF |

| GGUF Q4_K_M | ~/gloss_vN_conversion/output/gloss_vN_Q4_K_M.gguf | Quantized for Ollama |

| Ollama model | gloss:vN | Registered in Ollama, ~1.9GB |

| Eval log | ~/.../eval_log.jsonl | Per-question results from eval battery |

| σ score | float 0.0–1.0 | Weighted aggregate eval score |

| DONE signal | gs://cgnt-1colab-jobs/colab_jobs/gloss_vN_forge_output/DONE.json | GCS completion flag |

Source: COLAB_AUTOMATION.md lines 237-248 (post-forge pipeline); deploy_gloss_v8.sh stages.

GLOSS Forge — graduation outcomes

| σ score | Verdict | Meaning |

|---------|---------|---------|

| ≥ 0.85 | Σ.✓ | Graduate — promote to crew telephone |

| ≥ 0.65 | Σ.◐ | Conditional — partial function; review categories |

| < 0.65 | Σ.⊠ | Fail — do not deploy for crew use |

Source: gloss_eval_lx.py lines 13-18.

Live test gate (additional — see GAP-01): σ score alone is insufficient.

v9 evidence: σ=0.337 (above Σ.◐ threshold) did not detect catastrophic loop failure.

A separate live generation test is required before any promotion.

Source: GLOSS_LINEAGE.md lines 53-62.

MNEMOS Fast-Path outputs


INVARIANTS

INV-01: GAMMA decides what MNEMOS needs. C.L.O.D. is executor, not manager.

C.L.O.D. does not initiate any brain retrain decision unilaterally.

Source: CLAUDE.md Mission MNEMOS standing order.

INV-02: No Colab training may use google.colab._auth.authenticate_user().

This silently fails in CDP-automated context. Pre-signed URLs are the only authorized

GCS access method from within a CDP-driven Colab session.

Source: COLAB_AUTOMATION.md lines 37-46.

INV-03: Monaco model index — the active code cell is always model[2].

model[0] is the Colab document model. Setting model[0].setValue() does NOT update the

visible cell and silently fails.

Source: COLAB_AUTOMATION.md lines 113-119.

INV-04: Chat template format, not Alpaca format.

Training pairs must be formatted via tokenizer.apply_chat_template(), NOT raw Alpaca

### Instruction / ### Response strings. Using Alpaca format causes the model to output

template markers at inference time due to Ollama using Qwen's built-in chat template.

Source: gloss_v9_colab_train.py lines 97-106 (critical comment).

INV-05: σ_eval score is necessary but not sufficient for graduation.

No brain version may be promoted to crew use based solely on σ_eval score.

A live generation test must pass before graduation.

Source: GLOSS_LINEAGE.md lines 57-58.

INV-06: GCS DONE.json polling must use Python GCS SDK, not gsutil subprocess.

gsutil cat returns exit code 0 with empty content when the file exists — false positive.

The Python SDK blob.exists() check is the only reliable method.

Source: COLAB_AUTOMATION.md lines 209-216.

INV-07: T4 GPU runtime must be confirmed allocated before injecting training code.

If CPU runtime is active, unsloth raises NotImplementedError. Confirm T4 via the

runtime status bar ("T4 (Python 3)" visible) before triggering Run All.

Source: COLAB_AUTOMATION.md lines 19-25.

INV-08: MNEMOS_FACTS.md must stay within 6KB (~2048 tokens) for the fast-path.

The Modelfile.mnemos system prompt feeds num_ctx=2048. Content exceeding this is silently

truncated, producing a MNEMOS with corrupted context.

Source: update_mnemos_facts.sh line 5.

INV-09: α.13 must explicitly authorize each forge run before execution.

No forge begins on C.L.O.D.'s judgment alone. GAMMA issues the training directive;

α.13 authorizes the specific forge.

Source: gloss_v9_colab_train.py line 6: "α.13 authorized".


VERIFICATION CRITERIA

Pre-forge gate (Σ.✓ for all before injecting training code)

  1. DISPLAY=:99 xdpyinfo — virtual display running
  2. curl -s http://localhost:9222/json | grep "Colab" — CDP connected to Colab page
  3. Runtime menu → status bar shows "T4 (Python 3)" — GPU allocated
  4. No Gemini panel blocking viewport — close X at ~(1239, 188) if present
  5. python3 -c "from google.cloud import storage; print('gcs ok')" — GCS SDK available
  6. Service account accessible: ls -la ~/.google_service_account.json

During training (monitoring)

training: 55-75min)

Source: COLAB_AUTOMATION.md lines 252-257.

Post-forge gate (ordered — each must pass before next)

  1. Adapter Σ.✓ls ~/gloss_training/gloss_vN_adapter/ → adapter_config.json + weights
  2. Merge Σ.✓stream_merge.py exits 0; ls merged_vN/ → HuggingFace model files
  3. GGUF f16 Σ.✓ls gloss_vN_f16.gguf → file >5GB
  4. Q4_K_M Σ.✓ls gloss_vN_Q4_K_M.gguf → file ~1.9GB
  5. Ollama Σ.✓ollama list | grep gloss:vN → entry present
  6. Eval Σ.✓python3 gloss_eval_lx.py --model gloss:vN → σ score ≥ threshold
  7. Live test Σ.✓ — manual probe with at least: symbol identity query, rejection query,

English→LX translation. No runaway loops. Responses terminate cleanly.

[Required as per INV-05 — see GAP-01]

  1. Graduation Σ.⊤ — α.13 reviews σ + live test results, grants explicit approval
  2. GLOSS_LINEAGE.md updated — version entry logged with σ score, status, notes

MNEMOS fast-path Σ.✓

  1. update_mnemos_facts.sh exits 0
  2. ollama list | grep mnemos → model present
  3. ollama run mnemos "What is the Double Paradox?" → response mentions black hole merger

(one of the 13 hard facts from MNEMOS architecture)


FAILURE MODES

FM-01 — Google Colab auth silent failure

Description: Training cell runs to completion with no error, but no GCS uploads succeed.

DONE.json never appears. No output visible because Colab hides "private outputs."

Root cause: google.colab._auth.authenticate_user() fails in CDP-automated context.

Diagnosis: Read outputframe CDP target directly: Page.getFrameTree → find iframe with

outputframe → Runtime.evaluate in that context to see hidden output.

Fix: Remove all google.colab auth. Replace all GCS operations with pre-signed HTTPS URLs.

Source: COLAB_AUTOMATION.md lines 37-46. This was the root cause of 2.5hrs failure on v9 forge.

FM-02 — Wrong Monaco model injection

Description: Code is injected but the visible cell shows blank. Run All executes

the previous cell content (or empty cell). Training runs with wrong/no code.

Root cause: monaco.editor.getModels()[0].setValue() targets document model, not cell.

Fix: Always use model[2] or find focused editor via getDomNode().contains(activeElement).

Source: COLAB_AUTOMATION.md lines 113-119.

FM-03 — CPU runtime (no GPU)

Description: Training cell fails immediately with:

NotImplementedError: Unsloth cannot find any torch accelerator

Root cause: T4 GPU was not allocated before injection.

Fix: Verify runtime type before injecting code. Change runtime type → T4 GPU → Save → OK.

Source: COLAB_AUTOMATION.md lines 19-25.

FM-04 — Alpaca format template leak

Description: Model outputs ### Response: prefixes at inference time. Responses have

template artifact markers. QA scores artificially depressed.

Root cause: Training pairs formatted in Alpaca style instead of Qwen chat template.

Fix: Use tokenizer.apply_chat_template(messages, tokenize=False) exclusively.

Source: gloss_v9_colab_train.py lines 97-106.

FM-05 — Runaway generation loop (v9 confirmed)

Description: Symbol identity queries trigger infinite loop. Model emits escalating

variants of a pattern without terminating. Example: ⊙ α? → αα → ααα → ... until token limit.

Root cause (diagnosis): Training corpus contains repetition patterns for symbol definitions.

Model learns to repeat-with-increment rather than answer-and-stop. Generation stopping criteria

absent or inadequate.

Impact: Entire eval session after the looping prompt is unreachable.

Detection: Only visible in live generation test, NOT in σ_eval multiple-choice battery.

Status: v10 forging paused until corpus redesign + stop-token injection.

Version: v1.0

Source: GLOSS_LINEAGE.md lines 53-62.

FM-06 — gsutil subprocess false positive

Description: gsutil cat gs://bucket/DONE.json returns exit code 0 and empty content

even when the file exists, causing the monitor to believe training is not complete.

Fix: Use Python GCS SDK — blob.exists() + blob.download_as_text().

Source: COLAB_AUTOMATION.md lines 209-216.

FM-07 — MNEMOS facts overflow

Description: MNEMOS_FACTS.md exceeds 6KB. Ollama silently truncates the system prompt.

MNEMOS boots with partial facts — later items in the file (often most recent additions) are

absent from the model's context.

Detection: Test query for a recently-added fact returns "I don't have that information."

Fix: Keep MNEMOS_FACTS.md within 6KB. Archive older facts to MNEMOS_MEMORY.md which

feeds the deep retrain, not the fast-path.

Source: update_mnemos_facts.sh line 5.

FM-08 — Gemini panel blocking Run All

Description: CDP-injected Run All click lands on the Gemini assistant panel instead of

the "Run all" button. Cell does not execute. No error — just silence.

Symptom: "Accept & Run" / "Accept" / "Cancel" buttons visible in viewport right side.

Fix: Close Gemini panel via X button at display ~(1239, 188) before triggering Run All.

Source: COLAB_AUTOMATION.md lines 28-31.


DEPENDENCIES

DEP-01 — Virtual display (DISPLAY=:99)

Entire CDP automation layer requires Xvfb running at :99.

No virtual display → no browser control → no forge dispatch.

DEP-02 — CDP endpoint (Chromium remote debugging)

ws://localhost:9222 must be active. Page ID changes only if Chromium is restarted.

Verify: curl -s http://localhost:9222/json | python3 -m json.tool | grep Colab

Source: COLAB_AUTOMATION.md lines 86-91.

DEP-03 — GCS bucket (cgnt-1colab-jobs)

Single point of failure for DONE signal. All forge completions are signaled via

gs://cgnt-1colab-jobs/colab_jobs/gloss_vN_forge_output/DONE.json.

[GAP-06 — no backup or fallback if bucket is unavailable]

DEP-04 — Google Drive (cgnt1_adapters/)

Adapter storage between Colab session and local deploy. Colab → GDrive → local.

If GDrive is unavailable post-training, adapter is stranded in Colab (ephemeral session).

[GAP — no alternate artifact storage path]

DEP-05 — llama.cpp (GGUF conversion)

llama.cpp/convert_hf_to_gguf.py and llama.cpp/build/bin/llama-quantize must be

built and available locally.

DEP-06 — Service account JSON

~/.google_service_account.json — required for pre-signed URL generation (local side)

and DONE.json polling. Credentials must not be expired.

DEP-07 — GAMMA (retrain authority)

GAMMA decides when to retrain and what the training target is. The pipeline does not run

without GAMMA's directive.

Source: CLAUDE.md Mission MNEMOS standing order.


DEPENDENTS

being evaluated


EXAMPLES

Correct forge sequence (v9 — PROVEN, April 15 2026)


[κ] Σ.▷ — v9 forge dispatched via CDP.
    Training script: ~/colab_jobs/gloss_v9_combined.py
    Corpus: training_pairs_v9.jsonl (706 pairs)
    Runtime: T4 GPU confirmed
    Monaco model[2] set — content length: 4,892 chars
    Run triggered via Ctrl+Enter

[κ] Monitoring GCS every 3 min for DONE.json...
    gs://cgnt-1colab-jobs/colab_jobs/gloss_v9_forge_output/DONE.json

[κ] Σ.✓ — DONE.json found. Training: 1140 steps, loss: 0.345
    Running post-forge pipeline...
    python3 gdrive_download_v9.py → adapter pulled
    stream_merge.py → merged
    convert_hf_to_gguf.py → gloss_v9_f16.gguf
    llama-quantize → gloss_v9_Q4_K_M.gguf
    ollama create gloss:v9 → ef15d806c1a7 registered

[κ] Σ.✓ — eval: python3 gloss_eval_lx.py --model gloss:v9
    σ=0.337 | LX-C 75% | LX-E 75% | LX-A 50% | LX-B 12% | LX-H 12% | LX-Z/G/X 0%

[α.13] Initial graduation approved. ΩQ.◐

[LIVE TEST — FAILED]
    Prompt: "⊹: ⊙ α?" → runaway loop: αα, ααα, αααα... 90+ lines. Token limit hit.
    Source: GLOSS_LINEAGE.md lines 53-55.

[α.13] v9 DEMOTED. Σ.⊠. v10 PAUSED pending corpus redesign.
       INV-05 activated: σ_eval ≥ threshold NOT sufficient for graduation.

Correct MNEMOS fast-path (light retrain)


[GAMMA] MNEMOS_FACTS.md updated with BUDDHA_PROTOCOL content.
[κ] Σ.▷ — running update_mnemos_facts.sh
[κ] Σ.✓ — ollama create mnemos → success; ollama list confirms mnemos present
[κ] Σ.✓ — test query: ollama run mnemos "What is the Double Paradox?" → answered correctly
[α.13] Σ.⊤. MNEMOS updated.

GAPS

GAP-01 — No automated live generation test in pipeline

The eval battery (gloss_eval_lx.py) uses keyword-presence scoring on 50 multiple-choice

prompts. v9 proof: σ=0.337 passed Σ.◐ threshold but the model had catastrophic loop failure

visible only in live generation. A mandatory automated live generation test is not defined.

Required before any future graduation:

Source: GLOSS_LINEAGE.md lines 57-62.

GAP-02 — Stop-token / EOS injection in training corpus not defined

v9 failure mode: model learned to repeat-with-increment rather than answer-and-stop.

No specification for how training pairs should encode explicit stop signals. No EOS

enforcement in training configuration. This must be resolved before v10.

Source: GLOSS_LINEAGE.md lines 60-61.

GAP-03 — Distilling Step-by-Step not yet implemented

Training pairs are instruction→response only. No CSDM rationale is included.

Distilling Step-by-Step (teacher-student knowledge distillation with rationale chains)

would add "because [CSDM reasoning]" to each pair, improving generalization.

Listed as pending item #34 in MASTER_PRODUCT_LIST.md line 34.

Impact: model currently learns pattern matching, not causal reasoning about LATTICE.

GAP-04 — MNEMOS deep retrain pipeline not fully documented

The fast-path (update_mnemos_facts.sh) is documented. A deep retrain of MNEMOS

(Colab T4 QLoRA, like GLOSS) is referenced in project_mnemos_architecture.md

("Deep retrains: Google Colab (T4 GPU) via colab_dispatch.py") but colab_dispatch.py

spec and the MNEMOS Colab training script parameters are not formally documented.

Source: project_mnemos_architecture.md line 44.

GAP-05 — No formal live test protocol for graduation gate

INV-05 requires a live test before graduation, but no formal test set is defined.

Minimum probes, pass/fail criteria, who conducts the test, how results are logged —

all undefined. v9 used an informal probe that accidentally discovered the failure.

GAP-06 — GCS bucket is a single point of failure

All forge completions depend on gs://cgnt-1colab-jobs. No fallback signal mechanism

defined. If the bucket is unreachable, the pipeline monitor polls indefinitely.

GAP-07 — σ threshold not validated against live behavior

v9 showed σ=0.337 was above the Σ.◐ threshold (≥0.65 would require more pairs, but

the passing bar is not calibrated to live generation quality). The eval format

(multiple-choice keyword presence) may structurally overstate model capability.

Threshold recalibration required before v10.

Source: GLOSS_LINEAGE.md lines 57-58.

GAP-08 — No versioned corpus preservation checksum

Training pairs are in training_pairs_vN.jsonl files but no SHA-256 checksum is

recorded for each corpus version. If a file is modified after training, the link

between model weights and training data cannot be verified.


PRODUCTION PATH

GLOSS forge — confirmed scripts (per v9 execution)

| Stage | Script | Location |

|-------|--------|---------|

| Corpus | training_pairs_vN.jsonl | ~/gloss_training/ |

| Dispatch | gloss_vN_combined.py (injected) | ~/colab_jobs/ |

| CDP automation | cdp_*.py (PROVEN playbook) | ~/colab_jobs/ |

| Download | gdrive_download_vN.py | ~/gloss_training/ |

| Merge | stream_merge.py | ~/ |

| Convert | convert_hf_to_gguf.py | ~/llama.cpp/ |

| Quantize | llama-quantize | ~/llama.cpp/build/bin/ |

| Deploy | Modelfile_vN + ollama create | ~/ |

| Eval | gloss_eval_lx.py | ~/gloss_training/ |

| Deploy all | brain_deploy_all.sh | ~/ |

MNEMOS fast-path — confirmed scripts

| Stage | Script | Location |

|-------|--------|---------|

| Facts | MNEMOS_FACTS.md | ~/ |

| Update | update_mnemos_facts.sh | ~/ |

| Verify | ollama run mnemos [query] | (CLI) |

GCS bucket


REFERENCES

| File | Path | Relevance |

|------|------|-----------|

| CDP Playbook | ~/memories/COLAB_AUTOMATION.md | PROVEN v9 automation; all critical workarounds |

| GLOSS Lineage | ~/memories/GLOSS_LINEAGE.md | Version history, σ scores, v9 failure analysis, v10 status |

| Training Plan | ~/gloss_training/GLOSS_TRAINING_PLAN.md | Original plan v1; model selection; eval formula |

| Training script | ~/colab_jobs/gloss_v9_combined.py | v9 training parameters (rank=64, alpha=128, epochs=15) |

| Eval script | ~/gloss_training/gloss_eval_lx.py | 50q battery; 8 categories; σ formula + thresholds |

| MNEMOS arch | ~/memories/project_mnemos_architecture.md | Two-tier architecture; fast-path vs deep retrain |

| Facts script | ~/update_mnemos_facts.sh | MNEMOS fast-path implementation; 6KB limit |

| GLOSS eval spec | ~/memories/SPEC_GLOSS_EVAL_v2.md | Evaluation framework (downstream dependent) |

| Deploy script | ~/deploy_gloss_v8.sh | v8 full pipeline stages reference |

| CLAUDE.md | ~/CLAUDE.md | GAMMA authority; C.L.O.D. executor role |

| Master list | ~/memories/MASTER_PRODUCT_LIST.md | Item #34: Distilling Step-by-Step pending |


Jeremy Zlabis

Chronogeometer · Visionary · Disruptor · Chief

42 Sisters AI · East York, Toronto

🍁 Φ 0.042