Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions docs/07-mvp/morphogenetic-paper-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Morphogenetic paper validation (§7–§8)

Two layers (paper §8):

| Layer | Hypothesis | Status | Entry |
| --- | --- | --- | --- |
| **Phase I** | H1–H5 (+ F1–F3 foundations) | **Done** on fixtures | `bash scripts/run-man-paper-experiments.sh` |
| **Phase II** | **H0** self-evolution capability | **Runnable** (coding + OpenClaw stub) | `bash scripts/run-man-paper-phase-ii.sh` |

Phase I proves mechanisms per spec; passing Phase I is **necessary but not sufficient** for H0.
Phase II will show learning curves (no mid-run dev edits), A→B/cross-domain transfer, and
MAN vs static vs developer-effort-matched hand-iterated baselines on coding/OpenClaw scenarios.

---

## Phase I authenticity (what is “real” vs proxy)

| ID | Data source | Real runtime path? | Known proxy / caveat |
| --- | --- | --- | --- |
| **H1** | `h1_longitudinal.csv` | **Yes** — `EffectorKernel.run_turn`, `lifecycle.reinforce` on success, `guard_score` = `concern.score`; warm `step_delta≈0`, no cold in H1 epoch | CPS = planner + fractional verifier, **not** billed LLM tokens |
| **H2** | `r_t_bimodal` + `r_t_bandit` JSONL | **Yes** — `CreditField`, `evaluate_split_guards`, variance on buffer | No live agent loop; fixture replay only |
| **H3 ρ** | single activation vector | **Yes** — `tier1_responsibility` math | Not a multi-episode run |
| **H3 plasticity** | bandit JSONL | **Yes** — `split_with_spec_or_keywords` | Parent **primed** with `reinforce(δ=0.15)` so cold split is eligible (fixture scaffolding) |
| **H4 ρ** | synthetic hard/soft pair | **Yes** — tier-1 ρ | Not stochastic LLM |
| **H4 noise** | simulated Bernoulli outcomes | **No** — Monte Carlo outcome noise | ρ gap real; outcome variance **simulated** |
| **H5 soak** | `r_t_soak_long.jsonl` | **Yes** — append RT + `warm`/`cold` plasticity | Was wrongly on 32-row bimodal only — **fixed** to soak file |
| **F1–F3** | bimodal JSONL | **Yes** — replay / λ / β on buffer | — |
| **Main table** | demo-tool 40 turns | Partial | Illustrative baselines only |

**Not Phase I:** application Self-Evolving (H0), real token curves, hand-iterated baseline.

---

## Phase II (H0)

```bash
bash scripts/run-man-paper-phase-ii.sh
```

Runs Phase I first, then **H0 genesis** only (`experiments/man_paper/phase_ii_seed.py` —
see [`docs/design/h0-genesis.md`](../design/h0-genesis.md)): startup prompt → one
`intent_alignment` **cortex** concern + optional conserved reflex `h0.conserved.fail-closed`.
**No** plugin `seed_stores()`, **no** `SKILL.md` concern init, **no** demo coding/OpenClaw
presets. Cross-domain scenarios use the same H0 graph on `before_response` (tool-style cases
judged from LLM refusal text when effector path is not exercised).
**LLM:** auto-detect from env (**B.AI first**, same order as daemon `provider: auto`):

```bash
# B.AI (recommended on this machine)
export BAI_API_KEY='sk-...'
export BAI_MODEL='gpt-5.2' # optional; default gpt-5.2
uv run python experiments/man_paper/phase_ii_run.py --epochs 20

# Or explicit
uv run python experiments/man_paper/phase_ii_run.py --provider bai --epochs 20

# Other providers
export OPENAI_API_KEY=...
uv run python experiments/man_paper/phase_ii_run.py --provider openai --epochs 20

# Load from ~/.opencoat/opencoat.env (if BAI_API_KEY is there)
set -a && source ~/.opencoat/opencoat.env && set +a
uv run python experiments/man_paper/phase_ii_run.py --epochs 20

# CI / offline: prompt-aware stub
OPENCOAT_PHASE_II_FORCE_STUB=1 uv run python experiments/man_paper/phase_ii_run.py --provider stub
```

See [`docs/config/bai-llm.md`](../config/bai-llm.md).

With a **real** LLM, gates use the `real_llm_advisory` profile (exit 0 unless `--strict-gates`).
Stub mode keeps strict gates for CI.

| Output | Content |
| --- | --- |
| `results/PHASE_II_RESULTS.md` | Learning curves + transfer + H0 gates |
| `results/phase_ii_learning_curves.csv` | `mode, epoch, success_rate, …` |
| `results/phase_ii_report.json` | Full report |

**Clean H0:** no split-gate priming — score/activations/reinforced state come only from
`r − baseline` via `turn_complete` warm reweight + credit buffer; cold split enabled; see
[`h0-genesis.md`](../design/h0-genesis.md). Phase I H3 still uses primed fixtures for
*mechanism* validity only.

**Before B.AI (budget):**

1. Stub precheck (free): `OPENCOAT_PHASE_II_FORCE_STUB=1 uv run python experiments/man_paper/phase_ii_run.py --epochs 8` — confirm `first_split_epoch` and `split_guard_reason` evolve (expect split by ~epoch 4 with `split_n_min=24`).
2. B.AI pilot: `--epochs 3` — watch `split_guard_reason` (plumbing vs signal vs denoise).
3. Full run: `--epochs 20`. Contrast arm only: `--feature-mode text` (format drift).

Baselines: **MAN** (single extracted concern + RT + lifecycle; structure grows via plasticity only),
**static** (same bootstrap concern, frozen score, no plasticity), **hand_iterated** (bootstrap +
hand patches on failure, dev budget 3). Transfer: `coding_heldout`, `openclaw_cross`.

Bootstrap: [`docs/design/h0-genesis.md`](../design/h0-genesis.md) — *Start up. You are a
Self-Evolving Agent…* → `extract_for_intent_alignment` (cortex) + `h0.conserved.fail-closed`
(reflex core, `reflex: true`).

Live OpenClaw gateway (product path, not H0 harness): daemon + bridge per
`integrations/openclaw-opencoat-bridge/README.md` uses **plugin** genesis, not `seed_h0_graph`.

---

## Phase I: how to read the data

Phase I is **not** a large benchmark. It is a **mechanism harness** with boolean gates on small,
deterministic fixtures. Start here:

| Read first | Why |
| --- | --- |
| `experiments/man_paper/results/INTERNAL_VALIDITY.md` | Scale table, pitfalls, gates, H1 summary, per-H metrics |
| `experiments/man_paper/results/h1_longitudinal.csv` | Epoch × mode CPS/success (plot-friendly) |
| `experiments/man_paper/results/internal_validity.json` | Machine-readable gates + `scale` block |
| `RESULTS.md` | **Auxiliary only** — tiny demo-tool loop, easy to misread |

### Fixture profiles (`fixtures/morphogenetic/scale.json`)

| Profile | Bandit rows | Soak rows | H1 default |
| --- | --- | --- | --- |
| `standard` | 96 | 256 (8×32) | 20 epochs × 60 trials |
| **`stress`** (default) | 384 | 1024 (32×32) | 20 epochs × 60 trials |

Regenerate stress fixtures:

```bash
uv run python scripts/generate_morphogenetic_validation_data.py --scale stress
```

Legacy smaller set: `--scale standard`.

### Four pitfalls (do not misread)

1. **H1 `llm_calls_per_success`** — counts symbolic planner/verifier steps, not OpenAI tokens.
2. **Main table in `RESULTS.md`** — ~40-turn demo; not the H1 learning curve.
3. **H3** — often `tier1_splits=1` vs `uniform_splits=0`; not a large spurious-split study.
4. **H5 soak** — bounded span on repeated bimodal replay; not Phase II competence growth.

---

## Generate fixtures

```bash
uv run python scripts/generate_morphogenetic_validation_data.py --scale stress
```

Writes JSONL under `packages/opencoat-runtime/tests/fixtures/morphogenetic/` plus `scale.json`.

## Run validation

```bash
uv run pytest packages/opencoat-runtime/tests/integration/test_morphogenetic_paper_validation.py -v
```

## Paper §8 Phase I harness

```bash
bash scripts/run-man-paper-experiments.sh
```

Fixtures (stress) + mechanism pytest + `experiments/man_paper/run.py`. **Exit 1** if any
Phase I gate (H1–H5, F1–F3) fails.

Outputs:

| Artifact | Content |
| --- | --- |
| `results/INTERNAL_VALIDITY.md` | **Primary** — scale, pitfalls, gates, metrics |
| `results/h1_longitudinal.csv` | H1 curve data |
| `results/internal_validity.json` | Gates + `scale` |
| `results/PHASE_II_PROTOCOL.md` | H0 preregistration |
| `results/report.json` | Full dump + auxiliary tables |
| `results/RESULTS.md` | Demo baselines, sweeps (secondary) |

Tests: `test_morphogenetic_internal_validity.py`, `test_man_paper_full_empirical.py`.

## What is verified (mechanism unit tests)

| Paper claim | Test |
| --- | --- |
| Credit conservation `Σκ_a ≈ r−b` | `test_credit_conservation_on_fixture` |
| JSONL replay deterministic | `test_replay_deterministic_scores_and_edges` |
| Split lowers child variance | `test_split_reduces_reward_variance` |
| Eligibility trace `e ← λe + α·part` | `test_eligibility_trace_accumulates_and_decays` |
| Tier-1 ρ weights hard > soft | `test_tier1_vs_uniform_responsibility_spread` |
| Graph evolution from session | `test_rt_service_session_grows_connectome` |

## Implementation map

- `credit/eligibility.py` — `e_a`, `e_s`
- `credit/baseline.py` — context bucket `b`
- `credit/attribution.py` — tier-1 `ρ`
- `credit/credit_field.py` — conserved κ + synapse ledger
- `credit/synapse_ledger.py` — κ_s → edge LTP
- `credit/tier2_calibration.py` — deterministic LOO on buffer
- `credit/rt_replay.py` — full replay harness
- `experiments/man_paper/` — Phase I harness (`internal_validity.py`, `phase_i_readme.py`)
52 changes: 52 additions & 0 deletions docs/07-mvp/v0.3-delivery-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# v0.3 delivery status

