Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: use PostHog prod creds only for tagged Docker releases (#666)

Rohit Malhotradb976f2e66af
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index f1564fd493..6bb8790ec2 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -160,6 +160,13 @@ jobs:
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
+ # Use production PostHog key only for tagged releases
+ if [[ "$RELEVANT_REF" == refs/tags/v* ]]; then
+ echo "vite_app_env=production" >> "$GITHUB_OUTPUT"
+ else
+ echo "vite_app_env=" >> "$GITHUB_OUTPUT"
+ fi
+
echo "=== Build outputs ==="
echo "Short SHA: $SHORT_SHA"
echo "Tags: $TAGS"
@@ -179,6 +186,7 @@ jobs:
AUTOMATION_VERSION=${{ steps.prep.outputs.automation_version }}
OPENHANDS_BUILD_GIT_SHA=${{ env.RELEVANT_SHA }}
OPENHANDS_BUILD_GIT_REF=${{ env.RELEVANT_REF }}
+ VITE_APP_ENV=${{ steps.prep.outputs.vite_app_env }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
diff --git a/AGENTS.md b/AGENTS.md
index 6242dd4352..9d6d0cf684 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -445,6 +445,6 @@ return new ConversationClient(getAgentServerClientOptions()).someMethod(...);
- CI workflow: a `Read defaults from config/defaults.json` step uses `node -p` to extract values into `$GITHUB_OUTPUT`.
- Dockerfile ARG defaults are kept as fallbacks for local `docker build` without the CI workflow; CI always passes `--build-arg` overrides from the JSON.
- To bump a version, edit `config/defaults.json` only β€” the JS scripts, Docker build, and CI workflow all derive their values from it.
-- Docker all-in-one image: `.github/workflows/docker.yml` builds and publishes `ghcr.io/openhands/agent-canvas` β€” a combined image that bundles the agent-server (from `ghcr.io/openhands/agent-server`), the automation server (`openhands-automation` via pip), and the agent-canvas frontend (static build). The Dockerfile lives at `docker/Dockerfile`, the entrypoint at `docker/entrypoint.sh`. The workflow structure mirrors the SDK repo's `server.yml`: a `build-and-push-image` matrix job (2 Γ— arch: amd64 on `ubuntu-24.04`, arm64 on `ubuntu-24.04-arm`) pushes arch-suffixed tags, then `merge-manifests` creates multi-arch manifests via `docker buildx imagetools create`, then `consolidate-build-info` aggregates artifacts, and `update-pr-description` updates the PR body (using `<!-- AGENT_CANVAS_DOCKER_START -->` / `<!-- AGENT_CANVAS_DOCKER_END -->` markers). The workflow triggers on push to main, `v*` tags (releases), PRs, and `workflow_dispatch`. On release tags it also pushes semver tags (e.g. `1.2.3`, `1.2`, `1`, `latest`). Fork PRs are skipped (no GHCR auth). The image exposes port 8000 as a unified entry point: `/api/automation/*` β†’ automation (:18001), `/api/*` β†’ agent-server (:18000), `/*` β†’ static frontend. The entrypoint auto-generates **both** the session API key and `OH_SECRET_KEY` (persisted to `~/.openhands/agent-canvas/session-api-key.txt` and `secret-key.txt` respectively) when none is provided, so the image runs secure by default. Users can override either via env var (`OH_SECRET_KEY`, `SESSION_API_KEY` / `OH_SESSION_API_KEYS_0`). Unlike `scripts/dev-safe.mjs` (which uses a static default secret key for local dev convenience), the Docker entrypoint never falls back to a known default.
+- Docker all-in-one image: `.github/workflows/docker.yml` builds and publishes `ghcr.io/openhands/agent-canvas` β€” a combined image that bundles the agent-server (from `ghcr.io/openhands/agent-server`), the automation server (`openhands-automation` via pip), and the agent-canvas frontend (static build). The Dockerfile lives at `docker/Dockerfile`, the entrypoint at `docker/entrypoint.sh`. The workflow structure mirrors the SDK repo's `server.yml`: a `build-and-push-image` matrix job (2 Γ— arch: amd64 on `ubuntu-24.04`, arm64 on `ubuntu-24.04-arm`) pushes arch-suffixed tags, then `merge-manifests` creates multi-arch manifests via `docker buildx imagetools create`, then `consolidate-build-info` aggregates artifacts, and `update-pr-description` updates the PR body (using `<!-- AGENT_CANVAS_DOCKER_START -->` / `<!-- AGENT_CANVAS_DOCKER_END -->` markers). The workflow triggers on push to main, `v*` tags (releases), PRs, and `workflow_dispatch`. On release tags it also pushes semver tags (e.g. `1.2.3`, `1.2`, `1`, `latest`). Fork PRs are skipped (no GHCR auth). The image exposes port 8000 as a unified entry point: `/api/automation/*` β†’ automation (:18001), `/api/*` β†’ agent-server (:18000), `/*` β†’ static frontend. The Dockerfile accepts a `VITE_APP_ENV` build arg (default empty β†’ staging PostHog key); the CI workflow passes `VITE_APP_ENV=production` only for tagged releases (`refs/tags/v*`), so PR and main-branch images use the staging key while release images use the production key, matching the `build:lib` npm path. The entrypoint auto-generates **both** the session API key and `OH_SECRET_KEY` (persisted to `~/.openhands/agent-canvas/session-api-key.txt` and `secret-key.txt` respectively) when none is provided, so the image runs secure by default. Users can override either via env var (`OH_SECRET_KEY`, `SESSION_API_KEY` / `OH_SESSION_API_KEYS_0`). Unlike `scripts/dev-safe.mjs` (which uses a static default secret key for local dev convenience), the Docker entrypoint never falls back to a known default.
- Cloud conversation resume gating: when a cloud conversation is closed from the UI (`pauseCloudSandbox` is called), the conversation's `conversation_url` is NOT cleared -- it still points to the old sandbox host. `WebSocketProviderWrapper` must suppress the URL (pass `null` to `ConversationWebSocketProvider`) while `sandbox_status === "PAUSED"`, otherwise the WebSocket immediately tries the stale URL before the sandbox wakes. Symmetrically, `useActiveConversation`'s refetch interval must fast-poll (3 s) on both `!conversation_url` AND `sandbox_status === "PAUSED"` -- checking only the missing URL would leave the hook on the 30 s interval while the sandbox is resuming. The resume sequence: navigate -> sandbox PAUSED detected -> `resumeCloudSandbox` called (in `conversation.tsx`) -> fast-poll detects RUNNING -> `conversationUrl` unblocked -> WebSocket connects.
diff --git a/docker/Dockerfile b/docker/Dockerfile
index f4bce09a55..beb49ef7b7 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -35,7 +35,12 @@ RUN npm ci
# Copy everything needed for the build
COPY . .
-# Build the static frontend
+# Build the static frontend.
+# VITE_APP_ENV controls the PostHog telemetry key baked into the bundle:
+# "production" β†’ prod key (set by CI for tagged releases)
+# anything else β†’ staging key (default for PR / main / local builds)
+ARG VITE_APP_ENV=""
+ENV VITE_APP_ENV=${VITE_APP_ENV}
RUN npm run build
# ── Stage 1b: Generate shell-sourceable defaults from config/defaults.json ──