Search and contents

Two Nodes that disagree, and a record that waits for a person

This page makes the MES and ERP of a three-Node practice site hold different records for the same order, and then makes ERP's record wait for a person. You see a trail that reports the disagreement and takes neither side, a trail that is refused while a record waits, and the person's decision on the Node that holds the record, with who decided in that Node's own Activity Log. A third case shows what the trail looks like when two Nodes file the same order under different ids.

Every value on this page is invented. The order, the status values and the people are made up for this walk-through. Nothing here is a real order, and nothing says a real site would read this way.

This is test tooling, not part of the public API. The site script and the stand-ins behind it may change in any release, and the stability policy (public-api-stability.md) does not cover them. The trail and the review routes are documented in order-trail-assembly.md and management-api.md. The test that proves the behaviour in process is tests/test_drill_disagreement.py.

Practice only: ERP is given its records by a seed. A real ERP Node holds no identity record for an order (only the MES ingests orders here), so without a record there is nothing for it to disagree about. deployment/practice_site.sh seed-erp-order writes one through ERP's Identity Store and leaves a line in ERP's Activity Log (trigger practice_site_seed) saying it did. A seeded record is not something the ERP Node ingested.

What you need

  • A running practice site, with the order blocked, as in A Node stopped and started. The wait_blocked helper below waits for it. No model is asked by anything on this page.
  • A Postgres superuser you can reach, the way the site script reaches it: sudo -n -u postgres psql, or the command in KINDRED_PRACTICE_PSQL_ADMIN. The page reads each Node's own record from its own database, because no display puts two Nodes' values side by side, and this page adds none.

Run the commands from the repository root, in one shell, after this once:

SITE="${KINDRED_PRACTICE_DIR:-$HOME/.kindred-practice-site}"
export KINDRED_PRACTICE_DIR="$SITE"
ORDER=MD-2027-0301
PS=deployment/practice_site.sh
PSQL="${KINDRED_PRACTICE_PSQL_ADMIN:-sudo -n -u postgres psql}"
api() { # the asking Node's (MES) Management API, with its token
  KINDRED_MANAGEMENT_URL=http://127.0.0.1:18470 \
  KINDRED_MANAGEMENT_TOKEN_FILE="$SITE/asking-node.token" \
    deployment/kindred_management.sh "$@"
}
erp_api() { # ERP's own Management API, where a record that waits for a person is decided
  KINDRED_MANAGEMENT_URL=http://127.0.0.1:18471 \
  KINDRED_MANAGEMENT_TOKEN_FILE="$SITE/erp-reviewer.token" \
    deployment/kindred_management.sh "$@"
}
show() { # print the named fields of a JSON answer
  python3 -c 'import json, sys; d = json.load(sys.stdin); print({k: d.get(k) for k in sys.argv[1:]})' "$@"
}
record() { # DATABASE ORDER: a Node's own identity record: order, record status, the order's status
  $PSQL -At -d "$1" -c "SELECT reference_id, status, attributes->>'status' FROM identity_records WHERE reference_id = '$2'"
}
wait_blocked() { # wait until the MES's record of the order reads blocked
  for _ in $(seq 1 40); do
    status=$(api trail "$ORDER" 2> /dev/null |
      python3 -c 'import json, sys; print(json.load(sys.stdin)["record"]["attributes"]["status"])' 2> /dev/null) || status=""
    [ "$status" = blocked ] && return 0
    sleep 3
  done
  echo "the order never read blocked" >&2
  return 1
}
wait_blocked

Case 1: the status differs

The MES says the order is blocked. ERP is given a record that says it is completed. The trail should say the two disagree and take neither side.

Step 1: read each Node's own record. The MES's is what the site played into it; ERP holds none yet.

record practice_mes "$ORDER"
record practice_erp "$ORDER"
MD-2027-0301|resolved|blocked

One line, for the MES: its record is resolved (the identity status) and the order's status in it is blocked. ERP prints nothing. If the MES's line does not read blocked, the order has not been read yet: run wait_blocked.

Step 2: give ERP a different status.

$PS seed-erp-order "$ORDER" --status completed
record practice_erp "$ORDER"
Practice-only seed: this record is not something the ERP Node ingested.
ERP now holds a resolved record for order MD-2027-0301
MD-2027-0301|resolved|completed

The seed also prints a warning that no broker answers on localhost:1883, as every command of the site does when there is none. It is not part of the answer.

Step 3: ask for the trail.

api trail "$ORDER" | show complete local_complete not_contributed disagreements
{'complete': True, 'local_complete': True, 'not_contributed': [], 'disagreements': [{'first': 'MES mes (this Node)', 'second': 'ERP at 127.0.0.1:18421', 'first_node_type': 'MES', 'second_node_type': 'ERP', 'involves_this_node': True, 'fields': ['attributes.status']}]}

One disagreement, between the MES and ERP, on one field, attributes.status. It names no value. The trail's own record is the MES's, and ERP's value is in no part of the answer. involves_this_node is True because one of the two records is the asking Node's own, which is what the order trail page highlights.

Step 4: read both records again.

record practice_mes "$ORDER"
record practice_erp "$ORDER"
MD-2027-0301|resolved|blocked
MD-2027-0301|resolved|completed

Both are exactly as they were: the trail merged nothing and chose no side, and asking again changes nothing. ERP's one entry in the trail is the seed's own line, which is why ERP is among the Nodes that contributed.

Case 2: ERP's record waits for a person

ERP's record for the order is a first article that nobody has confirmed. The trail is refused until a person decides it, on ERP.

Step 1: start again, and make ERP's record pending. ERP holds one record for each order id, and the seed refuses an order it already holds (exit 4), so reset is the way back. It takes about 21 to 23 seconds and plays the order again.

$PS reset
wait_blocked
$PS seed-erp-order "$ORDER" --pending --status in-progress

Step 2: ask for the trail.

api trail "$ORDER"
echo "exit $?"
{"detail":"the order's identity record on a peer is not resolved"}curl: (22) The requested URL returned error: 409
exit 22

The trail is refused, with a fixed sentence and a non-zero exit. The route does not say which Node or what status: it is built not to repeat anything a Node holds. The test pins the fuller refusal that names ERP and pending. By hand you find the record by asking ERP what waits for a person:

erp_api identity-matches |
  python3 -c 'import json, sys; [print({k: m[k] for k in ("reference_id", "kind", "status")}) for m in json.load(sys.stdin)["matches"]]'
{'reference_id': 'MD-2027-0301', 'kind': 'first_article', 'status': 'pending'}

Step 3: decide it on ERP. Deciding is not one of the management tool's commands, which only read. Use curl with ERP's reviewer token, which up made with the scopes read and signoff. The token goes to curl through a pipe, so it is never on a command line. The same decision can be made on the review page at http://127.0.0.1:18471/ui, where the token is entered by hand; this page did not run that in a browser.

MATCH=$(erp_api identity-matches | python3 -c 'import json, sys; print(json.load(sys.stdin)["matches"][0]["id"])')
curl -sS --fail-with-body \
  --config <(printf 'header = "Authorization: Bearer %s"\n' "$(cat "$SITE/erp-reviewer.token")") \
  -X POST "http://127.0.0.1:18471/v1/identity-matches/$MATCH/resolve" \
  -H 'Content-Type: application/json' \
  -d "{\"decision\":\"confirmed\",\"action_id\":\"$(cat /proc/sys/kernel/random/uuid)\"}" |
  show status resolved_by changed_keys
{'status': 'resolved', 'resolved_by': 'practice-erp-reviewer', 'changed_keys': []}

resolved_by is the id of the token and never a name you typed: a body that names a reviewer is refused. Sending the same request again with the same action_id returns the same answer and writes nothing more.

Step 4: read the decision where it was recorded. It is in ERP's Activity Log, not the MES's:

erp_api activity-log task_type=identity_match_resolution |
  python3 -c 'import json, sys; [print(e["task_type"], e["outcome"], e["reference_ids"]) for e in json.load(sys.stdin)["entries"]]'
api activity-log task_type=identity_match_resolution |
  python3 -c 'import json, sys; print(len(json.load(sys.stdin)["entries"]))'
identity_match_resolution resolved {'kind': 'first_article', 'token_id': 'practice-erp-reviewer', 'action_id': '12c1e657-24c3-46b2-b25f-816252554dd1', 'entity_type': 'order', 'reference_id': 'MD-2027-0301', 'identity_record_id': '431a25a8-e399-4fd8-b1f1-08e011879bf7'}
0

One entry on ERP with the token's id, the action_id you sent and the order; none on the MES. The record's id and the action_id are different in every run.

Step 5: ask for the trail again.

api trail "$ORDER" | show complete contributing_node_types
{'complete': True, 'contributing_node_types': ['MES', 'ERP']}

Rejecting is a decision too. Had the person sent "decision":"rejected", the record would be rejected, ERP's log would hold an entry with the outcome rejected, and the trail would be refused the same way. A rejected or a merged record is refused exactly as a pending one is. An inferred match that a person confirms becomes merged (its attributes are folded into the record it matched), and a merged record still refuses the trail; only a first article becomes resolved when it is confirmed. This page seeds a first article for that reason, and the test pins both (test_a_record_a_person_rejected_refuses_the_trail_the_same_way, test_confirming_an_inferred_match_leaves_the_trail_refused_because_it_is_merged). Neither was run by hand.

Case 3: ERP files the order under another id

ERP calls the order ERP-0301, and the MES calls it MD-2027-0301. Peers are asked for the id the asking Node uses, so ERP is asked for MD-2027-0301 and holds nothing under that id. Nothing is wrong anywhere, and the trail looks complete.

$PS reset
wait_blocked
$PS seed-erp-order ERP-0301 --status in-progress
api trail "$ORDER" | show complete contributing_node_types not_contributed disagreements
{'complete': True, 'contributing_node_types': ['MES'], 'not_contributed': [], 'disagreements': []}

ERP is in neither list: it answered, and it holds nothing under this id, so the trail says nothing about it. There is no alias between ids and none is built. The remedy is one canonical id: every Node's mapping must produce the same order_id for the same order. On a real site that is a correction to ERP's mapping. The practice site's ERP does not file orders at all, so here the corrected mapping is played by a seed under the canonical id:

$PS seed-erp-order "$ORDER" --status in-progress
api trail "$ORDER" | show complete contributing_node_types
{'complete': True, 'contributing_node_types': ['MES', 'ERP']}

What this does not show

  • A Node that detects a bad peer's content. A Node does not. The trail reports that two records differ, by Node type and field, and that is all; it does not say which is right, and nothing on this page makes the two agree.
  • A Node that is down while the trail is asked. That is A Node stopped and started.
  • A certificate that is wrong. That is A certificate that fails.
  • A person who leaves, or a token that is revoked. The revocation cascade is not run by hand on this site.
  • What ERP's own order-status or shortage task would say about a record that differs. The seeded record is not something ERP ingested.
  • A model's wording, and anything about a real appliance, a network or a clock.

Limits

  • A disagreement is reported and nothing settles it. No command makes two Nodes agree. The trail names the fields; a person reads each Node's own record to see the values.
  • The route's refusal does not name the Node. A pending, rejected or merged record on a Node is one fixed sentence through the Management API. Finding which Node holds it is a question for each Node's own list of matches.
  • A person decides on the Node that holds the record. The MES's Management API cannot decide a match that is in ERP's database, and the decision is in ERP's Activity Log alone.
  • An id mismatch looks like a complete trail. There is no display that says a Node holds nothing for an order, and no alias between ids.
  • The ERP records here are seeded. A seeded record, and the line it leaves in ERP's log, stand in for what a site's mappings and ingestion would produce.
  • The review page was not run in a browser for this page: the decision was made with curl and the same token.

What the test checks

tests/test_drill_disagreement.py runs the three Nodes in process on a database each, and ERP's own Management API over ERP's Identity Store and Activity Log, with no model and no target system. It pins:

  • a status that differs is reported by Node type and field with no value (test_a_status_that_differs_is_reported_by_node_type_and_field_with_no_value) and neither record is changed (test_neither_nodes_record_is_changed_and_no_winner_is_picked);
  • a pending record on ERP refuses the trail and names ERP and the status in the fuller refusal (test_a_pending_record_on_erp_refuses_the_trail_naming_erp_and_the_status);
  • the person resolves it on ERP and the same request then succeeds (test_the_person_resolves_it_on_erp_and_the_same_trail_request_then_succeeds), with the decision in ERP's Activity Log against the token's id and not in the MES's (test_the_decision_is_in_erps_activity_log_against_the_tokens_id_and_not_in_mes);
  • an order filed under another id is a complete trail that says nothing is wrong (test_erp_under_another_id_is_a_complete_trail_that_says_nothing_is_wrong), and one canonical id shows ERP's part (test_one_canonical_id_from_erps_mapping_shows_erps_part).

tests/test_break_it_pages.py runs this page's setup and each recipe it can against a bare site directory and a throwaway database, checks that every script, flag, route and test file the page names exists, and that the page says what it does not show. A block that needs a running site is not run.

Release: v0.11.0