Skip to content

fix(codex): discover a ws:// app-server in the SessionStart plug - #1057

Merged
fujibee merged 1 commit into
fujibee:mainfrom
hiroyuki117339:fix/codex-ws-app-server-discovery
Sep 12, 2026
Merged

fix(codex): discover a ws:// app-server in the SessionStart plug#1057
fujibee merged 1 commit into
fujibee:mainfrom
hiroyuki117339:fix/codex-ws-app-server-discovery

Conversation

@hiroyuki117339

Copy link
Copy Markdown
Contributor

Fixes the first half of #1056.

_session-start.sh looks for the app-server in three places — the AGMSG_CODEX_BRIDGE_APP_SERVER variable, a unix:// token in the agent cmdline, and a .sock file — and then gives up:

[ -n "$app_server" ] || exit 0

A ws:// app-server matches none of them. codex-monitor.sh hands the URL to codex --remote (so there is no unix:// token to scrape) and records the port in run/codex-app-server.<hash>.port (so there is no socket file). The plug therefore exits before writing codex-bridge-request.<hash>, the launcher keeps using whatever that file last held, and every relaunch is pinned to a dead port with no self-recovery. #1056 has the full symptom and log evidence.

The port file does carry the URL, and _app-server.sh:32 already exports _agmsg_codex_app_server_url() to build it — codex-record-session.sh:115 calls it for the same reason. This change just adds it as the last resort in the plug.

SKILL_DIR and agmsg_sha1 are both available in this context (the plug is sourced by session-start.sh, see the header comment), and the helper returns empty rather than failing when it cannot resolve a port, so the existing exit 0 still handles the genuine "no app-server" case.

The second half of #1056 — the launcher trusting the request file without checking whether the endpoint is reachable — is a design judgment, so I left it out of this PR and described it in the issue instead.

Tests: bats was not installed locally, so I ran it via npx bats. tests/test_delivery.bats, tests/test_resume_seat_guard.bats, tests/test_close_fds.bats → 200 passed, 0 failed. tests/test_codex_*.bats (bridge, bridge_launcher, monitor, resume, shim) → 142 passed, 0 failed. I did not run the whole suite locally.

Discovery tried the AGMSG_CODEX_BRIDGE_APP_SERVER variable, a `unix://`
token in the agent cmdline, and a `.sock` file. A ws:// (TCP) app-server
matches none of them: codex-monitor.sh hands the URL to `codex --remote`
and records the port in a `.port` file, so the plug hit `exit 0` before
writing codex-bridge-request.<hash>. The launcher then kept using the
stale request file and pinned every relaunch to a dead port.

Fall back to _agmsg_codex_app_server_url, the helper _app-server.sh
already provides for exactly this and codex-record-session.sh already
uses.
@fujibee
fujibee merged commit a8c7d28 into fujibee:main Sep 12, 2026
79 of 85 checks passed
fujibee added a commit that referenced this pull request Sep 13, 2026
#1056) (#1172)

Adds coverage for the fourth app-server discovery fallback introduced in #1057: with AGMSG_CODEX_BRIDGE_APP_SERVER unset, no unix:// token on the agent cmdline, and no .sock file, the SessionStart plug still finds a ws:// app-server through its port file and writes the codex-bridge-request with that URL. Measured red on the commit immediately before #1057 landed on main and green from #1057 onward. Refs #1056.
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