Skip to content

donation: lend and borrow inference through a card, and reach a lent machine through a relay - #1223

Closed
zweck wants to merge 2 commits into
ashhart:mainfrom
zweck:feat/donation-relay
Closed

zweck wants to merge 2 commits into
ashhart:mainfrom
zweck:feat/donation-relay

Conversation

@zweck

@zweck zweck commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Two commits, each reviewable on its own.

1. donation: lend a machine's inference through a card

A card is the whole contract between two people's installs: endpoint, token, model, window, caps and a
measured spec. The donor runs a proxy beside its engine that enforces the window and the concurrency,
token and body caps, keeps the token out of the renderer, and writes receipts; the renter gets an
ordinary chat-completions provider that the router and the outbound guard treat exactly like managed
remote compute. No payment and no proof of computation — that is stated in the UI and in
app/docs/donation-poc.md.

2. relay: give a lent card a public address without inbound ports

The in-app donor binds loopback only, so until now a renter needed an SSH or third-party tunnel. The
relay inverts that: the donor dials out to wss://<relay>/donor/<card-id>, and the card carries
https://<relay>/<card-id> instead. The relay is deliberately not the security boundary — it forwards
the renter's authorization header untouched and the donor proxy still decides. relay/ is a Worker
with one Durable Object per card id; a card endpoint may now carry one path segment so it can address
a card on a shared host.

Testing

  • app: npm run verify → 854/857. The three failures are scripts/mobile-*-dependency.test.mjs,
    which need npm ci inside app/mobile; they fail identically on main.
  • relay: cd relay && npm install && npm test → 9/9 inside the Workers runtime (workerd via
    @cloudflare/vitest-plugin): health, 503 without a donor, 404 for unlent routes, 413 for an
    oversized body, a streamed reply, a donor refusal passed through untouched, one donor per card id,
    a wrong donor key refused, and the card-id path routing.
  • Manually, end to end: a real donor (27B on a GB10) lent through the app to a second chat; and the
    relay path driven from the packaged app — card import, picker, streamed reply, plus 401 / 503 / 413
    and a refused second donor key.

Deliberate limits

  • The relay terminates TLS, so it can read prompts. End-to-end encryption keyed off the card token is
    the obvious follow-up and is not in this PR.
  • The donate flow still mints loopback cards; wiring it to a relay (donor key storage, attach on
    start, reconnect, relay URL in the card) is the next slice. The dialer and CLI in this PR are what
    that slice will call.
  • No per-IP limits, revocation or abuse reporting on the relay yet — those are required before it
    takes strangers' traffic.
  • Nothing is deployed.

Coordination

  • atc overlap --json could not be run: atc is not installed in this environment.
  • No matching issue to link; the repo's issue rule covers new model families, backends and arithmetic
    changes, and this is none of those.

The two commits are stacked (the relay uses the card schema from the first). If you would rather review
them as separate PRs, the first commit can stand alone as its own PR and this one can follow it.

zweck added 2 commits October 24, 2026 00:25
A card is the whole contract between two installs: endpoint, token, model,
window, caps and a measured spec. The donor runs a small proxy beside its
engine that enforces the window, the concurrency, token and body caps, and
keeps the token out of the renderer; the renter gets an ordinary
chat-completions provider that the router and the outbound guard treat like
managed remote compute.

- shared/donation.ts: `tensorfold-donation/1` schema, parsing and the provider
  row a card becomes; an endpoint may carry one path segment, which a relay
  uses to address individual cards
- electron/donation-node-main.ts: the donor proxy, bundled separately
- electron/main/host/donation*: private card storage, import probe, supervisor
  that runs the proxy inside the app (a packaged Electron app cannot spawn
  itself as Node)
- DonationPanel, CommunityModels, onboarding and Models entry points
- docs/donation-poc.md: what the POC does and does not promise
The in-app donor binds loopback only, so today a renter needs an SSH or a
third-party tunnel. This adds a relay the donor dials out to: the card carries
one HTTPS base URL and nothing changes on the renter side.

- relay/: a Worker with one Durable Object per card id, a JSON frame protocol,
  donor attach over a WebSocket (the donor key travels as the second
  subprotocol), bounded request and response sizes, and tests that run on the
  real Workers runtime
- relay is not the security boundary: it forwards the renter's authorization
  header and the donor proxy still enforces token, window and caps
- electron/donation-relay-client.ts and scripts/donation-relay-attach.mjs: the
  donor dialer, which replays frames against the local proxy
- docs/donation-relay.md: protocol, limits and what is still missing;
  docs/donation-lending-options.md: addressing and hardware-only options
@ashhart ashhart mentioned this pull request Oct 24, 2026
6 tasks done

@ashhart ashhart left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zweck. The design is careful: nothing is on by default, the lender listens on loopback only, tokens compare in constant time, windows are rechecked at forward time, and borrowed machines are treated as external providers. Security problems to fix before we can take it:

  1. The donor trusted any path the relay sent (donation-relay-client.ts appends it to the local address unchecked), so a compromised relay could reach any route or method on the lender's node, and a path like 1/v1/models changes the port (6000 becomes 60001). Please allow-list the lent routes with their methods (/health GET, /v1/models GET, /v1/chat/completions POST, /v1/responses POST) and refuse everything else, with a test.
  2. Anyone who learns a card id before its donor attaches can claim it permanently (relay/src/donor.ts) and receive renters' tokens and prompts. Please bind the donor's key at card creation and expire stored claims with the card's window.
  3. The borrower's token is stored as plain JSON (donation/store.ts) while the app keeps other credentials in its encrypted store; please use that.
  4. Forward only content-type and accept headers, and allow-list body fields: on /v1/responses force store: false and drop previous_response_id, so renters don't fill the lender's response store.
  5. Remove the TF_DONATION_DEBUG token-hash prefix output, and consider authenticating /health (it shows the hardware spec).
  6. Pin the relay's vite and @cloudflare/vitest-plugin to releases at least a week old instead of ^ ranges on days-old versions.
  7. Product text: the onboarding line implies a public community directory that doesn't exist, the lending panel says renters can use https while the host accepts loopback only, expired cards stay in the provider list, and the zh-Hant reformat (about 500 lines) is unrelated.
    Both commits also use a personal email; please switch to your GitHub noreply address.

@ashhart

ashhart commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thank you for exploring this. We're going to decline it, mainly on security and scope:

  • Card squatting. A card id binds to whichever donor key attaches first and never expires, and the id is public in the card's endpoint URL. A squatter can attach first and then receive renters' prompts plus the card's bearer token (the relay forwards authorization), and answer as the donor.
  • The relay. It decrypts everything, renters aren't authenticated there (anyone can send 1 MiB bodies, 8 at a time), /health is unauthenticated and reveals model, window and load, the poc-insecure-lan mode sends the token in plaintext, and each card has one static token with no revocation. Someone would have to run it as a public, anonymous inference proxy.
  • What leaves the machine. The app treats donation providers as remote compute, so the agent harness would send workspace content to a stranger's machine.
  • Scope. It's an Electron app feature plus a Cloudflare Worker rather than engine code, and it carries unrelated translation churn and a new 3,150-line lockfile.
    A lending network would need authenticated renters, per-renter tokens with revocation, end-to-end encryption the relay can't read, and a named operator, and it would live outside this repository. Closing; thank you for the thorough write-up.

@ashhart ashhart closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants