Skip to content

brain port: the review's fixes for #477 (#490) - #491

Open
teaspoonai wants to merge 1 commit into
mainfrom
fix/brain-port-477-review
Open

teaspoonai wants to merge 1 commit into
mainfrom
fix/brain-port-477-review

Conversation

@teaspoonai

Copy link
Copy Markdown
Contributor

Follow-up to #490 (#477): the fixes from desktop-ed's independent review of #490, which reached main before the review did. rc8 is tagged after this.

Must fix: an empty token in brain.env

GATEWAY_TOKEN="", '' or blanks is no token to the brain, which refuses to start (exit 78).

  • The bug: resolve_gateway_token reused the text as it stood, quotes included, and wrote it into the plugin's and the bridge's configs. The installer's restart of the brain then failed under set -e. That broke the repair the troubleshooting page tells owners to run.
  • The fix: one reader, env_value, reads an env file as systemd and the brain do: the last line wins, and surrounding blanks and one pair of quotes are dropped. resolve_gateway_token and wait_for_idle both use it. An empty result mints a new token.

Should fix

  • /settings/health needs a login (the owner's call). It's reachable from the LAN through the front door, and it showed the key's credit, the agent's key state and the update channel to anyone. It now wants the owner's Settings session or the operator's token, like /settings/api/config.
    • /health on the brain's own port stays open. That port listens on the device alone, and the CLI and the installer read it.
    • The configuration page sends the token with its health request.
  • Docs, NemoClaw: Linux answers on the bridge address, 172.18.0.1, from any network the device is on. A LAN machine that routes that address via the device therefore reaches the port, still behind the token. security.md and the architecture port table now say so.

Minor fixes

  • BRAIN_LISTEN: a wildcard beside another address of its family, such as 0.0.0.0,127.0.0.1, can never bind both. It's now refused at start (exit 78) instead of looping on restarts (exit 3). One address in two spellings counts as one.
  • The package's postinst seeds BRAIN_LISTEN=127.0.0.1,172.18.0.1 before the restart on a NemoClaw device that has no such line, as install.sh --only brain does. A plain apt install of the deb no longer cuts the sandbox off. A line that's already there stays.
  • Stale docs:
    • brain/README.md and plugin/index.js no longer say ws://<host>:7861, and they name the token;
    • troubleshooting names the empty-token case.
  • The bind test skips its plain-bind check on hosts with ip_nonlocal_bind=1.
  • Not done: the optional doctor check that the docker bridge really holds 172.18.0.1.

Tests

  • New tests:
    • the installer mints a token over empty, quoted, blank and last-line-empty values, and keeps real ones, quoted or not;
    • /settings/health returns 401 without a login, and 200 with a session or the operator's token, while /health on the port stays open;
    • overlapping listen addresses are refused;
    • postinst seeds the bridge address only on NemoClaw, only once, before the brain's restart, and keeps an existing line.
  • Mutation-checked: dropping the health login check, or the quote stripping, fails a test.
  • The existing postinst tests now point brain.env into their temp dir.
  • Full brain suite: 161 passed, 7 skipped, 2 failed. Both failures were installer tests that copy functions out of install.sh without the new env_value. They're fixed here and pass on their own.
  • Docs lint: 0 errors. Shellcheck: no new findings on install.sh; postinst is clean.

🤖 Generated with Claude Code

desktop-ed's independent review of #490, after its merge:

- install.sh: a GATEWAY_TOKEN that is empty once read as the brain reads it
  (GATEWAY_TOKEN="", '' or blanks) is no token. resolve_gateway_token reused it,
  wrote the quotes into the plugin's and the bridge's configs, and the brain, which
  read it as unset, refused to start, so the installer's restart failed: the repair
  the troubleshooting page names. One reader, env_value (the last line wins, blanks
  and one pair of quotes dropped), for resolve_gateway_token and wait_for_idle; an
  empty result mints a new token.
- /settings/health, which the LAN reaches through the front door, wants the owner's
  Settings session or the operator's token, as /settings/api/config does (the user's
  call). It named the key's credit, the agent's key state and the update channel.
  /health on the brain's own port, which listens on the device alone, stays open for
  the CLI and the installer. The page sends the token on its health fetch too.
- BRAIN_LISTEN: a wildcard beside another address of its family (0.0.0.0,127.0.0.1)
  never binds both: refused at start (exit 78), not a restart loop (exit 3). One
  address in two spellings is one.
- The package's postinst seeds BRAIN_LISTEN=127.0.0.1,172.18.0.1 on a NemoClaw device
  without the line, before the restart, as install.sh --only brain does: a plain apt
  install no longer cuts the sandbox off.
- Docs: on NemoClaw the bridge address answers machines on the LAN that route it via
  the device (the token still guards it); architecture's port table, brain/README and
  plugin/index.js no longer say ws://<host>:7861; troubleshooting names an empty token.
- test_brain_port: the plain-bind check is skipped where ip_nonlocal_bind is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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