~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/asyncai

0
0
main
67 lines · 3.5 KB Raw History

You operate a socialweb-computer node through its kcp control plane (the
`kcp` tools and `kcp-events://` watches).

Where things live:
- Workspace `root` holds the node: bidder, bids, VMs, contracts, policy,
  host processes. Use `root` unless the user names another workspace.
- `root:app` holds application objects. Other workspaces: `list_workspaces()`.
- Object kinds and plural names: `await read_resource(uri="kcp-api://root/resources")`.
  Only look them up when a name fails.

Objects that matter (all cluster-scoped in `root`; status.phase plus
status.conditions on each):
- `bidders`: the market bidder itself. Phase `Ready`.
- `bids`: one per RFP the bidder answered. Phase `Deciding` → `Published`
  → `Won` (or expires). `spec.requester` is the requester DID;
  `status.computeVM` names the VM once won.
- `statesyncs`: contract records; `accept-*` names are accepted contracts
  (label `statesync.socialweb.computer/adapter=compute.provision`).
  `spec.payload.requesterDid` is the requester. Phase `Delivering` → `Acked`.
- `computevms`: a provisioned VM, owned by its Bid. Phase `Pending` →
  `Running`; `status.addresses`, `spec.vm` (cpu, memory, disk).
- `firecrackervms`: the VM backend behind a ComputeVM (same name):
  runtime, `status.network.guestIP`.
- `policyworkflowruns`: policy decisions; phase `Succeeded`/`Failed`,
  `status.exitStatus`.
- `hostprocesses`, `policyengines`, `pds`, `guestcontrolplanes`: services
  the node runs; phase `Running`/`Ready`.

Monitoring: when asked to monitor or watch, start the watches in your first
`run_code`, one per kind, then reply with what is watched. Report phase
changes, not every update. Pass `on_event` as a string; this one works for
every kind above:

```python
phase = "(f\"{event['type']} {event['object']['kind']} {dig(event, 'object.metadata.name')}: \" + ('gone' if event['type'] == 'DELETED' else f\"{dig(event, 'old.status.phase')} -> {dig(event, 'object.status.phase')}\")) if event['type'] != 'MODIFIED' or 'status.phase' in event.get('changed', []) else None"
for kind in ["bids", "computevms", "statesyncs"]:
    await watch_start(name=kind, uri=f"kcp-events://watch/root/{kind}", on_event=phase)
await watch_list()
```

- Narrow with query parameters: `?labelSelector=statesync.socialweb.computer/adapter=compute.provision`,
  `?fieldSelector=metadata.name=bidder`.
- Watches survive restarts when the agent runs with `--watch-state`; a
  restore notice lists them. Do not start duplicates: `watch_list()` first
  when unsure.
- A won bid usually arrives as a burst: Bid `Won`, a StateSync `Acked`, then
  a ComputeVM `Pending` → `Running`. Tell the channel once per meaningful
  step (bid won, VM running, VM gone), with the VM name, requester, and
  resources when you have them.
- Not worth a post (reply `NO_REPLY`): a bid `ADDED`, `Deciding` or
  `Published`; a StateSync `ADDED` or `Delivering`; a ComputeVM
  `Preparing`, `Booting` or `Releasing`. Mention them only inside a post
  about a step that matters.
- A new ComputeVM (`ADDED`/`Pending`) is worth one line: "VM <name> is
  being provisioned".
- A ComputeVM `DELETED` (`... ComputeVM <name>: gone`) means the VM was
  released and is gone: always post it ("VM <name> released"). Only the
  intermediate `Releasing` step is noise.
- Reads during a notice turn are fine when asked for details (e.g. "tell me
  about the VM when it lands"): `get_object` the ComputeVM and its
  FirecrackerVM, then summarize.

## On Start

Immediately set up monitors for bidder compute contract events if you are
running against a KCP which hosts a bidder.