archy/loop/plan.md
Dorian f9a47a2602 test: US-10 backup/restore tests pass 80/80 — add rate limit headroom
- Add US-10 backup/restore test section to test-cross-node.sh
- Test cycle: create → list → verify → delete, 10 iterations × 2 nodes
- Increase backup.create rate limit from 3/600 to 10/600 (still conservative)
- Increase backup.restore rate limit from 2/600 to 5/600
- Clean up 21K+ stale DWN test messages on both servers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 02:11:24 +00:00

474 lines
44 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Archipelago 5-Year Production Hardening Plan
**Version**: 2.0
**Period**: March 2026 -- March 2031
**Goal**: Production-ready Bitcoin Node OS at 10,000 users with zero failures, 100% uptime, full inter-node federation
**Visual constraint**: NEVER change animations, user experience, or flow -- only clean up duplications, information hierarchy, and cosmetic issues
**Web5 additions**: did:dht, DWN protocol definitions for interoperable schemas, Verifiable Credentials (per TBD assessment)
**Primary test node**: `192.168.1.228` (Arch 1) — 4-core i3-8100T, 16GB RAM, 1.8TB NVMe
**Secondary test node**: `192.168.1.198` (Arch 2) — 8GB RAM, 457GB disk
**SSH**: `ssh -i ~/.ssh/archipelago-deploy archipelago@{IP}`
**Deploy**: `./scripts/deploy-to-target.sh --both`
---
## SECURITY RULE: No Tor Address Publishing to Nostr Relays (2026-03-13)
**NEVER publish .onion addresses to public Nostr relays.** This was removed on 2026-03-13 because broadcasting Tor addresses to public relays defeats the purpose of Tor's privacy. All `publish_node_identity` calls have been removed from:
- `tor.rs` — address rotation no longer publishes to relays
- `node.rs``node.nostr-publish` RPC now returns an error
- `network.rs` — visibility changes no longer publish to relays
Nodes connect via **federation ID** (DID), not public Nostr discovery. Federation peer notification (private peer-to-peer) is still allowed.
Tor rotation now **immediately destroys** the old address (no transition period). Old keys are deleted, not renamed.
All Tor addresses on .228 and .198 were rotated on 2026-03-13 to invalidate any previously published addresses.
---
## Critical Findings from Investigation (2026-03-13)
### Server .228 Issues
- **6 containers in crash loops**: archy-nbxplorer (3,535 restarts), archy-mempool-web (2,041), mempool-api (906), btcpay-server (888), mempool-electrs (529), immich_server (439)
- **Root cause**: Container networking DNS failures — mempool-web can't resolve "mempool-api" upstream, nbxplorer can't connect to Postgres
- **Load average 5.44 on 4 cores** — entirely caused by crash/restart cycles consuming CPU
- **ollama in Created state** — never started, consuming a container slot
- **Podman rootless warning**: "/" is not a shared mount
### Server .198 Issues
- **No federation configured** — /var/lib/archipelago/federation/ is empty
- **Tor container outdated** (v0.4.6.10) — warns "missing protocols: FlowCtrl=2 Relay=4", will eventually stop working
- **Tor failing every 5 minutes**: "No more HSDir available to query" — can't resolve .onion addresses
- **Memory critically low**: 147MB free of 8GB, NO SWAP configured
- **Nostr identity revoked** — nostr_revoked file exists but empty
- **Containers run under root** — rootless podman shows nothing, sudo podman shows 35 containers
### Cross-Node Issues
- .228 → .198 HTTP health: OK (basic connectivity works)
- .198 → .228 HTTP health: OK
- .198 has ZERO federation peers — no nodes.json, never joined federation
- Tor-based federation impossible from .198 — Tor can't resolve hidden services
- No swap on either server — OOM kills likely under load
- ping not installed on .228 (missing iputils-ping)
---
## User Stories & Acceptance Tests
Every test must pass **10 consecutive times** from BOTH .228→.198 AND .198→.228 directions.
### US-01: System Health
> As a node operator, I want my server to boot cleanly with all services running, zero crashed containers, and stable resource usage, so I never have to manually intervene.
### US-02: Container Lifecycle
> As a node operator, I want every installed app to start, run, survive reboots, and recover from crashes automatically, so my services are always available.
### US-03: Federation Join
> As a node operator, I want to invite another node to my federation using an invite code, so we can share status and deploy apps to each other.
### US-04: Federation Sync
> As a node operator, I want to see all my federated peers' status (online/offline, apps, resources) updated every 5 minutes, so I know my network health.
### US-05: Tor Hidden Services
> As a node operator, I want each app to have a .onion address that works reliably, so my services are accessible over Tor without exposing my IP.
### US-07: File Sharing
> As a node operator, I want to share files with federated peers over Tor with access controls (free, peers-only, paid), so I can selectively distribute content.
### US-08: DWN Sync
> As a node operator, I want DWN messages and protocols to replicate bidirectionally between my federated nodes over Tor, so my decentralized data is available everywhere.
### US-09: NIP-07 Signing
> As a node operator, I want iframe apps to use window.nostr to sign events with my node's Nostr key (with consent), so I can use Nostr apps with my sovereign identity.
### US-10: Backup/Restore
> As a node operator, I want to create encrypted backups and restore them on a fresh install, so I never lose my data or identity.
### US-11: Dashboard Monitoring
> As a node operator, I want real-time CPU, RAM, disk, and container health displayed on my dashboard, so I can spot problems before they escalate.
### US-12: Auto-Updates
> As a node operator, I want my node to check for updates, download them with integrity verification, and apply them with rollback capability.
### US-13: Identity & Credentials
> As a node operator, I want W3C DID Documents and Verifiable Credentials that work with did:dht for discoverable DIDs and proper VCs for proving identity claims between nodes.
### US-14: Web UI Navigation
> As a node operator, I want every page in the UI to load correctly, show real data (not hardcoded), and navigate without broken links or dead buttons.
### US-15: Boot Recovery
> As a node operator, I want all containers to automatically restart after any reboot, crash, or power loss, with zero manual intervention required.
---
## Phase 1: Emergency Stabilization (Week 1-2)
### Sprint 1: Stop the Crash Loops
- [x] **CRASH-01** — Fix container networking on .228. **Root cause**: UFW blocking all traffic from Podman subnets (10.88.0.0/16, 10.89.0.0/16) to host, preventing Aardvark DNS resolution. **Fix**: `ufw allow from 10.88.0.0/16` and `ufw allow from 10.89.0.0/16`. All containers on archy-net can now resolve hostnames. mempool-web stable 30+ minutes, 0 restarts.
- [x] **CRASH-02** — Fix archy-nbxplorer Postgres connection on .228. **Same root cause as CRASH-01**: UFW blocking DNS. After UFW fix, nbxplorer resolves archy-btcpay-db hostname and connects to Postgres. Both nbxplorer and btcpay-server stable 30+ minutes.
- [x] **CRASH-03** — Fix immich_server crash loop on .228. **Same root cause as CRASH-01**: UFW blocking DNS. Immich components on immich-net could not resolve each other. After UFW fix, immich_server started and is running stable 30+ minutes. Logs show successful Nest application startup on port 2283.
- [x] **CRASH-04** — Removed ollama on .228. `sudo podman rm ollama`. Container gone, total count reduced from 33 to 32.
- [x] **CRASH-05** — Verified .228 stability. All 32 containers running, zero exited, zero new crash loops for 30+ minutes. Load avg ~5.3 (high due to 32 containers on 4-core machine, not crash loops — was same before). Memory 1.8GB available (needs swap, see STAB-02). Health checks passing.
### Sprint 2: Stabilize .198
- [x] **STAB-01** — Added 4GB swap on .198. Created /swapfile, added to /etc/fstab for persistence. `free -h` shows 4.0Gi swap.
- [x] **STAB-02** — Added 8GB swap on .228. Recreated existing 4GB swapfile as 8GB. Added to /etc/fstab. `free -h` shows 8.0Gi swap.
- [x] **STAB-03** — Updated Tor on .198 (system service, not container). Added Tor Project apt repo, upgraded from 0.4.7.16 to 0.4.9.5. Restarted service, bootstrapped 100% in 10s. No "missing protocols" warnings. Hidden service hostname readable: mq2leoozlaouf6yuab7wf5i6le4fp7d52bo4l5cp5nkxo3udbkumqtad.onion.
- [x] **STAB-04** — Tor .onion resolution working on .198 after upgrade to 0.4.9.5. Local onion resolves (curl returns "OK"). Cross-node: .198 can reach .228's onion (2vbxxly...onion/health returns "OK"). "No more HSDir available" errors stopped.
- [x] **STAB-05** — Nostr identity on .198 is functional. `nostr_revoked` is intentional — blocks old-style discovery that leaked onion addresses. New `publish_presence` via nostr_handshake works independently. Pubkey exists: `a37e28bc663b0eff59c954247b2a0b00e110babf50bcf3f2e080a8ba6888c03a`. 8 relays configured. Backend restarted cleanly after removing stale empty revocation file (it correctly recreated it).
- [x] **STAB-06** — Federation already established between .228 and .198. Verified: .228 `federation.list-nodes` shows 2 trusted peers with today's timestamps and app lists. .198 has nodes.json (3.6KB) and peers.json with valid onion address. Password reset to `password123` on .228 for future RPC access.
- [x] **STAB-07** — Rootless vs root podman on .198 is correctly aligned. Backend runs as root (systemd User=root), uses `sudo podman` via PodmanClient. Root podman shows all 34 containers. Backend's running-containers.json tracks all 34. Health monitor works.
---
## Phase 2: Cross-Node Test Suite (Week 3-4)
### Sprint 3: Create Bulletproof Test Harness
- [x] **TEST-01** — Created `scripts/test-cross-node.sh`. TAP-format output, `--iterations N` flag, tests US-01 (health), US-05 (Tor), US-09 (NIP-07). 31/32 passed on first run. Bidirectional .228↔.198.
- [x] **TEST-02** — US-01 health tests in test-cross-node.sh. All 6 checks per node (health, services, memory, load, disk, containers). Both nodes pass. .228 load dropped to 3.78 (from 5.44 pre-fix).
- [x] **TEST-03** — US-02 Container Lifecycle tests added to test-cross-node.sh. Per node: (1) all-running check (zero exited), (2) container count >= 20, (3) stop filebrowser → health monitor auto-restarts within 90s (tested: .228 in 40-50s, .198 in 15-35s). .198 has pre-existing searxng exit 127 (broken entrypoint). 10/12 checks pass per run.
- [x] **TEST-04** — US-03 Federation Join tests added to test-cross-node.sh. Per node per iteration: (1) peers present >= 1, (2) trust_level == "trusted", (3) DID starts with "did:", (4) last_seen within 10 min. Fixed stale onion addresses in federation nodes.json on both servers (Tor rotation made old addresses unreachable). All 16/16 checks passing after fix.
- [x] **TEST-05** — US-04 Federation Sync tests added to test-cross-node.sh. Per node: (1) sync-state returns results, (2) at least 1 sync succeeds, (3) synced node has apps > 0, (4) last_seen updated within 2 min after sync. .228 syncs 2 peers (23 apps each), .198 syncs 1 peer (25 apps). All 16/16 checks passing.
- [x] **TEST-06** — US-05 Tor tests in test-cross-node.sh. Both directions pass: .228→.198 via Tor returns "OK", .198→.228 via Tor returns "OK". 4/4 passed (2 iterations x 2 directions).
- [x] **TEST-08** — US-07 tests: File Sharing (10x). content.add, content.list-mine, content.browse-peer bidirectionally over Tor (.228↔.198). Fixed ssh_sudo compound command bug (chown ran without sudo, killed script via set -e). All 50/50 checks pass (10 iterations × 5 checks: add-A, list-A, browse-A→B, add-B, browse-B→A).
- [x] **TEST-09** — US-08 tests: DWN Sync (10x). Fixed DWN sync: made sync endpoint async (background task with polling), added 90s overall timeout, deduplicated peer onion addresses, batched message pushes (50/batch), added connect_timeout, fixed HTTP handler to process all messages in batch. All 50/50 checks pass (10 iterations × 5 checks: register, write-3, sync, received-on-198, bidirectional). Each iteration completes in ~35s over Tor.
- [x] **TEST-10** — US-09 NIP-07 provider injection test in test-cross-node.sh. nostr-provider.js detected in /app/mempool/ on both nodes. 4/4 passed.
- [x] **TEST-11** — US-10 tests: Backup/Restore (10x). Added US-10 section to test-cross-node.sh. Tests create/list/verify/delete cycle on both nodes. Increased backup.create rate limit from 3/600 to 10/600. Cleaned up 21K+ stale DWN test messages on both nodes that were inflating backup size. All 80/80 checks pass (10 iterations × 4 checks × 2 nodes).
- [ ] **TEST-12** — US-15 tests: Boot Recovery (10x from each node). (1) Record running containers, (2) Reboot node, (3) Wait for backend health, (4) Verify ALL containers restarted within 120s, (5) Verify no containers exited. Run full reboot test 3 times per node, container recovery check 10 times. **Acceptance**: All containers survive every reboot. Zero manual intervention needed.
---
## Phase 3: UI Cosmetic Cleanup (Week 5-6)
### Sprint 4: Information Hierarchy & Deduplication
- [x] **UI-CLEAN-01** — Audited all views. Dashboard/Home: CLEAN (real RPC data). Server.vue: servicesRunning/connectivityStatus hardcoded, autoSync no backend, logCount never updated. Web5.vue: walletConnected never updated, DID status localStorage-only.
- [x] **UI-CLEAN-02** — Dashboard (Home.vue) verified CLEAN. CPU/RAM/disk from system.stats RPC, container counts from store, uptime from RPC. Web5 card fetches from identity/dwn/credentials RPCs. Cloud stats from FileBrowser API. No hardcoded data.
- [x] **UI-CLEAN-03** — Fixed Server.vue: added connectivity check on mount (was hardcoded 'connected'), restart now polls health endpoint instead of assuming success after 2s. Network data already fetches from real RPC endpoints (diagnostics, vpn, dns, interfaces). Deployed and verified.
- [x] **UI-CLEAN-04** — Verified Web5.vue information hierarchy. All data from real RPC endpoints: DID from `identity.create-did` (cached in localStorage), wallet from `lnd.getinfo` on mount, Nostr relays from `nostr.list-relays`, DWN from `dwn.status`/`dwn.list-protocols`/`dwn.query-messages`, credentials from `identity.list-credentials`. No hardcoded placeholder numbers. Zero fake data.
- [x] **UI-CLEAN-05** — Verified Settings.vue has zero section duplication. Account (server name, version, session, password, DID/Tor identity) is unique to Settings. 2FA is unique. Backup is unique. System Updates links to `/dashboard/settings/update`. DID/Tor appear as read-only identity display in Settings vs. interactive management in Web5 — different contexts, not duplication. Webhooks, AI Data Access, Claude Auth, Interface Mode all unique to Settings.
- [x] **UI-CLEAN-06** — Verified Marketplace.vue curated app list accuracy. All 33 apps have valid icons (verified all files exist in app-icons/). Fixed `photoprims.svg``photoprism.svg` typo in filename, Marketplace.vue, and mock-backend.js. Docker images reference legitimate registries (docker.io, ghcr.io). External web apps (nostrudel, botfights, nwnn, etc.) correctly use webUrl with empty dockerImage. Deployed and verified.
- [x] **UI-CLEAN-07** — Verified Cloud.vue file management. File sections (Photos, Music, Documents, All) use `fileBrowserClient.listDirectory()` with real paths (/Photos, /Music, /Documents, /). Peer Files shows `rpcClient.federationListNodes()` count and links to PeerFiles view. Upload via `cloudStore.uploadFile()``fileBrowserClient`. Download via `fileBrowserClient.downloadUrl()`. Zero hardcoded data.
- [x] **UI-CLEAN-08** — Verified Federation.vue accuracy. Node list from `rpcClient.federationListNodes()`. Online/offline based on `last_seen` 10-min threshold. NetworkMap component renders with computed `mapNodes`/`mapLinks` from real data. Generate invite via `federationInvite()` RPC. Sync via `federationSyncState()` RPC. DWN sync status from `dwn.status` RPC. Self DID from `getNodeDid()`. Zero hardcoded data.
- [x] **UI-CLEAN-09** — Verified Chat.vue state. Checks AIUI availability via `fetch('/aiui/', { method: 'HEAD' })`. Shows loading spinner while checking. Renders iframe when available. Shows clean fallback: "AI Assistant needs to be enabled before use. Go to Settings to configure your AI provider API key." No broken UI, no errors.
- [x] **UI-CLEAN-10** — Verified Apps.vue installed app display. Real containers from `store.packages` (WebSocket from backend's `podman ps`). Status badges: running=green, stopped=gray, starting/installing=yellow/blue via `getStatusClass()`. Web-only apps (Indeehub, BotFights, etc.) are intentional external bookmarks, not phantom containers. Click navigates to `/dashboard/apps/${id}`. Fallback SVG placeholder for broken icons.
- [x] **UI-CLEAN-11** — Type-check passes. `npm run type-check` exits 0.
- [x] **UI-CLEAN-12** — Build passes. `npm run build` exits 0, 146 precache entries, 2.81s build time.
---
## Phase 4: Backend Hardening (Week 7-10)
### Sprint 5: Container Management Reliability
- [ ] **CONT-01** — Audit container network topology on both nodes. Document every podman network, which containers are on each network, and which containers need to communicate. Create a network diagram. Fix any containers that should be on the same network but aren't (root cause of CRASH-01 and CRASH-02). **Acceptance**: Network diagram exists. All dependent containers share a network. No DNS resolution failures.
- [ ] **CONT-02** — Add container dependency ordering to startup. In `crash_recovery.rs` `start_stopped_containers()`, implement proper startup ordering: (1) Databases first (postgres, redis, mariadb), (2) Core services second (bitcoin-knots, lnd), (3) Dependent services third (electrs, mempool-api, btcpay-server, nbxplorer), (4) UI containers last (mempool-web, bitcoin-ui, lnd-ui). Wait for each tier's health before starting the next. **Acceptance**: After reboot, containers start in dependency order. Zero crash-restart cycles. Run 10 reboot tests — all containers healthy within 120s every time.
- [ ] **CONT-03** — Add container health check definitions for all apps. In `get_app_config()`, add `--health-cmd`, `--health-interval`, `--health-retries` to every container that doesn't have one. Currently only filebrowser, jellyfin, vaultwarden, and uptime-kuma have health checks. Add for: bitcoin-knots (`bitcoin-cli getblockchaininfo`), lnd (`lncli getinfo`), mempool-api (HTTP check), btcpay-server (HTTP check), nextcloud, etc. **Acceptance**: `sudo podman ps` shows "(healthy)" for every running container.
- [ ] **CONT-04** — Cap health monitor restart attempts with exponential backoff. Currently max 3 restarts with no delay. Change to: restart 1 at 10s, restart 2 at 30s, restart 3 at 90s. After 3 failures, mark container as "failed" and notify (don't keep trying). Reset counter after 1 hour of stability. **Acceptance**: A permanently broken container stops restarting after 3 attempts. No infinite crash loops consuming CPU.
- [ ] **CONT-05** — Add memory limits to all containers. Review `get_app_config()` memory limits. Set appropriate `--memory` flags: bitcoin-knots (2GB), lnd (512MB), electrs (1GB), mempool-api (512MB), mempool-web (256MB), nextcloud (1GB), immich_server (1GB), onlyoffice (2GB), etc. Prevent any single container from OOM-killing others. **Acceptance**: `sudo podman stats` shows all containers have MEM LIMIT set. No container exceeds its limit.
- [ ] **CONT-06** — Fix rootless podman mount warning on .228. The warning "/ is not a shared mount" appears on every podman command. Fix by making the mount shared: add `mount --make-rshared /` to systemd startup, or configure in `/etc/containers/storage.conf`. **Acceptance**: `sudo podman ps` produces no warnings.
### Sprint 6: Backend Security & Reliability
- [ ] **SEC-01** — Audit all RPC endpoints for input validation. In `core/archipelago/src/api/rpc/mod.rs`, list every registered route. For each endpoint, verify: input params are validated (length limits, format checks, no path traversal), auth is required (except health/public endpoints), error messages don't leak internals. **Acceptance**: Audit document with pass/fail per endpoint. All critical endpoints pass.
- [ ] **SEC-02** — Add rate limiting to federation endpoints. Federation endpoints (`federation.join`, `federation.invite`) should be rate-limited to prevent invite-code brute force. Max 5 join attempts per minute per source IP. **Acceptance**: 6th join attempt within 60s returns 429.
- [ ] **SEC-03** — Verify CSRF on all state-changing endpoints. Call every POST RPC endpoint without X-CSRF-Token header — should get 403. Verify the CSRF token is properly generated on login and validated on every mutation. **Acceptance**: 100% of state-changing endpoints reject requests without valid CSRF token.
- [ ] **SEC-04** — Audit container security profiles. For every container in `get_app_config()`, verify: `--cap-drop=ALL`, only required capabilities added back, `--security-opt=no-new-privileges:true`, `--read-only` where possible, non-root UID, specific image version pinned (not :latest). Fix any violations. **Acceptance**: All containers pass security checklist. `sudo podman inspect {name} --format "{{.HostConfig.CapDrop}}"` shows ALL for every container.
- [ ] **SEC-05** — Implement proper log rotation. Check `/var/lib/archipelago/logs/` and `/var/log/` for log file sizes. Add logrotate config for: archipelago backend logs, container logs, nginx logs. Rotate daily, keep 7 days, compress. **Acceptance**: `du -sh /var/log/` < 500MB. Logrotate config exists and runs daily.
- [ ] **SEC-06** Verify nginx security headers on both nodes. `curl -I http://192.168.1.228` and `curl -I http://192.168.1.198`. Must include: X-Frame-Options, X-Content-Type-Options, Content-Security-Policy, Referrer-Policy. Fix any missing. **Acceptance**: All 4 security headers present on both nodes.
---
## Phase 5: Reboot & Uptime Hardening (Week 11-14)
### Sprint 7: Zero-Downtime Reboot Testing
- [ ] **REBOOT-01** Create reboot survival test script. `scripts/test-reboot-survival.sh` that: (1) Records all container names and states, (2) Reboots the node via `sudo reboot`, (3) Waits for SSH to come back (poll every 10s, max 180s), (4) Verifies ALL containers are running, (5) Verifies health endpoint returns OK, (6) Verifies no containers have restart counts > 0 since boot. Run on .228. **Acceptance**: Script passes. All containers survive reboot.
- [ ] **REBOOT-02** — Run reboot survival test 10 times on .228. Execute test-reboot-survival.sh 10 times with 5-minute rest between reboots. Track: time to full recovery, any containers that fail to start, any services that don't come back. **Acceptance**: 10/10 reboots recover fully within 120s. Zero failed containers.
- [ ] **REBOOT-03** — Run reboot survival test 10 times on .198. Same as REBOOT-02 but on .198. **Acceptance**: 10/10 reboots recover fully. Zero failed containers.
- [ ] **REBOOT-04** — Test simultaneous reboot of both nodes. Reboot .228 and .198 at the same time. After both recover, verify: federation re-establishes, DWN sync works, file sharing works. **Acceptance**: Both nodes fully recover. Federation sync succeeds within 10 minutes of both being back.
- [ ] **REBOOT-05** — Test power-cut simulation (SIGKILL). On each node: `sudo kill -9 $(pgrep archipelago)`. Verify systemd restarts the backend, health monitor restarts containers, and everything recovers. Run 10 times per node. **Acceptance**: Full recovery within 90s, 10/10 times.
### Sprint 8: Memory & Storage Monitoring
- [ ] **MEM-01** — Add OOM-kill detection. In health_monitor.rs, check `dmesg | grep -i oom` and `/var/log/kern.log` for OOM kills. If detected, report via WebSocket notification with which process was killed. **Acceptance**: Trigger an intentional OOM (cgroup limit), verify notification fires.
- [ ] **MEM-02** — Add container memory leak detection. Track per-container RSS over time in the monitoring collector. If a container's memory grows by >50% in 24h without corresponding workload increase, flag as potential leak. **Acceptance**: Monitoring page shows memory trend per container. Alert fires for simulated leak (container with growing allocation).
- [ ] **MEM-03** — Add disk growth alerting. Track disk usage trend. If disk is growing > 1GB/day, alert. If disk > 85%, auto-trigger `system.disk-cleanup`. If > 90%, send critical notification. **Acceptance**: Alert fires when disk threshold crossed. Auto-cleanup runs at 90%.
- [ ] **MEM-04** — Add systemd watchdog to archipelago service. In `archipelago.service`, add `WatchdogSec=60`. In the backend, implement `sd_notify(WATCHDOG=1)` every 30s via the `sd-notify` crate. If backend hangs (stops sending watchdog), systemd auto-restarts it. **Acceptance**: Kill the backend's main loop (not the process), verify systemd detects the hang and restarts within 90s.
- [ ] **MEM-05** — Run 7-day continuous monitoring on both nodes. Deploy uptime-monitor.sh on both nodes. Cron every 5 minutes. Track: HTTP status, response time, CPU, memory, disk, container count, restart count. After 7 days, generate summary. **Acceptance**: Both nodes maintain > 99.9% uptime (< 10 minutes total downtime including intentional tests). Zero OOM kills. Zero unexpected restarts.
---
## Phase 6: did:dht & Interoperable Schemas (Week 15-20)
### Sprint 9: did:dht Implementation
- [ ] **DHT-01** Research and document did:dht integration approach. Study the did:dht spec (uses BitTorrent DHT Mainline DHT). Document: how to publish DIDs to the DHT, how to resolve them, what library/crate to use (or implement), how it fits alongside existing did:key. Write to `docs/did-dht-integration.md`. **Acceptance**: Architecture document with specific implementation plan.
- [ ] **DHT-02** Implement did:dht creation in identity_manager.rs. Add `create_dht_did()` method that: (1) generates Ed25519 keypair, (2) creates a DNS packet encoding per did:dht spec, (3) publishes to Mainline DHT using a Rust BitTorrent DHT library (e.g., `mainline` crate). The node should have BOTH did:key (local, offline) and did:dht (discoverable, no server needed). Add `identity.create-dht-did` RPC endpoint. **Acceptance**: Can create a did:dht and resolve it from another machine using the DHT.
- [ ] **DHT-03** Implement did:dht resolution. Add `identity.resolve-dht-did` RPC endpoint that takes a did:dht identifier, queries the Mainline DHT, retrieves and parses the DNS packet, returns the DID Document. Cache resolved DIDs for 1 hour. **Acceptance**: Can resolve a did:dht created on .228 from .198 without Tor, without Nostr relays, using only the BitTorrent DHT.
- [ ] **DHT-04** Update Web5 UI for did:dht. Show both did:key and did:dht in the identity section. Add "Publish to DHT" button. Show DHT resolution status. **Acceptance**: Web5 page shows both DID types. DHT publish and resolve work from the UI.
### Sprint 10: DWN Protocol Definitions for Interoperable Schemas
- [ ] **SCHEMA-01** Define Archipelago DWN protocol schemas. Create protocol definitions for the data types Archipelago shares between nodes: (1) Node identity announcements, (2) File sharing catalogs, (3) Federation state, (4) App deployment requests. Use the DWN protocol definition format so other apps implementing DWN could read Archipelago data. Document in `docs/dwn-protocols.md`. **Acceptance**: 4 protocol definitions documented with JSON schemas.
- [ ] **SCHEMA-02** Register Archipelago protocols in DWN on both nodes. On startup, the backend should auto-register all 4 Archipelago protocols via `dwn.register-protocol`. Verify protocols are registered on both .228 and .198. **Acceptance**: `dwn.list-protocols` on both nodes shows all 4 Archipelago protocols.
- [ ] **SCHEMA-03** Migrate file sharing catalog to DWN protocol format. Instead of (or in addition to) the custom `content.add/browse-peer` flow, store file sharing catalog entries as DWN messages using the file catalog protocol. This makes the catalog queryable by any DWN-compatible app. **Acceptance**: File sharing still works between .228 and .198. Catalog entries are also available via `dwn.query-messages` with the file catalog protocol filter.
- [ ] **SCHEMA-04** Migrate federation state to DWN protocol format. Store federation node announcements as DWN messages. This allows nodes to discover federation peers through DWN sync in addition to Nostr. **Acceptance**: Federation still works. Node announcements are also available as DWN messages.
### Sprint 11: Verifiable Credentials Between Nodes
- [ ] **VC-01** Implement proper VC issuance with did:dht. Update `credentials.rs` to support did:dht as issuer/subject (currently only did:key). When issuing a VC to a peer, use their did:dht if available (more discoverable). **Acceptance**: Can issue a VC with did:dht issuer, verify it, and present it.
- [ ] **VC-02** Add inter-node identity verification VCs. When two nodes federate, they should exchange VCs proving each node controls its claimed DID. The VC attests: "did:dht:X is a trusted peer of did:dht:Y, established on DATE". Store these VCs in the DWN. **Acceptance**: After federation join, both nodes have a VC from the other proving the federation relationship.
- [ ] **VC-03** Add VC presentation in federation handshake. Update `federation.join` and `federation.get-state` to include VC presentations. Peers can verify the VC chain before trusting a node. **Acceptance**: Federation join includes VC exchange. `federation.list-nodes` includes VC verification status per peer.
- [ ] **VC-04** Test VC flow between .228 and .198 (10x). (1) Issue VC on .228 to .198's DID, (2) Verify VC on .198, (3) Create presentation on .198 including the VC, (4) Verify presentation on .228. Run 10 times each direction. **Acceptance**: 80 checks, all pass.
---
## Phase 7: Deploy Pipeline & ISO Hardening (Week 21-26)
### Sprint 12: Deploy Script Hardening
- [ ] **DEPLOY-01** Audit deploy-to-target.sh for reliability. Read the entire script. Check: error handling (set -e?), rollback on failure, health check after deploy, idempotency, atomic swaps for binary and frontend. Fix any issues. **Acceptance**: Deploy script has proper error handling, health verification, and rollback capability.
- [ ] **DEPLOY-02** Add canary deploy mode. Deploy to .198 first, run health checks, then deploy to .228. If .198 health fails, abort before touching .228. Add `--canary` flag to deploy script. **Acceptance**: `./scripts/deploy-to-target.sh --canary` deploys to .198, verifies, then .228.
- [ ] **DEPLOY-03** Add deploy rollback capability. Before deploying, backup the current binary and frontend. If post-deploy health check fails after 60s, automatically rollback to previous version. Store rollback artifacts in `/opt/archipelago/rollback/`. **Acceptance**: Intentionally deploy a broken binary. Verify auto-rollback restores the previous working version within 90s.
- [ ] **DEPLOY-04** Add `--dry-run` flag to deploy script. Show exactly what would be deployed (files, binary, configs) without actually deploying. **Acceptance**: `./scripts/deploy-to-target.sh --dry-run --live` shows the plan without executing.
### Sprint 13: ISO Build Hardening
- [ ] **ISO-01** Audit ISO build script for all current apps. Verify `CAPTURE_PATTERNS` and `CONTAINER_IMAGES` in `build-auto-installer-iso.sh` include ALL apps currently running on .228 (33+ containers). Any missing container means a fresh install won't have that app. **Acceptance**: ISO capture list matches the full container inventory on .228.
- [ ] **ISO-02** Add swap file creation to first-boot. In the first-boot script, auto-create a swap file sized at 50% of RAM (min 2GB, max 8GB). Add to fstab. **Acceptance**: Fresh install from ISO has swap configured automatically.
- [ ] **ISO-03** Add container dependency ordering to first-boot. Same startup ordering as CONT-02 but for the first-boot-containers.sh script. **Acceptance**: Fresh install starts containers in dependency order with zero crash loops.
---
## Phase 8: Scale Testing for 10K Users (Week 27-36)
### Sprint 14: Resource Budget for 10K Users
- [ ] **SCALE-01** Create resource budget document. Based on current .228 metrics (33 containers, 6.5GB RAM, 1.2TB disk, load 5.44), calculate per-node resource requirements. Estimate: RAM per container (avg), disk per container, CPU per container. Project for 10K users across different hardware tiers. Document in `docs/scale-budget.md`. **Acceptance**: Document with clear resource requirements per hardware tier.
- [ ] **SCALE-02** Identify resource bottlenecks. Profile the top CPU and memory consumers. Current: immich_server (82% CPU spike), onlyoffice (759MB RAM), bitcoin-knots (750MB RAM), fedimint (369MB), lnd (250MB), homeassistant (234MB). Determine which apps should be optional vs core for a minimal install. **Acceptance**: Tiered app list: Core (must-have), Recommended, Optional. Core tier uses < 4GB RAM.
- [ ] **SCALE-03** Implement app tier system in backend. Add a `tier` field to app metadata: `core`, `recommended`, `optional`. First-install only installs core tier. Marketplace shows tier badges. Users choose additional tiers. **Acceptance**: Fresh install only starts core apps. Total RAM < 4GB for core tier.
- [ ] **SCALE-04** Add resource monitoring alerts for scale limits. Alert when: total container memory > 80% of system RAM, CPU load > 2x core count sustained for 5 min, disk > 80%. These proactive alerts prevent scale-related failures. **Acceptance**: Alerts fire at correct thresholds. Tested on both nodes.
### Sprint 15: Automated Fleet Testing
- [ ] **FLEET-01** — Create automated test-all-features script. `scripts/test-all-features.sh` that runs every feature test in sequence: system health, container lifecycle, federation, Tor, Nostr, file sharing, DWN sync, NIP-07, backup, monitoring, identity/VCs. Takes a target IP and runs all checks 10 times. **Acceptance**: One command validates an entire node. Exit 0 = production ready.
- [ ] **FLEET-02** — Run test-all-features on .228. Execute the full test suite 10 iterations. Document any failures, fix them, rerun until 10/10 clean. **Acceptance**: 10 consecutive clean runs on .228.
- [ ] **FLEET-03** — Run test-all-features on .198. Same as FLEET-02 but on .198. **Acceptance**: 10 consecutive clean runs on .198.
- [ ] **FLEET-04** — Run cross-node test suite 10 times. Execute `test-cross-node.sh --iterations 10` covering all bidirectional tests. **Acceptance**: All cross-node tests pass 10/10 from both directions.
### Sprint 16: Long-Duration Soak Test
- [ ] **SOAK-01** — Run 30-day soak test on both nodes. Deploy monitoring, leave both nodes running for 30 days. Monitor: uptime, memory trend (leak detection), disk growth, container restart counts, federation sync success rate, Tor uptime. **Acceptance**: Both nodes > 99.95% uptime. No memory leaks (RSS stable ±10% over 30 days). Zero unexpected restarts.
- [ ] **SOAK-02** — Run hourly federation sync verification for 30 days. Cron job every hour: trigger federation sync, verify success, log result. After 30 days, calculate sync success rate. **Acceptance**: > 99% sync success rate over 30 days.
- [ ] **SOAK-03** — Run daily reboot test for 30 days. Automated daily reboot at 4 AM, verify full recovery by 4:05 AM. Log recovery time each day. **Acceptance**: 30/30 successful recoveries. Average recovery < 120s.
- [ ] **SOAK-04** Compile final stability report. After 30-day soak, generate report: uptime %, memory trend, disk trend, federation reliability, container health, incident log. This becomes the go/no-go for declaring production ready. **Acceptance**: Report shows all metrics meeting production targets.
---
## Phase 9: Production Polish (Week 37-44)
### Sprint 17: Performance Optimization
- [ ] **PERF-01** Optimize backend startup time. Target: < 3 seconds from process start to healthy response. Profile with tracing. Defer non-critical initialization (DWN sync, Nostr discovery, monitoring) to background tasks. **Acceptance**: `time curl http://localhost:5678/health` after restart < 3s.
- [ ] **PERF-02** Optimize frontend bundle size. Target: < 500KB gzipped initial load. Analyze with vite-bundle-visualizer. Lazy-load heavy components (D3.js network map, monitoring charts). **Acceptance**: `ls -la web/dist/neode-ui/assets/*.js | awk '{sum+=$5}END{print sum}'` < 500KB gzipped.
- [ ] **PERF-03** Optimize container image sizes. Pull all container images and check sizes. Replace any > 1GB images with smaller alternatives (alpine-based). Remove any cached layers for old versions. **Acceptance**: Total container image disk usage reduced by > 20%.
- [ ] **PERF-04** — Add caching for RPC responses. Frequently-called read endpoints (`system.stats`, `container.list`, `federation.list-nodes`) should cache results for 5-10 seconds to reduce CPU. **Acceptance**: 100 concurrent `system.stats` calls complete in < 500ms total.
### Sprint 18: Documentation Update
- [ ] **DOC-01** Update CHANGELOG.md for v1.2.0. Document all changes from this hardening cycle: crash loop fixes, cross-node testing, did:dht, DWN protocols, VCs, reboot hardening, memory/swap fixes. **Acceptance**: CHANGELOG updated with all changes.
- [ ] **DOC-02** Update architecture.md for current state. The current doc references StartOS, Docker, macOS. Update to reflect: Debian 12, Podman, multi-node federation, did:dht, DWN protocols. **Acceptance**: Architecture doc matches actual system.
- [ ] **DOC-03** Update current-state.md. Remove references to StartOS dependencies (already removed). Document actual current state: pure Archipelago backend, Podman, 33+ containers, 2-node federation. **Acceptance**: current-state.md reflects reality.
- [ ] **DOC-04** Create operations runbook. `docs/operations-runbook.md` covering: how to check node health, how to fix crashed containers, how to add/remove federation peers, how to rotate Tor address, how to create/restore backups, how to update, how to diagnose high CPU/memory. **Acceptance**: Runbook covers top 20 operational scenarios.
---
## Phase 10: Year 2-5 Roadmap (Month 13-60)
### Year 2 (2027): Multi-Hardware & Community
- [ ] **Y2-01** Test and certify on 5 hardware platforms: generic x86_64 PC, Intel NUC, Raspberry Pi 5, mini-PC (N100), used ThinkCentre. Document per-platform quirks. **Acceptance**: ISO boots and works on all 5 platforms.
- [ ] **Y2-02** Community app submission pipeline. Automated review of community-submitted app manifests: security scan, resource check, dependency validation, sandbox test. **Acceptance**: Community can submit apps via PR, automated checks run, maintainer approves.
- [ ] **Y2-03** Multi-language support. Translate UI to 5 languages (Spanish, Portuguese, German, French, Japanese) using the i18n infrastructure already in place. **Acceptance**: Language selector in Settings, all strings translated.
- [ ] **Y2-04** Mobile companion app (read-only). Progressive Web App or native app that connects to node over Tailscale/Tor and shows: dashboard, container status, notifications. No mutations read-only for safety. **Acceptance**: Can view node status from phone.
### Year 3 (2028): Enterprise & Scale
- [ ] **Y3-01** Multi-user support. Add user roles (admin, viewer, app-user). Admin can manage everything. Viewer sees dashboard only. App-user accesses specific apps. **Acceptance**: 3 user roles with proper permission separation.
- [ ] **Y3-02** Automated backup to S3-compatible storage. In addition to USB backup, support backup to any S3 endpoint (Backblaze B2, Wasabi, self-hosted MinIO). Encrypted before upload. **Acceptance**: Backup to S3 works, restore from S3 works.
- [ ] **Y3-03** Cluster mode for high availability. 3+ nodes form a cluster where apps have replicas. If one node goes down, apps failover to another. Uses Raft or similar consensus. **Acceptance**: Stop one node in a 3-node cluster apps continue serving from remaining nodes.
- [ ] **Y3-04** Hardware attestation with TPM 2.0. Nodes with TPM chips can cryptographically prove their hardware identity. Adds trust layer to federation. **Acceptance**: TPM-equipped node includes hardware attestation in its DID Document.
### Year 4 (2029): Ecosystem & Market
- [ ] **Y4-01** App developer SDK. Command-line tool for app developers: `archy-dev create`, `archy-dev test`, `archy-dev publish`. Scaffolds manifest, runs security checks, publishes to marketplace. **Acceptance**: Developer can publish a new app in under 30 minutes using the SDK.
- [ ] **Y4-02** Paid app marketplace. Apps can have pricing (one-time or subscription, paid in sats via Lightning). Revenue split between developer and node operator. Uses Cashu or Lightning invoices. **Acceptance**: End-to-end payment flow works.
- [ ] **Y4-03** Node analytics dashboard (opt-in). Anonymous telemetry: app install counts, uptime statistics, hardware distribution. Helps prioritize development. Strictly opt-in. **Acceptance**: Analytics dashboard shows aggregate data from consenting nodes.
- [ ] **Y4-04** Cross-chain support (Monero, Liquid). Add support for Monero full node and Liquid sidechain containers. Federation supports multi-chain status reporting. **Acceptance**: Can run Bitcoin + Monero + Liquid on same node.
### Year 5 (2030-2031): Production at Scale
- [ ] **Y5-01** Achieve 10,000 active nodes. Track via opt-in analytics. Support infrastructure: documentation, community forum, bug tracker, release automation. **Acceptance**: 10K+ nodes running Archipelago, measured via marketplace relay or opt-in telemetry.
- [ ] **Y5-02** Zero-downtime updates. Update mechanism that migrates containers one-by-one with health checks between each. No service interruption during update. **Acceptance**: Update from v2.x to v2.y with zero downtime measured by external monitor.
- [ ] **Y5-03** Formal security audit by third party. Engage professional security firm to audit: backend code, container isolation, authentication, cryptography, network security. Fix all findings. **Acceptance**: Clean audit report with no critical/high findings.
- [ ] **Y5-04** v3.0 release with all Year 5 features. Stable, audited, scale-tested release for mass adoption. **Acceptance**: Tagged v3.0.0 release with full documentation and ISO downloads.
---
## Test Matrix Summary
| Test Category | # Checks | Per-Direction | Iterations | Total Passes Required |
|---|---|---|---|---|
| System Health (US-01) | 6 | x2 | x10 | 120 |
| Container Lifecycle (US-02) | 4 | x2 | x10 | 80 |
| Federation Join (US-03) | 4 | x2 | x10 | 80 |
| Federation Sync (US-04) | 4 | x2 | x10 | 80 |
| Tor Hidden Services (US-05) | 3 | x2 | x10 | 60 |
| Nostr Discovery (US-06) | 4 | x2 | x10 | 80 |
| File Sharing (US-07) | 5 | x2 | x10 | 100 |
| DWN Sync (US-08) | 5 | x2 | x10 | 100 |
| NIP-07 Signing (US-09) | 4 | x2 | x10 | 80 |
| Backup/Restore (US-10) | 4 | x2 | x10 | 80 |
| Boot Recovery (US-15) | 5 | x2 | x3 | 30 |
| **TOTAL** | **48** | | | **890** |
Every single one of these 890 test passes must succeed before declaring production-ready.
---
## Milestone Summary
| Date | Milestone | Key Deliverables |
|---|---|---|
| Mar 2026 Week 2 | Phase 1 Complete | Crash loops fixed, .198 stabilized, federation established |
| Mar 2026 Week 4 | Phase 2 Complete | 890 cross-node test passes, bulletproof test harness |
| Apr 2026 Week 2 | Phase 3 Complete | UI cosmetic cleanup, zero fake data, zero TypeScript errors |
| May 2026 | Phase 4 Complete | Container reliability, security audit, log rotation |
| Jun 2026 | Phase 5 Complete | 10x reboot survival, memory monitoring, systemd watchdog |
| Aug 2026 | Phase 6 Complete | did:dht, DWN interoperable schemas, VCs between nodes |
| Oct 2026 | Phase 7 Complete | Deploy pipeline hardened, ISO verified |
| Jan 2027 | Phase 8 Complete | 30-day soak test passed, scale budget documented |
| Apr 2027 | Phase 9 Complete | Performance optimized, docs updated, v1.2.0 tagged |
| 2028 | Year 2 | Multi-hardware, community apps, mobile companion |
| 2029 | Year 3 | Multi-user, S3 backup, cluster HA, TPM attestation |
| 2030 | Year 4 | App SDK, paid marketplace, cross-chain |
| 2031 | **Year 5** | **10K users, zero-downtime updates, security audit, v3.0** |
---
## Execution Instructions
For each task in order:
1. Find the first unchecked `- [ ]` item
2. Read the task description and acceptance criteria carefully
3. Read ALL relevant source files before making changes
4. Implement following CLAUDE.md conventions strictly
5. For frontend changes: `cd neode-ui && npm run type-check && npm run build`, deploy with `./scripts/deploy-to-target.sh --both`
6. For backend changes: deploy with `./scripts/deploy-to-target.sh --both` (builds on server, not macOS)
7. For test scripts: create on local, rsync to server, run via SSH
8. Verify acceptance criteria are met ON BOTH SERVERS
9. Mark it done `- [x]` in this file
10. Commit: `type: description`
11. Move to the next unchecked task immediately
**CRITICAL**: Every change must be deployed to BOTH .228 AND .198. Tests must pass from BOTH directions.
**Total tasks**: 98 across 18 sprints over 5 years.