Skip to content

hooks: restore Codex session actions under shared app-server - #223

Open
khoi wants to merge 16 commits into
mainfrom
t3code/fix-codex-hook-pane-context
Open

hooks: restore Codex session actions under shared app-server#223
khoi wants to merge 16 commits into
mainfrom
t3code/fix-codex-hook-pane-context

Conversation

@khoi

@khoi khoi commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Why

Codex 0.151 can run hooks from a shared app-server instead of the pane's TUI process. The resulting SessionStart may inherit no Supaterm socket, another pane's session ID, or a runtime environment that cannot find the installed bridge. Supaterm then never binds the new Codex session to its pane, so Copy Session ID and Fork Session disappear from the agent panel.

Relying on inherited pane context cannot distinguish two Codex sessions hosted by the same process. The hook must rediscover the live Supaterm instances and prove which pane owns the session without reading the Codex transcript.

What changed

The managed hook now invokes the bundled sp executable by absolute path and discards stale CLI overrides. Root Codex starts query every live app instance and select a pane from exact process identity, terminal title, workspace, and global fork lineage; ambiguous evidence fails closed. Socket discovery now uses the private Darwin per-user temporary root and removes only dead-process endpoints.

Note

This does not read Codex transcripts or guess between ambiguous workspace-only panes. Nested sessions cannot replace an owned root session unless exact process or fork-lineage evidence proves the change.

Verification

A real Codex 0.151 E2E launched two sessions through one shared app-server and bound each session to its launching pane. The focused suite covers 173 routing, socket, launch-parser, state-restore, and hook-install cases; live app-server handshake and trust installation also pass.

khoi added 10 commits August 31, 2026 00:30
Hook hosts do not inherit pane paths, so the environment-based command can
skip delivery. Embed the canonical bundled CLI path in a marked shell wrapper
while retaining legacy ownership for repair and removal.
Hook processes can outlive pane context, so inherited environment and
workspace alone cannot identify the session owner. Query every live app,
rank only safe evidence, and reject incomplete or ambiguous matches.

Carry the selected pane's full process identity through final delivery so
PID reuse cannot bind a session to stale detection. Bound discovery and
delivery within the hook deadline.
Separate emitter queries from detected-process delivery and centralize durable
root parsing. Require unique working-directory evidence so ambiguous panes fail
closed.
Darwin rejects receive-timeout updates after a peer closes even when
response bytes remain buffered. Set the first timeout before the request,
then accept EINVAL only on later refreshes so the deadline stays enforced.
Codex session starts can run outside their terminal pane and carry stale
process context. Document the evidence order, ambiguity rules, fixed socket
namespace, and transcript boundary so the app, CLI, website, and installed
skill describe the same behavior.
Codex now runs hooks from a shared app-server whose child environment can
carry a stale pane, socket, or thread. Runtime path lookup could also skip
the bridge before routing began.

Invoke the bundled CLI directly, discover each compatible app, and bind
only when live process, title, workspace, or guarded fork evidence selects
one pane. Keep incomplete and ambiguous rounds fail-closed.
A fork starts with the same workspace as its parent and Codex reports it as
a startup, so cwd alone cannot prove pane ownership. Document the guarded
parent-session signal and the incompatible-instance rule.
@khoi khoi added the bug Something isn't working label Aug 31, 2026
…-pane-context

% Conflicts:
%	apps/mac/supaterm/Features/Terminal/TerminalAgentLaunchOptions.swift
%	apps/mac/supaterm/Support/CodexSettingsInstaller.swift
%	apps/mac/supatermE2E/CodexE2ETests.swift
%	docs/coding-agents-integration.md
%	integrations/supaterm-skills
@tuist

tuist Bot commented Aug 31, 2026

Copy link
Copy Markdown

🛠️ Tuist Run Report 🛠️

Tests 🧪

Scheme Status Cache hit rate Tests Skipped Ran Commit
supatermUITests 0 % 73 0 73 725b96438

Builds 🔨

Scheme Status Duration Commit
supatermUITests 1m 41s 725b96438

khoi added 5 commits August 31, 2026 10:43
Shared app-server routing must use the same process identity, socket
lookup, and argument parsing in the app and CLI. Keep each rule in one
place so multi-instance candidate selection stays complete and cannot
drift between callers.
The fork routing test sent its first prompt through the terminal after the
new session had loaded. The shared host could interrupt that input, leaving
the prompt as an unsent draft.

Pass the initial prompt to the fork command so session startup triggers the
hook and model turn as one operation.
The narrow fork pane inserts spaces when it wraps the response. Waiting for
the exact rendered text can time out even after the model exchange finishes.

Poll the fake server's existing completion check so the test waits on the
request it owns instead of terminal layout.
The agent E2E job installs pinned tools after the setup action finishes. That
later mise process had no token and could exhaust GitHub's public API limit
before tests began.

Keep the workflow token scoped to the agent test step that needs it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant