Skip to content

feat(hosting): workers refuse replicas of DIP-0036 labelled sites (policy_refusal, refused count) - #497

Merged
ralyodio merged 2 commits into
masterfrom
fix/444-worker-moderation
Nov 25, 2026
Merged

ralyodio merged 2 commits into
masterfrom
fix/444-worker-moderation

Conversation

@ralyodio

Copy link
Copy Markdown
Collaborator

DIP-0036 step 4: a hosting worker refuses to hold replicas of labelled content, says so with policy_refusal so the refusal is never a failed challenge, and owners see a count of refused replicas in hosting_push_status.

Refs #444 (not "Closes": striped sites and payout forfeiture are left out, see below).

What it does

Worker (c0mpute-core/src/hosting/policy.rs)

  • Reuses the gateway's [moderation] table and moderation::Gate (one shared instance, one decision cache). No parallel mechanism.
  • Workers hold blake3 chunks; labels name a file's SHA-256. The manifest has no SHA-256 (and a publisher's word would not be trusted anyway), so the worker reassembles each file from its local chunks and hashes it.
  • Hashes go to the labelers' /query in batches of 50 (Gate::decide_hashes, new). With a scan token, up to 64 web files per site under max_scan_bytes go to /scan first, as at the gateway.
  • New copy: judged in replicate after the chunks arrive and before the copy is held or announced. Refused: chunks deleted, typed PolicyRefused error, no retry backoff, not fetched again.
  • Held copies: re-judged every recheck_secs (file hashes are kept, the site is not re-read). A copy that became labelled is let go like a surplus copy: announce first, delete one holder TTL later.
  • A refusal is lifted when its labels are retracted or expire.
  • Fails open; a refusal already made stands while its label is unexpired.

policy_refusal (wire)

  • New gossip variant on c0mpute/hosting/v1: {"t":"policy_refusal","refusals":[{site_id, manifest, labeler, val}]}, the sender's whole list (at most 128), repeated with every holding announcement, lapsing with the holder TTL.
  • On receipt the peer is not a holder of that version, not a rendezvous candidate (the next ranked node takes the copy), not an effective preferred host, and so not challenged: no failed receipt.
  • Accepted only from peers that announced themselves as hosts, so the table is bounded by the peers table.

Refused count, end to end

  • ReplicaMap::refusal_tally -> Hosting::refusals -> GET /hosting/v1/sites (refused, refused_by).
  • hosting publish prints refused: N (<val> by <labeler> xN, ...); chat connect parses it into the push report.
  • apps/web/src/lib/chat/push.ts: two new nullable columns (refused, refused_by) added by an idempotent ALTER TABLE; publicPush (so hosting_push_status, hosting_pushes, the REST routes) returns refused and refused_by: [{labeler, val, count}].
  • c0mpute chat push hosting status shows (N refused by policy).
  • Peers are never named anywhere.

Config

  • No new table. [moderation] refuse_replicas (new, default true); false keeps the policy to the gateway.
  • Behaviour change to note: a node that already has [moderation] labelers and the hosting role starts refusing replicas on upgrade. With no labelers (the default) nothing changes.

Compatibility

  • Older nodes fail to parse the new variant and skip it (same as they did for receipt). They keep counting a refuser as a candidate, so on a mostly-old network a refused copy can take longer to be replaced.
  • Older publishing nodes send no refused: the web shows 0 / [].
  • LabelerClient gains a required query_many.

Not done

  • Striped sites (> 1 GiB) are not checked: a worker holds groups, not whole files.
  • Forfeiting accrued payout is not implemented: a refuser stops being challenged and stops earning, but earlier passes in the window are still paid.
  • PUT -> 451 does not apply: hosted copies are pulled. The storage role's object PUT is not gated.
  • The push's count is a snapshot from when the publishing node reported live (like copies); /hosting/v1/sites has the current one.
  • Sites the node's own challenger key owns or pays for are exempt.
  • Refusals are not persisted: after a restart the node re-fetches a labelled site once and refuses it again.

Tests

  • moderation: batching, caching, shared cache with the gateway path, fail-open, stale refusal stands, retraction (2 new).
  • hosting::replicas: refuser is no holder/candidate, tally, other-version refusal, TTL lapse, own refusal (2 new).
  • hosting::policy: refusal validation, typed error, message size and tag (2 new).
  • tests/hosting_moderation_e2e.rs: 4 hosts + publisher on loopback. Refusal at replicate, refusal of a held copy after a late label, replacement by the 4th node, /hosting/v1/sites output, lifting on retraction (~65 s).
  • c0mpute-cli: refused: line round trip, status line.
  • push.test.ts: report stores and returns the count, drops malformed causes and anything naming a peer, old-node report.

Run on vienna: the Rust tests above pass; bun test src/lib/chat/push.test.ts 20 pass; tsc --noEmit clean.

DIP-0036 and docs/hosting.md / docs/chat-push-hosting.md updated to describe what is built and what is left.

🤖 Generated with Claude Code

ralyodio and others added 2 commits November 25, 2026 07:12
…licy_refusal)

DIP-0036 step 4. A node with the hosting role and a [moderation] table (the
one its gateway already uses) no longer holds copies of sites that have a
file one of its labelers labelled with a `refuse` action.

- Workers store blake3 chunks and labels name a file's SHA-256, so the
  worker puts each file back together from its local chunks, hashes it and
  asks the labelers' /query in batches (Gate::decide_hashes); with a scan
  token, small web files go to /scan first, as at the gateway.
- A new copy is judged once its chunks are here and before it is held or
  announced (replicate -> policy_admit). Held copies are judged again every
  recheck_secs, since a label can arrive later; a refused one is let go the
  way a surplus copy is (announce first, delete after one holder TTL).
- The node gossips what it refuses as HostingMsg::PolicyRefusal
  (`"t":"policy_refusal"`). To every node a refusing peer is then no holder
  of that version, no candidate for it (the next ranked node takes the
  copy) and so never challenged for it: a refusal is not a failed proof.
- Owners see how many replicas refused and under which labeler and value,
  never which peers: /hosting/v1/sites (`refused`, `refused_by`),
  `hosting publish` (`refused:` line), the push report and
  hosting_push_status / `c0mpute chat push`.
- `[moderation] refuse_replicas = false` keeps the policy to the gateway.
  Fails open, like the gateway gate. A refusal is lifted when its labels
  are retracted or expire.

Not covered: striped sites (over 1 GiB), which a worker holds in groups and
cannot put back into files; sites the node's own key owns or pays for.

Refs #444

Co-Authored-By: Claude Fable 5.2 <[email protected]>
DIP-0036 gets a "Worker enforcement as built" section (subject, timing, the
policy_refusal gossip shape, what owners see, lifting, fail open) and names
what is left: striped sites, forfeiting accrued payout, the storage PUT.
docs/hosting.md documents the operator config and behaviour;
docs/chat-push-hosting.md and the hosting_push_status tool description
document `refused` / `refused_by`.

Refs #444

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

Copy link
Copy Markdown

ThreatCrush Security Scan

26 finding(s)

HIGH/CRITICAL: 2 | MEDIUM: 20 | LOW: 4

Severity Rule Location
HIGH js-ssrf-outbound-request apps/web/public/sw.js:24
HIGH sh-remote-script-execution scripts/install.sh:618
MEDIUM gha-ssh-key-secret .github/workflows/deploy-dev2.yml:180
MEDIUM js-unescaped-html-sink apps/web/src/app/blog/[slug]/page.tsx:53
MEDIUM js-unescaped-html-sink apps/web/src/app/layout.tsx:111
MEDIUM js-open-redirect apps/web/src/components/sign-in-options.tsx:16
MEDIUM sql-template-interpolation apps/web/src/lib/accounts/alerts.ts:458
MEDIUM sql-template-interpolation apps/web/src/lib/accounts/fleet.ts:386
MEDIUM sql-template-interpolation apps/web/src/lib/chat/convo-store.ts:116
MEDIUM sql-template-interpolation apps/web/src/lib/chat/convo-store.ts:117
MEDIUM sql-template-interpolation apps/web/src/lib/chat/push.ts:539
MEDIUM sql-template-interpolation apps/web/src/lib/chat/share-store.ts:171
MEDIUM sql-template-interpolation apps/web/src/lib/disk/apps.ts:194
MEDIUM sql-template-interpolation apps/web/src/lib/disk/store.ts:237
MEDIUM sql-template-interpolation apps/web/src/lib/earnings/store.ts:216
MEDIUM sql-template-interpolation apps/web/src/lib/earnings/store.ts:319
MEDIUM sql-template-interpolation apps/web/src/lib/gallery/store.ts:284
MEDIUM js-dynamic-code-execution apps/web/src/lib/router/verify.ts:91
MEDIUM py-stack-trace-returned docker/worker/status_ui.py:35
MEDIUM sh-remote-script-execution scripts/dev-setup.sh:25
MEDIUM sh-eval-expansion scripts/dev-setup.sh:35
MEDIUM redos-nested-quantifier scripts/dev2-dns-recovery.py:31
LOW py-ssrf-outbound-request examples/business-strategist-agent/chat.py:37
LOW py-ssrf-outbound-request examples/business-strategist-agent/train.py:54
LOW secret-generic-credential node/crates/c0mpute-core/src/webhook.rs:1171
LOW py-path-traversal node/crates/c0mpute-core/tests/fixtures/fake-infernet-text:29

Snippets are redacted; ThreatCrush never prints matched credential material.

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.

1 participant