Skip to content

feat: start cli-bridge when Local CLI Bridge finds none running - #333

Merged
drewstone merged 4 commits into
mainfrom
feat/local-bridge-autostart
Dec 2, 2026
Merged

drewstone merged 4 commits into
mainfrom
feat/local-bridge-autostart

Conversation

@drewstone

Copy link
Copy Markdown
Member

What changes

When Braid discovers the Local CLI Bridge (first-run setup, Retry discovery, and startup with a saved Local CLI Bridge connection) and nothing accepts a connection at its loopback address, Braid starts cli-bridge from PATH:

  • detached, in its own process group, bound to the endpoint's loopback host and port (BRIDGE_HOST, BRIDGE_PORT);
  • logging to cli-bridge/cli-bridge.log in Braid's data directory, with its data in cli-bridge/data there unless BRIDGE_DATA_DIR is set;
  • serving claude,codex,opencode,pi unless BRIDGE_BACKENDS is set (the bridge's own default omits Codex, OpenCode and Pi);
  • without Braid's BRAID_* variables in its environment.

Braid then waits up to 30 s for the bridge's health endpoint and reads its catalog as before.

Braid only starts a bridge when the normal, credentialed discovery got a refused connection. A bridge or anything else that answers, even with an error or a timeout, is left alone, and a remote or HTTPS endpoint never starts anything. Two Braids starting at the same moment cannot run two bridges: the second bridge fails to bind and exits, and both Braids see the first one answer.

When cli-bridge is not on PATH, setup shows one plain line and the setup link, with no stack trace or local path:

Connect a coding agent to start
A CLI Bridge must be installed or running.
https://github.com/tangle-network/braid/blob/main/docs/getting-started.md
#start-cli-bridge
Or save .braid/profile.json, then retry.

(90x24; the link wraps inside the setup panel.) The same sentence and link are the only bridge notice on the profile and connection steps, and the Local CLI Bridge row reads unreachable.

The started bridge outlives Braid

Braid never stops a bridge, including one it started. A bridge can hold native sessions that a later Braid resumes, and another Braid window can be using it; Braid cannot tell at exit whether either is true. Stopping only bridges Braid started would also mean tracking ownership across Braid processes. The cost is a background process that stays until the user stops it, which docs/getting-started.md now says.

Not covered

A bridge that dies during a session is not restarted at send; that send fails as it does today, and the next Braid start (or Retry discovery) starts it again. Switching to Local CLI Bridge with /connection inside a running session does not start one either.

Proof

New test/local-cli-bridge-autostart.test.ts runs the built braid in a real terminal at 90x24. The only stand-in is a cli-bridge script on PATH, an HTTP server that answers /health and /v1/models.

  • Nothing listening plus a cli-bridge on PATH: Braid starts it on 127.0.0.1 and the configured port, setup lists the started bridge's model, the Local CLI Bridge row is healthy, and setup reaches review. The bridge's log line is in cli-bridge/cli-bridge.log, and the bridge is still alive after Braid's terminal closes.
  • No cli-bridge on PATH: the screen shows the sentence and the link, with no stack trace or absolute path, and no bridge directory is created.
  • A bridge already answering: Braid uses it and starts none.

Red on e33a2133 (the test alone on main): the first two cases fail and the third passes. Green on 3b7b96e9, together with production-connection-setup and cloud-setup-user-path (18/18). An earlier revision sent an unauthenticated health probe before discovery; public plain startup uses private origin-bound Bridge auth caught it, and now discovery's own credentialed request is the only probe.

Run ID: run_e914760ec242f6e2ab5792467c7af78f
Session: 49bd7311-9fb3-429f-b162-213767718abd

@drewstone
drewstone marked this pull request as ready for review December 2, 2026 16:19
@drewstone

Copy link
Copy Markdown
Member Author

Marked ready through gh-drew by fleet lane op-factory:braid-readme (run run_e914760ec242f6e2ab5792467c7af78f, claude-code session 49bd7311-9fb3-429f-b162-213767718abd) at head 3b7b96e. Gate receipts for this head: 3, the newest exit 0 at 2026-12-02T16:18:53Z. Gates running or queued for this head: none.

@tangletools tangletools left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Auto-approved PR — 3b7b96e9

Blanket team auto-approval is intentional. This is not a code review.
No automated review runs on this PR. This approval rests on the rule above alone.

tangletools · auto-approval · reason: blanket_auto_approve · 2026-12-02T16:19:12Z

@drewstone
drewstone merged commit 6150876 into main Dec 2, 2026
1 check passed
@drewstone

Copy link
Copy Markdown
Member Author

Merged through gh-drew by fleet lane op-factory:braid-readme (run run_e914760ec242f6e2ab5792467c7af78f, claude-code session 49bd7311-9fb3-429f-b162-213767718abd) at head 3b7b96e. Gate receipts for this head: 3, the newest exit 0 at 2026-12-02T16:18:53Z. Gates running or queued for this head: none.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T16:25:26.584931Z 3b7b96e Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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