Skip to content

Replace DatabaseSettingsNode's Pro fields and accessors with a generic settings accessor #3340

Closed

Description

@mstomar125

Summary

Carry out ADR-083 §1 (proposed; decision 1-A):

  • Keys stay, owned by Pro. sync_enabled, auth_status, bound_tenant_schema and bound_tenant_collection remain in the database-settings singleton's bucket under their current names.
  • Core lets go of them. It no longer declares, seeds, validates or reads them, and its six typed accessors are deleted.
  • Core exposes one generic accessor pair: NodeService::database_settings() and a public NodeService::merge_database_settings(entries). The merge rejects keys that core itself declares.
  • New extension state uses plugin: keys (ADR-083 §5, ADR-063).

The singleton itself stays in core, unchanged: its id, its seeding, the owner has_role edge from the local PersonNode, and get_local_person.

Context (lines at af8ddb61 are hints)

Where the Pro fields are handled today:

  • Schema: the database-settings SchemaNode in packages/core/src/models/core_schemas.rs.
    • Comment ~1555-1559; fields ~1568-1664.
    • Module doc, line 21: "Singleton container for database-level config (sync state, roles)".
    • Test: test_database_settings_schema_has_fields (~1976-2021).
  • Behavior: DatabaseSettingsNodeBehavior in packages/core/src/behaviors/mod.rs (~2317-2396).
    • validate checks the four keys at the top level of properties, but they are stored in the bucket, so the checks never fire on stored data.
    • default_metadata names two of the keys. The trait default returns {}.
    • validate has no trait default, so the method must stay.
  • Seeding: seed_database_settings_if_needed in packages/core/src/services/node_service/mod.rs, doc ~1646-1652, seeded JSON ~1704-1709.
  • Accessors: in node_service/mod.rs.
    • get_bound_tenant (~2112-2139) and set_bound_tenant (~2141-2194).
    • The private merge_database_settings(&self, fields: &[(&str, Value)]) (~2196-2242).
    • set_sync_enabled, set_auth_status, get_sync_enabled and get_auth_status (~2244-2311).
    • Core calls none of these outside tests. nodespaced-pro (sync 17f9557) calls all six public ones.

Why this lands core-first with no gate (ADR-083 §7 item 3). The Pro daemon builds against pinned core 680c35d8. At its next pin bump it switches over:

  • it reads through database_settings() and writes through merge_database_settings;
  • it takes over the defaults today's getters apply: an absent or null sync_enabled means false, an absent or null auth_status means local, and a missing or empty binding means unbound.

Why this does not wait for #3333:

  • The in-core Pro UI reads the raw keys from the node store (plugins/ui-extensions.svelte.ts: settings?.auth_status === 'connected', settings?.sync_enabled === true). An absent key behaves exactly like today's seeded default.
  • The pinned Pro daemon still seeds the old values anyway.

Existing databases (no migration):

  • The keys stay in the bucket, inert to core.
  • The stored database-settings schema node keeps declaring all four fields until the database is reset, because seed_core_schemas_if_needed never rewrites a stored core schema. It keeps validating sync_enabled (boolean) and auth_status (local or connected).
  • That is why the new guard reads the compiled definition, not the stored one.

Tests that name the fields today:

  • In node_service/mod.rs:
    • test_seed_database_settings_singleton_with_owner_edge (asserts at ~9291-9292);
    • test_get_set_bound_tenant_roundtrip (~10347-10387);
    • test_set_sync_enabled_and_auth_status_roundtrip (~10389-10450);
    • test_create_second_database_settings_is_noop (~10452-10480).
  • In behaviors/mod.rs: the database_settings_* tests (~5653-5735).
  • In packages/core/tests/it/person_seed_test.rs: module-doc bullet 2 (line 7) and the auth_status absence assertion (~31-39).

Scope

  • core_schemas.rs: the module doc line, the schema comment, the fields and the schema test.
  • behaviors/mod.rs:
    • the DatabaseSettingsNodeBehavior doc, validate, and the default_metadata override;
    • the tests database_settings_valid_defaults_pass, database_settings_valid_auth_status_values_pass, database_settings_invalid_auth_status_fails, database_settings_non_bool_sync_enabled_fails, database_settings_default_metadata and database_settings_is_not_embeddable.
  • node_service/mod.rs: the seed doc and seeded JSON, the seven accessors, and the four tests listed above.
  • New: packages/core/tests/it/database_settings_extension_keys_test.rs, registered in tests/it/main.rs.
  • person_seed_test.rs: line 7 and ~31-39.

