resume active sessions
This commit is contained in:
1 parent
9e94c05fb6
commit
917a361370
19 files changed
+871
-42
No files matched your search
+6
-4
@@ -29,6 +29,8 @@ flowchart LR
|
||||
|
||||
**A message's path:** Slack event (`app_mention`, a DM, or a plain reply in a channel thread set to `all-messages`) → `bot` → `manager.Ensure` (find the container, or place and start it) → `manager.DialAgent` (direct on the master, relayed for slaves) → `acp` session → updates stream back through `bot`'s streamer, which edits the Slack message. While the reply runs, its newest message also has a status line (what the agent is doing, and when it last sent an update) and a **Cancel** button whose value is the placeholder's ts, the key in `Bot.running`. The final edit removes both.
|
||||
|
||||
**In-flight turns:** once the placeholder is posted, `bot.converse` records the turn (thread, message and placeholder ts, sender, text, attachments) in `state_dir/in-flight-<channel>.json`, one file per channel keyed by thread, and marks it `prompted` just before `session/prompt`. The record is removed when the turn ends, unless it ended because the bot is shutting down: then the reply ends with a restarting note, and `Bot.Run` waits up to 5s for those last edits. On start, `Bot.Run` resumes every recorded turn through the same path. If the agent already got the prompt, it gets a short "carry on" note in the same session instead of the message again, because goose keeps the partial turn and resending could repeat what it already did. If it didn't (or the session is gone), it gets the original message and attachments. Turns older than an hour, or already resumed 3 times, are dropped with a note asking the user to send them again. A broken file is skipped and left on disk. Super users can read the files with `in-flight` (Slack, answered ephemerally) or the `in_flight` tool.
|
||||
|
||||
**Lifecycle threads:** `manager.EnsureProgress` reports `StartEvent`s (placing, booting, registered) only when it really starts a container. The bot (`bot/lifecycle.go`) turns them into replies in a dedicated top-level message for that container, pins it, and unpins the previous run's message. The message's channel and timestamp are kept on the owner (`lifecycle_channel`, `lifecycle_ts`). The user's thread only gets a link. Stops (`stop`, the button, the idle reaper) post to the same thread, and `manager.WaitStopped` confirms when the machine is gone.
|
||||
|
||||
**Files:** attachments on a message (`file_share`, or `files` on an `app_mention`) are downloaded by the bot and written into the home with the node's `write_file` call, then their paths are added to the prompt. The other way, goose gets the `slackerbot` MCP server (`slackerbot tools`, run inside the container as `slackerbot-tools`) through `mcpServers` in `session/new` and `session/load`. Its `initialize` reply carries `instructions` (how to use Nix in the container), which goose adds to its system prompt. Its `send_file` tool only checks the path and size and answers "queued". The bot watches the ACP `tool_call` / `tool_call_update` messages, and when a `send_file` call completes it reads the file with `read_file` and uploads it to the thread with `files.uploadV2`. Bytes go node → master → Slack, so slaves never need a Slack token. Both calls work in 4 MB chunks, open files with `os.Root` so symlinks and `..` can't leave the home, and are capped by `max_send_file_mb`. An older slave answers "unknown call", which surfaces as `node.ErrTooOld` and a polite reply.
|
||||
@@ -41,7 +43,7 @@ flowchart LR
|
||||
|
||||
**System updates:** each node reports running containers whose `slackerbot-<machine>.service` command ends with a different system's `init` than the node's current `system` (`outdated` in `RunningMachine`, read over D-Bus; unknown counts as current). After a reply, the bot asks once per container (`bot/update.go`, remembered in memory) whether to restart. **Restart now** calls `manager.Restart` (power off, wait, then the normal start), unless a reply is in progress.
|
||||
|
||||
**State** lives only on the master, in `state_dir/state.json`: owners (container, size, node, drive, storage limits, idle limit, lifecycle message), sessions (Slack thread → ACP session id, plus the thread's listen mode), each channel's default listen mode, and permissions. Nodes report what's running and how much disk each home uses. Nothing else is stored.
|
||||
**State** lives only on the master, in `state_dir/state.json`: owners (container, size, node, drive, storage limits, idle limit, lifecycle message), sessions (Slack thread → ACP session id, plus the thread's listen mode), each channel's default listen mode, and permissions. Turns still in progress go in `state_dir/in-flight-<channel>.json` (see **In-flight turns**). Nodes report what's running and how much disk each home uses. Nothing else is stored.
|
||||
|
||||
## Placement and capacity
|
||||
|
||||
@@ -98,7 +100,7 @@ flowchart TD
|
||||
| `commands` | Parses Slack command text: `scale`, `keep`, `storage`, `grant`, and which permission a command needs |
|
||||
| `config` | Loads and validates `config.toml` |
|
||||
| `storage` | Drive math (`DriveReport`, headroom, overbooking) and btrfs subvolume/quota commands |
|
||||
| `state` | `state.json` persistence |
|
||||
| `state` | `state.json` and `in-flight-<channel>.json` persistence |
|
||||
| `node` | `Node` interface, wire types, offline/full errors, the WebSocket connection used to reach goose |
|
||||
| `local` | The `Node` on this machine: nspawn via `systemd-run`, machined and systemd over D-Bus, capacity detection, btrfs send/receive |
|
||||
| `balance` | Builds a view of each node and picks where a container goes |
|
||||
@@ -107,7 +109,7 @@ flowchart TD
|
||||
| `acp` | JSON-RPC client for goose's ACP endpoint. Tool permission requests are auto-approved |
|
||||
| `bot` | Slack events and buttons, replies, permission checks, `grant`/`revoke`, move announcements, idle reaper, streaming replies, thread listen modes, stop reactions, the assistant pane, commands the agent calls as tools |
|
||||
| `util` | `KeyedMutex`, `RandomHex` |
|
||||
| `testutil`, `testutil/clustertest` | Fake nodes, and a real master + slave harness for tests |
|
||||
| `testutil`, `testutil/clustertest` | Fake nodes, a fake goose, and a real master + slave harness for tests |
|
||||
| `nix/container.nix` | NixOS system for each container |
|
||||
| `nix/host.nix` | NixOS module: the service, the `ve-*` network, firewall |
|
||||
|
||||
@@ -119,6 +121,6 @@ There are two builds. Nix (`flake.nix`) builds the deployable package, the conta
|
||||
- Anyone in a channel controls that channel's container and everything the agent can reach from it.
|
||||
- The agent runs commands with the sender's permissions, so whatever steers it (a file, a web page) can scale, move or re-grant as far as that person may. The thread shows every change it makes.
|
||||
- Containers run as root without user namespaces, and container root can get around btrfs quotas. That's fine for fair sharing among trusted users, but not safe for hostile ones.
|
||||
- Restarting the master makes slaves look offline for a few seconds. Restarting the bot doesn't stop containers.
|
||||
- Restarting the master makes slaves look offline for a few seconds. Restarting the bot doesn't stop containers, and replies in progress are picked back up, but Slack doesn't replay messages sent while the bot was down.
|
||||
- `state.json` is fine for hundreds of users. Swap the `state` package for SQLite if you need more.
|
||||
- Home folders are never deleted automatically (see INSTALLATION.md).
|
||||
Reference in new issue
Block a user