Skip to content

fix(utils): misleading port-range comment in calculatePortOffset disagrees with actual basePort #1008

@kuishou68

Description

@kuishou68

Bug: Incorrect port range in comment vs actual code

Description

In packages/core/src/utils/port-allocation.ts, the inline comment inside calculatePortOffset states:

// 100-999 range: Offset starts at 100 to avoid default port 3000, results in ports 3100-3999
return (hash.readUInt16BE(0) % 900) + 100;

However, the actual basePort used in getPort() is 3090, not 3000:

const basePort = 3090;
// ...
const port = basePort + offset;  // 3090 + 100..999  =>  3190..4089

So the real port range allocated for worktrees is 3190–4089, not the 3100–3999 stated in the comment.

The JSDoc above the function already has the correct range:

* @returns Offset in range 100-999 (ports 3190-4089 when added to base 3090)

But the inline comment directly contradicts this, making it confusing for contributors.

Steps to reproduce

  1. Open packages/core/src/utils/port-allocation.ts
  2. Read the inline comment in calculatePortOffset
  3. Compare with basePort = 3090 and the JSDoc — the inline comment says 3100–3999 but the JSDoc says 3190–4089

Expected behaviour

The inline comment should match the correct JSDoc annotation and actual arithmetic:
// 100-999 range; produces ports 3190-4089 when added to basePort (3090)

Fix

Update the misleading inline comment to accurately describe the resulting port range.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions