Files
portal/docs/archive/llm-bootstrap-2026-05/ROLLBACK.md
T
Дмитрий f6b52df613 feat(brain): rollback infra + snapshots + e2e-verified BEFORE any destruction (phase 1 task 1)
Establishes a proven rollback mechanism for the LLM-first router overhaul before
any destructive step. Without this, Phase 1-3 work would be irreversible.

What this commit adds:
- Git tag 'brain-pre-llm-bootstrap' on origin/main 9d4a30c3 (pre-overhaul state).
- docs/archive/llm-bootstrap-2026-05/ archive structure with:
  - settings-snapshot/  — pre-overhaul ~/.claude/settings.json + project settings
  - user-hooks/         — all 14 ~/.claude/hooks/*.py pre-overhaul (incl. §12 ones)
  - runtime-flags-snapshot/ — pre-overhaul ~/.claude/runtime/*-mode.json
  - nodes-yaml-archive/ — pre-overhaul docs/registry/nodes.yaml
- tools/test-rollback.mjs    — rollback planner + executor (--dry-run / --execute)
- tools/test-rollback.test.mjs — TDD: 3 tests for planRollback() contract
- ROLLBACK.md — operator runbook with from->to manifest

E2E smoke proof was run BEFORE this commit (Task 1 step 9):
1. Created TEMP marker commit on top of tag with a dummy file + runtime flag.
2. Ran 'test-rollback.mjs --dry-run' (OK) then '--execute' (user state restored).
3. Reverted git-tracked state and verified marker + flag gone.
4. Verified Task 1 untracked files survived the rollback.

Smoke discovered a bug in the plan's procedure ('git checkout tag -- .' +
'git reset --soft tag' does NOT delete files committed-after-tag — they stay
staged). ROLLBACK.md uses 'git reset --hard <tag>' instead, which correctly
removes overhaul-added tracked files while preserving untracked artefacts
(episodes-*.jsonl, observer notes).

TDD: 3/3 green on test-rollback.test.mjs. Full vitest tools/: 546 passed (was
543 baseline, +3 from this commit), 4 pre-existing 'No test suite' failures
on tools/ruflo-* and tools/subagent-prompt-prefix.test.mjs (out of scope).

Plan: docs/superpowers/plans/2026-05-25-llm-first-router-overhaul.md Task 1.
Spec: docs/superpowers/specs/2026-05-24-llm-first-router-overhaul-design.md.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 14:28:01 +03:00

111 lines
5.5 KiB
Markdown

# Rollback Runbook — LLM-first router overhaul
**Anchor commit/tag:** `brain-pre-llm-bootstrap``9d4a30c3` (origin/main on 2026-05-25, before any Phase 1 destruction).
**When to use this:** any time the LLM-first overhaul (Phase 1/2/3) needs to be reverted in full. Partial rollback is via runtime flags (`~/.claude/runtime/*-mode.json`), not this runbook.
**Time to revert:** ~5 min (mechanical) + dependency reinstall.
## What this rollback restores
| Layer | Source of truth | Restore mechanism |
|---|---|---|
| Git-tracked files | tag `brain-pre-llm-bootstrap` | `git checkout brain-pre-llm-bootstrap -- .` |
| User settings (`~/.claude/settings.json`) | `settings-snapshot/user-settings.json.pre-overhaul` | `tools/test-rollback.mjs --execute` |
| User hooks (`~/.claude/hooks/*`) | `user-hooks/` (14 files snapshot) | `tools/test-rollback.mjs --execute` (full directory restore: wipes new hooks, restores snapshot) |
| Runtime flags (`~/.claude/runtime/*-mode.json`) | `runtime-flags-snapshot/` (only `router-gate-mode.json` at snapshot time) | `tools/test-rollback.mjs --execute` (strategy `restore-snapshot-delete-new`: deletes flags absent in snapshot, copies snapshot files back) |
| Node deps | `package-lock.json` from tag | `npm install` |
## What this rollback does NOT touch (intentional)
- `docs/observer/episodes-*.jsonl` — preserved (G6). Evidence accumulated during the experiment stays. Schema v4 episodes remain readable after rollback because the parser is forward-compatible (graceful skip of unknown schema versions — Task 15 / G5).
- `docs/observer/notes/*` — preserved.
- Database / production state — out of scope. This overhaul does not touch the portal's runtime.
## Procedure
### Step 1 — Verify rollback is ready (dry-run)
```bash
cd <repo root>
node tools/test-rollback.mjs --dry-run
```
Expected: `[dry-run] OK — rollback ready` and exit 0. If `MISSING ...` lines appear — **STOP**, fix the missing artefact first.
### Step 2 — Restore user-level state + runtime flags
```bash
node tools/test-rollback.mjs --execute
```
Expected output:
- `[execute] restored ~/.claude/settings.json`
- `[execute] restored ~/.claude/hooks/ (14 files)`
- `[execute] runtime flags: deleted N new, restored 1 from snapshot`
- `[execute] user-level + flags restored. Now run: git checkout brain-pre-llm-bootstrap -- . && npm install`
### Step 3 — Restore git-tracked state
```bash
git fetch origin
git reset --hard brain-pre-llm-bootstrap
git status
```
`git reset --hard <tag>` does both jobs in one shot: tracked files that EXISTED in the tag are restored to their tag content, and tracked files that were ADDED during the overhaul (e.g. `tools/test-rollback.mjs`, `tools/router-config.mjs`, `docs/archive/llm-bootstrap-2026-05/*`) are removed from the working tree.
**Why not `git checkout brain-pre-llm-bootstrap -- .`** (the naive command): `checkout -- <pathspec>` only restores files present in the target ref. Files committed during the overhaul but absent in the tag are left on disk and remain staged — the end-to-end smoke during Task 1 caught this. Use `reset --hard` instead.
Untracked files (never committed) survive `reset --hard`:
- `docs/observer/episodes-*.jsonl` — preserved by design (G6).
- `docs/observer/notes/*` — preserved.
- Any local scratch files — preserved.
If you want a fully hermetic revert that also wipes untracked files, follow with (use with care — also kills .gitignore'd local-only artefacts):
```bash
git clean -fd --exclude=docs/observer/episodes-*.jsonl --exclude='docs/observer/notes/*' --exclude=.env --exclude=node_modules
```
### Step 4 — Reinstall dependencies
```bash
npm install
```
Reverts `node_modules/` to the pre-overhaul tree (`@xenova/transformers` etc. removed; `package-lock.json` already restored by Step 3).
### Step 5 — Smoke verification
```bash
npx vitest run tools/ # all GREEN, no test-rollback or new modules
ls ~/.claude/hooks/ | sort # contains skill-marker.py + skill-check.py
cat ~/.claude/runtime/router-gate-mode.json # warn-only
git log --oneline -1 # brain-pre-llm-bootstrap (9d4a30c3)
```
Re-start Claude Code session to pick up restored user hooks.
## Snapshot manifest (from → to during execute)
| From (in archive) | To (live) |
|---|---|
| `settings-snapshot/user-settings.json.pre-overhaul` | `~/.claude/settings.json` |
| `user-hooks/*` | `~/.claude/hooks/*` (full replace) |
| `runtime-flags-snapshot/*.json` | `~/.claude/runtime/*.json` (new flags deleted) |
| `nodes-yaml-archive/nodes.yaml.pre-overhaul` | `docs/registry/nodes.yaml` (via `git checkout` in Step 3) |
| `settings-snapshot/project-settings.json.pre-overhaul` | `.claude/settings.json` (via `git checkout` in Step 3) |
## Failure modes
- **Tag missing**: `MISSING git tag: brain-pre-llm-bootstrap`. Recreate from the commit it pointed to (`git tag brain-pre-llm-bootstrap 9d4a30c3`).
- **Snapshot file missing**: same `--dry-run` will name it. Snapshots are also reachable via `git show brain-pre-llm-bootstrap:docs/archive/llm-bootstrap-2026-05/...` after Task 1 commit — never lose them.
- **User hooks partial restore**: `--execute` wipes the live hooks dir before restoring. If the snapshot is corrupted, Claude Code will start without hooks (graceful degrade) — restore from `git show`.
## Verification log
End-to-end smoke proof of this rollback was executed BEFORE any destructive Phase 1/2/3 work — see Task 1 Step 9 in `docs/superpowers/plans/2026-05-25-llm-first-router-overhaul.md` and the test-rollback commit message.