Skip to content

Replace DatabaseSettingsNode Pro fields and accessors with a generic settings accessor - #3378

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3340-settings-extension-keys
Sep 30, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3340-settings-extension-keys

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3340

Part of the Pro/core boundary epic. Carries out ADR-083 section 1 (proposed, decision 1-A), ahead of the ADR merging.

What changed

  • Schema. The database-settings core schema declares no fields (fields: vec![]). Module doc and schema comment reworded: the singleton is the anchor for database-level configuration and the owner has_role edge.
  • Behavior. DatabaseSettingsNodeBehavior::validate returns Ok(()); the default_metadata override is gone. No-children, no-markdown and not-embedded are unchanged.
  • Seed. The singleton is seeded with json!({}). The owner-edge repair logic is untouched.
  • Accessors. The six typed accessors are deleted. In their place: NodeService::database_settings() (returns the bucket as stored; empty map when the singleton or bucket is absent; InitializationError when the bucket is not an object) and a now-public NodeService::merge_database_settings(entries) (one versioned update_node, null stored as null, no key ever deleted, missing singleton is InitializationError, concurrent change is the ordinary VersionConflict).
  • Guard. merge_database_settings rejects, with InvalidUpdate and no write, any entry whose key the compiled database-settings definition declares. It reads the compiled definition, not the stored schema node, because a database created by an older build still declares the retired fields there and a stored-schema guard would reject the Pro daemon's own writes. The compiled list is empty today, so nothing is rejected yet.

Existing databases (no migration)

The repo forbids data migrations, and the issue specifies none: keys already in a bucket stay inert to core, and the stored database-settings schema node keeps declaring its old fields because seed_core_schemas_if_needed never rewrites a stored core schema. The compatibility handling is therefore (a) the guard reading the compiled definition, and (b) a legacy-shape integration test that seeds a database the way an older build left it (generic legacy_* key names, so core keeps no Pro key names) and asserts it opens, the owner edge is repaired, the values are read back unchanged and never rewritten (singleton stays at its original version), extension keys merge alongside, an out-of-range write to a still-declared legacy key is refused by the stored declaration, and the stored schema node keeps its four fields.

Deviations from the issue text

  • One extra seam. merge_database_settings computes the compiled declared list and delegates to a private merge_database_settings_rejecting(declared, entries). The issue's pure-helper test proves the matching logic but cannot show the guard is wired into the merge, since the compiled list is empty. With the seam, test_merge_database_settings_rejects_declared_key_and_writes_nothing proves a rejection writes nothing (including a clean sibling entry in the same call).
  • Extra tests beyond the issue's list: multi-entry merge writes every entry, missing singleton is InitializationError, non-object bucket is InitializationError for both read and merge, and the legacy owner-edge test asserts the has_role edge itself (get_local_person falls back to the first person, so resolving the person alone would not prove the repair).
  • Ratchet baseline not edited. scripts/check-pro-boundary.ts is not on main yet (its PR is open). See the delta below; whichever PR lands second must reconcile BASELINES.

Ratchet delta

Measured by running the ratchet script from the open ratchet PR's worktree against origin/main (faf64e3b) and against this branch (informational; the script is not on main yet).

marker main this branch
cloudBindState 321 203
tenantWording 507 466
cloudWording 88 83
proWording 314 304

The other eight markers are unchanged by this PR. When the ratchet script lands on main, lower those four values in BASELINES to the branch counts above.

Acceptance grep

  • 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 the follow-up docs rewording owns (seed_local_person_if_needed note and the PersonNodeBehavior doc).
  • The remaining set_bound_tenant / bound_tenant_* hits in packages/daemon/.../database_manager.rs belong to the daemon's own registry mirror, a separate item, and are not NodeService accessors.

Verification

  • bun run test:changed: scripts tier and the full Rust workspace nextest pass (run before the final two rebases onto main and the review-fix commit, which touches one test assertion).
  • cargo fmt -p nodespace-core -- --check and cargo clippy -p nodespace-core --all-targets -- -D warnings -D clippy::unused-async: clean.
  • Post-rebase re-run of the targeted lib and it tests: pass.
  • Manual, isolated NODESPACE_HOME (never ~/.nodespace). The pre-change daemon build created a database (singleton bucket {"auth_status":"local","sync_enabled":false}, stored schema declaring 4 fields); I then wrote populated Pro values (sync_enabled: true, auth_status: connected, a tenant binding) into that bucket via sqlite. The daemon built from this branch opened it with no error, no warning and no incompatible-database message, served the singleton with all four values intact through the CLI, and afterwards the singleton was byte-identical at version 1 with the stored schema still declaring 4 fields. Against a copy of the same database, set_local_person_identity saved the identity (the call the onboarding RPC delegates to), get_local_person resolved it, merge_database_settings merged plugin:example alongside the four values, and an out-of-range write to a legacy key was still refused.

Mutation checks

Each new test was checked by applying a mutation, confirming the test fails, and reverting.

mutation killed by
helper always returns None (guard no-op) test_first_core_declared_key_rejects_declared_keys, test_merge_database_settings_rejects_declared_key_and_writes_nothing
guard unwired from the merge test_merge_database_settings_rejects_declared_key_and_writes_nothing
guard reads the stored schema instead of the compiled one stored_declaration_still_validates_legacy_keys
entries written beside the bucket / only the first entry / update dropped test_merge_database_settings_keeps_other_keys, test_merge_database_settings_writes_every_entry_of_one_call
null deletes the key test_merge_database_settings_keeps_other_keys
database_settings() ignores the stored bucket keeps_other_keys and three legacy integration tests
database_settings() swallows a non-object bucket / merge replaces it a_bucket_that_is_not_an_object_is_an_initialization_error
merge succeeds on a missing singleton test_merge_database_settings_missing_singleton_is_initialization_error
seed writes settings into the singleton again test_seed_database_settings_singleton_with_owner_edge
seeded person carries a person property person_seed_tests::fresh_install_seeds_exactly_one_local_person
owner-edge repair removed legacy_database_opens_and_repairs_the_owner_edge
core rewrites a legacy value on open legacy_values_are_neither_read_nor_rewritten_by_core, extension_keys_merge_alongside_legacy_values
core rewrites the stored core schema on open stored_schema_node_keeps_its_declared_fields, stored_declaration_still_validates_legacy_keys
second create overwrites the singleton's properties test_create_second_database_settings_is_noop
core declares a field on the schema again test_database_settings_schema_declares_no_fields
behavior rejects plugin: keys database_settings_accepts_namespaced_extension_keys

One mutation the issue asks for cannot be killed: "stop preserving sibling keys". update_node deep-merges within a namespace bucket (deep_merge_namespaced_properties), so clearing the bucket before inserting in merge_database_settings still leaves the stored siblings in place. That is an equivalent mutant: sibling preservation is guaranteed by the storage layer as well as by the read-modify-write. The read-modify-write is kept because the non-object-bucket check needs the read, and the mutations above (wrong bucket, first entry only, update dropped, null deletes) do exercise the merge contract.

🤖 Generated with Claude Code

@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 (medium): APPROVE (posted as a comment, since GitHub blocks self-approval).

Review Type: Initial Review. Commit a428e0b9, 6 files. Reviewer read the full diff, the issue, the PR body and the write path in crud.rs, and ran --lib database_settings first_core_declared (16/16) and --test it database_settings_extension_keys_test:: person_seed_test:: (13/13).

