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

socialweb.computer/socialweb-computer-kcp

socialweb.computer: a compute market on atproto (kcp)

1 collaborator
0
0
161 lines · 12.4 KB Raw History

policy: policy records, attached policies, tangled-vouch

  • a market policy ALWAYS runs, both sides, both lanes (scope + full), every decision. no skip paths (the ssh gateway sign-in runs the scope lane only, by design: internal/services/sshserver/signin.go)
  • the requester publishes the workflow it runs as a record; the RFP strongRefs it; the bidder runs it next to its own
  • caching lives inside the engine run, never across parties; the scope lane's memo serves a stored outcome for the same key (every party is in the key: allow 5 min, deny 30 s, internal/policyengine/manager.go)
  • index: README.md. sequence steps: S1 (vouches), S3 (record + RFP), S4 (bidder runs), S5 (requester runs)

Records And Fields

NSID / fieldtyperkeywritten byread byGostep
computer.socialweb.temp.policy.ghaliterecordTID (putRecord at a TID the requester makes); one per contract, kept in state.Policyrequesterbidder (via the RFP strongRef), requester (re-check)internal/market/requester/policy.go BuildPolicyRecord, internal/market/requester/runner.go, internal/market/participant/policyrecord.goS3
market.rfp policies[]array of com.atproto.repo.strongRef-requesterbidderinternal/atproto/market/records.go BuildRFP; internal/market/requester/runner.go putRFPS3
computer.socialweb.infra#contract policy, policyArgsstrings-ownerrequester (via the ComputeContract)internal/market/requester/runner.goS2
sh.tangled.graph.vouchrecord (outside)subject DIDoperators, usersboth policies (trust snapshot)internal/policyengine/trust/trust.goS1
computer.socialweb.temp.policy.typescriptrecord (not in use; no fields defined)-nobodydeniedinternal/policyengine/registry/registry.go-
com.publicdomainrelay.temp.market.policies.denoWorkerrecord (not in use; no fields defined)-nobodydeniedinternal/policyengine/registry/registry.go-
computer.socialweb.temp.policy.wasmtest fixture only--denied as an unknown typeinternal/policyengine/controller/records.go-
  • no policy field on market.bid, market.offering or compute.*. the bidder's own Bid object keeps spec.policy {attached, verdict} in kcp only

computer.socialweb.temp.policy.ghalite

fieldvalue
$typecomputer.socialweb.temp.policy.ghalite
namethe workflow name, e.g. requester-tangled-vouch
workflowthe full YAML text of the bundled workflow (or its name when there is no text)
argsmap[string]string, from policyArgs
requesterthe requester's market DID
perspectiverequester
policies[{name, args?}]
createdAtdatetime
  • PolicyRecordWorkflow reads workflow as a YAML string or an object and denies any other $type (internal/market/participant/policyrecord.go)
  • typescript and denoWorker executors are registered as deny ("the policy engine is gha-lite only")
  • OAuth: requester and bidder sets carry create (+ update on requester) for ghalite and typescript; none for denoWorker (outside.md)

Infra Contract Fields

  • policy: the workflow name. resolution: cmp.Or(contract.Spec.Policy, cfg.PolicyWorkflow, DefaultPolicyWorkflow)
  • PolicyWorkflowName (internal/market/requester/policy.go) trims and lowercases, then: "" -> requester-tangled-vouch; only-me, only_me -> requester-only-me; mutuals -> requester-mutuals; tangled-vouch, tangled_vouch -> requester-tangled-vouch; any other name passes through
  • the bidder does not normalize: spec.policy or bidder-tangled-vouch (internal/market/bidder/policy.go)
  • the name must be a bundled workflow, else the contract fails before the RFP (the compute.vm record is already written then: runner.go)
  • policyArgs: a JSON object, parsed to map[string]string (internal/market/participant/policy.go ParsePolicyArgs) and stored in the record's args. No run receives them today: see "Not wired" below

RFP Policy StrongRefs

