Skip to content

[codex] Add chat-v2 attach-or-embed startup#154

Merged
roackb2 merged 1 commit into
mainfrom
codex/chat-v2-attach-embed
Jun 2, 2026
Merged

[codex] Add chat-v2 attach-or-embed startup#154
roackb2 merged 1 commit into
mainfrom
codex/chat-v2-attach-embed

Conversation

@roackb2
Copy link
Copy Markdown
Owner

@roackb2 roackb2 commented Jun 2, 2026

Summary

Adds the PR 3 chat-v2 startup behavior on top of the merged server lifecycle split.

  • Keeps chat-v2 bootstrap ownership inside src/cli-v2: runtime resolution lives in src/cli-v2/runtime.ts and the command runner lives in src/cli-v2/index.tsx.
  • Leaves src/cli/main.ts as the command router only; it dispatches chat-v2 to runChatCliV2.
  • Attaches to a fresh live control-plane server when one is registered.
  • Starts an embedded embedded-chat control-plane server when no fresh live server exists, using the shared startHeddleControlPlaneServer path and an OS-assigned local port.
  • Keeps cli-v2 as the API consumer by passing trpcUrl and the CLI-selected workspaceId through the existing store/client path.
  • Returns Ink render state from startChatCliV2 so the v2 runner can close the embedded server after the TUI exits.

Expected behavior change

yarn chat:dev:v2 no longer requires a pre-running heddle daemon or yarn server:dev.

Expected user-visible behavior:

  • If a fresh live control-plane server is registered, chat-v2 prints that it is attaching and uses that server.
  • If no fresh live server exists, chat-v2 starts an embedded local control-plane server, prints its endpoint/serverId, and opens the TUI against it.
  • The TUI still owns its initial active workspace by passing the current workspace id into the shared API client.
  • A second chat-v2 process should attach to the first embedded/live server instead of starting another server, assuming the first server remains registered and fresh.

This PR does not do the later PR 4 cleanup of request-workspace assumptions, logging placement, or heartbeat catalog ownership.

How to verify

Manual smoke:

  1. Ensure no Heddle control-plane server is running.
  2. Run yarn chat:dev:v2.
  3. Confirm it prints started embedded chat-v2 control-plane server and enters the TUI.
  4. In another terminal, run yarn cli:dev daemon and confirm it prints the existing server address/serverId and exits successfully.
  5. Stop the TUI, then run yarn chat:dev:v2 again to confirm it can start a new embedded server.
  6. With yarn server:dev already running, run yarn chat:dev:v2 and confirm it prints attaching chat-v2 to the live control-plane server.

Automated checks run locally:

  • yarn -s vitest run src/tests/unit/cli-v2/chat-v2-runtime.test.ts src/tests/unit/cli/main-command-routing.test.ts
  • yarn typecheck
  • yarn lint
  • Earlier on this branch before the ownership move: yarn test and yarn build

@roackb2 roackb2 force-pushed the codex/chat-v2-attach-embed branch from 18cc707 to d8f2f5a Compare June 2, 2026 07:38
@roackb2 roackb2 marked this pull request as ready for review June 2, 2026 07:39
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8f2f5a502

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

shuttingDown = true;
runtime.close()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Close the TUI before awaiting embedded shutdown

When an external SIGTERM/SIGINT reaches an embedded chat-v2 process after the TUI has started, this handler awaits runtime.close() while the mounted app still owns live tRPC/EventSource subscriptions (ControlPlaneSessionSubscriptionService only unsubscribes from App unmount). The HTTP server close path waits for active connections to finish, so those open subscriptions can keep runtime.close() from resolving and the .finally(process.exit) path is never reached. The signal path should first unmount/dispose the Ink app or otherwise force-close client/server connections before awaiting the server close.

Useful? React with 👍 / 👎.

@roackb2 roackb2 force-pushed the codex/chat-v2-attach-embed branch from d8f2f5a to abe785a Compare June 2, 2026 07:57
@roackb2 roackb2 merged commit 02f29b6 into main Jun 2, 2026
5 checks passed
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