Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog.d/route-choice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### `darkbloom route this-mac`, `my-macs` or `my-macs-first`

- `darkbloom route this-mac`, `darkbloom route my-macs` and `darkbloom route my-macs-first` save where your requests go when this Mac's local API can't take them (`[local] route`), so the route no longer needs a hand edit of `provider.toml` or a whole `darkbloom start --route`. Each says what it means: `my-macs` sends them to your other Macs, free, and never to the network; `my-macs-first` sends them to your other Macs, then to the Darkbloom network, billed, and requests from other machines (your LAN or tailnet) never use the paid network.
- `my-macs` and `my-macs-first` need your account API key: without one they save nothing, exit 1 and name `darkbloom route key`. They only ask whether a key is saved; no line shows a key.
- A running local API uses a saved route from its next request, with no restart and no model reload: its router reads `[local] route` again when `provider.toml` changes (one `stat` by a request this Mac can't take or a model list; none for a request this Mac serves). The command says "Saved. Your local API uses it now.", or "It applies when your local API starts." with none running. A malformed edit keeps the last good route and is said once in the local API's log, with nothing from the file. So does a read that catches an editor saving the file in place (it empties the file before it writes it): only a whole file counts, so a saved `this-mac` never passes a request on while the file is saved.
- `darkbloom route key` says the same when it saves or removes the key, which a running local API already read again from its next request. A key removed while the route passes requests on says that the next request this Mac can't take gets this Mac's own answer.
- That answer now says why. A request this Mac can't take, with `my-macs` or `my-macs-first` saved and no account key, or after `darkbloom route key --remove` removed the key a running local API used, keeps this Mac's 404, 429 or 503. Its message says that this Mac doesn't serve the model (or can't take the request now), and that reaching your other Macs needs an account key (`darkbloom route key`), with code `account_key_needed`. The local API's log says it once, never with the key. Before, it was this Mac's plain "Requested model is unavailable." with nothing in the log.
- In a two-Mac cluster, both commands say plainly that the leading Mac's route and key apply: the pair's local API runs there, and requests from the other Mac reach it from another machine, so with `my-macs-first` they never use the paid network, which both Macs now say. Their words are now true for each Mac. On the leading Mac, a removed key says that the pair passes nothing on until a key is saved there again, `route this-mac` says that the pair's local API passes nothing on, and the summary and `--no-auth` lines name this pair, not this Mac. The other Mac says only that the leading Mac's route decides what the pair passes on, and names `darkbloom route key`, or `darkbloom route key --remove`, to run on the leading Mac; refused for want of a key, it names the leading Mac first. A pair's local API without a local key (`--no-auth`) never claims to pass requests on.
- `darkbloom route key`, with `[local] route = "this-mac"`, now names `darkbloom route my-macs` to use the key.
79 changes: 75 additions & 4 deletions docs/provider/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ Subcommands declared by `Darkbloom.configuration.subcommands`:
| `doctor` | Diagnostics (see [troubleshooting](./troubleshooting.md#doctor-checks)) | ✓ | `DoctorCommand.swift` (`Doctor`) |
| `models` | `list`, `catalog`, `download`, `remove` | ✓ | `ModelsCommand.swift` (`Models`) |
| `local` | Print the local API's address and key | | `LocalCommand.swift` (`Local`) |
| `route` | Where your requests go when this Mac's local API can't take them: `this-mac`, `my-macs` or `my-macs-first` saves `[local] route` ([below](#darkbloom-route-this-mac-my-macs-my-macs-first)); `key` saves the account API key | ✓ | `RouteCommand.swift` (`Route`), `RouteChoiceCommand.swift` (`RouteChoiceFlow`) |
| `cluster` | Set up two Macs to serve one model together ([guided setup](./two-mac-cluster.md)); `cluster local` serves without a coordinator. In a terminal, the first setup asks how the pair serves (**Only me (this pair, local)**, **Darkbloom network**, or **Both, me first**, preselected: the leader's local API beside Darkbloom, which pauses while you use it), saves the answer in `[local] mode`, and asks nothing without a terminal ([Both, me first](./two-mac-cluster.md#both-me-first-the-pairs-own-api-beside-darkbloom)). Run again on a paired Mac it works like `darkbloom start` (which opens the same screen there): both Macs, the cable and the status, then the pair's models with the current one preselected (Enter keeps it or starts it again), each with the modes it runs there, the recommended one first and no speed, **Change how the pair serves** (the three choices below; `cluster local`'s list keeps its line to switch to Darkbloom), and **Start over**; another model asks once before the serving one stops, and every start ends with the outcome, the pair's card and `darkbloom stop` / `restart` / `status` ([after setup](./two-mac-cluster.md#the-steps-once)). It offers **Start over** after one question (also when the other Mac does not answer over the cable: the screen then names that Mac and what to run there), and **Pair again** without it only when the saved pairing was made with another Secure Enclave key; both take the steps of `cluster pair --forget` (`ClusterUnpairing`), then pair ([pairing again](./two-mac-cluster.md#pairing-again)) | ✓ | `ClusterCommand.swift` (`Cluster`) |
| `waitlist` | List the waitlists the coordinator offers and where the account stands (bare), or put the account on one and show where it stands (`waitlist cluster`, `waitlist sandbox`); waitlists are per account | ✓ | `Waitlist/WaitlistCommand.swift` (`Waitlist`) |
| `login` | Link the machine to an account (RFC 8628 device code) | ✓ | `LoginCommand.swift` (`Login`) |
Expand Down Expand Up @@ -957,6 +958,52 @@ the start summary's words) and `requests:` (where your requests go)
keyed server adds `tools: darkbloom --opencode · --hermes` (`Local.toolsLine`). `--json`
is unchanged.

### `darkbloom route this-mac`, `my-macs`, `my-macs-first`

| Command | Saves | A request this Mac can't take |
|---|---|---|
| `darkbloom route this-mac` | `[local] route = "this-mac"` | Gets this Mac's own answer; nothing is passed on. Needs no account key |
| `darkbloom route my-macs` | `[local] route = "my-macs"` | Goes on to your other Macs, free; never to the Darkbloom network |
| `darkbloom route my-macs-first` | `[local] route = "my-macs-first"` | Goes on to your other Macs (free), then to the Darkbloom network, billed to your balance |

Each takes `-c`, `--config` (the `provider.toml` to save in) and writes only
`[local] route` (`setLocalSettings`), so it replaces a hand edit of the file
and `darkbloom start --route`. It then says what the route means; with
`my-macs-first`, that requests from other machines (your LAN or tailnet) never
use the paid network ([the local router](./direct-mode.md#when-this-mac-cant-take-a-request-the-local-router)).
The same choice again writes nothing (`✓ Already saved. …`).

- **Without a saved account key,** `my-macs` and `my-macs-first` save nothing
and exit 1: ``✗ Not saved: `darkbloom route my-macs` passes your requests on
with your account API key, and this Mac has none saved.``, then the command
that saves one (`darkbloom route key`) and the one to run again. It only asks
whether a key is saved, and never prints one.
- **A local API running now uses it from its next request,** with no restart
and no model reload: `✓ Saved. Your local API uses it now.` With none
running: `✓ Saved. It applies when your local API starts.` Its router reads
`[local] route` again when `provider.toml` changes
([the local router](./direct-mode.md#when-this-mac-cant-take-a-request-the-local-router)).
One without a local key (`--no-auth`) keeps every request on this Mac (on a
pair's leading Mac, on this pair), whatever the route, and the command says
so.
- **In a two-Mac cluster,** the leading Mac's route applies: the pair's local
API runs there and passes on what the pair can't take, including requests
from the other Mac. Those reach it from another machine, so with
`my-macs-first` they never use the paid network, and both Macs say so. On
the leading Mac the command says so, or, with `this-mac`, that the pair's
local API passes nothing on. A pair's API without a local key
(`cluster local --no-auth`) gets the `--no-auth` line instead. On the other
Mac it saves the route for when that Mac serves alone (``It applies when
this Mac serves alone (`darkbloom start --solo`).``), says that the leading
Mac's route decides what the pair passes on (that Mac's route and key aren't
known here), and names the command to run there. Refused for want of a key,
it first names the leading Mac's `darkbloom route key` and route for the
pair, then a key saved here for this Mac alone.
- A `provider.toml` that doesn't load is refused with its reason, and nothing
is written (exit 1).

`RouteChoiceFlow` in `provider-swift/Sources/darkbloom/RouteChoiceCommand.swift`.

### `darkbloom route key`

| Flag | Type | Default | Effect |
Expand All @@ -977,9 +1024,29 @@ never printed (`RouteKeyFlow`, `provider-swift/Sources/darkbloom/RouteCommand.sw
`KeychainLocalRouterAccountKeyStore`). After it saves or removes the key, it
posts the Darwin notification `<keychain prefix>.route-key-changed`: a running
local API keeps the key in memory and reads it again on its next request that
needs it. When the local API running now has no local key (`--no-auth`), it
says that this API keeps every request on this Mac and never uses the key. ^C at the hidden prompt gives the terminal its echo
back before the command ends (`HiddenReadSignals`). See
needs it, so it says `Your local API uses it now.` (or, with none running, `It
applies when your local API starts.`). A key removed while the route passes
requests on says what the next request does: ``Your local API uses it now.
From its next request, one this Mac can't take gets this Mac's own answer
instead of going to your other Macs or the Darkbloom network.`` That answer
says an account key is needed (code `account_key_needed`, see
[the local router](./direct-mode.md#when-this-mac-cant-take-a-request-the-local-router)).

In a two-Mac cluster it says whose key the pair's local API uses, and on the
leading Mac its summary names the pair (`Your requests: this pair first, then
your other Macs (free).`):

| This Mac | Saved | Removed |
|---|---|---|
| Leads (the pair's local API runs here) | `In this pair, the pair's local API runs on this Mac and passes requests on with this key.` | ``From its next request, one the pair can't take gets the pair's own answer …``, then `In this pair, the pair's local API runs on this Mac, so the pair passes nothing on until a key is saved here again.` |
| Leads, with `[local] route = "this-mac"` | `In this pair, the pair's local API runs on this Mac and uses this Mac's key once its route passes requests on.` | `In this pair, the pair's local API runs on this Mac: once its route passes requests on, it needs a key saved here again.` |
| Follows | ``In this pair, the pair's local API uses the leading Mac's key (…), not this one: run `darkbloom route key` there.`` | ``… not this one: to stop the pair passing requests on, run `darkbloom route key --remove` there.`` |

When the local API running now has no local key (`--no-auth`), it says that
this API keeps every request on this Mac (on the leading Mac, on this pair) and
never uses the key; on the leading Mac it then says nothing of the pair's key. ^C at the hidden prompt
gives the terminal its echo back before the command ends
(`HiddenReadSignals`). See
[the local router](./direct-mode.md#when-this-mac-cant-take-a-request-the-local-router).

### Cluster placement request metadata
Expand Down Expand Up @@ -3184,12 +3251,16 @@ only, your other Macs (free), or your Macs first and then the Darkbloom network
(billed), from `[local] route` and a saved account API key.

```bash
darkbloom route this-mac # your requests stay on this Mac
darkbloom route my-macs # then your other Macs (free); needs the account key
darkbloom route my-macs-first # then your other Macs (free), then the Darkbloom network (billed); needs the key
darkbloom route key # ask for the key with hidden input, check it, save it in the Keychain
darkbloom route key --stdin # read it from standard input
darkbloom route key --remove # remove it: requests stay on this Mac
```

No output line contains the key. Flags: [`darkbloom route key`](#darkbloom-route-key).
No output line contains the key. Details: [the three routes](#darkbloom-route-this-mac-my-macs-my-macs-first)
and [`darkbloom route key`](#darkbloom-route-key).

## `darkbloom logs`

Expand Down
38 changes: 37 additions & 1 deletion docs/provider/direct-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,26 @@ gets `my-macs-first` as `my-macs` (`self` only, never `prefer`), and its
saved. A connection's peer is read once, when it opens, and nothing is added to
this Mac's own path.

The route is read when the local API starts (a change needs a restart). The
`darkbloom route this-mac`, `darkbloom route my-macs` and
`darkbloom route my-macs-first` save the route; the last two need a saved
account key and refuse without one
([CLI reference](./cli-reference.md#darkbloom-route-this-mac-my-macs-my-macs-first)).
A running local API uses a saved route from its next request that needs it,
with no restart and no model reload: its router reads `[local] route` again
when the provider config file it started with changes (`LocalRouterRouteFile`,
`provider-swift/Sources/ProviderCore/Server/LocalRouter.swift`). Only a
request this Mac can't take and a model list look at the file, one `stat` each
(its device, inode, size and modification time); a request this Mac serves
never does. A change is logged (`local router: route is now my-macs-first
(provider.toml changed)`). A file that doesn't read as a provider config, a
malformed edit or a file that is gone, keeps the last good route and is said
once in the log until it reads again (`local router: provider.toml doesn't read
as a provider config now; requests keep the route my-macs until it does`); the
line holds nothing from the file. Only a whole file counts: an editor that
saves in place empties the file before it writes it, so a read that finds it
empty, or shorter than its `stat` said, keeps the last good route the same way,
and a saved `this-mac` never passes a request on while the file is saved. A
pair's local API reads the leading Mac's `provider.toml`. The
key is read once, by the first request that needs it, and kept in memory:
`darkbloom route key` tells a running local API when it saves or removes the
key (a Darwin notification, `<keychain prefix>.route-key-changed`), and the
Expand All @@ -250,6 +269,23 @@ next request reads it again, with no restart.
serves this Mac only, never reads the account key and never dials the
coordinator, whatever the route. The start banner, `darkbloom local` and
`darkbloom route key` say so.
- **A route that needs the key, with none saved, says why.** That is a saved
`my-macs` or `my-macs-first` with no account key, or no route saved after
`darkbloom route key --remove` removed a key this local API had used. A
request this Mac can't take stays on this Mac. Its answer keeps this Mac's
status (`404`, `429` or `503`), `Retry-After` and
`X-Darkbloom-Served-By: this-mac`, with code `account_key_needed`:
``This Mac doesn't serve <model>, and reaching your other Macs needs an
account key: run `darkbloom route key`.`` A `429` or `503` starts `This Mac
can't take this request right now`. With `my-macs-first` it says `your other
Macs or the Darkbloom network`, except to a client on another machine. The
log says it once, until a key is read again, never with the key:
``local router: a request this Mac can't take stays on this Mac: reaching
your other Macs needs an account key, and none is saved (`darkbloom route
key` saves one)``. With no route saved and no key read while the local API
ran, or with `this-mac`, the answer is this Mac's own, as before
(`LocalRouter.needsAccountKey`,
`provider-swift/Sources/ProviderCore/Server/LocalRouterResponder.swift`).
- **What passes a request on:** only this Mac's own `404` (it doesn't serve
the model), `429` (its queue is full) or `503` (draining, an add-on hold, a
refused load, no capacity), before any byte reached the client. A client
Expand Down
20 changes: 15 additions & 5 deletions docs/provider/local-first.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,21 @@ busy, they can go on, like the Darkbloom iPhone app:
Requests from other machines never use the paid network; they can use this Mac
and your other Macs.

This needs your account API key, from the Darkbloom console, saved with
`darkbloom route key`. It goes into this Mac's Keychain and is never printed.
With a key saved, the question asks this too; you can also start with
`--route this-mac`, `--route my-macs` or `--route my-macs-first`. The details
are in [the local router](./direct-mode.md#when-this-mac-cant-take-a-request-the-local-router).
Choose with one command; it saves your choice and says what it means:

```bash
darkbloom route this-mac # Only this Mac
darkbloom route my-macs # Only my Macs (free)
darkbloom route my-macs-first # My Macs first, then the network (billed)
```

The last two need your account API key, from the Darkbloom console, saved
with `darkbloom route key`; without it they save nothing and say so. The key
goes into this Mac's Keychain and is never printed. With a key saved, the
start question asks this too. A running local API uses a new choice, and a key
saved or removed, from its next request: no restart, and no model reload. The
details are in
[the local router](./direct-mode.md#when-this-mac-cant-take-a-request-the-local-router).

## Your local API

Expand Down
7 changes: 6 additions & 1 deletion docs/provider/two-mac-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,13 @@ With **Both, me first**:
- **Requests the pair can't take** (a model it doesn't serve, a full queue) go
on as that Mac's `[local] route` says, with that Mac's account key
([the local router](./direct-mode.md#when-this-mac-cant-take-a-request-the-local-router)).
`darkbloom route this-mac`, `my-macs` or `my-macs-first` on that Mac sets it,
and the pair's API uses it from its next request, with no restart; on the
other Mac it says to run it on the leading Mac.
Requests from other machines never use the paid network; they can use the
pair and your other Macs.
pair and your other Macs. That includes the pair's other Mac: its requests
reach the leading Mac from another machine, so with `my-macs-first` tools
there use the pair and your other Macs, never the paid network.
- **Me first:** while one of your requests runs on it, or waits for a lane, the
pair takes no new Darkbloom request, and Darkbloom's running requests finish.
It takes Darkbloom requests again 2 minutes after your last request ends
Expand Down
Loading
Loading