Skip to content

feat: molt - self-healing update agent#2

Merged
CoreyH merged 7 commits into
mainfrom
molt
Jan 26, 2026
Merged

feat: molt - self-healing update agent#2
CoreyH merged 7 commits into
mainfrom
molt

Conversation

@CoreyH
Copy link
Copy Markdown
Owner

@CoreyH CoreyH commented Jan 25, 2026

Summary

Molt is a self-healing update system for self-hosted Clawdbot instances. It handles nightly updates from upstream with automatic rollback if something breaks.

Lobsters molt to grow — shedding their old shell and emerging fresh.

The Problem

Running Clawdbot on a self-hosted server means you want automatic updates. But updates can break things:

  • pnpm install fails (network, deps)
  • New code crashes the gateway
  • Gateway doesn't come back up
  • You're asleep when this happens

Currently: bot goes silent, you discover hours later, SSH in, diagnose, fix.

The Solution

Molt runs nightly and:

  1. Updates safely — pulls, installs, builds, restarts
  2. Verifies health — stability window catches crash loops
  3. Rolls back automatically — if health check fails
  4. Reports status — changelog + Slack notification

Key Design Decisions

Agentic Recovery

Traditional self-updaters are deterministic (blue/green, staging dirs). Molt is simpler: try, verify, rollback if broken. If rollback also fails, capture context for the AI (or human) to fix it.

Module Manifest

Personalized health checks. If you only use Slack, a broken Discord adapter isn't worth rolling back for:

{
  "modules": { "channels": ["slack"] },
  "healthCriteria": { "channels": "all" }
}

Files Changed

  • docs/molt.md — Full PRD with architecture and rationale
  • scripts/molt.sh — Reference implementation (bash)
  • .gitignore — Ignore local workspace files

Status

Running in production. Successfully updated 289 commits this morning:

STATUS: SUCCESS
FROM: 309fcc53 → TO: 003fff06
COMMITS: 289

Open Questions

  1. Where should this live? Core, plugin, or standalone?
  2. Auto-discover module manifest from config?
  3. TypeScript rewrite vs bash?

RFC — seeking feedback before formal upstream PR.

Corey H and others added 3 commits January 25, 2026 13:58
Molt is a self-healing update system for self-hosted Clawdbot instances.
It handles nightly updates from upstream with automatic rollback if
something breaks.

Key features:
- Pulls from upstream, installs deps, builds, restarts gateway
- Health check with stability window (catches crash loops)
- Automatic rollback to pre-update commit on failure
- Module manifest to define what *you* care about (personalized health checks)
- Changelog generation for morning reports
- Agentic recovery philosophy: capture context, let the AI fix edge cases

Files:
- docs/molt.md: Full PRD with architecture, config schema, and rationale
- scripts/molt.sh: Reference implementation (bash)

This is an RFC seeking feedback on approach and integration strategy.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
After a successful rollback, molt now triggers the clawdbot agent to
diagnose and fix the issue. The agent receives crash logs and context,
attempts common fixes, and reports to the user if manual intervention
is needed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace hardcoded "Corey" references with generic "the user" and
"configured channel" so the script works for any clawdbot user.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Corey H and others added 3 commits January 25, 2026 14:29
- Fix: mkdir -p for MOLT_DIR/WORKSPACE_DIR before use
- Fix: Replace broken `source --rollback-internal` with rollback() function
- Fix: Rollback now uses git checkout + reset --hard (no detached HEAD)
- Fix: Auto-switch to expected branch if on wrong branch
- Add: Recovery attempt marker prevents infinite agent loops
- Add: Capture pnpm-install.log and pnpm-build.log for agent context
- Add: Prompt injection guardrails in agent prompts (treat logs as data)
- Remove: Unused PING_TIMEOUT variable
- Change: git diff --stat now uses head -50 instead of tail -20

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add detailed cron job prompts for nightly update and morning report
- Add notify.target field to config.json (use platform user IDs, not usernames)
- Add troubleshooting section for common notification issues
- Document freshness check (30h window) to avoid stale reports
- Explain message tool fallback behavior
- Add error handling for git fetch in Phase 0
- Add error handling for pnpm install and build in Phase 1
- Fix heredoc quoting to allow variable expansion in recovery prompt
- Use time-based health check loop instead of counter-based
- Standardize changelog path to ~/.clawdbot/molt/changelog.md
- Make wake command syntax consistent (--mode now)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
cosmo-kring added a commit that referenced this pull request Jan 26, 2026
Adds the molt update system with portable configuration:
- Environment variable overrides for paths (CLAWDBOT_DIR, WORKSPACE_DIR, etc.)
- XDG_RUNTIME_DIR export for systemctl --user on headless servers
- Sensible defaults that work across different setups

From: #2

Co-Authored-By: CoreyH <corey@example.com>
- Use env var defaults for CLAWDBOT_DIR, WORKSPACE_DIR, REMOTE, BRANCH
- Export XDG_RUNTIME_DIR for systemctl --user on headless servers
- Tested on Hetzner VM with different directory layout
@CoreyH CoreyH merged this pull request into main Jan 26, 2026
10 of 41 checks passed
CoreyH pushed a commit to KRING-Ventures/cosmo-clawdbot that referenced this pull request Feb 1, 2026
Adds the molt update system with portable configuration:
- Environment variable overrides for paths (CLAWDBOT_DIR, WORKSPACE_DIR, etc.)
- XDG_RUNTIME_DIR export for systemctl --user on headless servers
- Sensible defaults that work across different setups

From: CoreyH#2

Co-Authored-By: CoreyH <corey@example.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants