Skip to content

Per-database bound-tenant storage (ADR-053 per-database cloud sync, S1) - #1604

Merged
mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:ns/adr053-s1-tenant-storage
Jul 10, 2026
Merged

mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:ns/adr053-s1-tenant-storage

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

First slice (S1) of ADR-053 per-database cloud sync (#1535): the additive, community-safe storage foundation for binding a database to a cloud tenant at runtime, replacing the current build-time-baked single tenant.

  • DatabaseSettingsNode (the authoritative per-database record) gains bound_tenant_schema and bound_tenant_collection string fields, with is_string/null validation in the behavior. Both are empty until the Pro sync daemon binds the database.
  • DatabaseEntry in databases.toml mirrors the same two fields (#[serde(default)], so existing registries parse) so the bound tenant can be shown before the database is opened, with a DatabaseManager::set_bound_tenant(id, schema, collection) setter that keeps the mirror in step (pass None to clear on unbind).

No behavior change yet — nothing reads these fields; later slices (remove build-time injection, per-database session config, activate/deactivate lifecycle, status plumbing) build on them. The community build is unaffected (the fields are inert without the Pro sync daemon).

Tests

  • Behavior: existing database_settings_* suite stays green (schema presence, defaults, validation).
  • set_bound_tenant_mirrors_persists_and_clears: a fresh registration is unbound; set → the mirror reflects the schema/collection; it survives a reload from disk; unbind clears it.
  • Validated green locally before the PR: full test:all + test:e2e + cargo test -p nodespace-app via the pre-push gate; cargo fmt + cargo clippy --workspace -- -D warnings clean.

Part of #1535 (this is S1 of the S1–S8 decomposition posted on the issue).

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Reviewed: small, additive storage slice. bound_tenant_schema/bound_tenant_collection on DatabaseSettingsNode (authoritative per-database record, with is_string/null validation) mirrored onto the databases.toml DatabaseEntry (#[serde(default)] so existing registries parse; a set_bound_tenant setter keeps the mirror in step and clears on None). Nothing reads the fields yet, so there is no behavior change and the community build is unaffected. Round-trip/persistence/clear test added; existing database_settings_* behavior suite stays green. Validated green locally before the PR via the pre-push gate (full test:all + test:e2e + cargo test -p nodespace-app); fmt + clippy clean.

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE — the slice itself is a clean, additive, community-safe storage foundation. One prominent process flag on the epic it opens (below).

S1 is genuinely inert and migration-safe

  • No registry migration break: both new DatabaseEntry mirror fields carry #[serde(default)], so an existing databases.toml written before this change deserializes fine (fields default to None). Verified. This is the key community-safety property and it's correct.
  • Nothing reads the fields for behavior: the only references are the schema definition, the is_string() || is_null() validation, the struct declarations, the set_bound_tenant setter (writes + saves), and the round-trip test. No code path consumes bound_tenant_schema/bound_tenant_collection to drive sync/routing/provisioning — so the community build is behaviorally unchanged (the fields exist but gate nothing). Matches the PR's "no behavior change yet" claim.
  • Mirror stays consistent: set_bound_tenant(id, schema, collection) updates the databases.toml mirror and saves; None clears on unbind; the authoritative record is DatabaseSettingsNode, the mirror is for pre-open display. set_bound_tenant_mirrors_persists_and_clears proves set → mirror → survives reload → unbind clears. Good.
  • CI: test:e2e green, test:all IN_PROGRESS at a2a86990.

⚠️ Process flag — this opens #1535, the user-gated cross-repo effort

This is S1 of the S1–S8 decomposition of #1535 (per-database cloud sync) — the follow-on that the batch plan explicitly carved out as: "LARGEST, cross-repo (private nodespace-sync / nodespaced-pro), tenant/billing/keychain/per-DB OAuth — DO NOT blind-ship; scope + check in with user before shipping."

  • This slice does not trip that gate — it's inert core storage with no cross-repo, tenant-provisioning, billing, or keychain surface. Safe to land incrementally, and decomposing the gated epic into an additive storage-first slice is exactly the right approach.
  • The gate binds the slices ahead, specifically wherever S2–S8 (a) wire the nodespace-sync / nodespaced-pro side that actually binds/provisions a tenant per database, (b) touch keychain / per-DB OAuth credential storage, or (c) intersect tenant/billing residency. Those are the ones the plan said need the user + Anoop scope/sign-off before shipping, not just before merging core plumbing.
  • Recommendation: confirm the user has seen the S1–S8 breakdown posted on Per-database cloud sync: runtime tenant binding and single-active session lifecycle #1535 and is bought into the direction before the first behavioral/cross-repo slice lands. I'll keep flagging on each subsequent Per-database cloud sync: runtime tenant binding and single-active session lifecycle #1535 slice and call out explicitly when one crosses into the sync-repo / billing / keychain territory.

Net: approve S1 (additive, inert, migration-safe); the flag is about the epic's trajectory, not this diff. Approve.

Record the cloud tenant a database binds to so per-database sync can resolve it
at runtime instead of from a build-time constant. Add bound_tenant_schema and
bound_tenant_collection to the DatabaseSettingsNode schema (the authoritative
per-database record) with string validation, and mirror them on the
databases.toml DatabaseEntry (persisted, shown before the database is opened)
with a DatabaseManager::set_bound_tenant setter. Both are empty until the Pro
sync daemon binds the database; the community build is unaffected.

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

Copy link
Copy Markdown
Contributor Author

APPROVE (re-review at 3beda67b, rebased onto main after #1603). The only delta since my prior review (a2a86990) is test-strengthening, so the approval stands.

  • New assertions in the database-settings schema test: field count == 4, and for both bound_tenant_schema/bound_tenant_collection — field_type == "string", protection == SchemaProtectionLevel::Core, required == Some(false), default == None. No production-logic change vs the reviewed slice.
  • Marking the two fields Core protection is the right call — they're the authoritative tenant binding, set only by the Pro sync daemon via set_bound_tenant, not by arbitrary user writes. (Note the pre-existing systemic caveat that SchemaProtectionLevel::Core isn't yet enforced on the write path — declarative today; not this PR's scope.)
  • CI now green: test:all + test:e2e both SUCCESS at 3beda67b.

The S1 substance (additive, inert, #[serde(default)] mirror = no registry migration break, nothing reads the fields yet, community-unaffected) and the #1535 user-gating flag from my prior comment are unchanged and still apply: this slice is safe to land, but the behavioral/cross-repo S2–S8 slices (nodespace-sync tenant binding / keychain / per-DB OAuth / billing residency) need the user + Anoop scope check-in before shipping. Approve.

@mstomar125
mstomar125 merged commit 5130199 into NodeSpaceAI:main Jul 10, 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