Repository navigation
fix(resource): reconcile global discovery anchor when a spec's scope changes - #151
Merged
Merged
Conversation
…changes update_resource_specification accepted a new scope but never touched the resource_specifications anchor, so widening Project to Public left the spec out of global discovery and narrowing Public to Project left it listed. The update now reads the anchor and makes it agree with the new scope: one AllResourceSpecifications link to the original action hash when listed, none when Project-scoped. Reading the anchor instead of diffing old and new scope keeps repeated edits idempotent and repairs specs edited before this fix. Refs #144
…ect its docs The scope-change Sweettests now wait for consistency and read the global listing from both the author and a second agent, so they prove the anchor change propagates rather than only showing the author's local view. The docs said a change away from Project adds the anchor link; the code reconciles on every update, unchanged scope included, which is how it repairs a drifted anchor. Both pages now say so. Refs #144
Soushi888
force-pushed
the
fix/issue-144-spec-scope-anchor
branch
from
October 27, 2026 17:44
f981e54 to
9add740
Compare
Soushi888
marked this pull request as ready for review
October 27, 2026 18:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
ResourceSpecification.scopeis mutable and decides one thing: whether the spec is linked from the globalresource_specificationsanchor.update_resource_specificationwrote the new scope into the entry and never touched that anchor, so wideningProjecttoPublickept the spec invisible inget_all_resource_specifications, and narrowingPublictoProjectkept it listed. This fixes the first half of #144.Changes
Coordinator:
update_resource_specificationnow calls a new private helper,reconcile_global_discovery_link, after the update link is written. The helper reads the anchor'sAllResourceSpecificationslinks targeting the spec's original action hash. If the new scope is listed globally and no link exists, it creates one; if the new scope isProject, it deletes every such link. The anchor keeps targeting the original create hash, as on create.Sweettests in
dnas/nondominium/tests/src/resource/mod.rs, both on aCommonsNDO (the regime where scope is genuinely the author's choice). Every listing check waits for consistency and readsget_all_resource_specificationsfrom both the author and a second agent, so the anchor change is shown to reach a peer:widening_spec_scope_to_public_adds_global_discovery_link:Projectspec absent from the global list, update toPublic, present exactly once, a secondPublicedit still lists it exactly once.narrowing_spec_scope_to_project_removes_global_discovery_link:Publicspec listed once, update toProject, absent.No integrity change: deleting an
AllResourceSpecificationslink was already valid, andcheck_scope_coherencestill pinsNondominiumandPublicregimes toPublicscope on update.Decisions
The helper reconciles against the anchor's actual state instead of comparing the old scope with the new one.
original_spec.scopewith the incoming scope (the shape the issue sketches)original_specis the create-time entry, not the chain head. AfterProjecttoPublictoPublic, the second edit still seesProjectas the old scope and would create a duplicate link.previous_action_hashentry's scope with the incoming scopeThe cost is one
get_linkson the global anchor per update, the same patternupdate_lifecycle_stageandupdate_operational_statealready use for their categorisation anchors.How to test
Run inside
nix develop, from the repo root:Results on this branch (2026-10-06, local):
hc dna pack dnas/nondominium/workdir: exit 0.cargo test -p nondominium_sweettest --test resource -- --test-threads=4: exit 0,17 passed; 0 failed.resource_specification.rsrestored toorigin/devand the DNA rebuilt,cargo test ... --test resource -- spec_scopeexits 101 with both new tests failing on their scope assertions ("widening to Public must add the spec to global discovery", "narrowing to Project must remove the spec from global discovery").cargo check -p nondominium_sweettest --tests: exit 0.cargo check --release --target wasm32-unknown-unknown -p zome_resource_coordinator: exit 0.Follow-up commit f981e54 (2026-10-06 19:59, local), after review:
await_consistency_20_s. Red: with thereconcile_global_discovery_linkcall replaced by a no-op and the DNA rebuilt,cargo test ... --test resource -- spec_scope --test-threads=2exits 101, both tests failing ("widening to Public must add the spec to global discovery", "narrowing to Project must remove the spec from global discovery"). Green with the call restored and the DNA rebuilt:cargo test ... --test resource -- --test-threads=4exits 0,17 passed; 0 failed.hc dna packexit 0,cargo check -p nondominium_sweettest --testsexit 0,RUSTFLAGS='--cfg getrandom_backend="custom"' cargo check --release --target wasm32-unknown-unknown -p zome_resource_coordinatorexit 0 (without thatRUSTFLAGSthe check exits 101 ongetrandom, as for any wasm build in this repo).Note: the full resource suite run with the default thread count (17 tests, 34 conductors at once) failed 14 tests at app install with
DatabaseError(Timeout)on this machine; with--test-threads=4all 17 pass. That is a local resource limit, not this change: the failures are insetup_two_agents, before any zome call.What was not verified
The delete branch removes every matching anchor link, but no test seeds two links to the same spec: only
create_resource_specificationand this helper create them, and a duplicate needs two concurrent edits by the author (for instance from two devices), which Sweettest cannot produce deterministically. Covering it needs a test-only extern or a decision on how to seed it.The hREA DNA and the full hApp (
bun run build:happ) were not rebuilt; only the nondominium DNA, which is all the resource Sweettests load.Other Sweettest binaries (
person,governance,nondominium,misc) and the UI were not run. The UI callsupdate_resource_specificationwith an unchanged signature.rustfmt --checkonresource_specification.rsreports diffs, all in lines already ondev; the added lines produce none. I did not reformat the file to keep the diff surgical.Still open from #144
The issue's second-order point stays open and needs a call:
get_all_resource_specificationsandget_specifications_for_ndoresolve each link to the original action hash andget()it, so both lists render pre-update content for any edited spec, including the oldscope. Resolving the latest record throughget_latest_resource_specification_recordis a small change, but it alters what both list endpoints return, so it is left for a separate PR once decided.Documentation
documentation/zomes/resource_zome.md:update_resource_specificationnow documents scope reconciliation.documentation/API_REFERENCE.md: side effects ofupdate_resource_specificationlist the anchor reconciliation.Related
Related issues:
Pre-open review
Run 2026-10-27 through PRReview after the fact (the PR predates the pre-open gate), at 9add740, rebased onto
devafter #157.Refs #144corrected toRelated #144. Opens with## Intent, which predates the Summary-and-folds rule (suggestion, not a blocker).dev(808fcd7), no conflicts.resource_zome.md,API_REFERENCE.md).update_resource_specification.AllResourceSpecificationslinks (existing integrity TODO), the stale list read from bug(resource): changing a specification's scope never reconciles the global discovery anchor #144, and a dedup guard against a missedget_linksread.