Skip to content

fix: bind an ephemeral port in session-self-exit-test.sh - #327

Merged
bborbe merged 1 commit into
masterfrom
fix/session-self-exit-test-free-port
Oct 20, 2026
Merged

bborbe merged 1 commit into
masterfrom
fix/session-self-exit-test-free-port

Conversation

@bborbe

@bborbe bborbe commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Problem

scripts/session-self-exit-test.sh hardcoded PORT=18099 for its stub attention store. On a host where anything else already listens on that port, the stub server fails to bind silently — and the test then reads whatever is on that port. A 404 on /api/1.0/attention is treated by session-self-exit.py as "store unreadable, not a clear gate", so the five cases that expect a clear gate fail.

Observed 2026-10-20: two unrelated processes held 18099 on the operator's Mac — a coding/bench node fixture up two days, and an orphaned /private/tmp/sc2-stub server. make test was red on the host and green in CI, where nothing squats the port.

❌ completed + phase done + zero boxes exits: want exit 0, got 10 — SELF-EXIT: stay — attention store unreadable (HTTP Error 404: Not Found)
❌ aborted exits even with open boxes: want exit 0, got 10 — …
session-self-exit: 13 passed, 5 failed

Fix

  • Bind an ephemeral port instead of a fixed one, so the test no longer depends on what else runs on the host.
  • Fail loudly when the stub server never answers, instead of silently reading another server's directory.

Verification

  • bash scripts/session-self-exit-test.sh → session-self-exit: 18 passed (was 13 passed, 5 failed)
  • make precommit → exit 0

@bborbe
bborbe marked this pull request as ready for review October 20, 2026 14:16

@ben-s-pull-request-reviewer ben-s-pull-request-reviewer Bot left a comment

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.

Review complete. This is a small, targeted bugfix. Here's the assessment:

Diff summary: 2 files — CHANGELOG.md (+1 unreleased bullet) and scripts/session-self-exit-test.sh (+20/−2: ephemeral port function + server-up guard).

Correctness:

  • free_port() correctly binds port 0 and reads back the assigned ephemeral port
  • The server_up guard (lines 158–169) properly fails with exit 2 if the stub never responds, solving the original silent failure mode
  • trap cleanup at line 31 correctly kills the server on exit
  • Port bound to 127.0.0.1 (not localhost) — no DNS dependency

No issues found.

{
  "verdict": "approve",
  "summary": "Targeted bugfix that replaces a hardcoded port (18099) with an ephemeral port and adds a loud failure if the stub server doesn't respond — directly addresses the observed CI failure where port collisions were silent.",
  "comments": [],
  "concerns_addressed": [
    {
      "concern": "correctness: test script port binding may fail if ephemeral port selection logic is incorrect",
      "disposition": "addressed",
      "detail": "free_port() uses Python socket.bind(('127.0.0.1', 0)) which delegates port selection to the OS — correct and standard pattern. The server-up guard (lines 158-169) additionally ensures the stub actually responds before tests run."
    }
  ]
}

@bborbe
bborbe merged commit e7a5339 into master Oct 20, 2026
5 checks passed
@bborbe
bborbe deleted the fix/session-self-exit-test-free-port branch October 20, 2026 14:36
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