sequenceDiagram
  autonumber
  participant R as requester
  participant RP as requester repo
  participant B as bidder
  participant E as policy engine (bidder)

  R->>R: policy name from Infra contract / ComputeContract
  R->>RP: S3 createRecord policy.ghalite {workflow text, args}
  R->>RP: getRecord it back: own repo, cid, name, body == bundled workflow
  R->>RP: S3 market.rfp {policies: [strongRef]}
  RP-->>B: market.rfp
  B->>E: own workflow (bidder-tangled-vouch), scope lane (DIDs only)
  B->>RP: getRecord each policies[] ref
  B->>E: own workflow + each attached workflow, full lane
  E-->>B: allow only if all allow
  B->>B: S4 bid or no bid
  • requester write path: runner.go step creatingRfp: BuildPolicyRecord -> putRecord at a TID -> attachedPolicy -> rfpOptions.Policies -> putRFP
  • requester re-check attachedPolicy (internal/market/requester/policy.go): the record is in the requester's own repo, the cid matches, the name matches the contract, the body equals the bundled workflow byte for byte
  • bidder: EvaluatePolicies (internal/market/bidder/policy.go) runs its own workflow (default bidder-tangled-vouch), then each RFP ref via RepoStore.Resolve (local getRecord or a foreign resolver), PolicyRecordWorkflow, runs.Request{Workflow, Source: uri}. first deny wins
  • the bidder runs the attached workflow with perspective=bidder (internal/market/bidder/bids.go)
  • a restarted runner reuses state.Policy; it does not write a second record

Lanes And Modes

laneinputwhere
scopeDIDs, mode: scope; the bidder passes no RFP, the requester passes the RFP refbidder bids.go (bid), adapters.go (accept); requester accept.go bidAllowedWithPolicy (each bid); ssh gateway signin.go
fullself, subject, counterparty, root requester DIDs, the RFP ref (bidder; the requester also the bid ref), mode: fullbidder bids.go fullInput, adapters.go; requester runner.go (the winner, a resume), session.go
sidedecisionselfcounterparty
bidderbid on an RFP: scope, then own workflow + every attached policy (full)the bidder DIDthe requester DID
biddertake an accept: scope and full againthe bidder DIDthe requester DID
requestereach bid: scopespec.operatorDID, else the market DIDthe bidder DID
requesterthe winner, before the accept: full, with the attached record's bodythe market DIDthe bidder DID
ssh gatewaysign-in admission: bidder-tangled-vouch, scopespec.ssh.operatorDid (none: nobody is admitted)the signing-in DID
  • run path: runs.Client.Run creates a PolicyWorkflowRun and waits (internal/policyengine/runs/client.go, timeout DefaultTimeout 2 min unless set); RunReconciler (internal/policyengine/controller/run.go) seeds the trust snapshot and executes
  • missing engine, evaluator or a non-boolean allow = deny

Caching (inside the run)

cachekeyTTL
trust snapshot seedtrust/<counterpartyDid>per run
recordrec/<uri>/<cid> (internal/policyengine/cache/cache.go)-
verdictpolicy/<workflow>/<mode>|<perspective>|<self>|<subject>|<counterparty>|<root>|<source>|<rfp>|<bid>|<accept>:<args sha8> (runs/client.go)30 s default (cacheTtlSec)
scope verdict memointernal/policyengine/controller/scopememo.goallow 5 min, deny 30 s (manager.go)
identlink walktrust.Resolver5 min (capped at the earliest expiresAt), 5 s with errors; a failed vouch lookup is not cached

Bundled Workflows

  • embedded: internal/policyengine/bundled-actions/embed.go (workflows/, tangy/), looked up by Workflow(name) and Lookup(uses)
  • every workflow is a workflow_dispatch wrapper with inputs self-did, rfp, bid, accept, policy-args, mode, counterparty-did, perspective, subject-did, root-requester-did, cache-key; it calls tangy/policy-<name>@v1 and outputs allow, violations
workflowkinddecides
bidder-tangled-vouchtrust (bidder default)allow when the counterparty is self, shares a root with self, has self as its root, or when any DID of self + its walk ancestors vouches any DID of the counterparty + its walk ancestors
requester-tangled-vouchtrust (requester default)the same function, from the requester side
bidder-mutuals, requester-mutualstrustself, the same operator, or vouches both ways: the self side vouches the counterparty (or its operator) and the counterparty side vouches self (or its operator). tangled vouches only; the action's description string still says "follows on Bluesky", which it does not read
bidder-only-me, requester-only-metrustthe counterparty is self or resolves to self or the operator of self
opentrustno restriction. only when named, never prod
bid-payloadwork (requester)the bid payload NSID is in allowedPayloadNsids (default market.bids.free)
under-4-cpuswork (bidder)the VM asks at most maxCpus vCPUs (default 4)
  • the action infers its perspective from the bidder- prefix unless the perspective input says otherwise
  • defaults: api/v1alpha1/types_computevm.go BidderDefaultPolicy, RequesterDefaultPolicy
  • the policy logic is the bundled tangy/policy-<name>/dist/index.js; its index.ts imports a source that is not in this repo

Not wired

  • a contract's policyArgs reach no run: the requester's runs client has no args, and the bidder runs every attached workflow with its own policyArgs (internal/services/bidder/wiring.go)
  • the work policies read numbers and arrays (maxCpus, allowedPayloadNsids, cacheTtlSec), and args are map[string]string: their defaults always apply

Tangled-Vouch

  • default on both sides everywhere; open only if the user sets it
  • a vouch is sh.tangled.graph.vouch at rkey = the subject DID in the voucher's repo; it counts when it exists and kind != "denounce": outside.md
  • both directions are needed for a deal: the bidder side vouches for the requester side and the requester side for the bidder side
flowchart LR
  SELF["self"] --> T["self side = self + its walk ancestors"]
  CP["counterparty"] --> OPC["counterparty side = counterparty + its walk ancestors (identity.md)"]
  T --> Q{"one getRecord per pair, both directions: a self-side DID vouches a counterparty-side DID?"}
  OPC --> Q
  Q -->|yes| ALLOW["allow"]
  OPC -->|"operator(counterparty) is self or operator(self)"| ALLOW
  Q -->|no| DENY["deny"]
  • snapshot: trust.BuildSnapshot (internal/policyengine/trust/trust.go): vouches between self + its walk ancestors and the counterparty + its walk ancestors (at most 256 pairs, nearest first); the vouches of every self-side DID count as self's
  • operator resolution (identlink walk): identity.md
  • who writes vouches: market networks declare operator vouches both ways (internal/app/marketnetwork/vouches.go, compose ApplyOperatorVouch); people write them from any client. the requester OAuth scope offers vouch write as an optional scope
  • requester discovery lists the vouches of its operators (self, spec.operatorDID, its walk roots; not intermediate ancestors) to add candidates (internal/market/requester/discovery.go vouchedBy, a listRecords that skips denounce and takes rkeys starting did:); the policy, not discovery, decides who is served

Real records: the prod requester aliceoa.bsky.social and the bidder operator bobvmbuilder.bsky.social vouch each other, so requester-tangled-vouch and bidder-tangled-vouch both allow (bob's bidders are his agents: their walk reaches him).

{"uri": "at://aliceoa.bsky.social/sh.tangled.graph.vouch/did:plc:ocnuqjlzgohypj3zoznermms",
 "value": {"$type": "sh.tangled.graph.vouch", "kind": "vouch", "createdAt": "2026-08-05T01:26:28+03:00"}}
{"uri": "at://bobvmbuilder.bsky.social/sh.tangled.graph.vouch/did:plc:lpfuqerea3deuoyrn7ojser4",
 "value": {"$type": "sh.tangled.graph.vouch", "kind": "vouch", "createdAt": "2026-08-05T01:26:51+03:00"}}

See Also