Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(deploy): let self-host Compose and Helm set feature flags (MUL-9776) (#11123)
Jiayuan Zhang5fbd8da84c89
diff --git a/.env.example b/.env.exampleindex 746e5b71cd..3f6968c411 100644--- a/.env.example+++ b/.env.example@@ -235,7 +235,8 @@ MULTICA_FEATURE_FLAGS_FILE=# FF_DOCS_V1=true# Workspace subscription Checkout/Portal/entitlement proxying is fail-closed;-# enable it only after multica-cloud billing.subscriptions is configured:+# enable it only after multica-cloud billing.subscriptions is configured. For+# multica-cloud deployments only, so the self-host stack does not pass it:# FF_BILLING_WORKSPACE_SUBSCRIPTIONS=true## Point multica-cloud's three subscription return URLs at this app'sdiff --git a/SELF_HOSTING.md b/SELF_HOSTING.mdindex 7ffd62821d..5d7d01e05e 100644--- a/SELF_HOSTING.md+++ b/SELF_HOSTING.md@@ -273,7 +273,7 @@ If the backend has to reach services whose certificates come from an internal CA#### Live doc co-editing (optional)-`collab.enabled` is off by default, and the chart then renders exactly what it did before. Turning it on runs one `multica-collab` pod and points the backend at it. Add the shared secret to `multica-secrets` first, then upgrade:+`collab.enabled` is off by default, and the chart then renders exactly what it did before. Turning it on runs one `multica-collab` pod and points the backend at it. Docs themselves are off until `backend.config.featureFlags.docs_v1=true` (see [Advanced Configuration → Feature Flags](SELF_HOSTING_ADVANCED.md#feature-flags-optional)). Add the shared secret to `multica-secrets` first, then upgrade:```bashkubectl -n multica patch secret multica-secrets --type=merge \@@ -281,7 +281,9 @@ kubectl -n multica patch secret multica-secrets --type=merge \helm upgrade multica oci://ghcr.io/multica-ai/charts/multica \--version <chart-version> \-n multica \- -f my-values.yaml --set collab.enabled=true+ -f my-values.yaml \+ --set backend.config.featureFlags.docs_v1=true \+ --set collab.enabled=true```The Ingress needs nothing new: editors open `/collab` on the backend host, which the backend forwards to collab, with the same WebSocket settings as `/ws`. Collab always runs as exactly one replica and is replaced with `Recreate`, because each open doc lives in that one process's memory. `collab.config.cdnDomain` is derived from the backend's storage settings; set it only if links to uploaded files stop turning into file cards in live docs.diff --git a/SELF_HOSTING_ADVANCED.md b/SELF_HOSTING_ADVANCED.mdindex 42c9680ed8..538f285db4 100644--- a/SELF_HOSTING_ADVANCED.md+++ b/SELF_HOSTING_ADVANCED.md@@ -207,9 +207,31 @@ rewrite configuration. Its backend fallback therefore accepts`BACKEND_PORT` → `API_PORT` → `SERVER_PORT` → `8080`, while an explicit`REMOTE_API_URL` or `NEXT_PUBLIC_API_URL` still takes priority.+### Feature Flags (Optional)++Some features are switched with `FF_<FLAG_KEY>` variables: `true`, `false` (or `on` / `off`), a percent rollout like `25%`, or a variant name.++| Variable | Default | Description |+|----------|---------|-------------|+| `FF_DOCS_V1` | off | Workspace Docs. |+| `FF_LOCAL_SEARCH_INDEX` | on | Web and Desktop keep a local search index per workspace. Set `off` to make clients search through the server again. |+| `FF_DASHBOARD_HISTORY_365D` | on | The 365-day range on the Analytics page. Set `off` if year-long dashboard queries are too slow for your database. |++With Docker Compose, set them in `.env` and run `make selfhost` (or `docker compose -f docker-compose.selfhost.yml up -d`) again. `docker-compose.selfhost.yml` passes only the flags listed above, and only when they are set, so leave a flag out of `.env` to keep its default: a flag set to an empty value is off.++With Helm, list flags by key under `backend.config.featureFlags`; each becomes `FF_<KEY>` in the backend ConfigMap, and the backend restarts when they change:++```yaml+backend:+ config:+ featureFlags:+ docs_v1: true+ local_search_index: false+```+### Live Doc Co-editing (Optional)-Docs (`FF_DOCS_V1=true`) work without it: every edit saves through the API. The `collab` service adds live co-editing, where everyone in a doc sees each other's cursors and changes as they type, and the editor shows **Live**. Editors never connect to it directly. They open a WebSocket to `/collab` on the backend, the same way they reach `/ws`, and the backend forwards it.+Docs (`FF_DOCS_V1=true`, see [Feature Flags](#feature-flags-optional)) work without it: every edit saves through the API. The `collab` service adds live co-editing, where everyone in a doc sees each other's cursors and changes as they type, and the editor shows **Live**. Editors never connect to it directly. They open a WebSocket to `/collab` on the backend, the same way they reach `/ws`, and the backend forwards it.| Variable | Service | Description ||----------|---------|-------------|diff --git a/deploy/helm/multica/templates/configmap.yaml b/deploy/helm/multica/templates/configmap.yamlindex 1f93806eb8..c623a02a06 100644--- a/deploy/helm/multica/templates/configmap.yaml+++ b/deploy/helm/multica/templates/configmap.yaml@@ -34,6 +34,10 @@ data:CLOUDFRONT_KEY_PAIR_ID: {{ .Values.backend.config.cloudfrontKeyPairId | quote }}MULTICA_MAX_PREVIEW_SIZE: {{ .Values.backend.config.maxPreviewSize | quote }}LOCAL_UPLOAD_BASE_URL: {{ .Values.backend.config.localUploadBaseUrl | quote }}+ {{- /* Same key -> env mapping as flagKeyToEnv in server/pkg/featureflag. */}}+ {{- range $key, $value := .Values.backend.config.featureFlags }}+ {{ printf "FF_%s" (regexReplaceAll "[^A-Za-z0-9]+" $key "_" | trimAll "_" | upper) }}: {{ $value | toString | quote }}+ {{- end }}{{- if not .Values.postgres.external.enabled }}# --- PostgreSQL (consumed by the backend to build DATABASE_URL) ---diff --git a/deploy/helm/multica/values.yaml b/deploy/helm/multica/values.yamlindex 99b3c1cf94..a6b7fdcae8 100644--- a/deploy/helm/multica/values.yaml+++ b/deploy/helm/multica/values.yaml@@ -185,6 +185,14 @@ backend:# Larger limits can slow browser previews.maxPreviewSize: 2MiBlocalUploadBaseUrl: http://api.multica.dev.lan+ # Feature flags by flag key, each rendered as an FF_<KEY> variable+ # (docs_v1 -> FF_DOCS_V1). An unlisted flag keeps its default; an empty+ # value turns the flag off. Values: true, false, a percent like "25%", or+ # a variant name. The flags documented in .env.example:+ # docs_v1: true # Workspace Docs, off until set+ # local_search_index: false # kill switch, on by default+ # dashboard_history_365d: false # kill switch, on by default+ featureFlags: {}resources:requests:cpu: 100mdiff --git a/docker-compose.selfhost.yml b/docker-compose.selfhost.ymlindex d5f0edb3ff..8c33faa27c 100644--- a/docker-compose.selfhost.yml+++ b/docker-compose.selfhost.yml@@ -242,9 +242,13 @@ services:# Tool steps shown in the streamed reply: auto (default; details in# private chats, kind of work in groups), off, summary or detail.MULTICA_TELEGRAM_TOOL_PROGRESS: ${MULTICA_TELEGRAM_TOOL_PROGRESS:-}- # Workspace Docs is off until FF_DOCS_V1=true. Passed only when set: an- # empty FF_ value would pin the flag off instead of leaving the default.+ # Feature flags, documented in .env.example. Each is passed only when+ # set: an empty FF_ value would pin the flag off instead of leaving the+ # default. Workspace Docs is off until FF_DOCS_V1=true; the other two are+ # kill switches for features that are on by default.FF_DOCS_V1:+ FF_LOCAL_SEARCH_INDEX:+ FF_DASHBOARD_HISTORY_365D:# Live co-editing for Workspace Docs, served by the optional collab# service below. Setting COLLAB_SECRET turns it on and points the API at# that service; enable the service with COMPOSE_PROFILES=collab.diff --git a/scripts/helm-config.test.sh b/scripts/helm-config.test.shindex 2a3aefe970..072e6a5f2a 100644--- a/scripts/helm-config.test.sh+++ b/scripts/helm-config.test.sh@@ -122,6 +122,28 @@ collab_backend_external="$(helm template multica "$CHART_DIR" --set collab.enablrequire_rendered_value "$collab_backend_external" 'name: COLLAB_INTERNAL_URL'reject_rendered_value "$collab_backend_external" 'name: DATABASE_URL'+# Feature flags render nothing by default, so every flag keeps the default the+# server gives it. Listed flags land in the ConfigMap the backend loads with+# envFrom, under the FF_<KEY> name the server looks up.+reject_rendered_value "$default_all" 'FF_'+flags_config="$(+ helm template multica "$CHART_DIR" \+ --show-only templates/configmap.yaml \+ --set backend.config.featureFlags.docs_v1=true \+ --set backend.config.featureFlags.local_search_index=false \+ --set-string 'backend.config.featureFlags.checkout\.algo-v2=25%'+)"+require_rendered_value "$flags_config" 'FF_DOCS_V1: "true"'+require_rendered_value "$flags_config" 'FF_LOCAL_SEARCH_INDEX: "false"'+require_rendered_value "$flags_config" 'FF_CHECKOUT_ALGO_V2: "25%"'+# `helm upgrade --reuse-values` from a chart without featureFlags.+legacy_flags_config="$(+ helm template multica "$CHART_DIR" \+ --show-only templates/configmap.yaml \+ --set backend.config.featureFlags=null+)"+reject_rendered_value "$legacy_flags_config" 'FF_'+capacity_config="$(helm template multica "$CHART_DIR" \--show-only templates/configmap.yaml \diff --git a/scripts/selfhost-config.test.sh b/scripts/selfhost-config.test.shindex b1795f5b1f..bc20e98f36 100755--- a/scripts/selfhost-config.test.sh+++ b/scripts/selfhost-config.test.sh@@ -83,20 +83,36 @@ require_config "$config" 'COLLAB_INTERNAL_URL: ""'collab_env="$tmp_dir/.env.collab"sed 's/^# COLLAB_SECRET=$/COLLAB_SECRET=collab-secret-from-env/;s/^# COMPOSE_PROFILES=collab$/COMPOSE_PROFILES=collab/;s/^# FF_DOCS_V1=true$/FF_DOCS_V1=true/' \"$tmp_env" >"$collab_env"-# Docs is off by default, and an empty FF_DOCS_V1 would pin it off, so the-# backend must not receive the variable at all until it is set.-docs_flag="$(env -u FF_DOCS_V1 docker compose --env-file "$tmp_env" -f docker-compose.selfhost.yml config --format json |- node -e '+# Feature flags reach the backend only when set: an empty FF_ value pins the+# flag off (Docs stays off, and a kill switch turns its feature off), so a flag+# left unset must not appear in the container at all.+backend_flags() {+ local env_file=$1+ # Unset every FF_ variable first so the agent's own environment cannot leak.+ # shellcheck disable=SC2046+ env $(compgen -e | grep '^FF_' | sed 's/^/-u /') \+ docker compose --env-file "$env_file" -f docker-compose.selfhost.yml config --format json |+ node -e 'let raw = "";process.stdin.on("data", (chunk) => (raw += chunk));process.stdin.on("end", () => {- process.stdout.write(String(JSON.parse(raw).services.backend.environment.FF_DOCS_V1 ?? "unset"));+ const env = JSON.parse(raw).services.backend.environment;+ // A bare `FF_X:` that nothing sets comes back as null: not passed.+ for (const [name, value] of Object.entries(env)) {+ if (name.startsWith("FF_") && value !== null) console.log(name + "=" + value);+ }});-')"-if [ "$docs_flag" != unset ]; then- echo "The backend must not receive FF_DOCS_V1 unless it is set, got: $docs_flag"+'+}+default_flags="$(backend_flags "$tmp_env")"+if [ -n "$default_flags" ]; then+ echo "The backend must not receive feature flags that are not set, got:"+ echo "$default_flags"exit 1fi+kill_switch_env="$tmp_dir/.env.kill-switch"+sed 's/^# FF_LOCAL_SEARCH_INDEX=off$/FF_LOCAL_SEARCH_INDEX=off/' "$tmp_env" >"$kill_switch_env"+require_env "$(backend_flags "$kill_switch_env")" 'FF_LOCAL_SEARCH_INDEX=off'collab_config="$(env -u COLLAB_SECRET -u COLLAB_INTERNAL_URL -u COMPOSE_PROFILES -u FF_DOCS_V1 \docker compose --env-file "$collab_env" -f docker-compose.selfhost.yml config --format json)"node -e '@@ -160,6 +176,29 @@ while IFS= read -r secret_key; dofidone <<<"$secret_keys"+# The same drift for feature flags: each FF_ variable .env.example tells an+# operator to set must be mapped into the backend, without a value so it is+# passed only when set. Flags that only matter to a multica-cloud deployment+# are left out on purpose.+cloud_only_flags=(FF_BILLING_WORKSPACE_SUBSCRIPTIONS)+documented_flags="$(grep -oE '^(# )?FF_[A-Z0-9_]+=' .env.example | sed -E 's/^# //;s/=$//' | sort -u)" || true+if [ -z "$documented_flags" ]; then+ echo "Found no FF_ variables in .env.example; this check no longer sees the"+ echo "documented feature flags and needs updating."+ exit 1+fi+while IFS= read -r flag; do+ if [[ " ${cloud_only_flags[*]} " == *" $flag "* ]]; then+ continue+ fi+ if ! grep -Eq "^[[:space:]]+${flag}:[[:space:]]*$" docker-compose.selfhost.yml; then+ echo "$flag is documented in .env.example but not mapped into the backend service"+ echo "in docker-compose.selfhost.yml as \`$flag:\`, so self-hosted deployments cannot"+ echo "set it. If it only matters to multica-cloud, add it to cloud_only_flags here."+ exit 1+ fi+done <<<"$documented_flags"+for script in scripts/dev.sh scripts/check.sh; doif ! grep -Fq '. scripts/local-env.sh' "$script"; thenecho "$script must source scripts/local-env.sh for shared local env derivation."