fix(cli): prevent dev server from killing its own process during port cleanup#1372
fix(cli): prevent dev server from killing its own process during port cleanup#1372devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
… cleanup When `agentuity dev` starts, Vite and the front-door proxy are configured to proxy requests to the Bun backend port (3501). If an orphan process from a previous session is still listening on that port, the cleanup logic uses `lsof -t -i :PORT` to find and kill it. The problem: `lsof -i :PORT` without state filtering returns ALL processes with any socket referencing that port — not just listeners. This includes the CLI's own Vite proxy and front-door proxy which have outbound connection configurations to port 3501. The code then `kill -9`s its own PID, causing `zsh: killed`. Fix: - Add `-sTCP:LISTEN` flag to only match processes with a LISTEN socket - Filter out the current process PID as a safety net Co-Authored-By: mcongrove@agentuity.com <mcongrove@agentuity.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
📝 WalkthroughWalkthroughRefined Unix port cleanup in the bun dev server to target LISTENing sockets and avoid killing the current process; reformatted a Zod schema field for workspace creation ( Changes
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
📦 Canary Packages Publishedversion: PackagesInstallAdd to your {
"dependencies": {
"@agentuity/evals": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-evals-2.0.9-513a25f.tgz",
"@agentuity/queue": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-queue-2.0.9-513a25f.tgz",
"@agentuity/opencode": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-opencode-2.0.9-513a25f.tgz",
"@agentuity/vector": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-vector-2.0.9-513a25f.tgz",
"@agentuity/migrate": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-migrate-2.0.9-513a25f.tgz",
"@agentuity/auth": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-auth-2.0.9-513a25f.tgz",
"@agentuity/task": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-task-2.0.9-513a25f.tgz",
"@agentuity/frontend": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-frontend-2.0.9-513a25f.tgz",
"@agentuity/core": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-core-2.0.9-513a25f.tgz",
"@agentuity/webhook": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-webhook-2.0.9-513a25f.tgz",
"@agentuity/drizzle": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-drizzle-2.0.9-513a25f.tgz",
"@agentuity/schedule": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-schedule-2.0.9-513a25f.tgz",
"@agentuity/cli": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-cli-2.0.9-513a25f.tgz",
"@agentuity/schema": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-schema-2.0.9-513a25f.tgz",
"@agentuity/coder": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-coder-2.0.9-513a25f.tgz",
"@agentuity/server": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-server-2.0.9-513a25f.tgz",
"@agentuity/workbench": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-workbench-2.0.9-513a25f.tgz",
"@agentuity/coder-tui": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-coder-tui-2.0.9-513a25f.tgz",
"@agentuity/react": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-react-2.0.9-513a25f.tgz",
"@agentuity/sandbox": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-sandbox-2.0.9-513a25f.tgz",
"@agentuity/postgres": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-postgres-2.0.9-513a25f.tgz",
"@agentuity/db": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-db-2.0.9-513a25f.tgz",
"@agentuity/keyvalue": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-keyvalue-2.0.9-513a25f.tgz",
"@agentuity/email": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-email-2.0.9-513a25f.tgz",
"@agentuity/runtime": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-runtime-2.0.9-513a25f.tgz",
"@agentuity/claude-code": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-claude-code-2.0.9-513a25f.tgz"
}
}Or install directly: bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-evals-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-queue-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-opencode-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-vector-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-migrate-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-auth-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-task-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-frontend-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-core-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-webhook-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-drizzle-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-schedule-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-cli-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-schema-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-coder-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-server-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-workbench-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-coder-tui-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-react-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-sandbox-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-postgres-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-db-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-keyvalue-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-email-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-runtime-2.0.9-513a25f.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-513a25f/agentuity-claude-code-2.0.9-513a25f.tgz |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/cli/src/cmd/build/vite/bun-dev-server.ts (1)
65-69: Consider adding a TODO or tracking issue for Windows support.The Windows code path currently returns
falsewithout attempting cleanup. While this is reasonable for now (as noted in the comment), consider adding a TODO comment or tracking issue to implement proper Windows support usingnetstatandtaskkillin the future, especially if Windows users encounter port conflict issues.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/src/cmd/build/vite/bun-dev-server.ts` around lines 65 - 69, In the Windows-specific branch inside packages/cli/src/cmd/build/vite/bun-dev-server.ts where the code checks process.platform === 'win32' and currently returns false, add a clear TODO comment (and optionally a link or placeholder to a tracking issue/issue number) stating that Windows support for port/process cleanup should be implemented (suggesting netstat + taskkill approach), so future contributors know this is intentional and tracked; update the comment to reference this TODO and the intended approach (netstat → PID → taskkill) and include an assignee or issue URL if one exists.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/cli/src/cmd/build/vite/bun-dev-server.ts`:
- Around line 65-69: In the Windows-specific branch inside
packages/cli/src/cmd/build/vite/bun-dev-server.ts where the code checks
process.platform === 'win32' and currently returns false, add a clear TODO
comment (and optionally a link or placeholder to a tracking issue/issue number)
stating that Windows support for port/process cleanup should be implemented
(suggesting netstat + taskkill approach), so future contributors know this is
intentional and tracked; update the comment to reference this TODO and the
intended approach (netstat → PID → taskkill) and include an assignee or issue
URL if one exists.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f8f942b5-4f1c-4ff7-9ec5-90c85ee42ac6
📒 Files selected for processing (1)
packages/cli/src/cmd/build/vite/bun-dev-server.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
- GitHub Check: Queue SDK Tests
- GitHub Check: Sandbox CLI Tests
- GitHub Check: Queue CLI Tests
- GitHub Check: Template Integration Tests
- GitHub Check: Storage CLI Tests
- GitHub Check: Framework Integration Tests (TanStack & Next.js)
- GitHub Check: Postgres SSL Integration Test
- GitHub Check: Package Installation & Usage Test
- GitHub Check: Playwright E2E Smoke Test
- GitHub Check: Cloud Deployment Tests
- GitHub Check: SDK Integration Test Suite
- GitHub Check: Standalone Agent Test
- GitHub Check: Windows WSL CLI Smoke Test
- GitHub Check: Pack & Upload
- GitHub Check: Build
🧰 Additional context used
📓 Path-based instructions (3)
packages/cli/**/*.ts
📄 CodeRabbit inference engine (packages/cli/AGENTS.md)
Use
Bun.file(f).exists()instead ofexistsSync(f)for file existence checks
Files:
packages/cli/src/cmd/build/vite/bun-dev-server.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use Biome as code formatter with tabs (width 3), single quotes, semicolons, lineWidth 100, and trailingCommas es5
Files:
packages/cli/src/cmd/build/vite/bun-dev-server.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Use TypeScript Strict mode with ESNext target and bundler moduleResolution
UseStructuredErrorfrom@agentuity/corefor error handling
Files:
packages/cli/src/cmd/build/vite/bun-dev-server.ts
🔇 Additional comments (3)
packages/cli/src/cmd/build/vite/bun-dev-server.ts (3)
55-59: LGTM!The added documentation clearly explains the critical importance of the
-sTCP:LISTENflag and the bug it prevents. This is excellent defensive documentation that will help future maintainers understand why this flag must not be removed.
88-94: LGTM!The double-filter approach (first matching only valid numeric PIDs, then excluding self-PID) is a solid defense-in-depth strategy. Even if the
-sTCP:LISTENflag were to behave unexpectedly, the self-PID filter prevents the most catastrophic failure mode.
74-79: No issues found with the-sTCP:LISTENflag implementation.The
-sTCP:LISTENflag is fully supported and works identically on both Linux and macOS. The code correctly uses this flag to filter lsof results to only listening TCP sockets, and the comment explaining why this flag is critical is clear and accurate.
|
devin - run |
Co-Authored-By: mcongrove@agentuity.com <mcongrove@agentuity.com>
|
@jhaynie Done — ran |
Summary
Fixes
agentuity devkilling itself during startup when an orphan process from a previous session is holding the Bun backend port (3501).Root cause:
killProcessOnPortusedlsof -t -i :PORTwhich returns all processes with any socket referencing that port — not just listeners. Since Vite's proxy and the front-door proxy (both running in-process) have outbound connection configurations to port 3501,lsofreturns the CLI's own PID. The code thenkill -9s itself, producingzsh: killed.Fix:
-sTCP:LISTENto thelsofcommand so it only matches processes with a LISTEN socket on the portprocess.pidfrom the kill list as a safety netReview & Testing Checklist for Human
-sTCP:LISTENflag works on macOS — this is where most users runagentuity dev. Runlsof -t -i :3501 -sTCP:LISTENwith a server listening on 3501 and confirm it returns only the listener PID, not processes with outbound connections to 3501.agentuity dev. Before this fix, the CLI would kill itself. After this fix, it should kill only the orphan and start normally.agentuity devwith port 3501 free and confirm startup is unaffected.Notes
killProcessOnPortat runtime, so manual testing of the actual orphan cleanup flow is recommended.Link to Devin session: https://app.devin.ai/sessions/a006ef092cae483e803d361c43850551
Summary by CodeRabbit
Bug Fixes
Chores