Skip to content

Replace the registry's tenant binding with opaque string extension keys (ADR-083 §3) - #3423

Merged
mstomar125 merged 3 commits into
mainfrom
issue-3412-registry-extensions
Oct 1, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-3412-registry-extensions

Conversation

@mstomar125

@mstomar125 mstomar125 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Part of #3412

Slice S3 of the one-pass strip: the database registry. Per ADR-083 §3, the registry's tenant binding becomes opaque extension keys. This PR does the Rust half; slice S4 removes the TypeScript boundTenant* fields and the Settings badge.

Acceptance (quoted from the slice)

  1. Registry. DatabaseEntry has no bound_tenant_* fields, set_bound_tenant is gone, and only set_extensions and the opaque extensions map remain, through DatabaseInfo, the DTO and the store. Core's frontend reads no key from it. You complete the Rust half. Slice S4 removes the TS boundTenant* fields and the badge; say so in the PR.
    • Done for Rust: DatabaseEntry, DatabaseManager, DatabaseInfo, listing_to_info, the app-lib DatabaseEntry DTO and to_entry. Slice S4 removes the TS boundTenant* fields from the database store and the "Syncs to tenant" badge. Until S4 lands, the DTO no longer sends those fields, so the store reads undefined for them.
  2. ADR: replace the #[serde(flatten)] toml::Table catch-all (database_manager.rs:107-110) with a string→string map (BTreeMap<String, String>). Non-string values are not carried: either rejected with a clear registry load error or dropped with a warning. Choose one, document it in the field's doc, and test it.
    • extensions: BTreeMap<String, String>, still flattened beside the defined fields. Chosen: reject. An entry carrying a non-string value fails the registry load with extension key `<key>` has a value of type <type>, but registry extension keys hold strings only. Reasons: nothing in core writes a non-string value (set_extensions takes strings), so one can only come from a hand edit. Dropping it would also erase it from the file on the next save without anyone seeing why. A malformed registry already fails the load today. This is documented on the field, and a_non_string_extension_value_fails_the_registry_load covers integer, float, boolean, datetime, array and table.
  3. ADR: pub async fn set_extensions(&self, id: &DatabaseId, entries: &[(String, Option<String>)]) -> Result<...>. Shape the signature like the existing mutators. It writes all entries in one save through mutate_and_save; None removes a key. A failed save leaves the previous registry live. Success notifies subscribe_changes subscribers. An unknown id fails not-found. A key the registry defines itself (id, name, path, created_at, last_opened_at) is rejected before anything is written.
    • pub async fn set_extensions(&self, id: &DatabaseId, entries: &[(String, Option<String>)]) -> Result<()>, the same shape as rename and set_default. The defined keys live in DEFINED_ENTRY_KEYS, and a test pins that list to the keys a fully populated entry serializes. A key from that list is refused, whether it is being set or removed, before the lock is taken. Entries apply in order, so a repeated key ends with its last value.
  4. ADR: proto DatabaseInfo drops fields 8 and 9 and their comments. Do NOT add reserved. extensions = 10 already exists.
    • Fields 8 and 9 and their comments are removed, and no reserved line is added. The comment on extensions = 10 no longer says "Only string values are carried", because every value is now a string.

Files

  • packages/daemon/src/services/database_manager.rs: the entry, DEFINED_ENTRY_KEYS, deserialize_string_extensions, set_extensions, and the tests.
  • packages/daemon/src/services/database_service.rs: listing_to_info copies the map, string_extensions is gone, and the test is replaced.
  • packages/proto/proto/database_service.proto: DatabaseInfo fields 8 and 9.
  • packages/desktop-app/app-lib/src/commands/database.rs: the DTO's two binding fields, to_entry, and a new DTO test.
  • packages/daemon/src/tray.rs: the registry fixture, and the bound_ fragment test (deleted). Outside the listed lines, a minimal compile fix: extension_keys_add_no_marker inserted toml::Values and now inserts strings.
  • No other Rust consumer broke. The CLI's db list printer (packages/cli/src/commands/database.rs) reads DatabaseInfo field by field and never read 8 or 9.

Tests

Deleted: set_bound_tenant_mirrors_persists_and_clears, set_bound_tenant_rolls_back_when_save_fails, registry_round_trips_entry_keys_it_does_not_define (it kept integer and datetime values), listing_to_info_carries_string_extensions_only (integer and boolean values), and the tray's a_recorded_binding_adds_no_marker.

Added:

  • database_manager: set_extensions_writes_every_entry_in_one_save, set_extensions_none_removes_a_key, set_extensions_for_an_unknown_id_is_not_found, set_extensions_rejects_each_key_the_registry_defines, set_extensions_rolls_back_when_save_fails (reuses break_registry_persistence; covers notify-on-success-only), set_extensions_round_trips_keys_that_need_quoting, extension_keys_round_trip_through_load_and_save, a_non_string_extension_value_fails_the_registry_load, and defined_entry_keys_match_the_serialized_entry. a_rename_keeps_extension_keys now uses a fixture with only string values.
  • database_service: listing_to_info_carries_the_extensions_map.
  • app-lib: the_dto_serializes_only_registry_fields_and_extensions checks the exact camelCase key set, plus a fragment needle (["ten", "ant"].concat()) that still fails if someone adds a binding key and updates the expected list.

Mutation checks

Each mutation was applied alone, the targeted tests were run, and the file was restored. All 20 were caught.

# Mutation Caught by
A set_extensions saves once per entry set_extensions_writes_every_entry_in_one_save
B None does not remove the key set_extensions_none_removes_a_key
C find_or_err dropped (unknown id accepted) set_extensions_for_an_unknown_id_is_not_found
D defined-key check disabled set_extensions_rejects_each_key_the_registry_defines
E defined-key check skips removals (None) set_extensions_rejects_each_key_the_registry_defines
F last_opened_at missing from DEFINED_ENTRY_KEYS set_extensions_rejects_each_key_the_registry_defines, defined_entry_keys_match_the_serialized_entry
G defined-key check moved after the save set_extensions_rejects_each_key_the_registry_defines
H mutate_and_save swaps the live registry before saving set_extensions_rolls_back_when_save_fails (and the other rollback tests)
I mutate_and_save notifies before saving (so also on failure) set_extensions_rolls_back_when_save_fails
J mutate_and_save does not notify on success set_extensions_rolls_back_when_save_fails, set_extensions_writes_every_entry_in_one_save
K extensions skipped on serialize extension_keys_round_trip_through_load_and_save (and others)
L an integer value is coerced to a string a_non_string_extension_value_fails_the_registry_load
M non-string values are dropped silently a_non_string_extension_value_fails_the_registry_load
N listing_to_info sends an empty map listing_to_info_carries_the_extensions_map
O DTO loses rename_all = "camelCase" the_dto_serializes_only_registry_fields_and_extensions
P DTO regains a binding field the_dto_serializes_only_registry_fields_and_extensions
P2 same, with the expected key list updated too (the fragment needle alone) the_dto_serializes_only_registry_fields_and_extensions
S to_entry drops the map to_entry_passes_extensions_through
Q tray adds a marker when an entry has extension keys extension_keys_add_no_marker
R Registry::save writes a dotted key bare set_extensions_round_trips_keys_that_need_quoting (the load then fails: extension key `ext` has a value of type table)

Verification

  • git grep -nP 'bound_?[tT]enant|set_bound_tenant|toml::Table' -- packages/daemon packages/proto packages/desktop-app/app-lib packages/cli → 0
  • No reserved line added to database_service.proto
  • git grep -nP 'pub async fn set_extensions' -- packages/daemon → 1
  • git grep -niP tenant -- packages/daemon/src/services packages/proto/proto/database_service.proto packages/desktop-app/app-lib/src/commands/database.rs → 0
  • cargo clippy -D warnings --all-targets clean for nodespace-daemon, nodespace-app-lib, nodespace-cli and nodespace-proto; bun run quality:fix exits 0
  • bun run scripts/check-pro-boundary.ts passes
  • bun run test:changed: passed (scoped to rust + scripts), on the original head and again after the review fixes

Ratchet

bun run scripts/check-pro-boundary.ts --changed: every marker is 0 in the changed files, so this PR adds no Pro lines.

Marker main (247e0de) this PR baseline
cloudBindState 196 153 (−43) 203
tenantWording 428 369 (−59) 463
every other marker unchanged unchanged

BASELINES is not edited (S5 rewrites the checker).

Registry reset

Delete ~/.nodespace/databases.toml on dev machines. Old bound_tenant_* lines would load as plain extension keys, and any non-string value now fails the load, so the file is not carried forward. Database files are unaffected; re-register them or let the daemon create a new default.

Extension API (for S4's release notes)

  • DatabaseManager::set_bound_tenant is replaced by DatabaseManager::set_extensions(id, &[(key, Option<value>)]).
  • DatabaseEntry.extensions is retyped to a string→string map (BTreeMap<String, String>), and the bound_tenant_* fields are removed.
  • DatabaseInfo fields 8 and 9 (bound_tenant_schema, bound_tenant_collection) are removed, with no reserved numbers.

EXTENSION_API_VERSION is S4's to bump.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Automated pragmatic-code-review (medium depth)

Review Type: Initial Review (PR #3423 @ 6eca27fa)

Requirements Check

  1. ✅ Registry: DatabaseEntry has no binding fields and set_bound_tenant is gone. Only set_extensions and the opaque extensions map remain, through DatabaseInfo, listing_to_info, the app-lib DTO and to_entry. The PR says S4 removes the TS fields and the badge.
    • Between S3 and S4, the leftover TS reads (database-settings.svelte:165, pro-sync.svelte.ts:303) are both falsy checks, so undefined breaks nothing at runtime.
  2. ✅ String map, reject chosen: BTreeMap<String, String> with #[serde(flatten, deserialize_with = …)].
    • Defined keys are consumed by their fields before the flatten buffer, so they cannot land in extensions.
    • A TOML datetime arrives as Value::Datetime, so that case really is rejected as a datetime.
    • Rejecting is sound for boot: main.rs:93 already stops on any malformed registry.
    • The choice is documented on the field. The test covers six non-string types, has a string positive control, and checks that DatabaseManager::load fails.
  3. ✅ set_extensions: the signature matches rename / set_default.
    • Defined keys are refused before the lock is taken, for both set and remove; the bad key sits second in the test, so every entry is scanned.
    • An unknown id fails through find_or_err.
    • There is one mutate_and_save per call, and only success notifies.
    • defined_entry_keys_match_the_serialized_entry pins the constant to the struct's serialized keys. The rejection test hard-codes the five names, which is why mutation F is caught.
  4. ✅ Proto: fields 8 and 9 and their comments are removed, no reserved line was added, and the stale comment on extensions = 10 is fixed.

Other Rust consumers: none missed. packages/cli reads DatabaseInfo field by field, and nothing else parses databases.toml.

Findings

  1. 🟢 Nit: 📁 packages/daemon/src/services/database_manager.rs:128-131
    • The load error reads "holds a integer" and "holds a array", because type_str() is a bare noun.
    • Recommendation: reword so no article is needed, and update the test assertion.
  2. 🟢 Nit: 📁 packages/daemon/src/services/database_manager.rs:748-752
    • "cannot be set as an extension key" also fires on a None removal.
    • Recommendation: "cannot be used as an extension key".
  3. 🟢 Nit: 📁 packages/desktop-app/app-lib/src/commands/database.rs (new absence test)
    • "binding fields" and "binding keys" is vocabulary core no longer has.
    • Recommendation: phrase it neutrally, for example "nothing beyond the registry's own fields and the opaque extensions map".

No Critical or Important findings.

Recommendation: APPROVE

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment because GitHub blocks self-approval). The full findings are in the review comment above: no Critical or Important findings, and 3 optional nits.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review

The review was APPROVE with no Critical or Important findings. All three nits are addressed in 7cedf3a:

  1. ✅ Load-error grammar: the error now reads extension key `<key>` has a value of type <type>, but registry extension keys hold strings only, so it no longer says "holds a integer". The test assertion was updated to match.
  2. ✅ Defined-key error on removal: it now says "cannot be used as an extension key", which is also correct for a None removal.
  3. ✅ "binding" wording: the DTO absence test's doc and message now say "nothing beyond the registry's own fields and the opaque extensions map". The fragment needle stays.

Skipped: none.

Verification after the change:

  • cargo clippy -D warnings --all-targets (daemon, app-lib) is clean, and bun run quality:fix exits 0.
  • bun run test:changed passed (rust + scripts).
  • The mutations that exercise the reworded assertions were re-run and are all still caught: L, M (the non-string load test); D, E, F, G (the defined-key test); P2 (the DTO needle).

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: only error-message text and a test doc comment changed. There is no logic change, and every affected test still catches its mutations.

@mstomar125
mstomar125 force-pushed the issue-3412-registry-extensions branch from 7cedf3a to 90b3892 Compare October 1, 2026 10:11
@mstomar125

Copy link
Copy Markdown
Contributor Author

Rebased onto main (df1077b, the S0 merge #3417); no conflicts and no content change. The review fixes from 7cedf3a are now 90b3892. bun run test:changed passed again on the rebased head (rust + scripts), and the ratchet is unchanged.

mstomar125 and others added 3 commits October 1, 2026 12:16
DatabaseEntry drops bound_tenant_schema and bound_tenant_collection, and its
flattened extension keys become a BTreeMap<String, String>. A non-string
value fails the registry load with an error naming the key.
DatabaseManager::set_bound_tenant is replaced by set_extensions, which
writes every (key, Option<value>) entry in one mutate_and_save, removes a
key on None, refuses the keys the registry defines and fails an unknown id
as not found. DatabaseInfo drops fields 8 and 9; the desktop DTO and the
tray fixtures follow.

Part of #3412

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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