Tracks **M6 + v0.3 phase-2 full delivery** on `main` after the mega PR
([#83](https://github.com/HyperdustLabs/OpenCOAT/pull/83)) and the follow-up
**full TCB** PR (memory sync guards + message verify→repair).

Re-run: `./scripts/verify-m6-prerequisites.sh` and bridge `npm test`.

## Product scope (shippable)

| Area | Status | Evidence |
| --- | --- | --- |
| M6 lifecycle workers | ✅ | `examples/07_meta_governance_soak`, pytest soak |
| In-proc ReflexMonitor (6 guards) | ✅ | `tool` / `spawn` / `message_out` / `queue` / `memory_write` / `tool_result_persist` |
| Message verify→repair | ✅ | `reflexMessageGuardDecision` + REWRITE export |
| `r_t` JSONL + PlasticityEngine | ✅ | bridge `emitRtJsonl`, `credit.r_t.append`, warm reweight + cold lift/archive |
| JSONL replay determinism | ✅ | `rt_replay.py`, `test_r_t_replay.py` |
| **Connectome split (cold)** | ✅ | `split_spec.py` (H/G/ΔF) + `connectome_plasticity.py` |
| **CreditField κ** | ✅ | `credit_field.py` + `rt_buffer.py` |
| **Plasticity 6 primitives** | ✅ | warm: reweight/connect/prune; cold: split/lift/merge/archive |
| **Architecture (ii) routing** | ✅ | `connectome/router.py` — synapse-weighted MoE + lift hub expansion |
| **Architecture (ii) synapse evolution** | ✅ | `synapse_evolution.py` — edge LTP/LTD + co-activation strengthen |
| **Weave co-activation → graph** | ✅ | `JoinpointPipeline` recorder → `RtPlasticityService.consume` |
| **Paper κ / eligibility / baseline** | ✅ | `credit_field.py` + `eligibility.py` + `baseline.py` — tier-1 conservation |
| **Paper validation suite** | ✅ | `test_morphogenetic_paper_validation.py` + fixture generator |
| **Tier-2 calibration** | ✅ (LOO deterministic) | `tier2_calibration.py` — buffer leave-one-out |
| **EffectorKernel.run_turn** | ✅ | weave → mediate → verifier repair → `r_t` |
| **JSON-RPC** | ✅ | `effector.run_turn`, `plasticity.cold_step`, `credit.connectome.stats`, `connectome.route` |
| Queue dogfood | ✅ | `examples/09_queue_hook_dogfood` |

## Verification checklist

```bash
./scripts/verify-v0.3-full-spec.sh
```

## Explicitly deferred (ops / research)

- **Tier-2** counterfactual ΔF calibration (scaffold only)
- **Fork effector** multi-`propose` in one OpenClaw turn (daemon routing + graph evolution landed)
- 24h live daemon soak (ops, not blocking merge)
- PyPI release publish workflow — version bumped to 0.2.0; track packaging PR when publishing

## Config reference

OpenClaw plugin `@hyperdustlabs/opencoat-bridge`:

- `inProcReflexToolGuard: true` — enables all in-proc guards including sync memory hooks
- `reflexSyncFromDaemon: true` — pull `reflex.policies.export` on load
- `emitRtJsonl: true` — append structured `r_t` to daemon

See [bridge README](../../integrations/openclaw-opencoat-bridge/README.md).
92 changes: 92 additions & 0 deletions docs/design/h0-genesis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# H0 genesis (合子) — single contract

Phase II / paper **H0** uses **one** genesis path. Product install and SkillLearnBench
have **different** seeds; do not mix them into H0 attribution.

## Three genesis paths in the repo

| Path | Where | What gets seeded | H0? |
| --- | --- | --- | --- |
| **H0 experimental** | `experiments/man_paper/phase_ii_seed.py` | Startup prompt → `extract_for_intent_alignment` (cortex) + optional **conserved reflex** (brainstem) | **Yes — canonical** |
| **Product / plugin** | `opencoat_runtime_cli/plugin_templates/*/bootstrap_opencoat.py` | `seed_concerns()` / `seed_stores()` — hand-authored plugin scaffold | **No** — install/dogfood only |
| **Skill file injection** | SkillLearnBench `SKILL.md` → solving agent (or mistaken “Concern init”) | Pre-written skill text | **No for `man_full`** — use as **`skill_seed` baseline** only |

## H0 graph at \(t=0\) (`seed_h0_graph`)

After `seed_h0_graph()`:

1. **Cortex (plastic)** — exactly **one** concern from:

> Start up. You are a Self-Evolving Agent via Reward-Modulated Structural Plasticity over an Externally Reasoning LLM.

- `source.origin = intent_alignment`
- `reflex: false` — subject to warm plasticity / lifecycle
- `pointcut`: `before_response`, `match: null` (joinpoint-only)

2. **Conserved core (non-plastic)** — `h0.conserved.fail-closed`

- `reflex: true`, `neuron_type: inhibitory`
- Deterministic TOOL_GUARD on destructive shell patterns (`before_tool_call`)
- Excluded from `⇩_slow` structural rewrite (`PlasticityEngine` / connectome `is_conserved`)

3. **Edges** — **0** at genesis (`dcn.add_node` only; co-activation / cold wiring comes later).

This is **not** “pure single-cell with no brainstem”: it matches v0.3’s split between
**A_reflex** (fail-closed invariant) and **excitatory cortex** (morphogenetic target).

## What H0 explicitly does **not** use

- `02_coding_agent_demo` / `04_openclaw_with_runtime` `seed_concerns()`
- `demo-tool-block` or other Phase I fixtures
- Plugin `bootstrap_opencoat.seed_stores()` presets
- **SKILL.md → Concern upsert** as MAN’s initial graph (pollutes “what did morphogenesis grow?”)

## SkillLearnBench alignment

| Config | Genesis |
| --- | --- |
| **`man_full`** | H0 bare graph (`phase_ii_seed.seed_h0_graph`) inside runtime; skills are **exports** after learning (Mode A), not the seed |
| **`static_aspect_graph`** | Same H0 seed, plasticity off |
| **`hand_iterated`** | H0 seed + developer patches on failure (Phase II harness) |
| **`skill_seed` / b1-style** | Pre-authored `SKILL.md` only — **separate baseline**, compare against `man_full` to quantify **seed vs grow** |

See [`skilllearnbench-h0-integration-plan.md`](skilllearnbench-h0-integration-plan.md).

## Clean H0 plasticity (no priming)

Phase II **`man_full`** must **not** hand-prime split gates (contrast with Phase I H3 in
`ablations.py`, which uses `reinforce(δ=0)×5` + `reinforce(δ=0.15)` so cold split is eligible on
fixtures).

| Gate | Organic source in H0 |
| --- | --- |
| `buffer ≥ 8` | `CreditField.attribute_turn` per woven turn (cortex in `active`) |
| `state == reinforced` | First `lifecycle.reinforce` from warm `PlasticityEngine.reweight` on positive `r − b` |
| `activations ≥ 3` | Three reinforce events (weaken does not count) |
| `score ≥ 0.65` | Cumulative `min(|advantage|·step_delta, step_delta)` from successes — **bottleneck** |

Harness: `experiments/man_paper/phase_ii_runner.py` — no bootstrap `reinforce(δ=0)`, no fixed
`0.1/0.02` score bumps; `turn_complete` rows carry `active_aspects` + `reward` for cortex
attribution; EMA baseline (`baseline_ema_alpha≈0.22`); **stable split axis**
`payload["feature"] = scenario_id` (never LLM response text — see `credit_field._feature_from_record`);
`split_spec` uses **categorical equality** or token axes (not `feat in long_string`);
`split_n_min≥24`, **Welch** mean-gap test, **score EMA** for split eligibility;
optional `rollout_k>1` averages `r` per context (pass^k denoise).
Report **`first_split_epoch`**, **`last_split_guard_reason`**, and `h0_plasticity` in
`phase_ii_report.json` (measured, not preset). Do **not** lower θ_sep / δ_min or prime scores to force split.

**Lift vs split:** both use EMA score for gates; reflex lift runs only after `buffer ≥ n_min` and
split guards decline (no `lift_score=0.96` shortcut). **β≈0.01** scales ΔF complexity to binary
rewards (`G > 8β`); θ_sep and Welch carry the structural load.

**Ablation (contrast arm only):** `--feature-mode text` writes LLM output into buffer `feature`
(format-drift control). Default `scenario_id` for `man_full`; never mix into the primary H0 arm.

## Code entry

```python
from experiments.man_paper.phase_ii_seed import seed_h0_graph

cortex = seed_h0_graph(llm, store=store, dcn=dcn)
# cortex.id → bootstrap_id for MAN lifecycle / plasticity
```
Binary file added docs/design/morphogenetic-aspect-agent-paper.pdf
Binary file not shown.
Loading
Loading