socialweb.computer

Request and provide VMs on an atproto compute market.

Compute Contracts - Alpha

demo video

This is a spec for ATProto accounts to request and advertise (compute) resources.

This spec is for you if you run an organization and want to leverage decentralized identity to allow access to your org's compute (and in the future more) resources to your members and their workloads/agents.

The flow is: Request For Proposal -> Bid -> Accept -> Receipt

Caution

This is alpha software and it has yet to have a thorough review!!! Multiple passes of refactors were done and while things work they are just to play with right now! The compute contract flow can be considered proven. However, there is a lot of security pieces involved here and they need to be gone through with a fine toothed comb before Alpha. Please consider re-writing everything using your favorite LLM etc. let's please have many implementations! :D

Quickstart

Linux amd64 or arm64, the current release of channel stable:

curl -sfL https://socialweb.computer/install.sh | bash -e
echo 'export PATH="$HOME/.local/bin:$PATH"' | tee -a ~/.bashrc ~/.bash_profile

Or from a clone (rc for the release candidate):

git clone --depth 1 https://knotless.dev/socialweb.computer/socialweb-computer-kcp
cd socialweb-computer-kcp
scripts/install.sh stable
export PATH=$HOME/.local/bin:$PATH

scripts/install.sh reads the channel record from the releases account (did:plc:gmlkrhimoueejcertevr4hl3), follows it by CID to the version and manifest, and verifies the download against the binary's CID in that manifest before installing to ${PREFIX:-$HOME/.local}/bin.

It prints installed stable <version> (<sha256>) to ... and the version line. For a main commit or dev build, see docs/bidder.md.

Ephemeral Accounts with association records

A bidder gets a DID of its own and an association record that makes it an agent of your ATProto account once you sign in when prompted (scan the QR code / open the link in the logs). It bids only for requesters you vouch for.

Bid on compute contracts

sudo "$(command -v socialweb-computer)" install bidder --handle <your handle> --bidder-operator-signin <your handle>

Linux with /dev/kvm: docs/bidder.md; an agent of your account or your account itself: Who you run as.

Try a local market

One machine, its own PLC, relay, PDSes and a bidder; nothing leaves it:

S=~/.swc/demo
socialweb-computer dev up --instance demo --profile market-network --host-backend proc --state-dir $S
socialweb-computer run request --network demo --state-dir $S --name vm1 --exec -- id

You see uid=0(root) ... again, from a VM of your own bidder. Then:

socialweb-computer dev down --instance demo --state-dir $S

More: docs/quickstart-local.md.

BlueSky Accounts via QR Code Session Transfer

Both operators scan the QR codes from their own processes using the did-key-associator webapp at https://qr.fedfork.com.

Request Compute

socialweb-computer run request --name vm1 --atproto-oauth-qr --exec -- id

Sign in with the QR code (or the URL under it); you see uid=0(root) gid=0(root) groups=0(root) and the VM is released. A bidder serves you only when its operator vouches for you: docs/quickstart-prod.md. Hold a VM, ssh in, sizes, app passwords, the long-lived requester: docs/quickstart-prod.md. As your account or as an identity associated to it: Who you run as.

Secrets

To send secrets to the VM without putting them in cloud-init (public ATproto data), just pass a JSON file to --secrets:

For example, if you wanted to send your https://cocore.dev token to a new VM you could do it like so:

# Set ATP_HANDLE and ATP_PASSWORD for goat account login or provide like so:
goat account login -u "aliceoa.bsky.social" -p "aaaa-aaaa-aaaa-aaaa"

TOKEN=$(goat account service-auth \
  --lxm dev.cocore.account.createApiKey \
  --aud did:web:appview.cocore.dev)

PI_CONFIG=$(curl -sS -X POST \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  'https://appview.cocore.dev/xrpc/dev.cocore.account.createApiKey' \
  -d '{"name":"my-pi"}' | jq -r '{"apiKey": .secret}')

socialweb-computer run request --name pi \
  --secrets <(jq -n \
    --arg pi "${PI_CONFIG}" \
    --arg provider "cocore" \
    --arg model "mlx-community/Qwen2.5-7B-Instruct-4bit" \
    '[
      {
        path: "/root/.pi/agent/cocore-config.json",
        value: $pi,
      },
      {
        "path": "/root/.pi/agent/settings.json",
        "value": {
          "defaultProvider": $provider,
          "defaultModel": $model
        }
      }
    ]') \
  --atproto-oauth-qr

Here's a quick jq example of using env var names as arguments instead of writing each one out (then you'd pass --secrets /tmp/secrets.json):

jq -n --args '[$ARGS.positional[] | {path: ("/root/secrets/" + ascii_downcase), value: env[.]}]' \
  SOME_API_KEY OTHER_ENV_VAR > /tmp/secrets.json

Passing secrets this way works by leveraging Workload Identity Federation. We thereby avoid storing anything sensitive in the public compute.vm record.

Kubernetes

The page at k8s.socialweb.computer creates a cluster; a pod that cannot be placed rents a node from the market. The create form takes the node's vCPUs and memory (empty keeps 2 vCPUs and 4 GiB); a bidder that cannot serve the size declines the rent. Docs.

Protocol

diagram
Request For Proposal (RFP)BidAcceptPayment Settlement Flow (NOP if bids.free)ReceiptProvision ComputeConnect to compute at/via addressAliceBobcreateRecord: compute.vm(CPUs, Memory, Disk, etc.)1createRecord: rfp(strongRef to compute.vm)2createRecord: bids.free (or x402)(determine price)3createRecord: bid(strongRef to RFP + payment type)4createRecord: accept(strongRef to RFP + Bid + receipt-of-payment)5createRecord: receipt(strongRef to RFP + Bid + Accept)6createRecord: compute.events.vm.onNetwork(address: iroh ticket)7createRecord: market.event(strongRef to onNetwork + receipt)8AliceBob

Compute Contract Flow (High level)

The compute contract flow can be executed purely over the firehose/relays. That's what we'll cover in this section. For more details see the open-architecture repo's COMPUTE_CONTRACT_FLOW_MAP.md.

All market.* records use https://badge.blue signatures, not shown here for brevity.

Alice createRecord's the type of compute she wants

$type: com.publicdomainrelay.temp.compute.vm
cpus: 2
mem: 4G
disk: 40G
network: 500G
role: my-cool-role
user_data: |
  #cloud-config
  runcmd:
    - [sh, -c, "echo hello world"]
location:
  country: USA
  region: west

Alice createRecord's a Request For Proposal (rfp) strongReferencing the compute she wants.

$type: com.publicdomainrelay.temp.market.rfp
payload:
  $type: com.atproto.repo.strongRef
  uri: at://did:plc:alice/com.publicdomainrelay.temp.compute.vm/3mm3dolfolz2c
  cid: bafyrei...vm

Bob decides what he wants Alice to pay for the compute and createRecord's the payment type for his bid.

$type: com.publicdomainrelay.temp.market.bids.free
reason: free
# Can also do x402 but haven't tested this in a while:
# $type: com.publicdomainrelay.temp.market.bids.x402
# cost: 100000 (0.10 USDC, in the currency's smallest unit)
# currency: USDC
# frequency: hourly
# prepay: true
# url: https://compute-contract.bob.example/receipt

Bob createRecord's a Bid (bid) strongReferencing the compute she wants.

$type: com.publicdomainrelay.temp.market.bid
rfp:
  $type: com.atproto.repo.strongRef
  uri: at://did:plc:alice/com.publicdomainrelay.temp.market.rfp/3mm3doliee72s
  cid: bafyrei...rfp
payload:
  $type: com.atproto.repo.strongRef
  uri: at://did:plc:bob/com.publicdomainrelay.temp.market.bids.x402/3mm4...
  cid: bafyrei...x402

Alice settles the payment and gets a payment receipt according to settlement sub-flow. If bids.free, then that's a NOP.

Note

Settlement subflow hasn't been tested in a while for x402 and these docs will be updated in the future once we re-test and validate. We're focusing on orgs who want to distribute compute to their members in an ATProto native way for free first.

Alice then createRecord's an Accept (accept) record which wraps her proof-of-payment receipt (only if not bids.free)

$type: com.publicdomainrelay.temp.market.accept
rfp:
  $type: com.atproto.repo.strongRef
  uri: at://did:plc:alice/com.publicdomainrelay.temp.market.rfp/3mm3doliee72s
  cid: bafyrei...rfp
bid:
  $type: com.atproto.repo.strongRef
  uri: at://did:plc:bob/com.publicdomainrelay.temp.market.bid/3mm4...
  cid: bafyrei...bid

Finally, Bob provisions the compute and issues a Receipt (receipt) when he sees the Accept.

$type: com.publicdomainrelay.temp.market.receipt
rfp:
  $type: com.atproto.repo.strongRef
  uri: at://did:plc:alice/com.publicdomainrelay.temp.market.rfp/3mm3doliee72s
  cid: bafyrei...rfp
bid:
  $type: com.atproto.repo.strongRef
  uri: at://did:plc:bob/com.publicdomainrelay.temp.market.bid/3mm4...
  cid: bafyrei...bid
accept:
  $type: com.atproto.repo.strongRef
  uri: at://did:plc:alice/com.publicdomainrelay.temp.market.accept/3mlagijgoeb23
  cid: bafyrei...accept
cid: bafyrei...attestation

Alice then awaits the onNetwork event

$type: com.publicdomainrelay.temp.compute.events.vm.onNetwork
kind: iroh
address: <the VM's iroh ticket>
$type: com.publicdomainrelay.temp.market.event
payload:
  cid: bafyreihp5j7tc6xbj4yqnzanwjsqfqasazqr6cbdthuwni3xdrgy2ymmeq
  uri: at://did:plc:5svqtrhheairglgiiyvutzik/com.publicdomainrelay.temp.compute.events.vm.onNetwork/3mqqgq57oss26
  $type: com.atproto.repo.strongRef
receipt:
  cid: bafyreicpqkmnigboxueqaa2y6lvn7b5qjaiw46jb6mqgymlahpl3v5fal4
  uri: at://did:plc:5svqtrhheairglgiiyvutzik/com.publicdomainrelay.temp.market.receipt/3mqqgpxvfls26
  $type: com.atproto.repo.strongRef

Docs

docwhat
docs/quickstart-prod.mdrequest from prod bidders: vouches, hold and ssh, sizes, sign-in modes, run requester
docs/bidder.mdbuilds and channels, a bidder in the foreground or as a service, upgrade, self-update
docs/quickstart-local.mda whole market on one machine
docs/gateway.mdKubernetes clusters from the gateway
docs/how-it-works.mdthe protocol: request, bid, accept, receipt
docs/README.mdevery other doc

The protocol, record by record: overview, one contract step by step, identity, market, policy, guest events, releases, glossary. Every record and XRPC method, generated from the lexicons: lexicon and XRPC reference.