Skip to content

ADR-053: stamp WatchNodes events with the serving database id - #1593

Merged
mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:ns/adr053-event-database-id
Jul 9, 2026
Merged

mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:ns/adr053-event-database-id

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Part of the ADR-053 epic ("One Daemon, Multiple Local Databases", #1532). One of the two remaining acceptance criteria: event streams carry database_id so a client watching a specific database can attribute the events it receives when the daemon serves several.

What changed

  • Proto: NodeEvent gains an additive string database_id = 7; (sibling of the event oneof). Backward-compatible — existing consumers (the tauri watcher, the frontend) ignore it, so the community app is behaviorally unchanged.
  • NodeServiceImpl gains a database_id, set via a with_database_id builder. build_database_services calls it with the registry id when a database is opened through the manager. NodeServiceImpl::new is unchanged, so the single-database Pro daemon (nodespaced-pro constructs it directly) and direct-construction unit tests keep an empty id and carry no cross-repo break.
  • Watch handler stamps this.database_id (the routed database, resolved by the existing route()) onto every emitted event. convert_domain_event now returns the inner NodeEventKind so the id is applied at a single construction site.

Header-less/default watch streams carry the default database's id; a stream routed by x-ns-database-id carries that database's id.

Verification

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings — clean.
  • cargo test -p nodespace-daemon — 51 lib + all integration suites green.
  • e2e (database_service_e2e.rs): opens watch streams on the default and a second database over the real transport, then routes a write to each and asserts each stream's Created event carries its own database id (default id for the header-less stream, the second id for the routed stream).

Cross-repo

No constructor or BaseServices change — nodespaced-pro is unaffected and inherits the additive proto field transparently on its next pin bump.

Add `database_id` to the proto NodeEvent and stamp it onto every WatchNodes
event so a client watching a specific database can attribute events when the
daemon serves several.

NodeServiceImpl gains a `database_id`, set via a `with_database_id` builder that
build_database_services calls with the registry id when a database is opened
through the manager. `new()` is unchanged, so the single-database Pro daemon and
direct-construction tests keep an empty id (their events carry no database id) —
no cross-repo break. convert_domain_event now returns the inner event kind so
the id is applied at one construction site.

The e2e test opens watch streams on the default and a second database and
asserts each stream's events carry its own database id.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE — clean additive Stage 6; verified against the code.

Verified

  • Proto is truly additive, no field collision. On upstream/main, NodeEvent uses field numbers 1–6 (all inside oneof event); string database_id = 7; is the next free number and a sibling of the oneof, not a oneof arm — so it accompanies every event regardless of kind, and proto3 unknown-field handling means existing consumers (tauri watcher, frontend) ignore it. Wire-backward-compatible. Community app behaviorally unchanged. ✅
  • No cross-repo break (deliberate, unlike ADR-053: DatabaseService gRPC server (local-database registry) #1592). NodeServiceImpl::new keeps its 2-arg signature — the struct gains database_id: String defaulted to String::new() inside new, and the id is applied via a separate with_database_id(self, String) -> Self builder. nodespaced-pro constructs NodeServiceImpl directly, so it keeps an empty id and needs no coordinated change (it inherits the additive proto field on its next pin bump). Confirmed no BaseServices/ctor-signature change in the diff. ✅
  • Id is stamped from the routed target, at a single site. The watch loop reads this.database_id (node_service.rs:75) — and this is the service that route() resolved to, i.e. the target DB's NodeServiceImpl (whose id was set by with_database_id when build_database_services opened it through the manager). So a header-routed stream carries that DB's id and a header-less stream carries the default's. convert_domain_event was refactored to return the inner NodeEventKind, so the wrapping NodeEvent { event, database_id } is built at one construction site (:86) — no risk of a kind that forgets to stamp the id. ✅
  • e2e proves the attribution, not just compilation: database_service_e2e.rs opens watch streams on the default and a second DB over real transport, writes to each, and asserts each stream's Created event carries its own id. Strong.

Note (not a defect)

Per sync#294, the Pro daemon opens its single DB directly (not through the manager, no DbManagerLayer), so Pro watch events will carry an empty database_id. That's exactly what the proto comment documents ("Empty when the daemon serves a single unregistered database (Pro daemon)") and the sync consumer already tolerates it (ignores field 7). Consistent — flagging only so the empty-id-on-Pro stream isn't later mistaken for a bug.

Merge gate

CI test:all + test:e2e QUEUED at 2db9f060 — must go green before merge. (Core: I re-review on each new head SHA.)

This is one of the two remaining #1532 acceptance criteria (event streams carry database_id); the other is Stage 7 (drop active_database_path). Approve.

@mstomar125
mstomar125 merged commit 7fe5a89 into NodeSpaceAI:main Jul 9, 2026
2 checks passed
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