Requirements Check (issue acceptance criteria)

  • ✅ Grep 1 (bound_?[tT]enant|get_sync_enabled|... over packages/core) prints nothing. The daemon's set_bound_tenant is its own registry-mirror method, not a NodeService accessor.
  • ✅ Grep 2 (sync_?[eE]nabled|auth_?[sS]tatus over packages/core) prints exactly the two allowed doc lines.
  • ✅ A fresh database seeds the singleton with json!({}) and the owner edge; database_settings() is empty.
  • ✅ A legacy-shape database opens: owner edge repaired, values read back unchanged, singleton still version == 1, plugin:example merges alongside, an out-of-range legacy write is refused by the stored declaration, the stored schema keeps its four fields. seed_core_schemas_if_needed only creates missing schema nodes and never rewrites a stored one. No migration, backfill or lazy-upgrade code in the diff.
  • ✅ merge_database_settings is public, keeps siblings and rejects core-declared keys (helper test plus seam test, which also proves nothing is written).
  • ⚠️ Ratchet criterion cannot be met yet: scripts/check-pro-boundary.ts is not on main (open PR #3376). That script is a one-way ratchet in this respect: landing order causes no gate failure, only a stale ceiling to lower. Disclosed in the PR body.
  • ✅ Tests and clippy pass.

Focus items

  1. Accessors, guard, helper: no defects. first_core_declared_key matches the issue's signature. The guard runs before the singleton lookup and before any write. Error variants are right: guard rejection is InvalidUpdate, missing singleton or non-object bucket or root is InitializationError, schema validation failure is ValidationFailed. null is stored as null. The private merge_database_settings_rejecting seam is justified: with the compiled list empty, guard wiring and "rejection writes nothing" are otherwise unobservable, at the cost of one private function.
  2. Equivalent-mutant claim verified. merge goes through update_node to update_with_version_check_returning_node_in_tx, which runs deep_merge_namespaced_properties (per-field insert when both sides are objects), so clearing the bucket in memory cannot drop stored siblings. The read-modify-write is still needed for the expected version and the non-object check. The substitute mutations are adequate; each is killed by a named test.
  3. Outside packages/core: nothing breaks. No Rust caller outside core calls the removed accessors; default_metadata() has no runtime consumer; flatten_namespaced_properties is schema-free; frontend raw-key reads treat an absent key like the old seeded default; other core schemas already have fields: vec![], so the zero-field validation path is well trodden.
  4. Tests. None pass regardless of the code except the issue-mandated regression guard database_settings_accepts_namespaced_extension_keys. No flakiness risk. The owner-edge test asserts the has_role edge itself; the version-unchanged assertion detects a rewrite on open; the stored-versus-compiled guard is pinned by the later "a" write.
  5. Leftovers in packages/core: none beyond the excluded doc lines. No #NNNN references, allow(, deprecated or migration code in the added lines.

Findings

  • 🟢 Suggestion: tests/it/database_settings_extension_keys_test.rs:201-207, stored_declaration_still_validates_legacy_keys asserts only refused.is_err(). Asserting NodeServiceError::ValidationFailed would make "the stored declaration, not core's guard, refused it" explicit.
  • 🟢 Suggestion (no action): the merge_database_settings doc's VersionConflict promise is inherited from update_node and untested here; the issue did not ask for a test.

No Critical or Important findings.

Recommendation: APPROVE

@mstomar125
mstomar125 force-pushed the issue-3340-settings-extension-keys branch from a428e0b to d254fe8 Compare September 30, 2026 10:09
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary

Addressed: 1 of 2 suggestions. Skipped: 1. Commits: 1 (Address review: name which refusal the legacy-key test expects). Tests: pass.

  • ✅ Suggestion 1: make explicit that the stored declaration, not core's guard, refused legacy_state = "z". Applied, with one correction to the review's premise. The review proposed asserting ValidationFailed; running it showed the stored enum validation raises InvalidUpdate("Invalid value 'z' for enum field 'legacy_state'..."), the same variant as core's key guard, so the variant cannot tell the two apart. The test now asserts on the enum-validation message instead. Mutation check re-run: with the guard reading the stored schema, the test still fails (now on the first refusal as well as the later "a" write). cargo fmt --check and cargo clippy -p nodespace-core --all-targets -- -D warnings -D clippy::unused-async are clean; the targeted lib (16) and it (13) tests pass after rebasing onto current main.
  • ⏭️ Suggestion 2: test that a concurrent change returns VersionConflict. Skipped. That behavior is inherited unchanged from update_node's optimistic-concurrency check (already covered by that path's own tests); reproducing it here needs an interleaving hook between the read and the write that does not exist, so a test would be either non-deterministic or need production code added only for testing. The issue did not ask for it. Revisit if merge_database_settings ever gains its own retry loop.

Also: the PR body's ratchet table is updated to the current base (faf64e3b), measured base-versus-branch.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The only change since the reviewed commit is one test assertion tightened (no production code touched), plus a rebase onto main commits that do not touch packages/core.

mstomar125 and others added 2 commits September 30, 2026 12:18
…settings accessor

Core no longer declares, seeds, validates or reads the database-settings
bucket keys. The singleton stays as the anchor for database-level
configuration and the owner has_role edge; extensions keep namespaced keys
in its bucket through NodeService::database_settings and the public
NodeService::merge_database_settings.

merge_database_settings rejects keys the compiled database-settings
definition declares (none today). The guard reads the compiled definition,
not the stored schema node, because a database created by an older build
still declares the retired fields there.

Existing databases keep their stored values and stored schema declaration
untouched; a legacy-shape integration test covers opening, merging alongside
and validating against them.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Both the stored enum validation and core's key guard return InvalidUpdate,
so the test asserts on the enum-validation message to make clear that the
stored declaration, not the guard, refused the out-of-range value.

Co-Authored-By: Claude Sonnet 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.

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

1 participant