Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
fix(chat): keep native conversation roots where the Docker daemon can mount them (#580)
crispinhu273d3254f30b97
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 69b93cfe..14ff335f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ Platform releases use `vX.Y.Z` tags and publish `ghcr.io/tencent/loopforge`. Loo- SOP sandboxes of the published image install OpenCode, Kimi Code and Pi on first use, as they already did for Claude Code. An SOP role on one of these CLIs used to fail with `exec: <cli>: not found` (exit 127) even after a conversation installed it.- Run logs and telemetry redact every environment variable ending in `_API_KEY`, `_TOKEN`, `_SECRET` or `_PASSWORD`. Agent CLI keys such as `DEEPSEEK_API_KEY`, and `AGENTFLOW_CLI_API_KEY` used with a custom Base URL, used to appear in clear text in the `docker exec` line of an SOP run log, readable by project members. Rotate a key that ran an SOP role before this release.- Upgrading with `./start.sh pull` now re-applies the schema pieces gorm AutoMigrate cannot create: the `run_telemetry.adapter` and `run_logs.level` generated columns from `migrations/001_run_obs_generated_columns.sql`, and the `INSERT IGNORE` starter catalog. A data volume from an older release no longer fails with `Error 1054 Unknown column 'adapter'` the first time someone opens a run detail. The installer and the upgrade command share one script, `scripts/install-schema-extensions.sh`, and a failed step stops the command with the migration file an operator has to run by hand.+- Native conversation roots move to `AGENTFLOW_CONVERSATION_DIR`, which `compose.yaml` sets to `${LOOPFORGE_DATA_DIR}/conversations`. They used to sit in the `platform-data` volume under `/data/assistant`, a path the host Docker daemon does not have, so opening a conversation workspace on a Compose installation failed with `mkdirat ... read-only file system`. Attachments and other per-user assistant data stay in `/data/assistant`; nothing needs moving. A customised `compose.yaml` needs the same setting. `docs/deployment.md` now spells out the upgrade steps: update the checkout, then `./start.sh pull`.- `docs/deployment.md` splits `migrations/` into scripts the installer already covers, scripts an upgrade must run once, and scripts that only backfill existing rows.- The 预览/源码 switch in the chat artifact preview now matches the 30px copy and download buttons beside it (36px on narrow screens) instead of using the 48px page-level tab size.- Requirement clarification, Bot replies, run evals and the SOP preview build list only CodeBuddy models, because they run on CodeBuddy. `POST /api/chat-clarify`, `POST /api/issues/{id}/chat-clarify` and `POST /api/runs/{id}/eval` answer 400 for a model of another CLI (such as `codex:…`) instead of switching it to the CodeBuddy default; a Codex model saved earlier in these pickers falls back to the CLI default (#228).diff --git a/compose.yaml b/compose.yamlindex 718e6dfb..bf51fdf5 100644--- a/compose.yaml+++ b/compose.yaml@@ -34,6 +34,7 @@ services:AGENTFLOW_GITHUB_CLIENT_ID: ${AGENTFLOW_GITHUB_CLIENT_ID:-}AGENTFLOW_GIT_SSH_KNOWN_HOSTS: ${AGENTFLOW_GIT_SSH_KNOWN_HOSTS:-}AGENTFLOW_ASSISTANT_SESSION_DIR: /data/assistant+ AGENTFLOW_CONVERSATION_DIR: ${LOOPFORGE_DATA_DIR}/conversationsAGENTFLOW_CLARIFY_SESSION_DIR: /data/clarifyAGENTFLOW_ASSISTANT_MODEL: ${AGENTFLOW_ASSISTANT_MODEL:-}AGENTFLOW_ASSISTANT_MODELS: ${AGENTFLOW_ASSISTANT_MODELS:-}diff --git a/docs/conversation-native-cli.md b/docs/conversation-native-cli.mdindex 1998de7b..ffc385c7 100644--- a/docs/conversation-native-cli.md+++ b/docs/conversation-native-cli.md@@ -16,7 +16,7 @@ Docker 工作区内的原生文件、补丁和命令在三种审批模式下均Runner 需要 0.10.1 或以上版本,该版本支持取消后台导出并释放工作区锁。Docker 镜像优先使用已安装的 CLI;支持官方安装器的 CLI 缺失时自动安装。ZCode 没有独立 npm 包,须在执行机器及工作区镜像内预装官方 CLI 并加入 PATH,缺失时明确报错。原生工具调用围栏与进程生命周期管理依赖 Python3。每个 Docker 会话阶段使用独立的 Linux 子进程收养进程,结束或取消时回收其全部后代,包含另建进程组的原生命令;不影响容器里的其他命令。平台会在启动前检查依赖,固定安装步骤以容器 root 用户在 `/` 中运行,实际 CLI 保留工作区的容器用户;无法准备时中止,不降级绕过调用围栏。建议在受控工作区镜像中预安装 CLI 和依赖。-原生会话的工具回调在执行机器上中继。宿主进程使用 Docker host gateway;通过 docker.sock 管理工作区的容器进程自动识别自身容器网络,工作区加入相同网络并访问该地址。自定义路由可通过 `AGENTFLOW_CONVERSATION_RELAY_HOST` 和 `AGENTFLOW_CONVERSATION_DOCKER_NETWORK` 显式指定工作区能访问的执行进程地址与 Docker 网络。Docker 工作区需要工作区脚本视图辅助程序:部署时设置 `AGENTFLOW_GATE_MCP_BINARY`(指向已构建的辅助二进制)或 `AGENTFLOW_SOURCE_ROOT`(源码目录,按需构建),两者都缺失时打开工作区会报 `script view helper unavailable`。+原生会话的工具回调在执行机器上中继。宿主进程使用 Docker host gateway;通过 docker.sock 管理工作区的容器进程自动识别自身容器网络,工作区加入相同网络并访问该地址。自定义路由可通过 `AGENTFLOW_CONVERSATION_RELAY_HOST` 和 `AGENTFLOW_CONVERSATION_DOCKER_NETWORK` 显式指定工作区能访问的执行进程地址与 Docker 网络。会话目录会以相同路径挂进工作区,而 docker.sock 背后的 Docker 守护进程按自己所在主机解析挂载源,因此容器内的平台进程须把 `AGENTFLOW_CONVERSATION_DIR` 设在与宿主机同路径挂载的目录中;`compose.yaml` 将其设为 `${LOOPFORGE_DATA_DIR}/conversations`。Runner 不读该变量,原生会话目录固定在其工作区根目录的 `.conversations` 下,容器内运行 Runner 时须同路径挂载该工作区目录。未设置时会话目录位于 `AGENTFLOW_ASSISTANT_SESSION_DIR` 下,该目录在命名卷里时打开工作区会报 `mkdirat ... read-only file system`。附件等按用户保存的助手数据仍在 `AGENTFLOW_ASSISTANT_SESSION_DIR`,不挂进工作区。Docker 工作区需要工作区脚本视图辅助程序:部署时设置 `AGENTFLOW_GATE_MCP_BINARY`(指向已构建的辅助二进制)或 `AGENTFLOW_SOURCE_ROOT`(源码目录,按需构建),两者都缺失时打开工作区会报 `script view helper unavailable`。模式交接时,交接工具要求模型只回复一句「好的。」再结束旧阶段,交接之后的展示由平台隐藏;不要求“不输出任何内容”,否则模型可能只产出推理、没有正文的回合,该回合写入原生日志后,续接时会被模型服务拒绝(如 `the conversation must end with a user message`)。交接工具成功后,旧阶段即使未输出 `type=result` 或异常退出,也继续完成交接。续接原生会话时,如果原生日志缺失,或模型服务在本阶段产生任何输出或工具调用之前就拒绝了续接(400/422、会话结构无效、无结果退出),平台用完整对话上下文新建一次原生会话重试;已有输出或工具调用的中断,以及鉴权、限流、额度、网络、执行机器不可用等原因,仍续接原会话或直接报错,不重复执行副作用。diff --git a/docs/deployment.md b/docs/deployment.mdindex 678659cd..28e0ff73 100644--- a/docs/deployment.md+++ b/docs/deployment.md@@ -38,6 +38,15 @@ Run it as the installation owner, including an ordinary Linux user. If that user`compose.yaml` is the published-image stack and never builds: `./start.sh`, `scripts/install.sh` and a plain `docker compose --profile platform up` all pull the GHCR release pinned there (currently `ghcr.io/tencent/loopforge:0.3.8`). The pin matches the checkout's migrations and seeds, so check out a release tag when you install. Set `LOOPFORGE_IMAGE` (for example to an `@sha256:` digest) only to override it; a value saved in `.env` takes precedence over later pin changes.+To upgrade, update the checkout first, then refresh the containers:++```bash+git fetch --tags && git checkout vX.Y.Z+./start.sh pull+```++The new `compose.yaml` brings the image pin and any new platform settings together, and `./start.sh pull` recreates the platform container when either changes. A source build from `./start.sh dev` is not rebuilt by `./start.sh pull`; run `./start.sh dev` again after updating the checkout. Running `./start.sh pull` alone keeps the pinned version. With `LOOPFORGE_IMAGE` saved in `.env`, change it to the checked-out release as well; a newer image with an older `compose.yaml` can miss settings that release needs.+Where `ghcr.io` downloads stall, set `MIRROR` to the registry host that replaces `ghcr.io`. `./start.sh` and `./start.sh pull` pull that reference and tag it back to the name in `compose.yaml`. Setting `MIRROR` trusts that host, because the result is tagged with the official name. The GitHub Release records the image digest; `docker image inspect --format '{{index .RepoDigests 0}}' ghcr.io/tencent/loopforge:<pin>` should show the same digest after `@`. The pull policy stays `missing` on install, so a local image is kept; `./start.sh pull` refreshes it from the same host. Leaving `MIRROR` unset preserves the direct `ghcr.io` pull. [ghcr.nju.edu.cn](https://doc.nju.edu.cn/books/e1654/page/ghcr) is one compatible host. Docker's `registry-mirrors` setting, including `https://docker.nju.edu.cn`, only applies to Docker Hub and cannot be used as `MIRROR`. A `LOOPFORGE_IMAGE` value that is not a `ghcr.io` name:tag is left unchanged.```bash@@ -66,7 +75,7 @@ The platform exposes a built-in default sandbox (`local`) even when the catalogFor native services running as an ordinary host user, default/root Docker images run with that service user's UID/GID so private workspaces remain accessible without relaxing their permissions or adding capabilities. Images that explicitly select a non-root user retain that identity; operators must arrange compatible bind-mount ownership for those images.-The Compose deployment mounts the host Docker socket into the platform container so built-in AI SOPs run out of the box. `AGENTFLOW_ISOLATED_IMAGE` points to the installed platform image: default sandboxes start separate sibling containers from that same image, with no second CLI download or image build. They do not mount the Docker socket. Custom Dockerfiles still build and cache their own images. The run workspace is mounted at `/workspace` on the Compose network. Because bind mounts are resolved by the host Docker daemon, `LOOPFORGE_DATA_DIR` (written to `.env` by `scripts/configure.sh`, default `./.data`) is mounted into the platform container at the same absolute path; workspaces and CLI state live under it.+The Compose deployment mounts the host Docker socket into the platform container so built-in AI SOPs run out of the box. `AGENTFLOW_ISOLATED_IMAGE` points to the installed platform image: default sandboxes start separate sibling containers from that same image, with no second CLI download or image build. They do not mount the Docker socket. Custom Dockerfiles still build and cache their own images. The run workspace is mounted at `/workspace` on the Compose network. Because bind mounts are resolved by the host Docker daemon, `LOOPFORGE_DATA_DIR` (written to `.env` by `scripts/configure.sh`, default `./.data`) is mounted into the platform container at the same absolute path; workspaces and CLI state live under it. Native conversation workspaces bind-mount their conversation roots the same way, so `compose.yaml` sets `AGENTFLOW_CONVERSATION_DIR` to `${LOOPFORGE_DATA_DIR}/conversations`. Attachments and other per-user assistant state stay in `AGENTFLOW_ASSISTANT_SESSION_DIR` (`/data/assistant` in the `platform-data` volume), which is never mounted into a workspace. A platform container whose `AGENTFLOW_CONVERSATION_DIR` is unset keeps conversation roots there too, and opening a conversation workspace then fails with `mkdirat ... read-only file system`.Access to the Docker socket is equivalent to root on the host. Two safeguards follow from that: the platform runs every task in a sandbox container, including SOPs configured for the `local` driver (`AGENTFLOW_LOCAL_SANDBOX=docker`), and only platform administrators can point a repository at a host source path. Even so, anyone who can run SOPs can execute code in containers on this host, so only give accounts to people you trust and do not expose the service to untrusted networks. To run without the socket, remove the `docker.sock` volume and the `AGENTFLOW_LOCAL_SANDBOX` setting from `compose.yaml`, then connect a separate Docker-capable worker or execution machine for AI SOPs; the script-only welcome SOP then runs inside the platform container.diff --git a/internal/httpapi/assistant_native_session.go b/internal/httpapi/assistant_native_session.goindex 7af74f0c..e4d679d6 100644--- a/internal/httpapi/assistant_native_session.go+++ b/internal/httpapi/assistant_native_session.go@@ -41,7 +41,7 @@ type assistantNativeSession struct {func assistantSharedSessionRoot(id string) string {sum := sha256.Sum256([]byte(id))- return filepath.Join(assistantSessionBase(), "shared", hex.EncodeToString(sum[:]))+ return filepath.Join(assistantConversationBase(), "shared", hex.EncodeToString(sum[:]))}func assistantMessageHashes(messages []assistantMessage) []string {diff --git a/internal/httpapi/assistant_session.go b/internal/httpapi/assistant_session.goindex 69583e49..0671fa67 100644--- a/internal/httpapi/assistant_session.go+++ b/internal/httpapi/assistant_session.go@@ -448,12 +448,22 @@ func assistantSessionRoot(userID int64) string {return filepath.Join(assistantSessionBase(), strconv.FormatInt(userID, 10))}+// assistantConversationBase holds the native conversation roots. They are+// bind-mounted into Docker workspaces, so a platform that reaches the daemon+// through docker.sock must keep them at a path the daemon's host has too.+func assistantConversationBase() string {+ if override := strings.TrimSpace(os.Getenv("AGENTFLOW_CONVERSATION_DIR")); override != "" {+ return override+ }+ return assistantSessionBase()+}+// assistantConversationRoot is the CLI root (home and ws) of one personal// conversation. It is keyed by owner and session, so a reused session ID can// never reach another user's native state.func assistantConversationRoot(userID int64, sessionID string) string {sum := sha256.Sum256([]byte(strconv.FormatInt(userID, 10) + "/" + sessionID))- return filepath.Join(assistantSessionBase(), "conversations", hex.EncodeToString(sum[:]))+ return filepath.Join(assistantConversationBase(), "conversations", hex.EncodeToString(sum[:]))}func assistantCLIHome(userID int64) string {diff --git a/internal/httpapi/assistant_subagents_test.go b/internal/httpapi/assistant_subagents_test.goindex 197c463a..190794f4 100644--- a/internal/httpapi/assistant_subagents_test.go+++ b/internal/httpapi/assistant_subagents_test.go@@ -61,6 +61,53 @@ printf '%s\n' '{"type":"result","result":"好"}'}}+func TestConversationRootsFollowConversationDir(t *testing.T) {+ sessions, conversations := t.TempDir(), t.TempDir()+ t.Setenv("AGENTFLOW_ASSISTANT_SESSION_DIR", sessions)+ under := func(root, base, kind string) bool {+ return filepath.Base(filepath.Dir(root)) == kind && filepath.Dir(filepath.Dir(root)) == base+ }+ for _, unset := range []string{"", " "} {+ t.Setenv("AGENTFLOW_CONVERSATION_DIR", unset)+ if root := assistantConversationRoot(7, "s"); !under(root, sessions, "conversations") {+ t.Fatalf("personal root with AGENTFLOW_CONVERSATION_DIR=%q = %s", unset, root)+ }+ if root := assistantSharedSessionRoot("s"); !under(root, sessions, "shared") {+ t.Fatalf("shared root with AGENTFLOW_CONVERSATION_DIR=%q = %s", unset, root)+ }+ }+ t.Setenv("AGENTFLOW_CONVERSATION_DIR", conversations)+ if root := assistantConversationRoot(7, "s"); !under(root, conversations, "conversations") {+ t.Fatalf("personal root = %s, want under %s", root, conversations)+ }+ if root := assistantSharedSessionRoot("s"); !under(root, conversations, "shared") {+ t.Fatalf("shared root = %s, want under %s", root, conversations)+ }+ for _, path := range []string{assistantSessionRoot(7), assistantCLIHome(7), workbenchAttachmentDir(7)} {+ if !strings.HasPrefix(path, sessions+string(filepath.Separator)) {+ t.Fatalf("per-user state %s left AGENTFLOW_ASSISTANT_SESSION_DIR", path)+ }+ }++ native := filepath.Join(assistantConversationRoot(7, "s"), "home", "state")+ attachment := filepath.Join(workbenchAttachmentDir(7), "kept.bin")+ for _, file := range []string{native, attachment} {+ if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(file, []byte("x"), 0600); err != nil {+ t.Fatal(err)+ }+ }+ deleteAssistantCLISession(7, "s")+ if _, err := os.Stat(assistantConversationRoot(7, "s")); !os.IsNotExist(err) {+ t.Fatalf("deleting the conversation left its root: %v", err)+ }+ if _, err := os.Stat(attachment); err != nil {+ t.Fatalf("deleting the conversation removed per-user state: %v", err)+ }+}+func TestProjectConversationIsolatesReferencesAndOffersProjectRoles(t *testing.T) {h, u := workbenchFixture(t)h.repo.PutProject(domain.Project{ID: "other", Name: "Other", OwnerID: u.ID})diff --git a/internal/httpapi/main_test.go b/internal/httpapi/main_test.gonew file mode 100644index 00000000..0efe35a9--- /dev/null+++ b/internal/httpapi/main_test.go@@ -0,0 +1,15 @@+package httpapi++import (+ "os"+ "testing"+)++// Tests isolate assistant state by pointing AGENTFLOW_ASSISTANT_SESSION_DIR at+// a temporary directory. Conversation roots follow it only while+// AGENTFLOW_CONVERSATION_DIR is unset, so a value from the shell would send+// them to a real directory shared by every test.+func TestMain(m *testing.M) {+ os.Unsetenv("AGENTFLOW_CONVERSATION_DIR")+ os.Exit(m.Run())+}