Skip to content

fix(setup): use reserved port for Electric container in multi-worktree#1417

Merged
Kitenite merged 1 commit into
mainfrom
kitenite/electric-port-base
Feb 12, 2026
Merged

fix(setup): use reserved port for Electric container in multi-worktree#1417
Kitenite merged 1 commit into
mainfrom
kitenite/electric-port-base

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Feb 12, 2026

Summary

  • When SUPERSET_PORT_BASE is set, the Electric container now starts on BASE+9 (the reserved offset) instead of an auto-assigned port
  • Fixes a mismatch where .env wrote the reserved port but the container ran on a random one

Changes

  • .superset/setup.sh: step_start_electric checks SUPERSET_PORT_BASE and uses -p $ELECTRIC_PORT:3000 instead of -p 3000. Falls back to auto-assign + docker port lookup when no port base is set.

Test Plan

  • Setup workspace without SUPERSET_PORT_BASE — Electric auto-assigns port (unchanged behavior)
  • Setup workspace with SUPERSET_PORT_BASE — Electric starts on BASE+9, matching .env

Summary by CodeRabbit

  • Chores
    • Improved Electric service startup configuration with dynamic port binding support. The setup now calculates container port values based on configuration parameters when available, while maintaining backward compatibility with default port assignment. Enhanced robustness for auto-assigned port resolution and service health verification.

When SUPERSET_PORT_BASE is set, the Electric container now starts on
BASE+9 (the reserved offset) instead of an auto-assigned port. This
fixes a mismatch where .env wrote the reserved port but the container
ran on a random one.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

The .superset/setup.sh script is modified to support dynamic port binding for the Electric container based on the SUPERSET_PORT_BASE environment variable, calculating the port as SUPERSET_PORT_BASE + 9 when available, with fallback to static port 3000, and adding post-startup port resolution for auto-assigned scenarios.

Changes

Cohort / File(s) Summary
Setup Script Configuration
.superset/setup.sh
Modified Electric container startup to use dynamic port binding via SUPERSET_PORT_BASE environment variable, replacing static -p 3000 with computed port_flag; added post-start port resolution when ELECTRIC_PORT is not pre-set.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Ports now flow with nimble grace,
No more rigid three-thousand's place!
BASE plus nine guides Electric's way,
Flexible binding, come what may!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(setup): use reserved port for Electric container in multi-worktree' directly describes the main change—ensuring the Electric container uses the reserved port calculated from SUPERSET_PORT_BASE.
Description check ✅ Passed The description includes a clear summary of the fix, detailed changes, and a test plan covering both scenarios; it aligns well with the template structure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/electric-port-base

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.superset/setup.sh:
- Around line 282-285: The docker port parsing can break on IPv6 or multi-line
output; update the ELECTRIC_PORT assignment (where ELECTRIC_PORT is set from
docker port "$ELECTRIC_CONTAINER" 3000) to robustly handle multi-line and
bracketed IPv6 addresses by selecting the last non-empty line of the output and
extracting only the trailing numeric port (strip any brackets/hosts), e.g. use a
pipeline that filters out empty lines, picks the final line, and applies a regex
to capture only the digits at the end of the line so ELECTRIC_PORT becomes a
clean numeric port.
🧹 Nitpick comments (1)
.superset/setup.sh (1)

263-274: Port binding logic is correct and addresses the PR objective well.

The conditional port assignment properly uses the reserved offset (BASE+9) when SUPERSET_PORT_BASE is set.

Minor nit: $port_flag is intentionally unquoted on line 274 to allow word splitting. A Bash array would be more robust and avoid ShellCheck SC2086, but since the values are fully controlled numerics, this is fine in practice.

Optional: use an array for port_flag
   # Use reserved port from SUPERSET_PORT_BASE if available, otherwise auto-assign
-  local port_flag
+  local port_flag=()
   if [ -n "${SUPERSET_PORT_BASE:-}" ]; then
     ELECTRIC_PORT=$((SUPERSET_PORT_BASE + 9))
-    port_flag="-p $ELECTRIC_PORT:3000"
+    port_flag=(-p "$ELECTRIC_PORT:3000")
   else
-    port_flag="-p 3000"
+    port_flag=(-p 3000)
   fi

Then on the docker run line:

   if ! docker run -d \
       --name "$ELECTRIC_CONTAINER" \
-      $port_flag \
+      "${port_flag[@]}" \
       -e DATABASE_URL="$DIRECT_URL" \

Comment thread .superset/setup.sh
Comment on lines +282 to +285
# Resolve actual port (needed when auto-assigned)
if [ -z "${ELECTRIC_PORT:-}" ]; then
ELECTRIC_PORT=$(docker port "$ELECTRIC_CONTAINER" 3000 | cut -d: -f2)
fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

docker port output parsing may break with IPv6 or multi-line output.

docker port can return multiple lines (IPv4 + IPv6), e.g.:

0.0.0.0:12345
[::]:12345

cut -d: -f2 on the IPv6 line yields :] instead of the port. The multi-line output could also embed a newline in ELECTRIC_PORT.

Suggested fix: extract port reliably
-    ELECTRIC_PORT=$(docker port "$ELECTRIC_CONTAINER" 3000 | cut -d: -f2)
+    ELECTRIC_PORT=$(docker port "$ELECTRIC_CONTAINER" 3000 | head -1 | awk -F: '{print $NF}')
🤖 Prompt for AI Agents
In @.superset/setup.sh around lines 282 - 285, The docker port parsing can break
on IPv6 or multi-line output; update the ELECTRIC_PORT assignment (where
ELECTRIC_PORT is set from docker port "$ELECTRIC_CONTAINER" 3000) to robustly
handle multi-line and bracketed IPv6 addresses by selecting the last non-empty
line of the output and extracting only the trailing numeric port (strip any
brackets/hosts), e.g. use a pipeline that filters out empty lines, picks the
final line, and applies a regex to capture only the digits at the end of the
line so ELECTRIC_PORT becomes a clean numeric port.

@Kitenite Kitenite merged commit 91bc9ce into main Feb 12, 2026
14 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 12, 2026

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) View Branch
Fly.io Electric (Fly.io) View App
Fly.io Streams (Fly.io) View App
Vercel API (Vercel) Open Preview
Vercel Web (Vercel) Open Preview
Vercel Marketing (Vercel) Open Preview
Vercel Admin (Vercel) Open Preview
Vercel Docs (Vercel) Open Preview

Preview updates automatically with new commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant