Skip to content

feat(lib): AtomicNode runtime boundary (slice 1) - #1324

Merged
joepio merged 1 commit into
developfrom
feat/atomic-node-slice
Sep 1, 2026
Merged

feat(lib): AtomicNode runtime boundary (slice 1)#1324
joepio merged 1 commit into
developfrom
feat/atomic-node-slice

Conversation

@joepio

@joepio joepio commented Sep 1, 2026

Copy link
Copy Markdown
Member

What

First slice of the node runtime boundary accepted in planning/runtime-boundary-decision.md: atomic_lib::runtime::AtomicNode, a thin struct wrapping Db that gives adapters one surface instead of each wrapping Db themselves.

No behaviour change. Every method delegates to a function that already existed:

AtomicNode Delegates to
open(NodeConfig) Db::init_memory / init_redb / init_redb_file / init_redb_opfs
get(subject, for_agent) Storelike::get_resource_extended
query(&Query) Storelike::query
apply_commit(json, IngestPolicy::Hub{..} | Peer) sync::engine::ingest_commit (body extracted from ingest_commit_json, which now wraps it)
apply_commit(json, IngestPolicy::Replica) sync::ws_apply::apply_commit_json (now returns CommitResponse; its one caller ignored the value)
apply_commit(json, IngestPolicy::LocalCache) the former WASM applyCommit body (parse_json_ad_resource + no-validation CommitOpts)
mutate(ResourceEdit::Update | Genesis) Resource::save_locally / save_as_genesis
subscribe() Db::subscribe_events (existing DbEvent broadcast; no new bus)
sync_with_peer (iroh feature) sync::peer::sync_drive_with_peer_outcome

IngestPolicy::{Hub, Peer, Replica, LocalCache} is named to match the CommitIngestOpts::{hub, peer, replica} presets in #1274 plus the WASM "fourth policy", so that PR can map onto it 1:1 once merged. Until then the enum carries literal CommitIngestOpts matching the server handler and apply_peer_commit.

First consumer: wasm/src/lib.rs ClientDb now holds an AtomicNode and routes applyCommit and query through it (getResource deliberately stays on the raw Db::get_resource since it has no for_agent).

Tests

lib/src/runtime/node.rs (--features db-redb):

  • two AtomicNodes in one process: mutate(Genesis) on Alice, apply_commit(Peer) of the wire commit on Bob, get + query(parent) reflect it, and Bob's DbEvent::Changed stream includes the subject
  • LocalCache accepts a commit with a tampered signature, Peer rejects it
  • mutate without a default agent errors

Verified: cargo test -p atomic_lib --features db-redb --lib (429 passed), cargo clippy -p atomic_lib --features db-redb,iroh --lib --tests (no new warnings), cargo check -p atomic-wasm --target wasm32-unknown-unknown, cargo check -p atomic-server, cargo check --manifest-path flutter/rust/Cargo.toml.

Not in this slice (documented in planning/atomic-lib-runtime.md)

Consumers

https://claude.ai/code/session_019asLKBrBWY5ovyeCgtmdSd

Adds `atomic_lib::runtime::AtomicNode`, the thin node surface proposed in
planning/runtime-boundary-decision.md. It wraps `Db` and delegates every
method to code that already existed, so there is no behaviour change:

- `open(NodeConfig)` -> `Db::init_memory/init_redb/init_redb_file/init_redb_opfs`
- `get` -> `get_resource_extended`, `query` -> `Storelike::query`
- `apply_commit(json, IngestPolicy)`:
  Hub/Peer -> `sync::engine::ingest_commit` (extracted from
  `ingest_commit_json`, which now wraps it and serialises the response),
  Replica -> `sync::ws_apply::apply_commit_json` (now returns
  `CommitResponse`), LocalCache -> the WASM `applyCommit` path.
- `mutate(ResourceEdit)` -> `Resource::save_locally` / `save_as_genesis`
- `subscribe()` -> `Db::subscribe_events`
- `sync_with_peer` (iroh) -> `sync::peer::sync_drive_with_peer_outcome`

`IngestPolicy::{Hub, Peer, Replica, LocalCache}` mirrors the
`CommitIngestOpts::{hub, peer, replica}` presets of #1274 plus the WASM
no-validation path, so that PR can map onto it 1:1 once merged.

The WASM `ClientDb` is the first consumer: it now holds an `AtomicNode`
and routes `applyCommit` and `query` through it.

Tests: two nodes in one process, `mutate` on one, `apply_commit(Peer)`
on the other, query and `DbEvent` reflect it; LocalCache accepts a
tampered signature while Peer rejects it; mutate without agent errors.

Claude-Session: https://claude.ai/code/session_019asLKBrBWY5ovyeCgtmdSd
@joepio
joepio force-pushed the feat/atomic-node-slice branch from deb7165 to 2a6bab4 Compare September 1, 2026 20:07
@joepio
joepio merged commit d60832a into develop Sep 1, 2026
4 checks passed
@joepio
joepio deleted the feat/atomic-node-slice branch September 1, 2026 20:07
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