Skip to content

Address review feedback on port conflict rescue#33

Merged
fredrivett merged 2 commits into
mainfrom
fredrivett/port-conflict-followups
Jul 1, 2026
Merged

Address review feedback on port conflict rescue#33
fredrivett merged 2 commits into
mainfrom
fredrivett/port-conflict-followups

Conversation

@fredrivett

@fredrivett fredrivett commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Follow-up to #32 (merged), addressing the four issues cubic raised in review. All four were valid.

Fixes

  1. parsePort — restrict long-form to --port= (PM2Process.swift)
    hasPrefix("--port") also matched unrelated flags like --port-range=9000, which would parse the wrong port and could trigger the kill/restart rescue against it. Now matches --port= exactly. Added a regression test.

  2. Recency gate on conflict detection (PM2Service.swift / PM2Service+Parsing.swift)
    Detection claimed to require a recent bind error but didn't enforce it. It now ignores an error log last modified before the process's current run start (pm_uptime), so a stale EADDRINUSE from a previous run can't prompt the user to kill whatever legitimately holds the port now.

  3. Confirmation keyed to the port, not a Bool (ProcessRowView.swift)
    confirmingFreePort is now Int? (the port awaiting confirmation). If a poll changes portConflict between the two clicks, a stale confirmation can no longer authorize killing a different port's holder.

  4. Demo transfers port ownership on rescue (DemoData.swift)
    The demo's one-click free previously left the old holder still showing :3000 and the rescued service with no port. freePort now mirrors the real action: the holder is stopped and loses the port, and the rescued process comes online bound to it.

Tests

Full suite green (133 tests), incl. the new --port-range= regression test. swiftlint --strict clean.

🤖 Generated with Claude Code


Summary by cubic

Hardens port-conflict rescue to avoid wrong-port kills and ignore stale bind errors. Aligns the demo and confirmation flow with real behavior, and ensures the confirm timeout can’t clear a newer confirm.

  • Bug Fixes
    • Arg parsing: only accept --port=; ignore --port-range=. Adds a regression test.
    • Conflict detection: gate error-log match by recency using pm_uptime; stale EADDRINUSE is ignored.
    • Confirmation: key to the specific port (Int?) and scope the 3s timeout to that port to avoid authorizing or clearing the wrong confirm after a poll.
    • Demo: freePort now transfers port ownership—stop the holder, clear its port, and bring the target online bound to it.

Written for commit 3523993. Summary will update on new commits.

Review in cubic

- parsePort: only treat `--port=` (not any `--port`-prefixed flag such as
  `--port-range=`) as the long-form port, avoiding a wrong-port rescue.
- Port-conflict detection now gates the error-log match on recency: a log
  last modified before the process's current run start (pm_uptime) is
  stale and ignored, so an old bind error can't prompt killing whatever
  legitimately holds the port now.
- ProcessRowView: key the free-port confirmation to the specific port
  rather than a Bool, so a poll that changes portConflict mid-confirm
  can't authorize killing a different port's holder.
- DemoData: freePort now transfers port ownership — the holder is stopped
  and loses the port, the rescued process comes online bound to it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 6 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread Sources/Reeve/Views/ProcessRowView.swift Outdated
The 3s reset task cancels on re-arm, but if it passes its isCancelled
check just as a newer confirmation is armed, its queued MainActor.run
could still clear the fresh confirmation. Guard the clear on the port the
timer armed for so a newer confirmation for a different port stands.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@fredrivett fredrivett merged commit fcae1a7 into main Jul 1, 2026
2 checks passed
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