Subduction

From dxos/dxos · View interactive version

Subduction is an AI agent skill from the GitHub repository dxos/dxos. Reference for `SubductionPolicy` (the four hooks `authorizeConnect`, `authorizeFetch`, `authorizePut`, `filterAuthorizedFetch` passed via `Subduction.hydrate(..., policy)` or `new Repo({ subductionPolicy })`). Use when designing client-side access control over Subduction-replicated data, choosing wh

How to use this skill

Skill file

`SubductionPolicy`: authoritative reference

This skill covers the policy (authorization) surface. For subduction sync reliability — the

60 s round-timeout amplifier, the O(N²) bulk-sync cliff, why connection replacement must close/evict

immediately (drain is harmful, 200× slower), the in-flight gate + heal re-drive, the edge-replicator

Effect layer-ordering bug (silent serviceOption→none), and the workerd dead-context alarm pump —

see CODE0.

SubductionPolicy is the JS-imported policy object the Subduction Wasm bridge consults for every authorization decision. The TypeScript shape (verbatim from subduction_wasm/src/policy.rs's TS_POLICY block):

export interface Policy {
  authorizeConnect(peerId: PeerId): Promise<void>;
  authorizeFetch(peerId: PeerId, sedimentreeId: SedimentreeId): Promise<void>;
  authorizePut(requestor: PeerId, author: PeerId, sedimentreeId: SedimentreeId): Promise<void>;
  filterAuthorizedFetch(peerId: PeerId, ids: SedimentreeId[]): Promise<SedimentreeId[]>;
}

Convention: resolving allows, throwing (or returning a rejected promise) denies. All peerId arguments are subduction-level Ed25519 identities derived from the signer (MemorySigner.peerId() / WebCryptoSigner.peerId()), NOT automerge-repo's PeerId string.

This skill is the source of truth. It supersedes any older guidance that called authorizeFetch "server-side fetch-RPC only" or filterAuthorizedFetch "completely dead". Those were both wrong; see below for what they actually do.

Where each hook is consulted

Verified against inkandswitch/subduction@main (subduction_core/src/{subduction.rs,subduction/peers.rs,storage/powerbox.rs}).

`authorizeConnect(peerId)`

Use it when you want a per-peer kill-switch ("never talk to this peer at all").

Don't use it when you want per-document gating — authorizeConnect is all-or-nothing for that peer.

`authorizeFetch(peerId, sedimentreeId)`

Use it when you want per-peer, per-sedimentree control over what data leaves this node.

This is the only Policy hook that gates outbound serving of sedimentree contents to a connected peer.

`authorizePut(requestor, author, sedimentreeId)`

Use it when you want to refuse inbound data:

Combinations work, since you control the predicate.

`filterAuthorizedFetch(peerId, ids)`

```rust

let subscriber_conns = self.get_authorized_subscriber_conns(id, &self_id).await;

if subscriber_conns.is_empty() {

// No subscribers for sedimentree, broadcasting to all connections

self.all_connections().await

} else {

subscriber_conns

}

```

Use it when you want to gate which subscribers receive proactive broadcasts of NEW local commits. Only meaningful if peers actually subscribe (syncWithAllPeers(id, subscribe=true) or syncWithPeer(..., subscribe=true)).

Don't rely on it for batch-sync flows (fullSyncWithAllPeers, syncWithAllPeers(..., false)); those go through authorizeFetch instead.

Summary table

| Hook | Side consulted | Triggers | Useful for |

| ----------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------- |

| authorizeConnect | both (on addConnection) | every handshake | per-peer kill-switch |

| authorizeFetch | holder (sender) | every send_requested_data → every batch-sync round, including connect-time fullSync and post-addBatch syncWithAllPeers | per-peer × per-sedimentree outbound gate |

| authorizePut | receiver | every inbound commit/fragment; NOT the holder's own writes | per-(requestor, author, sedimentree) inbound gate |

| filterAuthorizedFetch | holder, only for subscribers | proactive broadcast of NEW local commit when at least one peer is subscribed | per-subscriber broadcast gate |

The "can the client gate replication purely client-side?" answer

YES. Two hooks, two directions:

authorizeConnect is the nuclear all-or-nothing option for refusing a peer entirely (cuts the channel in both directions).

The server side does NOT need to cooperate. A passive/permissive server is fine — the client can stop both inbound writes and outbound serving entirely on its own.

Per-peer gating requires knowing the peer's Ed25519 id

peerId / requestor / author arguments are subduction-level Ed25519 identities, not automerge-repo string PeerIds. To gate per-peer you need the peer's signer public key out-of-band, e.g. by constructing peers with explicit MemorySigner instances and reading signer.peerId().toString(). In DXOS production code where the edge DO mints its own signer at startup, the client does not currently know the DO's subduction peer-id — that mapping has to be plumbed through (e.g. captured at handshake on EdgeSubductionReplicatorConnection).

Recovery after denial → allow

Subduction has a single documented fast-recovery escape hatch: repo.shareConfigChanged(). It "resets entries whose lastSyncResult === 'all-failed' to null, clears the heal-retry backoff, and triggers an immediate re-sync" (from SubductionSource.shareConfigChanged() in @automerge/automerge-repo/dist/subduction/source.js).

Empirically verified recovery behavior:

Production implication: when flipping a client-side authorizePut gate from deny → allow (e.g. authorizing a new space), drive a no-op commit on any doc you want to pull through.

Mutating policy behavior at runtime

The subductionPolicy reference passed to Repo is captured at construction; there is no setter. Use closure-captured state inside hook bodies. The wasm bridge invokes the JS hook on every authorization decision, so changes to closure state are observed immediately for new requests.

What changed from prior guidance

If you've read older internal docs claiming any of the following, they were wrong:

| Claim (old) | Reality (current) |

| ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |

| authorizeFetch only fires for explicit fetch RPCs, not proactive push | Fires on every batch-sync send_requested_data, which is the actual mechanism behind both proactive push and explicit fetch in this bridge. |

| filterAuthorizedFetch is completely dead | Dead for batch-sync flows. ALIVE for proactive addCommit broadcast — but only consulted for peers that have explicitly subscribed. |

| The holder's own writes go through authorizePut | They go through local_putter which bypasses policy ("the node trusts itself"). |

| The only way to gate outbound replication is server-side authorizePut | Client-side authorizeFetch also gates outbound — verified empirically and in the upstream source. |

Test suite

The empirical findings above are pinned by packages/core/echo/echo-host/src/automerge/automerge-repo-subduction.test.ts under describe('subductionPolicy: characterizing client-only gates') (Blocks A–H). Re-run the suite if you suspect bridge behavior has changed:

cd packages/core/echo/echo-host && pnpm vitest run src/automerge/automerge-repo-subduction.test.ts
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.