Skip to content

Update PC bridges in the background, with progress and time left - #26

Merged
devswha merged 4 commits into
mainfrom
feat/background-bridge-updates
Sep 24, 2026
Merged

devswha merged 4 commits into
mainfrom
feat/background-bridge-updates

Conversation

@devswha

@devswha devswha commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Summary

A bridge update on a phone meant tapping Update bridge… and then sitting on the dialog until it finished: closing the dialog cancelled the job (MachineDialog.tsx did that on unmount), the approval step waited on it, and "Installing…" gave no sense of how long. Every install also downloaded the ~130MB bundle again into memory.

Automatic, with the app update as the approval. When a PC is refused for an out-of-date bridge, the server updates it in the background, one PC at a time. This also covers a PC that only has an older runtime and no bridge running.

  • The job uses the PC's saved key only (BatchMode) and skips the approval step, since installing the app update was the approval.
  • A PC that needs a password fails with the reason and waits. Its Sign in and update… button opens the dialog.
  • Settings → Remote PCs → Update PC bridges automatically turns this off. It's a server preference in <stateDir>/machine-settings.json, on by default. With it off, the PC's Update bridge button starts the same background job in one tap (POST /api/machines/:id/update-bridge).
  • A first install still asks for approval in the dialog.

Doesn't block. The job runs on the server. After approval, closing the dialog leaves it running (Continue in background), and Cancel update stops it. The setup's 10-minute timer stops once installing starts, and the install itself allows 30 minutes.

Progress. Jobs report their stage (download → upload to the PC → verify and install → restart), plus bytes and rate. A PC mirrors its running update as updating over the machine events. The sidebar shows the step, a bar, "45 MB of 130 MB · about 1 min left" and a live seconds count for stages with no size. The header shows the step and percentage.

Faster and lighter. Bundles are kept by checksum under <stateDir>/bundles (the newest four) and re-verified on use. Each checksum is downloaded once, even when PCs update together. The file is streamed to the PC with backpressure instead of being held in memory: a local 130MB pipe test peaked at 22MB RSS.

No remote-v3 is needed: all of this is on the connection-server side.

Commits

  1. feat(remote): bundle cache, streaming download and upload, progress callbacks.
  2. feat(pcs): automatic and one-tap background jobs, progress, the setting and its API.
  3. feat(ui): sidebar, header and dialog progress, the Settings toggle, docs and CHANGELOG.

Each one typechecks on its own.

Testing

  • bun run typecheck passes, bun test passes 300/300 (new: the bundle cache, and progress wording), bun run test:ui passes 7/7, and bun run test:ssh passes 8/8 (the dialog install path, the streamed upload, failed-install recovery).
  • End to end, automatic (isolated sshd and HOME, v0.3.0 installing the published remote-v1, then this branch with the published remote-v2): no approval call. The PC reached connected on v2 in 20s, all four stages were reported (download went 0→100%), the remote workspace was kept, and the bundle was cached. A phone screenshot during the download showed the sidebar progress and the header percentage.
  • End to end, setting off: the PC waited with action_required=update_bridge and nothing started on its own. One update-bridge call then connected it on v2 in 20s.

🤖 Generated with Claude Code

devswha and others added 4 commits September 25, 2026 05:17
Every bridge install downloaded the bundle (~130MB) into memory and piped it
to the PC as one blob: a second PC or a retry downloaded it again, several
PCs at once held several copies, and nothing could say how far it got.

bundleFile() now returns a verified file: a local manifest's own, or a
release asset downloaded once per checksum into <stateDir>/bundles (the
newest four kept), streamed to disk with its hash checked on the way and
shared by concurrent installs. SshConnection.run() can stream a file to a
command's stdin, writing each chunk once ssh took the last one, and
installBundle() reports download, upload and install progress.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A bridge update needed its dialog open from start to finish: the dialog
cancelled the job when it closed, and the approval step waited on it.

- A bridge update can run as an automatic job: key-only SSH (BatchMode),
  approval already given, and no setup timeout once installing. A PC that
  needs a password fails with the reason and waits.
- When a PC is refused for an out-of-date bridge (or has only an older
  runtime and no bridge running), the server queues such a job, one at a
  time, if machine-settings.json has auto_update_bridges (default true).
- POST /api/machines/:id/update-bridge starts the same job from one tap;
  GET/PATCH /api/machines/settings read and change the preference.
- Jobs carry progress (stage, bytes, rate), and a PC mirrors its running
  update as `updating` over the machine events.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…nning

- The PC's notice shows a running update: step, bar, bytes and time left,
  and Cancel update. Update bridge starts the background update in one tap;
  Sign in and update… opens the dialog for PCs that need a password.
- The header line shows the running update's step and percentage.
- The setup dialog shows the same progress, and closing it after approval
  leaves the install running (Continue in background).
- Settings → Remote PCs toggles automatic bridge updates, and the app
  update hint says bridges follow.
- docs/remote-pcs.md and the CHANGELOG describe the new flow.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… the older-runtime check

- A background or one-tap bridge update that failed with an ordinary error
  (no network, SSH refused) cleared action_required, so the PC lost its
  Update bridge / Sign in and update… notice. It now keeps update_bridge
  and shows the reason.
- The "older runtime, no bridge" check also fired for Add PC and Reconnect
  dialogs, telling a PC that was never registered to update its bridge. It
  now applies only to automatic reconnects.
- A download cut short by a restart left its .part file in the bundle
  cache; part files older than an hour are removed on the next download.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@devswha

devswha commented Sep 24, 2026

Copy link
Copy Markdown
Owner Author

Follow-up commit 1feea9f fixes two failure-path bugs found while reviewing:

  • A background or one-tap update that failed with an ordinary error (no network, SSH refused) cleared action_required, so the PC lost its notice and buttons. It now keeps update_bridge and shows the reason.
  • The older-runtime check also fired for Add PC and Reconnect dialogs (for example, re-adding a removed PC). It now applies only to automatic reconnects.
  • Stale .part downloads left by a restart are cleaned up.

Verified end to end in the isolated harness:

  • failfirst: the automatic attempt had no bundle source, so the PC kept update_bridge with getaddrinfo ENOTFOUND bundles.invalid. The retry connected on v2 in 18s.
  • cancel: cancelled during the upload. The remote install.lock was released and the button was kept. The retry reused the cached bundle (no download stage) and connected in 22s.

bun test passes 300/300 and test:ssh passes 8/8.

@devswha
devswha merged commit 5f25f37 into main Sep 24, 2026
@devswha
devswha deleted the feat/background-bridge-updates branch September 26, 2026 14:48
devswha pushed a commit that referenced this pull request Oct 6, 2026
…ersion mismatch (#506)

## Change

A connect (Add PC) or a reconnect that is refused on the bridge version
check used to dead-end in its dialog: the job failed with the raw server
text and a **Retry connection** that repeated the same refusal, and
because a first connect that fails never registers the PC, no sidebar
row appeared to offer the update. The dialog now turns that refusal into
the action itself:

- `SetupJob` carries an optional `action_required`
(`shared/machines.ts`), set in `setup()`'s catch alongside the existing
`Machine.action_required`. A PC that was never registered has no machine
to carry it, and an interrupted `update_remote` retry keeps offering
itself (`job.update` alone).
- On `action_required === "update_bridge"` the dialog replaces **Retry
connection** with **Update bridge and connect**, which re-runs the setup
with `update_remote: true` — through the same approval list a first
install shows, so passwords and host keys still work and nothing
installs unattended. Approving installs the bundle, restarts the
verified bridge and connects; herdr sessions keep running.
- An approved replacement accepts a different bridge protocol only for
identity verification, preserving authenticated socket, managed
ownership and PID checks. The replacement must match the current
protocol and bundle version before connecting. Restart waits for the
verified old process with a deadline and ignores its stale descriptor.
- Both Connect and Update submit the same form: Enter works, required
addresses and SSH port limits are enforced, and requesting an update
still requires the separate installation approval.
- New string `Update bridge and connect` in ko, ja and zh; the hint
reuses the sidebar's translated line.

This closes the gap left by #22 and #26, which give a registered PC the
sidebar/banner button and the background update. Raising
`REMOTE_BUNDLE_VERSION` is the moment every reconnecting PC lands
exactly here.

| Failure offers the update | Approval before install |
| --- | --- |
|
![failure](https://raw.githubusercontent.com/suho-han/herdr-web-ui/pr-evidence/pc-dialog-update-offer.png)
|
![approval](https://raw.githubusercontent.com/suho-han/herdr-web-ui/pr-evidence/pc-dialog-approval.png)
|

## Validation

Latest main merged; original contribution by @suho-han is retained and
credited in CHANGELOG.md.

- Generated-type check, typecheck and production build passed on Bun
1.4.2.
- Full unit suite: **1,457 passed, 15 skipped, 0 failed**.
- Nine new loopback/fake-SSH regression cases cover first-connect
failure, explicit approval, old-protocol replacement,
authentication/socket/PID/ownership refusal without stopping a process,
and strict verification of the replacement.
- Real MachineDialog browser regression passed at **1280px and 390px**:
Enter submission, required address, SSH port range, explicit update
intent, separate approval and Open PC. Added to browser CI.
- Required **Fast checks** and **Integration and browser** passed on
`75ee1f304ebf16ffc47beff8aca07417c9dd83e4`. Native Windows installation,
all Linux/macOS/Windows bundle checks, real SSH bridge updates and
password authentication also passed.

All new local tests use disposable state, synthetic endpoints and a fake
SSH host; they do not update a real PC or touch a user's herdr session.

---------

Co-authored-by: e2e <[email protected]>
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