diff --git a/vibn-dev/CRON.md b/vibn-dev/CRON.md new file mode 100644 index 00000000..dfab3659 --- /dev/null +++ b/vibn-dev/CRON.md @@ -0,0 +1,105 @@ +# Path B cron entries + +Two background jobs keep dev containers cheap and recoverable. Wire +both to whatever scheduler is convenient (host crontab, Coolify +Scheduled Tasks, or a separate vibn-cron service later). + +## 1. Workspace autosave — every 5 min + +Force-pushes `/workspace` of every running dev container to a +`vibn-autosave/main` branch in the project's Gitea repo. Throttled +internally so it's safe to call more often than 5 min if needed. + +```cron +*/5 * * * * curl -fsS -X POST \ + -H "Authorization: Bearer $NEXTAUTH_SECRET" \ + -H "Content-Type: application/json" \ + -d '{"sweep":true}' \ + https://vibnai.com/api/admin/path-b/autosave \ + >> /var/log/vibn-autosave.log 2>&1 +``` + +What it does on a per-project basis (see +`autosaveWorkspace` in `vibn-frontend/lib/dev-container.ts`): + +1. Skips containers that aren't `state='running'`. +2. Skips containers without a `.git` directory in `/workspace`. +3. `git checkout -B vibn-autosave/main`, adds everything, commits if + there are changes, force-pushes. +4. Records the push in `fs_dev_autosaves` (per-project history, + bounded by retention you can prune later). + +## 2. Idle-suspend sweep — every 5 min + +Suspends every running dev container whose last `shell.exec` is older +than 30 minutes. Coolify-stops the service; the workspace + cache +volumes persist; resume happens automatically on the next +`shell.exec` (~3-5s). + +```cron +*/5 * * * * curl -fsS -X POST \ + -H "Authorization: Bearer $NEXTAUTH_SECRET" \ + "https://vibnai.com/api/admin/path-b/idle-sweep?minutes=30" \ + >> /var/log/vibn-idle.log 2>&1 +``` + +Override the threshold per-tier later by passing a different +`?minutes=` value. 30 was chosen because it covers a coffee break +without disrupting active work. + +## Quick install on the Coolify host + +```bash +sudo tee /etc/cron.d/vibn-path-b > /dev/null < + +# Workspace autosave to Gitea +*/5 * * * * root curl -fsS -X POST \ + -H "Authorization: Bearer \$NEXTAUTH_SECRET" \ + -H "Content-Type: application/json" \ + -d '{"sweep":true}' \ + https://vibnai.com/api/admin/path-b/autosave \ + >> /var/log/vibn-autosave.log 2>&1 + +# Idle-suspend dev containers (30m threshold) +*/5 * * * * root curl -fsS -X POST \ + -H "Authorization: Bearer \$NEXTAUTH_SECRET" \ + "https://vibnai.com/api/admin/path-b/idle-sweep?minutes=30" \ + >> /var/log/vibn-idle.log 2>&1 +EOF +sudo chmod 0644 /etc/cron.d/vibn-path-b +sudo systemctl reload cron +``` + +## Manual smoke + +```bash +# autosave one project +curl -X POST -H "Authorization: Bearer $NEXTAUTH_SECRET" \ + -H "Content-Type: application/json" \ + -d '{"projectId":""}' \ + https://vibnai.com/api/admin/path-b/autosave + +# sweep all +curl -X POST -H "Authorization: Bearer $NEXTAUTH_SECRET" \ + -H "Content-Type: application/json" \ + -d '{"sweep":true}' \ + https://vibnai.com/api/admin/path-b/autosave + +# idle suspend (use a huge minutes value to dry-run safely) +curl -X POST -H "Authorization: Bearer $NEXTAUTH_SECRET" \ + "https://vibnai.com/api/admin/path-b/idle-sweep?minutes=99999" +``` + +## Disabling + +If something goes wrong, flip the kill switch — the chat will fall +back to gitea-write tools and the cron sweeps will return `scanned: 0` +because no containers will be running. + +```bash +curl -X POST -H "Authorization: Bearer $NEXTAUTH_SECRET" \ + https://vibnai.com/api/admin/path-b/disable +``` + +Re-enable later with `/api/admin/path-b/enable`. diff --git a/vibn-frontend b/vibn-frontend index 41d4d374..e0844b5f 160000 --- a/vibn-frontend +++ b/vibn-frontend @@ -1 +1 @@ -Subproject commit 41d4d3748f4e42448cbc964f46f481afa1b90fba +Subproject commit e0844b5f2e9ae23f1d8a0b6b1c93187d5afcde2b