Skip to content

perf(updates): run independent targets concurrently - #700

Merged
nixuuu merged 5 commits into
devfrom
perf/parallel-updates
Nov 14, 2026
Merged

nixuuu merged 5 commits into
devfrom
perf/parallel-updates

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Update all now runs independent computers, workers and different agent CLIs concurrently, with four global slots. A slow acknowledgement, failure or timeout no longer stalls unrelated targets. Equal npm prefixes, Bun global projects, pnpm global projects and Volta inventories serialize through installation, validation and rollback. Different prefixes and standalone installers overlap. Duplicate tools are deduplicated per worker; older workers without resource metadata retain their single installer slot.

This Canopy app restarts last. A standalone gateway drains independent peer work before restarting, then resumes protocol-dependent local workers from the durable run. Workers still target the running gateway version and must pass compatibility checks before their CLIs start. Linked apps execute on their own computers and are tracked until they return. The frozen UpdateService is unchanged; WorkerLink adds optional installer resource metadata without changing its protocol version.

Web and mobile share compact activity/success/failure counters. The web popover reserves three lines for active targets, so names and changing activity do not move the list below. Mobile remains a JS/TS change on the existing OTA path; no native modules, app configuration, dependencies or fingerprint inputs changed. OTA publication remains the release workflow's responsibility after merge.

Performance

Measured wall time for 4 fake workers × 2 CLIs, each with 25 ms synthetic service time:

Execution Total wall time
Sequential workload 202.5 ms
Concurrent scheduler, cap 4 52.6 ms

This is a 3.85× speedup for the fake workload. It excludes production polling, network and real installer variability. Timing is informational; deterministic gates, rather than timing thresholds, assert overlap and caps.

Validation

  • Install, generated-code check, monorepo typecheck, lint and formatting passed. The production web build and both native JS/Hermes exports passed.
  • Gated scheduler tests cover same-worker independent tools, cross-worker overlap, equal/different prefixes, global caps, failure/timeout isolation, deduplication, older workers, app-last ordering and gateway-before-worker compatibility. Real worker modules run fake npm executables and prove independent prefixes overlap while shared prefixes serialize; duplicate commands are refused and queued commands acknowledge immediately.
  • CI exposed races in the fake npm fixture: it overwrote an executable while a report could probe it, and announced its start before recording overlap. The fixture now publishes atomically and records overlap before signalling readiness. After the correction, 200 repetitions of both variants passed (400 tests), followed by all 21 worker/scheduler tests with clean temp directories, lint and formatting.
  • Authenticated gRPC, linked-computer, durability, owner-scoping and protocol coverage passes in the focused update suites. All 570 repository test files were executed across resumed segments after two command processes exited with signal 143. The final segment ran 1497 tests: 1418 passed, 78 skipped, and one existing Codex visual-harness test exceeded its 5-second timeout. Its isolated rerun passed all 5 tests without code changes (the timed-out case took 640 ms). Both completed segments reported no temp-directory leftovers. The aggregate full-suite attempt therefore had one transient timeout; it was not a single uninterrupted green run.
  • Browser review used the disposable checkout on the designated review host: real Updates components with the development gallery's fake data, light/dark, 1280 px desktop and 390 px phone width, typical and long names. Active labels retained their 60 px reservation, truncation worked and the document had no horizontal overflow. Only the disposable gallery bootstrap was isolated from the unavailable backend; this was not a full application E2E run. No device session was run. The review checkout, server and tunnel were removed.
  • Fingerprints generated on both the base commit's tree and the final implementation are identical: iOS 138e0c6b171c82b4933e86808cdfef56da73b8c6; Android 906dc944f94eb8333fa384ed9f198834fdd30d13. Native fingerprint sources, app configuration, dependency manifests and the lockfile are unchanged.

Copy audit (§8)

  • “Updating · n/m completed” → “Updating N · N done · N failed” on web, with the same summary on mobile: parallel activity and failures are explicit in one compact line. The progress bar counts successful and failed/blocked terminal steps and excludes skipped steps.
  • The duplicate-install error now identifies the same agent CLI and ends with “Wait for it to finish.” It gives a concrete recovery action; independent tools no longer receive that refusal.
  • Existing action labels, empty states and error details retain their patterns. No new glossary terms, humour or colour-only meanings. Counters use the existing compact type scale; web digits are tabular. Typical/long labels were checked in both themes and at desktop/phone widths. Full step outcomes remain available in Update results and the mobile list.

@nixuuu
nixuuu marked this pull request as ready for review November 14, 2026 11:45
@nixuuu
nixuuu merged commit 472fb83 into dev Nov 14, 2026
16 of 18 checks passed
@nixuuu
nixuuu deleted the perf/parallel-updates branch November 14, 2026 12:26
nixuuu added a commit that referenced this pull request Nov 14, 2026
The delayed-rejection test sometimes reads `expired` before the
successful turn's account update runs, even though the turn is already
committed. This is a test race: ingestion commits the turn, then awaits
settling, broadcasts and agent-bus handling before calling
`coreTurnLogin`. A database count therefore cannot establish that the
success has entered `ProviderAccounts.afterTurn`; the test's no-op queue
barrier can run ahead of it.

Observe the real account-update enqueue, keep the rejected account read
held until the success is queued, then wait for both real updates to
finish before asserting `signed_in`. Waiting for both independently also
catches a stale rejection when ordering is broken. Remove the
database-count helper and the two-second sampling loop. Product ordering
in `provider-accounts.ts` and `turn-logins.ts` stays unchanged.

Related: #696, #700, #703

### Verification

- Stress: **171 passed, 29 failed out of 200 (14.5% failures)** before;
**200 passed, 0 failed** after. Each repetition runs the focused file,
including the earlier device-login scenario this case depends on; the
target case executes once per repetition. The after run passed all
**800/800** tests in **310.99 s**. No retries, sleeps or timeout
increases were added.
- The baseline used 48 completed direct repetitions, then 152 with the
repository's shared-Postgres runner. The after run used `nice -n 10 bun
run check:tmp <focused-file> --rerun-each=200`; its identical source was
staged under a temporary test filename so the unchanged baseline could
run alongside it. Both used a private `TMPDIR` under `/var/tmp`.
- Mutation check: bypassing the real queue with `update()` makes the new
test fail with `Expected: signed_in / Received: expired`. The mutation
was confined to a temporary test copy and removed.
- `bun install`, `bun run typecheck`, `bun run lint`, `bun run
format:check`, and the final focused file: **passed**, all with `nice -n
10` and temp under `/var/tmp`. The shared-Postgres runner reported no
test temp directories left behind.

No UI, protocol or runtime behavior changes.
nixuuu added a commit that referenced this pull request Nov 14, 2026
…#743)

## Summary

Redesign of the sidebar **Updates** popover and the mobile Updates
sheet, following the approved audit. The goal: an immediate state on
every click, one summary, rows that never move.

**Popover**
- One summary line in the header (`Starting update…`, `Updating · 2 of 5
done`, `1 update failed · 4 updated`, `All 5 updates finished`, `5
updates available`, `Up to date · Checked 5:39 PM`). The header divider
doubles as the run's 2 px progress bar.
- Removed from the popover: the progress block, the empty 3-line slot
(#700), the active-step list and "Update results". The step history
stays in Settings → Workers → Updates.
- One counter, `N of M done`. M counts every planned step, including
queued ones, so the old "Updating 1" next to "0/2" can't happen. `· K
failed` appears only when K > 0.
- Footer: a `Settings` link; `What's new` only when there are unseen
notes; one labelled primary action on the right: `Update all`, `Restart
to update`, `Retry failed`, or a disabled `Starting…` / `Updating…` with
a spinner.
- Sidebar trigger: `arrow-down-tray`, with a dot when something waits, a
progress ring while updating, and `exclamation-circle` on failure. No
more green check for "downloaded" and no spinning ⟳.

**Rows** (web `UpdateItem`, mobile `UpdateRow`)
- Always two lines. The badge sits in a fixed slot, the bar in the
bottom padding, and the action in a fixed column, so a state change only
swaps text (`t-swap`). Only an error expands, and only on click.
- One vocabulary from `@canopy/domain/release/update-status`: Up to date
(quiet text), Available, Downloaded (was "Ready"), Queued, Starting,
Updating, Waiting, Restarting, Updated (the only green, for 1 h, via
`UpdateStep.finished_at`) and Failed. Edge states keep their own words.
- Icon actions, one meaning each, with a tooltip and `aria-label`:

  | Icon | Action |
  |---|---|
  | `arrow-down-tray` | Update `<name>` |
  | `power` (new) | Restart to update |
  | `repeat` (new) | Retry |
  | `plus` | Install |
  | `information-circle` | Details |

`arrow-path` (⟳) is used only for **Check now**. There is no cancel
glyph, because the API has no cancel action.
- A feed check no longer turns every row into "Checking".

**Immediate states, root cause of the late statuses**
- Before, the UI rendered only server-confirmed state, `reload()` was
blocked while an action was pending, and rows read the targets' own
reports, not the run's steps.
- Now `UpdatesState` (web) and the mobile state apply an overlay as soon
as you click: every planned step shows `Queued` (`plannedUpdateRun`, the
same plan the gateway writes), a row action shows `Starting`, and Retry
failed marks its steps. The gateway's answer replaces the overlay; an
error reverts it.
- Reads keep running during an action. A row shows the further of its
run step and its own report, so it never goes back.
- Gateway: `UpdateCenter.begin()` plans, persists and launches the first
steps before answering, and the response reuses the planning snapshot.
The first answer to Update all already has `running` steps.

**Calm restarts**
- A computer that announced its own update restart shows `Restarting`
with "Restarting to update…".
- The gateway no longer sets "…is unavailable. Trying again
automatically." for it. Its workers and CLIs get "… is restarting to
update." instead.
- After 3 min the row turns amber: "Still restarting after N min. Check
that computer." The 35-min step timeout still ends in Failed with Retry.

**Gateway / contracts**
- `ManageUpdates.retry_failed` (action string; proto comment only):
re-queues every failed or blocked step of the stopped run in one durable
write, keeps successes and their versions, and needs `confirm_restart`
when this app is among them.
- Additive `UpdateStep.finished_at = 12`.
- `updatePlan` moved into the domain as `plannedUpdateRun`.
`computerUpdate()` moved from web to
`@canopy/domain/release/computer-update`, so web and mobile derive rows
the same way.

**Bug fix:** this app's "Restart to update" stayed enabled during Update
all (`CompactAppUpdate.svelte`, old line 89). A click restarted this
computer mid-run, before the linked computers finished. Row actions are
now disabled while a run is active or an action is pending. No `Fixes:`
link: the enable logic dates from #207, and Update all already included
this app before #700, so no recent PR introduced it.

**Mobile parity:** the same summary, rows, icons, overlay, footer and
trigger. JS/TS only. `bun.lock`, the mobile `package.json`, app config,
plugins and native folders are unchanged, so the runtime fingerprint is
unchanged and this ships OTA. No EAS was run.

## Tests

- `packages/domain/src/release/update-status.test.ts`: the shared
planner predicts the gateway's steps and their row keys (skipped steps
apart, this computer last); rows never go back; Updated stays an hour;
the single counter; restart grace.
- `tests/integration/update-concurrency.test.ts`: Update all answers
with its first steps already running, from the snapshot it planned with;
Retry failed re-queues every failed step at once, keeps successes,
rejects a stale run id and a second retry.
- Updated for the new vocabulary and module paths: `linked-updates`,
`paired-app-updates`, `updates-bundled`,
`apps/desktop/test/update-controller`.

## Checks

`bun install` · `bun run gen:check` · `bun run typecheck` · `bun run
lint` · `bun run format:check` · the focused tests above (all update
suites: `update-center`, `update-concurrency`, `updates-bundled`,
`stale-app-updates`, `update-all-computers`, `paired-app-updates`,
`linked-updates`, desktop `update-controller`, domain) · `bun run
--filter @canopy/web build` · `expo export` for Android and iOS.

## Copy audit (docs/copy.md §8)

| Before | After | Reason |
|---|---|---|
| `Updates in progress` (header) | `Updating · 2 of 5 done` | one
counted summary replaces 4 places (§2.12) |
| `Updating 1 · 0 done · 0 failed` | removed | merged into the header;
zero counts hidden (§5) |
| `Update results · 0/2` (popover) | removed | duplicate; stays in
Settings |
| `Mac-Studio… · Canopy app · Updating` | removed | the row says it |
| `Ready` | `Downloaded` | says what happened |
| `Updating…` (presence badge) | `Restarting` | one word for an expected
restart; no ellipsis in badges (§2.11) |
| `Waiting for idle` | `Waiting` + `Restarts after its current turns
end.` | slot width; no jargon (§2.8) |
| `{name} is unavailable. Trying again automatically.` (during its own
restart) | `Restarting to update…`, after 3 min `Still restarting after
N min. Check that computer.` | an expected restart isn't a failure; the
warning ends with an action (§2.6) |
| `This Canopy app` | `This computer` | rows are computers (§3 glossary)
|
| `Checked 5:39 PM` on every row | once: `Up to date · Checked 5:39 PM`
| §2.12 |
| `Show update progress` | removed (`Updating…` while disabled) | no-op
action |
| `Update details` / `App updates` | `Settings` | one link (§5) |
| `What's new` always | only with unseen notes | no empty actions (§5) |
| tooltip `Restart to update Canopy. This stops agents running on this
computer.` | `Restart to update. Agents running on this computer stop.`
| one idea per sentence, active voice |
| `Request update again on X` | `Retry` | verb first, 1–3 words (§4.1) |
| `Installing` (CLI) | `Updating` | one vocabulary |
| `Agent CLIs · Installing…` (mobile) | `Agent CLIs · 6 · Updating` |
count kept; shared word |
| — | `Starting update…`, `Starting…`, `Retry failed`, `1 update failed
· 4 updated`, `All 5 updates finished` | -ing + ellipsis for ongoing
actions (§4.6); counted results; no exclamation marks |

Glossary: computer, worker, agent CLI, update channel; no new terms. No
sentences with "soul". Live numbers use `tabular-nums` and sit at the
end of the line. Checked with short, typical and long names (the gallery
has "Build server in the rack room · linux-x64 · 64 GB" and "Sleeping
computer with a rather long name") at desktop and phone width, light and
dark.

## Browser review

On the review host: the `/dev/updates` gallery against a local gateway,
captured with Playwright, light + dark, desktop (1100 px) + phone (390
px), in every state. New gallery params: `state=quiet`,
`state=starting`, `restart=1|slow`.

States checked: all up to date, available, starting (immediate),
updating in parallel with a restarting computer, slow restart, one
failed, finished.

- Found and fixed (second commit): on phones the edge badge "Manual
update" was wider than the fixed slot and overlapped the name. The slot
is now a minimum width that fits every shared word, so state changes
still move nothing; a rare long edge word truncates the name instead.
- Fixture caveat: in "finished" the gallery leaves some versions
unchanged, so those rows correctly show Available again (a newer version
beats Updated).
- Not reviewed: the native mobile sheet on a device. It typechecks and
exports for both platforms; no build or EAS was run.
nixuuu added a commit that referenced this pull request Nov 18, 2026
## Change

Paired desktop apps in **Update all** previously waited for every binary
worker and CLI update on their gateway. After the gateway update
finishes, each desktop can now update alongside other workers once its
control stream reconnects and its own CLI updates finish. The run still
allows up to four active steps.

Fixes: #700

## Verification

- All 22 tests passed via `bun run check:tmp
./tests/integration/update-concurrency.test.ts
./tests/integration/update-center.test.ts`. The tests cover concurrent
worker and desktop updates, a desktop reconnecting after gateway
restart, and a desktop waiting for its own CLI.
- Scoped formatting, lint and `git diff --check` passed.
- GitHub CI covers the full repository checks.
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