Out of scope

Steps

  1. Start up. Follow core CLAUDE.md's startup sequence:
    • EnterWorktree({name: "issue-<N>-settings-extension-keys"});
    • bun install;
    • the bun run test baseline;
    • gh:assign, then gh:status.
  2. Schema.
    • Set the database-settings SchemaNode to fields: vec![].
    • Rewrite the schema comment: this is the singleton anchor for database-level configuration and for the owner has_role edge. Core declares no fields on it, and extensions keep namespaced keys in its bucket (ADR-083, ADR-063).
    • Change the module doc line to "Singleton anchor for database-level configuration and the owner role edge".
    • Replace the schema test with test_database_settings_schema_declares_no_fields. It asserts the schema exists, has is_core set, and has empty fields.
  3. Behavior.
    • Rewrite the doc: the singleton anchor for database-level configuration and the owner has_role edge (ADR-037). Core declares no fields on it; extensions store their own keys through NodeService::merge_database_settings.
    • Make validate return Ok(()). Keep no-children, no-markdown and not-embedded.
    • Delete the default_metadata override.
    • Delete the five tests that check the Pro keys and their defaults.
    • Change the database_settings_is_not_embeddable fixture to json!({}).
    • Add database_settings_accepts_namespaced_extension_keys: {"plugin:example": 1} validates.
  4. Seed.
    • Seed the singleton with no properties (json!({})).
    • Rewrite the seed doc: it seeds the singleton and one owner has_role edge.
    • Leave the owner-edge repair logic untouched.
  5. Accessors.
    • Delete get_bound_tenant, set_bound_tenant, set_sync_enabled, set_auth_status, get_sync_enabled and get_auth_status.
    • Add pub async fn database_settings(&self) -> Result<serde_json::Map<String, serde_json::Value>, NodeServiceError>:
      • it returns the singleton's database-settings bucket, keys as stored;
      • it returns an empty map when the singleton or the bucket is absent;
      • it returns InitializationError when the bucket is not a JSON object, as the merge does.
    • Make merge_database_settings(&self, entries: &[(&str, serde_json::Value)]) pub. Its doc names no specific key and states:
      • it merges into the bucket as one versioned update_node, keeping every other key;
      • a JSON null is stored as null, and no key is ever deleted;
      • a missing singleton returns InitializationError;
      • a concurrent change returns the ordinary VersionConflict, and the caller re-reads and retries;
      • new extension keys use the plugin: prefix (ADR-063).
    • Guard. Before writing, reject any entry whose key the compiled database-settings definition declares (get_core_schemas()). Return NodeServiceError::InvalidUpdate and write nothing.
      • Put the check in a pure helper, e.g. fn first_core_declared_key<'a>(declared: &[String], entries: &'a [(&'a str, Value)]) -> Option<&'a str>, so it can be tested with a synthetic declared list.
      • The compiled list is empty today, so nothing is rejected yet.
      • Add a comment explaining why the guard must not read the stored schema: existing databases still declare the Pro keys there, and the guard would then reject the Pro daemon's own writes.
  6. Unit tests (`node_service/mod.rs):
    • test_seed_database_settings_singleton_with_owner_edge: assert that database_settings() is empty.
    • Delete test_get_set_bound_tenant_roundtrip and test_set_sync_enabled_and_auth_status_roundtrip. This also removes the two uses of the legacy root id c0000000-…0001 that Remove the tenant-binding root fallback from the collections tree #3330 mentions.
    • Add test_merge_database_settings_keeps_other_keys: merge plugin:a, then plugin:b, then plugin:a = null. database_settings() then shows both keys, with plugin:a stored as null.
    • Add test_first_core_declared_key_rejects_declared_keys, which exercises the helper with a synthetic declared list.
    • test_create_second_database_settings_is_noop: create the duplicate with {"plugin:marker": true}, and assert that the singleton's properties equal a snapshot taken before the second create.
  7. Legacy-shape integration test (the new module). It uses generic key names on purpose, so core keeps no Pro key names; the mechanics are identical.
    • Setup, on a fresh temp database, before NodeService::new:
      • Build a database-settings SchemaNode shaped like an older build's declaration, with these fields:
        • legacy_flag: boolean, default false;
        • legacy_state: enum, required, default "a", core values a and b;
        • legacy_ref_a and legacy_ref_b: optional strings.
      • Insert it with SqliteStore::create_node(schema.into_node(), None, None).
      • Insert the singleton (database-settings-singleton) with those four values in its bucket.
    • Assert:
      • NodeService::new succeeds, and get_local_person() resolves, because the owner edge is repaired;
      • database_settings() returns the four values unchanged;
      • merge_database_settings(&[("plugin:example", json!(1))]) succeeds and leaves the four values untouched;
      • merging legacy_state = "z" is refused, because the stored declaration still validates (this documents the ADR-083 §1 caveat);
      • the stored schema node still has its four fields.
  8. person_seed_test.rs.
    • Replace bullet 2 with "The seeded person carries no person properties until the user fills them in".
    • Replace the auth_status absence assertion (~31-39) with an assertion that the seeded person's person bucket is absent or empty. This is stronger than the old check, and names no Pro key.
  9. Ratchet. Run bun run scripts/check-pro-boundary.ts and set BASELINES to the printed counts. Expect large drops in cloudBindState and tenantWording, and smaller ones in cloudWording and proWording.
  10. Finish.
    • bun run test:changed, then bun run quality:fix, then commit.
    • Push to issue-<N>-settings-extension-keys.
    • gh pr create --repo NodeSpaceAI/nodespace-core --base main --head issue-<N>-settings-extension-keys, then gh:status "In Review".
    • After approval, run bun run merge <PR#> in the background.

Acceptance criteria

  • git grep -n -E 'bound_?[tT]enant|get_sync_enabled|set_sync_enabled|get_auth_status|set_auth_status' -- packages/core prints nothing.
  • git grep -n -E 'sync_?[eE]nabled|auth_?[sS]tatus' -- packages/core prints only the two doc lines Reword core data-model and identity docs that cite Pro, Supabase, RLS or tenants #3365 owns (the seed_local_person_if_needed note and the PersonNodeBehavior doc), and nothing once Reword core data-model and identity docs that cite Pro, Supabase, RLS or tenants #3365 has merged.
  • A fresh database seeds the singleton and its owner edge, and database_settings() returns an empty map.
  • A legacy-shaped database opens. Core neither reads nor rewrites its values, and extension keys merge alongside them.
  • merge_database_settings is public, keeps sibling keys, and rejects core-declared keys (proven by the helper test).
  • bun run scripts/check-pro-boundary.ts exits 0, and BASELINES equals its printed counts.
  • Core builds and all tests pass. The free app's onboarding, local person and Settings → Databases are unchanged.

Tests and verification

  • bun run test:changed
  • .tools/bin/cargo-nextest nextest run -p nodespace-core --lib database_settings
  • .tools/bin/cargo-nextest nextest run -p nodespace-core --test it database_settings_extension_keys_test::
  • .tools/bin/cargo-nextest nextest run -p nodespace-core --test it person_seed_test::
  • cargo clippy -p nodespace-core --all-targets -- -D warnings -D clippy::unused-async
  • Mutation-check each new test:
    • make the guard a no-op, and the helper test fails;
    • stop preserving sibling keys, and the merge test fails.
  • Manual check. Use an isolated NODESPACE_HOME holding a database created by the current release. The dev app opens it with no incompatible-database screen, and the onboarding identity still saves.

Dependencies

Risks and rollback

  • Sync's pin bump fails to compile until it switches to the accessor pair. That failure is the intended signal.
  • Existing databases keep validating two Pro keys through their stored schema. The Pro daemon must keep to the values it writes today. A new state needs a new plugin: key (ADR-083 §1).
  • Rollback: revert the PR. Databases created while the change was live lack the seeded defaults, but the restored getters already treat absent values as false and local.

Plan key: C7.4 (pro-boundary DAG).

🤖 Generated with Claude Code

Activity

  1. self-assigned this
    on Sep 30, 2026
  2. added
    pro-boundary
    on Sep 30, 2026
  3. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Completed in #3378 (merged). Auto-close did not fire; closing manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions