Skip to content

fix(dev): make worktree startup resilient - #5026

Merged
jeanduplessis merged 2 commits into
mainfrom
security-agent-socket
Aug 5, 2026
Merged

fix(dev): make worktree startup resilient#5026
jeanduplessis merged 2 commits into
mainfrom
security-agent-socket

Conversation

@jeanduplessis

Copy link
Copy Markdown
Contributor

Summary

Make local development startup recover from stale shared tmux state and avoid an automatic port that Next.js rejects.

Why this change is needed

Worktree startup could stall while waiting for Stripe when a shared tmux server retained the working directory of a deleted sibling worktree. After recovering from that failure, automatic offset selection could assign port 6000 to Next.js, which Next.js rejects because it is in the X11 range.

These failures required developers to repair shared tmux state or manually choose another offset even though dev:start is intended to isolate worktree sessions.

How this is addressed

  • Start tmux login shells from the active worktree even when the shared tmux server has stale PWD or OLDPWD values.
  • Preserve the intended worktree directory for newly created service windows.
  • Skip the X11 port range during automatic offset selection while leaving explicit offsets unchanged.
  • Add regression coverage for stale tmux environments and reserved automatic ports.

Human Verification

  • Ran 30 focused port allocation and service tests successfully.
  • Ran the tmux shell-wrapper and stale-working-directory regression tests successfully.
  • Started the core development stack with automatic offset selection.
  • Confirmed Next.js became ready at http://localhost:6100.
  • Confirmed PostgreSQL, Redis, and Redis HTTP reported healthy.
  • Confirmed the Stripe listener captured its webhook secret and began forwarding without uv_cwd or shell-init errors.

Reviewer Notes

Human Reviewer Flags

  • Automatic selection avoids only the X11 range (6000–6063) that Next.js rejects; explicit offsets remain authoritative.

Code Reviewer Agent

Code Reviewer Notes
  • The tmux wrapper uses an outer /bin/sh to enter the worktree before starting the configured login shell, preventing shell initialization from resolving a deleted cwd.
  • Session and window environments explicitly set the active worktree PWD; session OLDPWD is also reset.
  • Reserved-port checks cover resolved service listeners and worker inspector ports.

Comment thread dev/local/tmux.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of commit c713ad5: the single-line change in dev/local/tmux.ts resolves the previous SUGGESTION by passing undefined for the dashboard shell, so buildInteractiveShellCommand falls back to process.env.SHELL || '/bin/sh' (matching service windows) while the outer /bin/sh -c 'cd ... && exec ...' wrapper keeps the stale-cwd fix intact; no new issues found.

Files Reviewed (4 files)
  • dev/local/cli.ts
  • dev/local/port-offset-lease.test.ts
  • dev/local/tmux.test.ts
  • dev/local/tmux.ts
Previous Review Summary (commit 2041f75)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 2041f75)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1

The reserved-port skip logic and tmux stale-cwd wrapper are sound and well covered by regression tests; the only finding is a minor UX behavior change where the tmux dashboard window's interactive shell is hardcoded to /bin/sh instead of the user's default shell.

Issue Details (click to expand)

SUGGESTION

File Line Issue
dev/local/tmux.ts 85 Dashboard window now starts /bin/sh -l instead of the user's default shell (service windows still honor process.env.SHELL)
Files Reviewed (4 files)
  • dev/local/cli.ts - 0 issues
  • dev/local/port-offset-lease.test.ts - 0 issues
  • dev/local/tmux.test.ts - 0 issues
  • dev/local/tmux.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by kimi-k3 · Input: 60.3K · Output: 4.6K · Cached: 251.4K

Review guidance: REVIEW.md from base branch main

Co-authored-by: kilo-code-bot[bot] <240665456+kilo-code-bot[bot]@users.noreply.github.com>
@jeanduplessis
jeanduplessis enabled auto-merge (squash) August 5, 2026 13:48
@jeanduplessis
jeanduplessis merged commit e3b75af into main Aug 5, 2026
16 checks passed
@jeanduplessis
jeanduplessis deleted the security-agent-socket branch August 5, 2026 13:52
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.

2 participants