instance.watch/v1
An edge follows a mothership without holding every instance. It opens one stream; the first time a request names a hostname, it asks for it; from then on it hears every change to what that hostname serves, until it stops caring. Nothing is sent that no edge asked for, except the list of edges and the edge's standing set (instances it must hold whatever its traffic, such as a copy waiting to be made).
A wire contract (watch.go) at /api/_c/instance.watch/v1/. Superusers only (scope fleet).
Use
| Operation | ||
|---|---|---|
stream |
GET /stream?edge=<edge id> |
Server-sent events, each {kind, seq, ...}: hello first (conn, self, edges, standing), then host (host, answer), edges, standing, and ping when idle |
watch |
POST /watch {conn, edge, host} |
Registers host on the stream conn and sends its answer there. With no live conn, the answer comes in the reply and nothing is watched |
unwatch |
POST /unwatch {conn, host} |
Stops changes for host on conn |
The promise is in the order:
- The hostname is registered before it is read, so no write between the two is missed.
- The answer goes on the stream, never in the reply, so the answer and every later change arrive in the order they
happened. A
hostevent with noanswermeans the hostname couldn't be resolved (an error, not "not found"). - "No such host" is an answer (
found: false), watched like any other: the instance that later takes the name arrives. - A change is sent only when the answer differs from the one sent last on that stream.
seqnumbers a stream's events from 1; a gap means something was lost and the edge reconnects.- A dropped stream forgets every watch. An edge starts over on its next stream; what it cached before is unwatched.
In Go, ext/mothership/client is the edge side: it is a multisite host's instance.source/v1 and instance.lookup/v1.
Provide
Implement watchv1.Watcher and provide it on the mothership app. ext/mothership's
Server is the provider: it keeps each stream's watches in memory, indexes them by the deps
instance.resolve/v1 returns, and resolves again after every committed write that
touches them.
Commands and APIs
Every operation is a REST endpoint, a pocketone command and an MCP tool, all generated from the contract and behind the same token scope check and hooks. See Remote CLI, or the full CLI, Extension APIs and MCP references.
stream
Opens this edge's stream: a hello first, then answers and changes for the hostnames it watches, the edges list when it changes, and its standing set when that changes.
| REST | GET /api/_c/instance.watch/v1/stream |
| CLI | pocketone remote instance watch stream --edge <value> |
| MCP | instance_watch_stream |
| Token scope | fleet |
| Answer | a stream of JSON entries (server-sent events); the command prints one line each |
| Input field | Flag | Type |
|---|---|---|
edge |
--edge |
string |
watch
Registers a hostname on a stream and sends its answer there (or, with no live stream, in the reply).
| REST | POST /api/_c/instance.watch/v1/watch |
| CLI | pocketone remote instance watch --conn <value> --edge <value> --host <value> |
| MCP | instance_watch_watch |
| Token scope | fleet |
| Input field | Flag | Type |
|---|---|---|
conn |
--conn |
string |
edge |
--edge |
string |
host |
--host |
string |
unwatch
Stops changes for a hostname on a stream.
| REST | POST /api/_c/instance.watch/v1/unwatch |
| CLI | pocketone remote instance watch unwatch --conn <value> --host <value> |
| MCP | instance_watch_unwatch |
| Token scope | fleet |
| Input field | Flag | Type |
|---|---|---|
conn |
--conn |
string |
host |
--host |
string |
Extensions
| Extension | |
|---|---|
| mothership | provides |
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.