Skip to content

Commit 592b119

Browse files
lroolleclaude
andcommitted
fix: trace UI review findings — unpublished-port survival, probe gap, 127.0.0.1
Per review on #426: - docker port exits non-zero for unpublished mappings; under set -euo pipefail that killed the launch — swallow it, keep the warn - probe loop could publish an untested port when 9317-9328 were all busy; publish only a confirmed-free port, warn and skip otherwise - URLs use 127.0.0.1 to match the bind (localhost can resolve ::1 first); docs/changelog aligned, port shown as placeholder Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c90d7db commit 592b119

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
instead of silently attaching a stale CLI to the same config home.
3333
Label-less images keep the bare agent name (#420)
3434
- Traced sessions publish the cctrace live UI to the host loopback:
35-
free port probed from 9317, `Trace UI: http://localhost:<port>` printed
35+
free port probed from 9317, `Trace UI: http://127.0.0.1:<port>` printed
3636
before the TUI starts, and the host browser opens the moment the UI
3737
answers (poll-then-open; `DEVA_TRACE_OPEN=0` disables). Attaching to a
3838
persistent container created without the port warns instead (#425)

agents/shared_auth.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,23 @@ DEVA_TRACE_UI_URL=""
233233
setup_trace_ui_port() {
234234
local port=9317
235235
local tries=0
236+
local free_port=""
236237
while [ "$tries" -lt 12 ]; do
237238
if ! (exec 3<>"/dev/tcp/127.0.0.1/$port") 2>/dev/null; then
239+
free_port="$port"
238240
break
239241
fi
240242
port=$((port + 1))
241243
tries=$((tries + 1))
242244
done
243-
DOCKER_ARGS+=("-p" "127.0.0.1:${port}:9317")
244-
DEVA_TRACE_UI_URL="http://localhost:${port}"
245+
246+
if [ -z "$free_port" ]; then
247+
echo "warning: no free host port in 9317-9328; trace UI will not be reachable from the host" >&2
248+
return 0
249+
fi
250+
251+
DOCKER_ARGS+=("-p" "127.0.0.1:${free_port}:9317")
252+
DEVA_TRACE_UI_URL="http://127.0.0.1:${free_port}"
245253
}
246254

247255
# Print the trace UI URL before the TUI takes the screen, and open the host
@@ -253,13 +261,15 @@ announce_trace_ui() {
253261

254262
local url="$DEVA_TRACE_UI_URL"
255263
if [ "${1:-new}" = "existing" ]; then
264+
# docker port exits non-zero for unpublished mappings; under
265+
# set -euo pipefail that must not kill the launch.
256266
local mapping
257-
mapping=$(docker port "$CONTAINER_NAME" 9317/tcp 2>/dev/null | head -1)
267+
mapping=$(docker port "$CONTAINER_NAME" 9317/tcp 2>/dev/null | head -1 || true)
258268
if [ -z "$mapping" ]; then
259269
echo "warning: trace UI not reachable — container was created without the trace port; recreate it (deva rm) or use --rm" >&2
260270
return 0
261271
fi
262-
url="http://localhost:${mapping##*:}"
272+
url="http://127.0.0.1:${mapping##*:}"
263273
fi
264274
[ -n "$url" ] || return 0
265275

docs/advanced-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ published to the host loopback. deva prints the URL before the TUI takes
186186
the screen and opens your host browser the moment the UI answers:
187187

188188
```text
189-
Trace UI: http://localhost:9317 (live once the agent starts)
189+
Trace UI: http://127.0.0.1:<port> (live once the agent starts)
190190
```
191191

192192
Set `DEVA_TRACE_OPEN=0` to keep the banner but skip the auto-open.

0 commit comments

Comments
 (0)