Skip to content

fix(hrea): apply every mutable field in update_rea_economic_event - #420

Draft
Soushi888 wants to merge 6 commits into
sproutfrom
fix/economic-event-sparse-update
Draft

Soushi888 wants to merge 6 commits into
sproutfrom
fix/economic-event-sparse-update

Conversation

@Soushi888

@Soushi888 Soushi888 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

SoushAI analysis. Drafted by Soushi's AI assistant, reviewed and posted by @Soushi888.

Intent

update_rea_economic_event declared eleven update params and applied only note, discarding the other ten while still returning a success record (#416). This PR makes the update honest, and settles what it may change.

Lynn's rule, from the maintenance discussion: any field that could change the economic meaning of an event (anything that would move a periodic accounting report) cannot be changed after creation. Every EconomicEvent field except note fails that test: who and what, how much and when, and also which agreement it realizes, which commitment it fulfils, which intent it satisfies, which claim it settles and whose scope it is in, since each of those decides which balance or report the event counts toward. So only note may change, and a wrong event is fixed the ValueFlows way, with a new event that corrects it.

Changes

The rule lives in the integrity zome. validate_economic_event_update now refuses a change to any field but note (and id, which is bookkeeping set on the first update), with EconomicEvent <field> cannot be changed after creation. It previously guarded provider, receiver and action only. Because it is integrity, every peer enforces it, so a modified client cannot slip a change past the network. An exhaustive destructure of the entry makes a field added later fail to compile until it is classified as fixed or mutable.

The coordinator stops discarding fields. It merges the params with merge_partial, the sparse-update pattern the other entities got in 449b17a3, so a changed field reaches the integrity rule and is refused by name instead of silently dropped, an absent note leaves the stored one alone, and a client that echoes the whole event back with a new note succeeds. agreed_in, reciprocal_realization_of and settles are added to the params struct for the same reason: the GraphQL input already exposed them and serde dropped them. The relationship indexes now follow the latest revision, settles included (ClaimToSettlingEvents was never re-pointed on update before).

Visible behaviour changes for clients: an update that omits note no longer clears it; an update that sends a new agreedIn, triggeredBy, realizationOf, reciprocalRealizationOf or settles through GraphQL is now refused, where before it was silently ignored.

Decisions

  • Note only, not the ValueFlows schema's four fields. The base EconomicEventUpdateParams in @valueflows/vf-graphql declares note, agreedIn, triggeredBy and realizationOf, which is probably the earlier decision. realizationOf fails Lynn's test (it moves an agreement's balance), so this PR follows the test rather than the schema. The schema is left as it is here; whether VF itself should drop those three is a question for the VF repo.
  • Integrity, not coordinator. The first version of this PR guarded inputOf, outputOf and corrects in the coordinator to keep the DNA hash. Soushi chose to close it at the DHT gate instead: this changes the DNA hash, so the next release is a new network for anyone on happ-0.5.0-beta.1. Beta is the cheapest moment for that.
  • Superseded in this revision: the coordinator's reject_immutable_change and its Agreement type check on reciprocal_realization_of are gone, since no change to either can now pass integrity.

How to test

nix develop
RUSTFLAGS='--cfg getrandom_backend="custom"' CARGO_TARGET_DIR=target cargo build --release --target wasm32-unknown-unknown
hc app pack workdir --recursive
cargo test -p hrea-sweettest --test economic_event
yarn run build:graphql:adapter && yarn run test:acceptance

Sweettest cases for the update, in tests/sweettest/tests/economic_event.rs: a note change reads back with every other field identical and the agreement, claim, commitment and intent indexes on the new revision; an absent note is left alone; a change to each of the thirteen non-note params is refused with the message naming that field, and leaves no revision behind; every field resent unchanged is accepted. The acceptance step in rea-flows refuses a new realizationOf and a new agreedIn by name through GraphQL, then updates the note and checks the agreement still lists the event.

Results, all inside nix develop at a37e6469:

  • cargo test -p hrea-sweettest → exit 0, 51 passed, 0 failed (economic_event 17).
  • Red first: with the integrity rule cut back to provider, receiver and action, cargo test -p hrea-sweettest --test economic_event → exit 101, update_rejects_a_change_to_any_field_but_the_note the only failure; restored, 17 passed.
  • yarn install --frozen-lockfile && yarn run build:graphql:adapter && yarn run test:acceptance → ACCEPTANCE PASSED — 74/74 steps green.

Not covered

  • The fact fields the update params do not carry (resourceQuantity, hasPointInTime and the rest) can only change through a hand-crafted write, which Sweettest does not build; the integrity rule covers them by the same macro line as the tested fields.
  • The old-base deletes in reindex_single and reindex_many are now reachable only if the rule is relaxed, so they have no test.

Documentation

  • docs/graphql-api.md: what updateEconomicEvent can change, why, and how to fix a wrong event.
  • tests/sweettest/README.md and clients/acceptance/README.md: the new coverage.

Pre-open review

Re-reviewed 2026-10-09 after Lynn's feedback reshaped the rule.

  • Description: rewritten for the note-only rule; Intent, Changes, Decisions, How to test, Documentation, Related present.
  • Merge state: up to date with sprout, no conflict.
  • Code findings: none open. The first revision's coordinator guards are superseded by the integrity rule and removed.
  • Documentation: docs/graphql-api.md and both test READMEs updated.
  • Tests: Sweettest at the zome boundary, acceptance at the GraphQL boundary; the rejection test shown red without the rule.
  • CI: running on a37e6469.

Related

Closes #416

update_rea_economic_event declared eleven update params and applied only
`note`, discarding the rest while still returning a success record. It now
merges the params sparsely with merge_partial, like the other entities: a
present field replaces the stored value, an absent one is left alone.

ValueFlows treats an EconomicEvent as an observed fact, so the update splits
the params in two:

- context, applied when present: note, agreed_in, realization_of,
  reciprocal_realization_of, settles, in_scope_of, triggered_by, fulfills,
  satisfies. agreed_in, reciprocal_realization_of and settles are new on the
  zome struct; the GraphQL update input already exposed them and serde
  dropped them silently.
- the fact, fixed at creation: provider and receiver are applied and the
  integrity rule vf_validate_unchanged rejects a change (that rule was
  unreachable before); input_of, output_of and corrects have no integrity
  rule, so the coordinator rejects a change with a message naming the
  field. Resending the stored value is accepted.

Relationship indexes are now maintained against old and new values, so a
changed realization_of, triggered_by, settles, fulfills or satisfies drops
the link under the old base. The settles index is re-pointed at the new
revision like the others.

Seven Sweettest cases cover the read-back of every mutable field, sparse
semantics, the moved agreement index, the three rejections and the
unchanged echo. docs/graphql-api.md documents what updateEconomicEvent can
change.

Closes #416
…In through GraphQL

Proves the #416 fix end to end: the update reaches the zome, both fields read back, the omitted note survives, and agreement.economicEvents lists the event. The existing update step only ever changed note, which is why the discarded fields went unnoticed.

Refs #416
Create checks that reciprocal_realization_of references an Agreement, but
the update path did not and no link index validates that field. Also cover
the outputOf guard, the settles index move, and the fulfills/satisfies link
deletion with failing-first Sweettest cases.
Every other EconomicEvent field carries economic meaning that a report
computed earlier relies on, so the integrity zome now refuses a change to
any of them by name. The coordinator guards it supersedes are removed.
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.

update_rea_economic_event silently discards ten of its eleven declared fields

1 participant