mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-18 10:06:30 +03:00
fix(session): preserve history across storage relocation
Co-authored-by: lmzopq <1646888+lmzopq@users.noreply.github.com>
This commit is contained in:
@@ -149,7 +149,7 @@ Defaults:
|
||||
|---|---|
|
||||
| Config | `~/.nanobot/config.json` |
|
||||
| Workspace | `~/.nanobot/workspace/` |
|
||||
| Sessions | `~/.nanobot/sessions/<workspace-hash>/*.jsonl` |
|
||||
| Sessions | `<config-dir>/sessions/<workspace-id>/*.jsonl` (default: `~/.nanobot/sessions/...`) |
|
||||
| Memory | `<workspace>/memory/` |
|
||||
| Cron store | `<workspace>/cron/jobs.json` |
|
||||
| WebUI/media/log runtime data | config directory subdirectories such as `webui/`, `media/`, and `logs/` |
|
||||
@@ -180,7 +180,7 @@ Session history is the near-term conversation replay. Memory is the longer-term
|
||||
|
||||
| Store | File area |
|
||||
|---|---|
|
||||
| Session JSONL files | `~/.nanobot/sessions/<workspace-hash>/` |
|
||||
| Session JSONL files | `<config-dir>/sessions/<workspace-id>/` |
|
||||
| Long-term memory | `<workspace>/memory/MEMORY.md` |
|
||||
| Consolidation source history | `<workspace>/memory/history.jsonl` |
|
||||
| Bootstrap identity files | `<workspace>/SOUL.md`, `<workspace>/USER.md`, templates under `nanobot/templates/` |
|
||||
|
||||
@@ -94,6 +94,24 @@ follow the printed WebUI **Settings → Models** or `nanobot onboard --wizard` r
|
||||
| `nanobot agent --no-markdown` | Print plain text instead of Rich-rendered Markdown |
|
||||
| `nanobot agent --logs` | Show runtime logs while chatting |
|
||||
|
||||
## Session Storage and Rollback
|
||||
|
||||
Session JSONL files live under `<config-dir>/sessions/<workspace-id>/`, outside the
|
||||
agent-readable workspace. On the first upgraded start, nanobot safely migrates existing
|
||||
`<workspace>/sessions/*.jsonl` files after verifying an atomic copy. Stop every old nanobot
|
||||
process that uses the workspace before upgrading; old and new binaries must not write the
|
||||
same session concurrently.
|
||||
|
||||
To prepare a downgrade, stop nanobot and copy the current sessions back to the path understood
|
||||
by older releases:
|
||||
|
||||
```bash
|
||||
nanobot sessions restore-workspace --config ./bot-a/config.json --workspace ./bot-a/workspace
|
||||
```
|
||||
|
||||
The command never deletes the external store and refuses to overwrite a different existing
|
||||
workspace file. Back up both the config directory and workspace before changing versions.
|
||||
|
||||
In interactive mode, `Enter` sends the current message. Press `Alt+Enter` to add a newline before sending.
|
||||
|
||||
Interactive mode exits with `exit`, `quit`, `/exit`, `/quit`, `:q`, or `Ctrl+D`.
|
||||
|
||||
+8
-2
@@ -27,7 +27,7 @@ The default instance lives under `~/.nanobot/`:
|
||||
|---|---|
|
||||
| `~/.nanobot/config.json` | Instance configuration: providers, model defaults, channels, tools, gateway, API, and runtime options |
|
||||
| `~/.nanobot/workspace/` | Agent workspace: memory, heartbeat tasks, cron jobs, skills, and generated artifacts |
|
||||
| `~/.nanobot/sessions/<workspace-hash>/` | Session history stored outside the agent-accessible workspace and namespaced by its canonical path |
|
||||
| `~/.nanobot/sessions/<workspace-id>/` | Session history stored outside the agent-accessible workspace; the opaque ID follows workspace moves |
|
||||
|
||||
You can override both with command flags:
|
||||
|
||||
@@ -126,11 +126,17 @@ nanobot uses two related stores:
|
||||
|
||||
| Store | Location | Purpose |
|
||||
|---|---|---|
|
||||
| Sessions | `~/.nanobot/sessions/<workspace-hash>/*.jsonl` | Recent conversation turns replayed into context |
|
||||
| Sessions | `<config-dir>/sessions/<workspace-id>/*.jsonl` | Recent conversation turns replayed into context |
|
||||
| Memory | `<workspace>/memory/MEMORY.md` and `<workspace>/memory/history.jsonl` | Long-term facts and consolidated history |
|
||||
|
||||
Dream is a periodic consolidation job. It reads accumulated history and updates workspace memory so useful context can survive beyond short session replay.
|
||||
|
||||
The configured workspace contains a `.nanobot/workspace-id` file. It contains only an
|
||||
opaque random identifier—never conversation content or credentials. Keep it with workspace
|
||||
backups: it lets nanobot find the same external session namespace after the workspace is
|
||||
renamed, moved, or restored. A live copy opened alongside the original receives a new ID so
|
||||
the two workspaces do not share conversations accidentally.
|
||||
|
||||
See [`memory.md`](./memory.md) for the detailed design.
|
||||
|
||||
## Apps and Agent Plugins
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ Check these once before Render, Docker, systemd, or LaunchAgent:
|
||||
| `nanobot status` shows the expected config and workspace | Confirms the process will read the instance you meant to run |
|
||||
| `nanobot agent -m "Hello!"` works | Proves install, config, provider, model, and workspace writes before adding a service layer |
|
||||
| Secrets are in environment variables or protected config files | API keys, bot tokens, OAuth state, and chat credentials should not be world-readable |
|
||||
| `~/.nanobot/` (including `sessions/`) and any custom config/workspace paths are persistent | Sessions, memory, channel login state, generated artifacts, and cron jobs live there |
|
||||
| The active config directory (including `sessions/`) and workspace are persistent | Sessions follow `--config`; memory, generated artifacts, and the workspace identity marker follow the workspace |
|
||||
| Channel access control is intentional | Use `allowFrom`, pairing, WebSocket `token`/`tokenIssueSecret`, or private test channels before exposing the bot |
|
||||
| Ports are planned | Gateway health defaults to local-only `127.0.0.1:18790`; WebUI/WebSocket defaults to `8765`; `nanobot serve` defaults to `8900` |
|
||||
| Logs are easy to reach | Use `docker compose logs`, `journalctl`, LaunchAgent log files, or `nanobot gateway --verbose` while diagnosing startup |
|
||||
|
||||
@@ -47,8 +47,8 @@ nanobot gateway logs
|
||||
- Docker Compose is the most repeatable Linux container path.
|
||||
- systemd user services are useful for Linux user-level gateway deployments.
|
||||
- macOS LaunchAgent keeps the gateway alive after login.
|
||||
- Persist `~/.nanobot/sessions/` together with config, workspace, memory files,
|
||||
channel login state, and generated artifacts.
|
||||
- Persist the active config directory's `sessions/` folder together with the workspace
|
||||
(including `.nanobot/workspace-id`), memory files, channel login state, and generated artifacts.
|
||||
- Restart the gateway after editing `config.json`.
|
||||
|
||||
## Security notes
|
||||
|
||||
@@ -58,6 +58,7 @@ nanobot agent -c ~/.nanobot-telegram/config.json -w /tmp/nanobot-telegram-test
|
||||
|-----------|---------------|---------|
|
||||
| **Config** | `--config` path | `~/.nanobot-A/config.json` |
|
||||
| **Workspace** | `--workspace` or config | `~/.nanobot-A/workspace/` |
|
||||
| **Sessions** | config directory + workspace ID | `~/.nanobot-A/sessions/<workspace-id>/` |
|
||||
| **Cron Jobs** | workspace directory | `~/.nanobot-A/workspace/cron/` |
|
||||
| **Media / runtime state** | config directory | `~/.nanobot-A/media/` |
|
||||
|
||||
@@ -126,6 +127,6 @@ nanobot gateway --config ~/.nanobot-telegram/config.json --workspace /tmp/nanobo
|
||||
## Notes
|
||||
|
||||
- Each instance must use a different port if they run at the same time
|
||||
- Use a different workspace per instance if you want isolated memory, sessions, and skills
|
||||
- Session data follows the active config directory; use a different workspace per instance to isolate memory, skills, and the stable session namespace ID
|
||||
- `--workspace` overrides the workspace defined in the config file
|
||||
- Cron jobs are stored in the active workspace; runtime media/state is derived from the config directory
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ The WebUI launcher creates or updates:
|
||||
|---|---|
|
||||
| `~/.nanobot/config.json` | Provider, model, WebUI, channel, tool, and runtime settings |
|
||||
| `~/.nanobot/workspace/` | Memory, skills, automations, and generated files |
|
||||
| `~/.nanobot/sessions/<workspace-hash>/` | Recent session history, isolated by canonical workspace path |
|
||||
| `~/.nanobot/sessions/<workspace-id>/` | Recent session history stored outside the workspace; the ID remains stable across workspace moves |
|
||||
|
||||
If the installer did not open the browser, run:
|
||||
|
||||
|
||||
@@ -319,7 +319,8 @@ See [`chat-apps.md`](./chat-apps.md) for channel-specific setup.
|
||||
|---|---|
|
||||
| Conversation context seems wrong | Confirm the active workspace and session. WebUI chats and chat app threads may use different sessions. |
|
||||
| Memory does not update immediately | Dream consolidation is periodic; recent turns still live in session history. |
|
||||
| Old sessions appear after moving config | Session files are stored under `~/.nanobot/sessions/<workspace-hash>/`; verify the canonical workspace path recorded in the directory's `.workspace` marker. |
|
||||
| Sessions disappear after changing `--config` | Sessions follow the config directory at `<config-dir>/sessions/<workspace-id>/`; use the original config path or copy that `sessions/` directory into the new config directory while nanobot is stopped. |
|
||||
| Sessions disappear after moving a workspace | Keep the workspace's `.nanobot/workspace-id` file with the move or backup. If it was lost, restore that marker from backup before starting nanobot. |
|
||||
| You want one shared session across devices | Set `agents.defaults.unifiedSession` intentionally; otherwise keep separate sessions. |
|
||||
|
||||
## Collect Useful Evidence
|
||||
|
||||
Reference in New Issue
Block a user