Skip to content

fix(machines): tell a PC's own Ovis port and https link to the bridge token (#2191) - #2248

Merged
devswha merged 3 commits into
mainfrom
fix/own-ovis-port-url
Oct 28, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/own-ovis-port-url

Conversation

@devswha

@devswha devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Closes #2191

Change

The connection server learns where a PC's own Ovis really answers (its port, which differs from
the registered one for a relayed bridge, #1960, and the https address Tailscale serves it at) by
reading GET /api/access through the SSH tunnel with the bridge token. The bridge token opens only
GET /api/updates and POST /api/updates/install there (#2054), so a PC whose own Ovis asks for
OVIS_TOKEN always answered 401: its card and dialog showed the registered port and no
"Open that PC's Ovis" link.

/api/access stays closed to the bridge token. Instead:

  • server/index.ts, server/update-api.ts: GET /api/updates adds port and serving_url to its
    answer for the bridge token only (the port this server listens on and
    tailscale.serving_url, the same values /api/access gives). A browser's answer is unchanged,
    and its polls never run tailscale. A tailscale that cannot be read leaves
    serving_url null, and the status is answered either way.
  • shared/update.ts: the two optional fields on UpdateStatus; shared/protocol.ts notes them.
  • server/machines.ts ownOffer: takes both from the status, with the same checks as before
    (an integer port in 1..65535, an https:// URL without credentials, at most 300 characters).
    When the status names no port (an Ovis older than this change) it asks /api/access as before.
  • docs/remote-pcs.md, changelog.d/own-ovis-port-url.md.

The fix takes effect once that PC's own Ovis runs this version too; until then nothing changes.

Tests

  • server/machine-own-update.test.ts: a PC whose /api/access answers 401 and whose status tells
    its port and https address. Before the fix the card showed pc.invalid:29431 and no link; now
    pc.invalid:7317 and the https address, and /api/access is not asked.
  • server/api.contract.test.ts (real createServer, port: 0, own token + bridge token): the
    bridge token's status has port === server.port and a string-or-null serving_url; the owner
    token's has neither; the bridge token still gets 401 from /api/access.
  • server/update-api.test.ts: no where, no fields; a where that throws still answers 200
    (failed before the second commit).
  • server/machine-own-update.test.ts: a status that told where it answers while a check ran,
    then a 503: the card keeps that port and link (failed before the third commit).

bun run check fast: every step green except one unit case in scripts/self-hosted-runner.test.ts
("starts the runners after --cache-wait when the first refresh hangs": its stub missed a 5 s
deadline at load ~108 on 128 cores); the file is untouched here and passes 30/30 run alone.

Review

Adversarial reviews before opening (read-only, unit tests only):

  • omo-native-code-reviewer on 86828ec: PASS, no CRITICAL/HIGH/MEDIUM. LOW: a tailscale that cannot be
    started made the bridge's status a 500 (fixed in fa1b3a2, with a unit test that failed before);
    no unit test of the merge (added).
  • Codex Sol 6.1 fast xhigh on 86828ec: FAIL with the same tailscale case as a MEDIUM, and a LOW: a
    read that failed after a "checking" status dropped the address it had already told. Both fixed in
    d5795b4: the status always tells the port and leaves serving_url null when tailscale fails,
    and ownOffer keeps the last status that told where it answers (a test that failed before).
  • Codex Sol re-review of 86828ec..d5795b4: PASS, no findings.

Known LOW, left as is:

  • Each bridge read of /api/updates runs tailscale status and tailscale serve status on that PC
    (in parallel, 2.5 s timeout each), also during the 2 s polls of a running own-update. Bounded and
    only on the bridge path; a short cache could follow if it shows up.
  • port / serving_url live on UpdateStatus, which the browser also reads; it never receives them.

… token (#2191)

The connection server read GET /api/access on a PC's own Ovis with the bridge
token to learn the port it answers on and its Tailscale https address. The
bridge token opens only GET /api/updates and POST /api/updates/install there,
so a token-gated PC always answered 401 and its card showed the registered
port and no "Open that PC's Ovis" link.

GET /api/updates now adds `port` and `serving_url` to its answer for the
bridge token only; /api/access stays closed to it, and browser polls do not
run tailscale. ownOffer takes both from the status and falls back to
/api/access for an older server that does not tell them.
… be read

A tailscale that cannot be started made the bridge token's GET /api/updates a 500 and refused the PC's own update (omo review, LOW). The status now stands without port and serving_url, and the connection server asks /api/access as of an older server.
Codex review: the bridge's status now always tells the port this server listens on and leaves serving_url null when tailscale cannot be read (MEDIUM), and ownOffer keeps the last status that told where it answers when a read after a check for releases fails (LOW).
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 8dd95b3 and d5795b4.

Files selected for processing: 10
  • changelog.d/own-ovis-port-url.md
  • docs/remote-pcs.md
  • server/api.contract.test.ts
  • server/index.ts
  • server/machine-own-update.test.ts
  • server/machines.ts
  • server/update-api.test.ts
  • server/update-api.ts
  • shared/protocol.ts
  • shared/update.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit did not review this PR (review limit reached). Because the PR touches an HTTP contract and what a bridge token may read, here is the code-review agents' record in its place.

omo-native-code-reviewer on 86828ec: PASS, no CRITICAL/HIGH/MEDIUM.

  • LOW: when tailscale could not be started (Bun.spawn throws before run's catch), the bridge token's GET /api/updates returned 500 and the PC's own update was refused. Fixed in fa1b3a2: where() failing leaves the status as it was. A unit test in server/update-api.test.ts failed before the fix.
  • LOW: no unit test of the merge in handleUpdateRequest. Added in the same commit.
  • LOW, not changed: each bridge read runs tailscale status and tailscale serve status, also during the 2 s own-update polls. Both run in parallel with a 2.5 s timeout, and only on the bridge path. Noted in the PR body.
  • LOW, not changed: port and serving_url are on UpdateStatus, which the browser also reads, but the browser never receives them (documented on the fields).

Codex Sol 6.1 fast xhigh on 86828ec: FAIL.

  • MEDIUM: the same tailscale spawn failure, reproduced with a #!/does/not/exist shim (500 on the bridge path). Fixed in d5795b4: the status always tells the server's own port, serving_url is null when tailscale fails, and the handler-level catch from fa1b3a2 stays.
  • LOW: a status that told where it answers during a running check, followed by a failed read, dropped that address (registered port, no link). Fixed in d5795b4: ownOffer keeps the last status that named a port. A test in server/machine-own-update.test.ts failed before the fix.

Codex Sol re-review of 86828ec..d5795b4: PASS, no findings. It confirmed that spawn EACCES now answers 200 with the port and serving_url: null, and that the address survives 503, network errors, timeouts, malformed and oversized answers.

Checked by both: only the bridge token gets the two fields (the owner token's answer is unchanged, and the contract test asserts it); /api/access still answers 401 to the bridge token; hostile remote JSON is checked as before (integer port 1..65535, an https:// URL without credentials, at most 300 characters).

@devswha

devswha commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

Merging d5795b4. An HTTP contract change next to authentication, so it got a strict review; Codex was at capacity, so an omo reviewer on gpt-6.1-sol and an independent second reviewer reviewed it; both pass with no MEDIUM or above. The new fields are gated on the same isAuthenticated(request, bridgeToken) result as the existing bridge allowance. Contract-tested on a real server with OVIS_TOKEN and a separate bridge token: only the bridge token (Bearer or its existing cookie forms) gets port and serving_url on GET /api/updates; a browser token or cookie gets the unchanged answer, no or a wrong token gets 401, and other header forms of the bridge token are refused. /api/access stays 401 to the bridge token. Eight browser polls ran tailscale zero times; a failing or unspawnable tailscale leaves serving_url null with status 200. ownOffer drops http, credentialed, javascript:, data:, file:, ftp: and over-300-character URLs and ignores ports 0, 65536, 3.5 and "8080". On main the bridge read of /api/access is refused and the card falls back to the registered port with no link (#2191); this head shows the real port and https link. Rollout: the fields are optional, so older peers keep the /api/access fallback, REMOTE_BUNDLE_VERSION needs no bump for this, and the link appears once both the connection server and that PC's own Ovis run this version. Not filed: the URL check reused from the /api/access path is a regex, so a compromised PC can still advertise a malformed https link such as https://pc.invalid:65536 (server/machines.ts ~1028; validating with new URL would be stricter); each bridge status read runs two tailscale reads, as the PR notes; the API contract harness's four agent-fixture failures (Grok, Agy, Muse, Codex) reproduce on the base and are local.

@devswha
devswha merged commit 02f8ae6 into main Oct 28, 2026
26 of 27 checks passed
@devswha
devswha deleted the fix/own-ovis-port-url branch October 28, 2026 13:01
devswha added a commit that referenced this pull request Oct 28, 2026
…PC on Try again, show the QR with a token and a readable log (#2264) (#2275)

Closes #2264

## Problem

Testing the Windows app's Update for an older server (#2091, #2113) in
the Windows 11 VM, with `Ovis.exe` 0.4.19 and `devswha.herdr-web-ui`
0.3.45 installed under the old id, found four problems (reproduced again
on main 9a44f27 before this change):

1. **An old-id server that outlived herdr was never stopped, so Update
failed and then looped.** The app and install.ps1 run the old checkout's
`scripts/plugin.ts stop` outside herdr. Releases before 0.4.13 read
their pid from `HERDR_PLUGIN_STATE_DIR` and, without it, from
`~/.local/state/herdr-web-ui`, while herdr keeps it in
`%LOCALAPPDATA%\herdr\plugins\devswha.herdr-web-ui\server.pid`. The stop
said "not running", install.ps1's `herdr plugin uninstall
devswha.herdr-web-ui` failed with `Os { code: 32 }`, and the
half-deleted checkout kept serving 0.3.45 on 7317 under a herdr list
that names only `devswha.ovis`.
2. **Try again after that ran the deleted checkout** (`error: Module not
found ...devswha.herdr-web-ui-210f619d6b7b\scripts\plugin.ts`, shown as
"Could not stop the Ovis server").
3. **With a token, no QR:** `GET /api/access` was read without the
token, answered 401, and the app told a PC that runs Tailscale to
install it.
4. **The log showed raw CLIXML** (`#< CLIXML <Objs ...>`).

## Change

- **Old-id stop** (`install.ps1`, `Model.PluginCommand`): the old id's
`plugin.ts` (stop, status, phone) runs with `HERDR_PLUGIN_STATE_DIR` set
to herdr's state dir for the plugin, found as `scripts/plugin-state.ts`
finds it (`XDG_STATE_HOME`, else `%LOCALAPPDATA%`), and restored
afterwards. A stop that finds no server there runs once more with the
original environment, so a server started by hand from the old checkout
(pid in its own dir) is still stopped. Every new-id release (0.4.14+)
finds herdr's dir by itself and is run as before.
- **Try again after a failed Update** reads the PC again: it updates
again while one is due (or the plugin is gone), and for a current server
it runs the update's last steps again: the login start, and the start
when it is stopped.
- **Phone address with a token:** the token that opened `GET
/api/updates` (the PC's own, from the plugin's `env`/`.env`, as before)
is sent to `GET /api/access` at the same origin. When that still answers
401 the app says the token is missing or did not work, instead of
"install Tailscale".
- #2248's `port` and `serving_url` in `GET /api/updates` are given only
to the connection server's bridge token, which this app does not hold,
so they cannot replace this; the app's own token already opens
`/api/access`, which also tells Tailscale's state (needed for "Make the
phone address" and "Sign in to Tailscale"). No server change.
- **Log:** the installer starts with `-Command` instead of
`-EncodedCommand`. In the VM, Windows PowerShell 5.1 started with
`-EncodedCommand` and redirected output wrote progress, warning and
error records to stderr as CLIXML whatever `-OutputFormat` and stdin
were; `-Command` writes the plain lines. `Run` hands the script to cmd
in an environment variable, so its `|` and quotes arrive as written.

## Tests

- `scripts/windows-install.test.ps1`: the old id's stop is told herdr's
state dir (with and without `XDG_STATE_HOME`), the variable is not left
set, and a stop that finds no server there asks again without it. Fails
on main's install.ps1 ("The old id's stop must look for its pid where
herdr keeps the plugin's state"), passes with this change (VM, desktop
session).
- `app/windows/tests` (`Ovis.Tests.exe`): the state dir, the phone step
for a token the app could not use, and a real Windows PowerShell run
with the app's arguments that must print host, warning and error lines
without CLIXML. 20/20 pass in the VM; the PowerShell case fails with
main's `-EncodedCommand` arguments.
- `bun run check fast`: green.

## Manual QA (winvm, Windows 11, herdr 0.9.3, Bun 1.4.2; `Ovis.exe`
built at version 0.4.19)

Setup each time: `winvm reset` (dev-ready-4), `herdr plugin install
devswha/herdr-web-ui --ref v0.3.45`, a `HERDR_WEB_TOKEN` and a marker
line in its `env`, `herdr server`, then herdr alone ended (`taskkill /IM
herdr.exe /F`): the 0.3.45 server keeps running.

| | main | this change |
| --- | --- | --- |
| Update | "The installer stopped with an error", CLIXML in the log;
afterwards the old server (same pid) still serves 0.3.45 on 7317, the
old checkout is half-deleted, herdr lists only `devswha.ovis` | Running
on this PC: only `devswha.ovis` 0.4.19, `/api/updates` says
`current_version 0.4.19`, no old process or checkout, env marker and
token moved, Run value set |
| Phone step with a token | "Install Tailscale on this PC..." with Get
Tailscale | "Tailscale runs here" → Make the phone address → QR code and
`https://winvm.tail1e211e.ts.net` |
| Failed Update, then Try again | "Could not stop the Ovis server",
`Module not found ...devswha.herdr-web-ui-...\scripts\plugin.ts` | (a
file in the old checkout held open, so the old id's uninstall fails with
os error 32) the log shows herdr's error and `herdr failed (exit 1)` as
plain lines; Try again reads the PC again and lands on Running on this
PC (`devswha.ovis` 0.4.19), no `Module not found` |

<details><summary>Screenshots</summary>

main: ![main: Update fails with CLIXML in the
log](https://gist.githubusercontent.com/devswha/b219c94d730a39dad12aed6c218e9cd2/raw/a2d27c3a1b453a04ad351318340ba16e6b6f54da/main-1-update-fails.png)
![main: Try again runs the deleted
checkout](https://gist.githubusercontent.com/devswha/b219c94d730a39dad12aed6c218e9cd2/raw/a2d27c3a1b453a04ad351318340ba16e6b6f54da/main-2-try-again-module-not-found.png)
![main: with a token, install
Tailscale](https://gist.githubusercontent.com/devswha/b219c94d730a39dad12aed6c218e9cd2/raw/a2d27c3a1b453a04ad351318340ba16e6b6f54da/main-3-token-install-tailscale.png)

this change: ![fix: Update ends running
0.4.19](https://gist.githubusercontent.com/devswha/b219c94d730a39dad12aed6c218e9cd2/raw/a2d27c3a1b453a04ad351318340ba16e6b6f54da/fix-1-update-running.png)
![fix: QR with a
token](https://gist.githubusercontent.com/devswha/b219c94d730a39dad12aed6c218e9cd2/raw/a2d27c3a1b453a04ad351318340ba16e6b6f54da/fix-2-token-qr.png)
![fix: a failed update shows plain log
lines](https://gist.githubusercontent.com/devswha/b219c94d730a39dad12aed6c218e9cd2/raw/a2d27c3a1b453a04ad351318340ba16e6b6f54da/fix-3-failed-update-readable-log.png)
![fix: Try again reads the PC
again](https://gist.githubusercontent.com/devswha/b219c94d730a39dad12aed6c218e9cd2/raw/a2d27c3a1b453a04ad351318340ba16e6b6f54da/fix-4-try-again-recovers.png)

</details>

## Reviews

- omo-native-code-reviewer: PASS, four LOWs, all fixed here (a stop that
finds no server through herdr's dir asks again without it; the
token-needed text also covers a token that did not work;
`[IO.Path]::Combine` for an empty `XDG_STATE_HOME`; the PowerShell test
waits with a bound).
- Codex (gpt-6.1-sol, fast, xhigh), four rounds: round 1 BLOCK with two
MEDIUMs (Try again skipped a start that failed after a successful
reinstall; forcing the state dir hid an old server started by hand),
round 2 BLOCK with one MEDIUM (Try again skipped the login start while
the server already ran), all fixed; rounds 3 and 4 (the `-Command`
switch) PASS with no findings.

## Not in this PR (LOW, pre-existing)

- When install.ps1 fails after installing the new id but before the old
id's uninstall (as in the forced failure above), the old checkout's
leftovers stay on disk; herdr no longer lists the old id and the app
shows the new one running, so nothing breaks, but nothing removes them
either.
- `check fast` once failed `scripts/self-hosted-runner.test.ts` ("the
stub never hung") under load; it passes alone on this branch and on main
(30/30), and a rerun of the whole check was green.
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.

Own-Ovis offer: the bridge token cannot read /api/access, so a token-gated PC loses its real port and https link

1 participant