Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: pass container workspaces path as VITE_WORKING_DIR (#259)

Hiep Le137fbae87f89
diff --git a/__tests__/scripts/dev-docker.test.ts b/__tests__/scripts/dev-docker.test.ts
new file mode 100644
index 0000000000..27bc1d82b1
--- /dev/null
+++ b/__tests__/scripts/dev-docker.test.ts
@@ -0,0 +1,11 @@
+import { describe, expect, it } from "vitest";
+
+import { CONTAINER_WORKSPACES_DIR } from "../../scripts/dev-docker.mjs";
+
+describe("CONTAINER_WORKSPACES_DIR", () => {
+ it("points at the dockerized agent-server's in-container persistence dir so the working_dir the GUI sends is one the container can mkdir (regression guard for the host-path leak that caused 500 on POST /api/conversations)", () => {
+ expect(CONTAINER_WORKSPACES_DIR).toBe(
+ "/home/openhands/.openhands/agent-canvas/workspaces",
+ );
+ });
+});
diff --git a/scripts/dev-docker.mjs b/scripts/dev-docker.mjs
index 50a28dd493..19376f2e1c 100644
--- a/scripts/dev-docker.mjs
+++ b/scripts/dev-docker.mjs
@@ -57,6 +57,15 @@ const CONTAINER_NAME = "agent-canvas-dev-agent-server";
// decryptable across docker / non-docker runs.
const DEFAULT_SECRET_KEY = "openhands-dev-secret-key-change-in-prod";
+// Path inside the container where the agent-server stores per-conversation
+// workspace directories. Mirrors dev-with-automation.mjs's host-side
+// `${stateDir}/workspaces`, but rooted under the container's persistence
+// dir (which is `~/.openhands` on the host, mounted in below). The frontend
+// receives this via VITE_WORKING_DIR so the working_dir it sends to the
+// agent-server is one the container can actually mkdir.
+const CONTAINER_WORKSPACES_DIR =
+ "/home/openhands/.openhands/agent-canvas/workspaces";
+
/**
* Resolve the docker image to use based on environment.
*
@@ -197,6 +206,7 @@ if (isMainModule) {
bannerTitle: "Agent Canvas + Automation Development Stack (Docker)",
extraPrereqs: checkDockerPrereqs,
startAgentServer: startAgentServerDocker,
+ viteWorkingDir: CONTAINER_WORKSPACES_DIR,
}).catch((err) => {
logError(`Fatal error: ${err.message}`);
if (err.stack) {
@@ -209,6 +219,7 @@ if (isMainModule) {
export {
AGENT_SERVER_REPO,
CONTAINER_NAME,
+ CONTAINER_WORKSPACES_DIR,
DEFAULT_AGENT_SERVER_TAG,
checkDockerPrereqs,
resolveAgentServerImage,
diff --git a/scripts/dev-with-automation.mjs b/scripts/dev-with-automation.mjs
index a72442c803..277f6be2f9 100644
--- a/scripts/dev-with-automation.mjs
+++ b/scripts/dev-with-automation.mjs
@@ -556,7 +556,7 @@ function startVite(config) {
// Point Vite at the ingress (so client-side fetches work)
VITE_BACKEND_HOST: `127.0.0.1:${config.ingressPort}`,
VITE_BACKEND_BASE_URL: `http://127.0.0.1:${config.ingressPort}`,
- VITE_WORKING_DIR: join(config.stateDir, "workspaces"),
+ VITE_WORKING_DIR: config.viteWorkingDir ?? join(config.stateDir, "workspaces"),
VITE_FRONTEND_PORT: config.vitePort.toString(),
// Session API key for frontend to authenticate with agent-server
VITE_SESSION_API_KEY: config.sessionApiKey,
@@ -689,6 +689,7 @@ async function main(options = {}) {
bannerTitle = "Agent Canvas + Automation Development Stack",
startAgentServer: startAgentServerOverride,
extraPrereqs,
+ viteWorkingDir,
} = options;
const args = parseArgs();
@@ -704,6 +705,7 @@ async function main(options = {}) {
// Build config with dynamic port allocation
const config = await buildConfig(args);
+ if (viteWorkingDir) config.viteWorkingDir = viteWorkingDir;
ensureDirectories(config);
if (typeof extraPrereqs === "function") {
extraPrereqs(config);